add IItemValidator to SlotFiltered
This commit is contained in:
@@ -4,6 +4,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import storagecraft.StorageCraftItems;
|
||||
import storagecraft.container.slot.BasicItemValidator;
|
||||
import storagecraft.container.slot.SlotFiltered;
|
||||
import storagecraft.tile.TileDrive;
|
||||
|
||||
@@ -18,7 +19,7 @@ public class ContainerDrive extends ContainerBase
|
||||
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
addSlotToContainer(new SlotFiltered(drive, i, x, y, StorageCraftItems.STORAGE_CELL));
|
||||
addSlotToContainer(new SlotFiltered(drive, i, x, y, new BasicItemValidator(StorageCraftItems.STORAGE_CELL)));
|
||||
|
||||
if ((i + 1) % 2 == 0)
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@ import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import storagecraft.StorageCraftItems;
|
||||
import storagecraft.block.EnumGridType;
|
||||
import storagecraft.container.slot.BasicItemValidator;
|
||||
import storagecraft.container.slot.SlotDisabled;
|
||||
import storagecraft.container.slot.SlotFiltered;
|
||||
import storagecraft.container.slot.SlotGridCraftingResult;
|
||||
@@ -64,7 +65,7 @@ public class ContainerGrid extends ContainerBase
|
||||
|
||||
addSlotToContainer(new SlotDisabled(grid.getPatternCraftingResultInventory(), 0, 133 + 4, 120 + 4));
|
||||
|
||||
addSlotToContainer(new SlotFiltered(grid.getPatternInventory(), 0, 137, 98, StorageCraftItems.PATTERN));
|
||||
addSlotToContainer(new SlotFiltered(grid.getPatternInventory(), 0, 137, 98, new BasicItemValidator(StorageCraftItems.PATTERN)));
|
||||
addSlotToContainer(new SlotOutput(grid.getPatternInventory(), 1, 137, 150));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import storagecraft.StorageCraftItems;
|
||||
import storagecraft.container.slot.BasicItemValidator;
|
||||
import storagecraft.container.slot.SlotFiltered;
|
||||
import storagecraft.container.slot.SlotOutput;
|
||||
import storagecraft.tile.TileWirelessTransmitter;
|
||||
@@ -15,8 +16,8 @@ public class ContainerWirelessTransmitter extends ContainerBase
|
||||
{
|
||||
super(player);
|
||||
|
||||
addSlotToContainer(new SlotFiltered(wirelessTransmitter, 0, 8, 20, Items.ender_pearl));
|
||||
addSlotToContainer(new SlotFiltered(wirelessTransmitter, 1, 101, 20, StorageCraftItems.WIRELESS_GRID));
|
||||
addSlotToContainer(new SlotFiltered(wirelessTransmitter, 0, 8, 20, new BasicItemValidator(Items.ender_pearl)));
|
||||
addSlotToContainer(new SlotFiltered(wirelessTransmitter, 1, 101, 20, new BasicItemValidator(StorageCraftItems.WIRELESS_GRID)));
|
||||
addSlotToContainer(new SlotOutput(wirelessTransmitter, 2, 152, 20));
|
||||
|
||||
addPlayerInventory(8, 55);
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package storagecraft.container.slot;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class BasicItemValidator implements IItemValidator
|
||||
{
|
||||
private Item item;
|
||||
|
||||
public BasicItemValidator(Item item)
|
||||
{
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(ItemStack stack)
|
||||
{
|
||||
return item == stack.getItem();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package storagecraft.container.slot;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IItemValidator
|
||||
{
|
||||
public boolean isValid(ItemStack stack);
|
||||
}
|
||||
@@ -2,23 +2,22 @@ package storagecraft.container.slot;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class SlotFiltered extends Slot
|
||||
{
|
||||
private Item item;
|
||||
private IItemValidator validator;
|
||||
|
||||
public SlotFiltered(IInventory inventory, int id, int x, int y, Item item)
|
||||
public SlotFiltered(IInventory inventory, int id, int x, int y, IItemValidator validator)
|
||||
{
|
||||
super(inventory, id, x, y);
|
||||
|
||||
this.item = item;
|
||||
this.validator = validator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack item)
|
||||
{
|
||||
return item.getItem() == this.item;
|
||||
return validator.isValid(item);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user