PowerMiner/src/InventorySlot.java

37 lines
1.2 KiB
Java
Raw Normal View History

import java.awt.Point;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
2018-01-31 08:12:02 -05:00
public class InventorySlot {
2018-02-01 22:39:57 -05:00
private static final int INVENTORY_SLOT_WIDTH = 171 / 4;
private static final int INVENTORY_SLOT_HEIGHT = 254 / 7;
Rectangle rectangleToCapture;
BufferedImage inventorySlotImage;
2018-01-31 08:12:02 -05:00
public InventorySlot(int row, int column) {
initializeRectangleToCapture(row, column);
}
2018-01-31 08:12:02 -05:00
private void initializeRectangleToCapture(int row, int column) {
2018-02-01 22:39:57 -05:00
rectangleToCapture = new Rectangle(row * INVENTORY_SLOT_WIDTH, column * INVENTORY_SLOT_HEIGHT, INVENTORY_SLOT_WIDTH, INVENTORY_SLOT_HEIGHT);
2018-01-31 08:12:02 -05:00
}
2018-02-01 22:39:57 -05:00
public void updateInventorySlot(BufferedImage image) throws IOException {
this.inventorySlotImage = image.getSubimage(rectangleToCapture.x, rectangleToCapture.y, rectangleToCapture.width, rectangleToCapture.height);
}
2018-01-31 08:12:02 -05:00
public String getItemNameInInventorySlot(InventoryItems items) {
return items.getNameOfItemFromImage(this.inventorySlotImage);
}
2018-02-01 22:39:57 -05:00
public boolean isInventorySlotEmpty(InventoryItems items) {
return ("empty" == items.getNameOfItemFromImage(this.inventorySlotImage));
}
2018-01-31 08:12:02 -05:00
}