Container cleanup, vast refactors of all containers

This commit is contained in:
tterrag1098 committed 2015-07-06 21:22:55 -04:00
1 parent 7c7d673290
commit 9af57bfea8
30 files changed
+215 -361

No files matched your search

@@ -4,5 +4,4 @@ import com.enderio.core.common.TileEntityEnder;
public abstract class TileEntityEio extends TileEntityEnder {
// Nothing yet ;D
}
@@ -58,7 +58,7 @@ public class TooltipHandlerBurnTime implements ITooltipCallback {
private TileEntityStirlingGenerator getStirlingGen(ItemStack stack) {
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
if (player != null && player.openContainer instanceof StirlingGeneratorContainer) {
AbstractMachineEntity te = ((StirlingGeneratorContainer) player.openContainer).getTileEntity();
AbstractMachineEntity te = ((StirlingGeneratorContainer) player.openContainer).getInv();
if (te instanceof TileEntityStirlingGenerator) {
return (TileEntityStirlingGenerator) te;
}
@@ -12,38 +12,36 @@ import com.enderio.core.common.util.Util;
import crazypants.enderio.machine.gui.AbstractMachineContainer;
public class ContainerAlloySmelter extends AbstractMachineContainer {
public class ContainerAlloySmelter extends AbstractMachineContainer<TileAlloySmelter> {
private final EntityPlayer thePlayer;
private final TileAlloySmelter smelter;
public ContainerAlloySmelter(InventoryPlayer playerInv, TileAlloySmelter te) {
super(playerInv, te);
thePlayer = playerInv.player;
smelter = te;
}
@Override
protected void addMachineSlots(InventoryPlayer playerInv) {
addSlotToContainer(new Slot(tileEntity, 0, 54, 17) {
addSlotToContainer(new Slot(getInv(), 0, 54, 17) {
@Override
public boolean isItemValid(ItemStack itemStack) {
return tileEntity.isItemValidForSlot(0, itemStack);
return getInv().isItemValidForSlot(0, itemStack);
}
});
addSlotToContainer(new Slot(tileEntity, 1, 79, 7) {
addSlotToContainer(new Slot(getInv(), 1, 79, 7) {
@Override
public boolean isItemValid(ItemStack itemStack) {
return tileEntity.isItemValidForSlot(1, itemStack);
return getInv().isItemValidForSlot(1, itemStack);
}
});
addSlotToContainer(new Slot(tileEntity, 2, 103, 17) {
addSlotToContainer(new Slot(getInv(), 2, 103, 17) {
@Override
public boolean isItemValid(ItemStack itemStack) {
return tileEntity.isItemValidForSlot(2, itemStack);
return getInv().isItemValidForSlot(2, itemStack);
}
});
addSlotToContainer(new SlotSmelter(tileEntity, 3, 79, 57));
addSlotToContainer(new SlotSmelter(getInv(), 3, 79, 57));
}
@@ -86,7 +84,7 @@ public class ContainerAlloySmelter extends AbstractMachineContainer {
if(!thePlayer.worldObj.isRemote) {
ItemStack outputSized = output.copy();
outputSized.stackSize = numResults;
float experience = smelter.getExperienceForOutput(outputSized);
float experience = getInv().getExperienceForOutput(outputSized);
Util.giveExperience(thePlayer, experience);
}
numResults = 0;
@@ -6,7 +6,7 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import crazypants.enderio.machine.gui.AbstractMachineContainer;
public class ContainerBuffer extends AbstractMachineContainer {
public class ContainerBuffer extends AbstractMachineContainer<TileBuffer> {
public ContainerBuffer(InventoryPlayer playerInv, TileBuffer te) {
super(playerInv, te);
@@ -14,11 +14,11 @@ public class ContainerBuffer extends AbstractMachineContainer {
@Override
protected void addMachineSlots(InventoryPlayer playerInv) {
TileBuffer buf = (TileBuffer) tileEntity;
TileBuffer buf = (TileBuffer) getInv();
if(buf.hasInventory()) {
Point point = new Point(buf.hasInventory() && buf.hasPower() ? 96 : 62, 15);
for (int i = 0; i < 9; i++) {
addSlotToContainer(new Slot(this.tileEntity, i, point.x + ((i % 3) * 18), point.y + ((i / 3) * 18)));
addSlotToContainer(new Slot(this.getInv(), i, point.x + ((i % 3) * 18), point.y + ((i / 3) * 18)));
}
}
}
@@ -220,7 +220,7 @@ public class BlockCapBank extends BlockEio implements IGuiHandler, IAdvancedTool
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileCapBank) {
return new ContainerCapBank(player, player.inventory, (TileCapBank) te);
return new ContainerCapBank(player.inventory, (TileCapBank) te);
}
return null;
}
@@ -1,6 +1,7 @@
package crazypants.enderio.machine.capbank;
import net.minecraft.entity.Entity;
import java.awt.Point;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
@@ -8,33 +9,42 @@ import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import com.enderio.core.common.ContainerEnder;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import crazypants.enderio.machine.capbank.network.InventoryImpl;
import crazypants.enderio.machine.gui.ContainerEIO;
import crazypants.util.BaublesUtil;
import crazypants.util.ShadowInventory;
public class ContainerCapBank extends ContainerEIO {
public class ContainerCapBank extends ContainerEnder<TileCapBank> {
private final TileCapBank tileEntity;
private final InventoryImpl inv;
private InventoryImpl inv;
// Note: Modifying the Baubles inventory on the client side of an integrated
// server is a bad idea as Baubles does some very bad things...
private IInventory baubles;
public ContainerCapBank(final Entity player, InventoryPlayer playerInv, TileCapBank cb) {
tileEntity = cb;
if(tileEntity.getNetwork() != null && tileEntity.getNetwork().getInventory() != null) {
inv = cb.getNetwork().getInventory();
public ContainerCapBank(InventoryPlayer playerInv, TileCapBank cb) {
super(playerInv, cb);
}
public boolean hasBaublesSlots() {
return baubles != null;
}
@Override
protected void addSlots(final InventoryPlayer playerInv) {
if(getInv().getNetwork() != null && getInv().getNetwork().getInventory() != null) {
inv = getInv().getNetwork().getInventory();
} else {
inv = new InventoryImpl();
}
baubles = BaublesUtil.instance().getBaubles((EntityPlayer) player);
baubles = BaublesUtil.instance().getBaubles(playerInv.player);
if (baubles != null && BaublesUtil.WhoAmI.whoAmI(player.worldObj) == BaublesUtil.WhoAmI.SPCLIENT) {
if (baubles != null && BaublesUtil.WhoAmI.whoAmI(playerInv.player.worldObj) == BaublesUtil.WhoAmI.SPCLIENT) {
baubles = new ShadowInventory(baubles);
}
@@ -43,17 +53,6 @@ public class ContainerCapBank extends ContainerEIO {
addSlotToContainer(new SlotImpl(inv, i, 59 + armorOffset + i*20, 59));
}
// add players inventory
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 9; ++j) {
addSlotToContainer(new Slot(playerInv, j + i * 9 + 9, +armorOffset + 8 + j * 18, 84 + i * 18));
}
}
for (int i = 0; i < 9; ++i) {
addSlotToContainer(new Slot(playerInv, i, +armorOffset + 8 + i * 18, 142));
}
//armor slots
for (int i = 0; i < 4; ++i) {
final int k = i;
@@ -69,7 +68,7 @@ public class ContainerCapBank extends ContainerEIO {
if(par1ItemStack == null) {
return false;
}
return par1ItemStack.getItem().isValidArmor(par1ItemStack, k, player);
return par1ItemStack.getItem().isValidArmor(par1ItemStack, k, playerInv.player);
}
@Override
@@ -90,16 +89,11 @@ public class ContainerCapBank extends ContainerEIO {
});
}
}
}
public boolean hasBaublesSlots() {
return baubles != null;
}
public void updateInventory() {
if(tileEntity.getNetwork() != null && tileEntity.getNetwork().getInventory() != null) {
inv.setCapBank(tileEntity.getNetwork().getInventory().getCapBank());
if(getInv().getNetwork() != null && getInv().getNetwork().getInventory() != null) {
inv.setCapBank(getInv().getNetwork().getInventory().getCapBank());
}
}
@@ -108,6 +102,13 @@ public class ContainerCapBank extends ContainerEIO {
return true;
}
@Override
public Point getPlayerInventoryOffset() {
Point p = super.getPlayerInventoryOffset();
p.translate(21, 0);
return p;
}
@Override
public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slotIndex) {
@@ -76,7 +76,7 @@ public class GuiCapBank extends GuiContainerBase {
private final ContainerCapBank container;
public GuiCapBank(Entity player, InventoryPlayer playerInv, TileCapBank te) {
super(new ContainerCapBank(player, playerInv, te));
super(new ContainerCapBank(playerInv, te));
capBank = te;
container = (ContainerCapBank) inventorySlots;
@@ -13,13 +13,10 @@ import com.enderio.core.client.gui.widget.GhostSlot;
import crazypants.enderio.machine.gui.AbstractMachineContainer;
import crazypants.enderio.network.PacketHandler;
public class ContainerCrafter extends AbstractMachineContainer {
private final TileCrafter crafter;
public class ContainerCrafter extends AbstractMachineContainer<TileCrafter> {
public ContainerCrafter(InventoryPlayer playerInv, TileCrafter te) {
super(playerInv, te);
crafter = (TileCrafter) tileEntity;
}
public void addCrafterSlots(List<GhostSlot> ghostSlots) {
@@ -59,11 +56,11 @@ public class ContainerCrafter extends AbstractMachineContainer {
for (int col = 0; col < 3; ++col) {
int x = leftX + col * 18;
int y = topY + row * 18;
addSlotToContainer(new InputSlot(tileEntity, index, x, y));
addSlotToContainer(new InputSlot(getInv(), index, x, y));
index++;
}
}
addSlotToContainer(new Slot(tileEntity, 9, 172, 34) {
addSlotToContainer(new Slot(getInv(), 9, 172, 34) {
@Override
public boolean isItemValid(ItemStack itemStack) {
return false;
@@ -80,7 +77,7 @@ public class ContainerCrafter extends AbstractMachineContainer {
@Override
public boolean isItemValid(ItemStack itemStack) {
ItemStack refStack = crafter.craftingGrid.getStackInSlot(slotNumber);
ItemStack refStack = getInv().craftingGrid.getStackInSlot(slotNumber);
if(refStack == null || itemStack == null) {
return false;
}
@@ -99,7 +96,7 @@ public class ContainerCrafter extends AbstractMachineContainer {
@Override
public ItemStack getStack() {
return crafter.craftingGrid.getStackInSlot(slotIndex);
return getInv().craftingGrid.getStackInSlot(slotIndex);
}
@Override
@@ -111,7 +108,7 @@ public class ContainerCrafter extends AbstractMachineContainer {
stack = stack.copy();
stack.stackSize = 1;
}
PacketHandler.INSTANCE.sendToServer(PacketCrafter.setSlot(crafter, slotIndex, stack));
PacketHandler.INSTANCE.sendToServer(PacketCrafter.setSlot(getInv(), slotIndex, stack));
}
}
}
@@ -3,49 +3,48 @@ package crazypants.enderio.machine.crusher;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import crazypants.enderio.machine.AbstractMachineEntity;
import crazypants.enderio.machine.gui.AbstractMachineContainer;
public class ContainerCrusher extends AbstractMachineContainer {
public class ContainerCrusher extends AbstractMachineContainer<TileCrusher> {
public ContainerCrusher(InventoryPlayer playerInv, AbstractMachineEntity te) {
public ContainerCrusher(InventoryPlayer playerInv, TileCrusher te) {
super(playerInv, te);
}
@Override
protected void addMachineSlots(InventoryPlayer playerInv) {
addSlotToContainer(new Slot(tileEntity, 0, 80, 12) {
addSlotToContainer(new Slot(getInv(), 0, 80, 12) {
@Override
public boolean isItemValid(ItemStack itemStack) {
return tileEntity.isItemValidForSlot(0, itemStack);
return getInv().isItemValidForSlot(0, itemStack);
}
});
addSlotToContainer(new Slot(tileEntity, 1, 122, 23) {
addSlotToContainer(new Slot(getInv(), 1, 122, 23) {
@Override
public boolean isItemValid(ItemStack itemStack) {
return tileEntity.isItemValidForSlot(1, itemStack);
return getInv().isItemValidForSlot(1, itemStack);
}
});
addSlotToContainer(new Slot(tileEntity, 2, 49, 59) {
addSlotToContainer(new Slot(getInv(), 2, 49, 59) {
@Override
public boolean isItemValid(ItemStack par1ItemStack) {
return false;
}
});
addSlotToContainer(new Slot(tileEntity, 3, 70, 59) {
addSlotToContainer(new Slot(getInv(), 3, 70, 59) {
@Override
public boolean isItemValid(ItemStack par1ItemStack) {
return false;
}
});
addSlotToContainer(new Slot(tileEntity, 4, 91, 59) {
addSlotToContainer(new Slot(getInv(), 4, 91, 59) {
@Override
public boolean isItemValid(ItemStack par1ItemStack) {
return false;
}
});
addSlotToContainer(new Slot(tileEntity, 5, 112, 59) {
addSlotToContainer(new Slot(getInv(), 5, 112, 59) {
@Override
public boolean isItemValid(ItemStack par1ItemStack) {
return false;
@@ -7,7 +7,7 @@ import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import crazypants.enderio.machine.gui.AbstractMachineContainer;
public class FarmStationContainer extends AbstractMachineContainer {
public class FarmStationContainer extends AbstractMachineContainer<TileFarmStation> {
private static final int ROW_TOOLS = 19;
private static final int ROW_IO = 44;
@@ -54,15 +54,15 @@ public class FarmStationContainer extends AbstractMachineContainer {
for(Point p : points) {
final int slot = i;
i++;
addSlotToContainer(new Slot(tileEntity, slot, p.x, p.y) {
addSlotToContainer(new Slot(getInv(), slot, p.x, p.y) {
@Override
public boolean isItemValid(ItemStack itemStack) {
return tileEntity.isItemValidForSlot(slot, itemStack);
return getInv().isItemValidForSlot(slot, itemStack);
}
@Override
public int getSlotStackLimit() {
return ((TileFarmStation)tileEntity).getInventoryStackLimit(slot);
return ((TileFarmStation)getInv()).getInventoryStackLimit(slot);
}
});
}
@@ -3,21 +3,20 @@ package crazypants.enderio.machine.generator.stirling;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import crazypants.enderio.machine.AbstractMachineEntity;
import crazypants.enderio.machine.gui.AbstractMachineContainer;
public class StirlingGeneratorContainer extends AbstractMachineContainer {
public class StirlingGeneratorContainer extends AbstractMachineContainer<TileEntityStirlingGenerator> {
public StirlingGeneratorContainer(InventoryPlayer playerInv, AbstractMachineEntity te) {
public StirlingGeneratorContainer(InventoryPlayer playerInv, TileEntityStirlingGenerator te) {
super(playerInv, te);
}
@Override
protected void addMachineSlots(InventoryPlayer playerInv) {
addSlotToContainer(new Slot(tileEntity, 0, 80, 34) {
addSlotToContainer(new Slot(getInv(), 0, 80, 34) {
@Override
public boolean isItemValid(ItemStack itemStack) {
return tileEntity.isItemValidForSlot(0, itemStack);
return getInv().isItemValidForSlot(0, itemStack);
}
});
}
@@ -3,41 +3,33 @@ package crazypants.enderio.machine.gui;
import java.awt.Point;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import com.enderio.core.api.common.util.IProgressTile;
import com.enderio.core.common.ContainerEnder;
import com.enderio.core.common.util.Util;
import crazypants.enderio.machine.AbstractMachineEntity;
import crazypants.enderio.machine.SlotDefinition;
public abstract class AbstractMachineContainer extends ContainerEIO {
protected final AbstractMachineEntity tileEntity;
protected Map<Slot, Point> playerSlotLocations = new HashMap<Slot, Point>();
public abstract class AbstractMachineContainer<T extends AbstractMachineEntity> extends ContainerEnder<T> {
protected Slot upgradeSlot;
public AbstractMachineContainer(InventoryPlayer playerInv, T te) {
super(playerInv, te);
}
protected final int startPlayerSlot;
protected final int endPlayerSlot;
protected final int startHotBarSlot;
protected final int endHotBarSlot;
@SuppressWarnings("OverridableMethodCallInConstructor")
public AbstractMachineContainer(InventoryPlayer playerInv, AbstractMachineEntity te) {
this.tileEntity = te;
@Override
protected void addSlots(InventoryPlayer playerInv) {
addMachineSlots(playerInv);
final T te = getInv();
if(te.getSlotDefinition().getNumUpgradeSlots() == 1) {
upgradeSlot = new Slot(te, te.getSlotDefinition().getMinUpgradeSlot(), getUpgradeOffset().x, getUpgradeOffset().y) {
@@ -48,40 +40,16 @@ public abstract class AbstractMachineContainer extends ContainerEIO {
@Override
public boolean isItemValid(ItemStack itemStack) {
return tileEntity.isItemValidForSlot(tileEntity.getSlotDefinition().getMinUpgradeSlot(), itemStack);
return te.isItemValidForSlot(te.getSlotDefinition().getMinUpgradeSlot(), itemStack);
}
};
addSlotToContainer(upgradeSlot);
}
int x = getPlayerInventoryOffset().x;
int y = getPlayerInventoryOffset().y;
// add players inventory
startPlayerSlot = inventorySlots.size();
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 9; ++j) {
Point loc = new Point(x + j * 18, y + i * 18);
Slot slot = new Slot(playerInv, j + i * 9 + 9, loc.x, loc.y);
addSlotToContainer(slot);
playerSlotLocations.put(slot, loc);
}
}
endPlayerSlot = inventorySlots.size();
startHotBarSlot = inventorySlots.size();
for (int i = 0; i < 9; ++i) {
Point loc = new Point(x + i * 18, y + 58);
Slot slot = new Slot(playerInv, i, loc.x, loc.y);
addSlotToContainer(slot);
playerSlotLocations.put(slot, loc);
}
endHotBarSlot = inventorySlots.size();
}
@Override
public boolean canInteractWith(EntityPlayer entityplayer) {
return tileEntity.isUseableByPlayer(entityplayer);
return getInv().isUseableByPlayer(entityplayer);
}
public Point getPlayerInventoryOffset() {
@@ -96,15 +64,11 @@ public abstract class AbstractMachineContainer extends ContainerEIO {
return upgradeSlot;
}
public AbstractMachineEntity getTileEntity() {
return tileEntity;
}
protected abstract void addMachineSlots(InventoryPlayer playerInv);
@Override
public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slotIndex) {
SlotDefinition slotDef = tileEntity.getSlotDefinition();
SlotDefinition slotDef = getInv().getSlotDefinition();
ItemStack copystack = null;
Slot slot = (Slot) inventorySlots.get(slotIndex);
@@ -162,20 +126,20 @@ public abstract class AbstractMachineContainer extends ContainerEIO {
protected void addInventorySlotRange(List<SlotRange> res, int start, int end) {
for (int i = start; i < end; i++) {
int slotNumber = getSlotFromInventory(tileEntity, i).slotNumber;
int slotNumber = getSlotFromInventory(getInv(), i).slotNumber;
res.add(new SlotRange(slotNumber, slotNumber + 1, false));
}
}
protected void addInputSlotRanges(List<SlotRange> res) {
SlotDefinition slotDef = tileEntity.getSlotDefinition();
SlotDefinition slotDef = getInv().getSlotDefinition();
if(slotDef.getNumInputSlots() > 0) {
addInventorySlotRange(res, slotDef.getMinInputSlot(), slotDef.getMaxInputSlot() + 1);
}
}
protected void addUpgradeSlotRanges(List<SlotRange> res) {
SlotDefinition slotDef = tileEntity.getSlotDefinition();
SlotDefinition slotDef = getInv().getSlotDefinition();
if(slotDef.getNumUpgradeSlots() > 0) {
addInventorySlotRange(res, slotDef.getMinUpgradeSlot(), slotDef.getMaxUpgradeSlot() + 1);
}
@@ -191,8 +155,8 @@ public abstract class AbstractMachineContainer extends ContainerEIO {
}
protected List<SlotRange> getTargetSlotsForTransfer(int slotIndex, Slot slot) {
if (slot.inventory == tileEntity) {
SlotDefinition slotDef = tileEntity.getSlotDefinition();
if (slot.inventory == getInv()) {
SlotDefinition slotDef = getInv().getSlotDefinition();
if (slotDef.isInputSlot(slot.slotNumber) || slotDef.isUpgradeSlot(slot.slotNumber)) {
return Collections.singletonList(getPlayerInventorySlotRange(false));
}
@@ -210,8 +174,8 @@ public abstract class AbstractMachineContainer extends ContainerEIO {
}
protected int getProgressScaled(int scale) {
if(getTileEntity() instanceof IProgressTile) {
Util.getProgressScaled(scale, (IProgressTile) getTileEntity());
if(getInv() instanceof IProgressTile) {
Util.getProgressScaled(scale, (IProgressTile) getInv());
}
return 0;
}
@@ -1,96 +0,0 @@
package crazypants.enderio.machine.gui;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public abstract class ContainerEIO extends Container {
/**
* Added validation of slot input
*/
@Override
protected boolean mergeItemStack(ItemStack par1ItemStack, int fromIndex, int toIndex, boolean reversOrder) {
boolean result = false;
int checkIndex = fromIndex;
if(reversOrder) {
checkIndex = toIndex - 1;
}
Slot slot;
ItemStack itemstack1;
if(par1ItemStack.isStackable()) {
while (par1ItemStack.stackSize > 0 && (!reversOrder && checkIndex < toIndex || reversOrder && checkIndex >= fromIndex)) {
slot = (Slot) this.inventorySlots.get(checkIndex);
itemstack1 = slot.getStack();
if (itemstack1 != null && itemstack1.getItem() == par1ItemStack.getItem()
&& (!par1ItemStack.getHasSubtypes() || par1ItemStack.getItemDamage() == itemstack1.getItemDamage())
&& ItemStack.areItemStackTagsEqual(par1ItemStack, itemstack1) && slot.isItemValid(par1ItemStack)
&& par1ItemStack != itemstack1) {
int mergedSize = itemstack1.stackSize + par1ItemStack.stackSize;
int maxStackSize = Math.min(par1ItemStack.getMaxStackSize(), slot.getSlotStackLimit());
if(mergedSize <= maxStackSize) {
par1ItemStack.stackSize = 0;
itemstack1.stackSize = mergedSize;
slot.onSlotChanged();
result = true;
} else if(itemstack1.stackSize < maxStackSize) {
par1ItemStack.stackSize -= maxStackSize - itemstack1.stackSize;
itemstack1.stackSize = maxStackSize;
slot.onSlotChanged();
result = true;
}
}
if(reversOrder) {
--checkIndex;
} else {
++checkIndex;
}
}
}
if(par1ItemStack.stackSize > 0) {
if(reversOrder) {
checkIndex = toIndex - 1;
} else {
checkIndex = fromIndex;
}
while (!reversOrder && checkIndex < toIndex || reversOrder && checkIndex >= fromIndex) {
slot = (Slot) this.inventorySlots.get(checkIndex);
itemstack1 = slot.getStack();
if(itemstack1 == null && slot.isItemValid(par1ItemStack)) {
ItemStack in = par1ItemStack.copy();
in.stackSize = Math.min(in.stackSize, slot.getSlotStackLimit());
slot.putStack(in);
slot.onSlotChanged();
if(in.stackSize >= par1ItemStack.stackSize) {
par1ItemStack.stackSize = 0;
} else {
par1ItemStack.stackSize -= in.stackSize;
}
result = true;
break;
}
if(reversOrder) {
--checkIndex;
} else {
++checkIndex;
}
}
}
return result;
}
}
@@ -32,7 +32,7 @@ import crazypants.enderio.machine.invpanel.server.InventoryDatabaseServer;
import crazypants.enderio.machine.invpanel.server.ItemEntry;
import crazypants.enderio.network.PacketHandler;
public class InventoryPanelContainer extends AbstractMachineContainer implements ChangeLog {
public class InventoryPanelContainer extends AbstractMachineContainer<TileInventoryPanel> implements ChangeLog {
public static final int CRAFTING_GRID_X = 24+7;
public static final int CRAFTING_GRID_Y = 16;
@@ -48,7 +48,6 @@ public class InventoryPanelContainer extends AbstractMachineContainer implements
private Slot slotFilter;
private int slotCraftResult;
@SuppressWarnings("unused")
private int firstSlotReturn;
private int endSlotReturn;
private int firstSlotCraftingGrid;
@@ -71,17 +70,17 @@ public class InventoryPanelContainer extends AbstractMachineContainer implements
@Override
protected void addMachineSlots(InventoryPlayer playerInv) {
slotCraftResult = inventorySlots.size();
addSlotToContainer(new SlotCrafting(playerInv.player, tileEntity, tileEntity, TileInventoryPanel.SLOT_CRAFTING_RESULT, CRAFTING_GRID_X + 59,
addSlotToContainer(new SlotCrafting(playerInv.player, getInv(), getInv(), TileInventoryPanel.SLOT_CRAFTING_RESULT, CRAFTING_GRID_X + 59,
CRAFTING_GRID_Y + 18) {
@Override
public void onPickupFromSlot(EntityPlayer player, ItemStack p_82870_2_) {
FMLCommonHandler.instance().firePlayerCraftingEvent(player, p_82870_2_, tileEntity);
FMLCommonHandler.instance().firePlayerCraftingEvent(player, p_82870_2_, getInv());
for (int i = TileInventoryPanel.SLOT_CRAFTING_START; i < TileInventoryPanel.SLOT_CRAFTING_RESULT; i++) {
ItemStack itemstack = tileEntity.getStackInSlot(i);
ItemStack itemstack = getInv().getStackInSlot(i);
if(itemstack == null)
continue;
tileEntity.decrStackSize(i, 1);
getInv().decrStackSize(i, 1);
if(!itemstack.getItem().hasContainerItem(itemstack))
continue;
@@ -90,13 +89,13 @@ public class InventoryPanelContainer extends AbstractMachineContainer implements
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, containerIS));
} else {
if(itemstack.getItem().doesContainerItemLeaveCraftingGrid(itemstack)) {
if(ItemUtil.doInsertItem(tileEntity, 10, 20, itemstack) > 0)
if(ItemUtil.doInsertItem(getInv(), 10, 20, itemstack) > 0)
continue;
if(player.inventory.addItemStackToInventory(containerIS))
continue;
}
if(tileEntity.getStackInSlot(i) == null) {
tileEntity.setInventorySlotContents(i, containerIS);
if(getInv().getStackInSlot(i) == null) {
getInv().setInventorySlotContents(i, containerIS);
} else {
player.dropPlayerItemWithRandomChoice(containerIS, false);
}
@@ -108,12 +107,12 @@ public class InventoryPanelContainer extends AbstractMachineContainer implements
firstSlotCraftingGrid = inventorySlots.size();
for (int y = 0, i = TileInventoryPanel.SLOT_CRAFTING_START; y < 3; y++) {
for (int x = 0; x < 3; x++, i++) {
addSlotToContainer(new Slot(tileEntity, i, CRAFTING_GRID_X + x * 18, CRAFTING_GRID_Y + y * 18));
addSlotToContainer(new Slot(getInv(), i, CRAFTING_GRID_X + x * 18, CRAFTING_GRID_Y + y * 18));
}
}
endSlotCraftingGrid = inventorySlots.size();
slotFilter = addSlotToContainer(new Slot(tileEntity, TileInventoryPanel.SLOT_VIEW_FILTER, FILTER_SLOT_X, FILTER_SLOT_Y) {
slotFilter = addSlotToContainer(new Slot(getInv(), TileInventoryPanel.SLOT_VIEW_FILTER, FILTER_SLOT_X, FILTER_SLOT_Y) {
@Override
public int getSlotStackLimit() {
return 1;
@@ -123,7 +122,7 @@ public class InventoryPanelContainer extends AbstractMachineContainer implements
firstSlotReturn = inventorySlots.size();
for (int y = 0, i = TileInventoryPanel.SLOT_RETURN_START; y < 2; y++) {
for (int x = 0; x < 5; x++, i++) {
addSlotToContainer(new Slot(tileEntity, i, RETURN_INV_X + x * 18, RETURN_INV_Y + y * 18));
addSlotToContainer(new Slot(getInv(), i, RETURN_INV_X + x * 18, RETURN_INV_Y + y * 18));
}
}
endSlotReturn = inventorySlots.size();
@@ -137,14 +136,14 @@ public class InventoryPanelContainer extends AbstractMachineContainer implements
@Override
public void onContainerClosed(EntityPlayer player) {
super.onContainerClosed(player);
if(!tileEntity.getWorldObj().isRemote) {
((TileInventoryPanel) tileEntity).eventHandler = null;
if(!getInv().getWorldObj().isRemote) {
((TileInventoryPanel) getInv()).eventHandler = null;
}
removeChangeLog();
}
public TileInventoryPanel getInventoryPanel() {
return (TileInventoryPanel) tileEntity;
return (TileInventoryPanel) getInv();
}
public Slot getSlotFilter() {
@@ -219,10 +218,10 @@ public class InventoryPanelContainer extends AbstractMachineContainer implements
}, 3, 3);
for (int i = 0; i < 9; i++) {
tmp.setInventorySlotContents(i, tileEntity.getStackInSlot(i));
tmp.setInventorySlotContents(i, getInv().getStackInSlot(i));
}
tileEntity.setInventorySlotContents(9, CraftingManager.getInstance().findMatchingRecipe(tmp, tileEntity.getWorldObj()));
getInv().setInventorySlotContents(9, CraftingManager.getInstance().findMatchingRecipe(tmp, getInv().getWorldObj()));
checkCraftingRecipes();
}
@@ -304,6 +303,7 @@ public class InventoryPanelContainer extends AbstractMachineContainer implements
super.detectAndSendChanges();
}
@SuppressWarnings("unchecked")
private void sendReturnAreaSlots() {
for (int slotIdx = firstSlotReturn; slotIdx < endSlotReturn; slotIdx++) {
ItemStack stack = ((Slot) inventorySlots.get(slotIdx)).getStack();
@@ -420,7 +420,7 @@ public class InventoryPanelContainer extends AbstractMachineContainer implements
if(!executeMoveItems(fromSlot, toSlotStart, toSlotEnd, amount)) {
return false;
}
if(getTileEntity().getWorldObj().isRemote) {
if(getInv().getWorldObj().isRemote) {
PacketHandler.INSTANCE.sendToServer(new PacketMoveItems(fromSlot, toSlotStart, toSlotEnd, amount));
}
return true;
@@ -3,21 +3,20 @@ package crazypants.enderio.machine.killera;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import crazypants.enderio.machine.AbstractMachineEntity;
import crazypants.enderio.machine.gui.AbstractMachineContainer;
public class ContainerKillerJoe extends AbstractMachineContainer {
public class ContainerKillerJoe extends AbstractMachineContainer<TileKillerJoe> {
public ContainerKillerJoe(InventoryPlayer playerInv, AbstractMachineEntity te) {
public ContainerKillerJoe(InventoryPlayer playerInv, TileKillerJoe te) {
super(playerInv, te);
}
@Override
protected void addMachineSlots(InventoryPlayer playerInv) {
addSlotToContainer(new Slot(tileEntity, 0, 80, 25) {
addSlotToContainer(new Slot(getInv(), 0, 80, 25) {
@Override
public boolean isItemValid(ItemStack itemStack) {
return tileEntity.isItemValidForSlot(0, itemStack);
return getInv().isItemValidForSlot(0, itemStack);
}
});
}
@@ -3,12 +3,11 @@ package crazypants.enderio.machine.obelisk.attractor;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import crazypants.enderio.machine.AbstractMachineEntity;
import crazypants.enderio.machine.gui.AbstractMachineContainer;
public class ContainerAttractor extends AbstractMachineContainer {
public class ContainerAttractor extends AbstractMachineContainer<TileAttractor> {
public ContainerAttractor(InventoryPlayer playerInv, AbstractMachineEntity te) {
public ContainerAttractor(InventoryPlayer playerInv, TileAttractor te) {
super(playerInv, te);
}
@@ -20,10 +19,10 @@ public class ContainerAttractor extends AbstractMachineContainer {
x = 62;
for (int col = 0; col < 4; col++) {
final int index = (row * 4) + col;
addSlotToContainer(new Slot(tileEntity, index, x, y) {
addSlotToContainer(new Slot(getInv(), index, x, y) {
@Override
public boolean isItemValid(ItemStack itemStack) {
return tileEntity.isItemValidForSlot(index, itemStack);
return getInv().isItemValidForSlot(index, itemStack);
}
});
x += 18;
@@ -3,12 +3,11 @@ package crazypants.enderio.machine.obelisk.aversion;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import crazypants.enderio.machine.AbstractMachineEntity;
import crazypants.enderio.machine.gui.AbstractMachineContainer;
public class ContainerAversionObelisk extends AbstractMachineContainer {
public class ContainerAversionObelisk extends AbstractMachineContainer<TileAversionObelisk> {
public ContainerAversionObelisk(InventoryPlayer playerInv, AbstractMachineEntity te) {
public ContainerAversionObelisk(InventoryPlayer playerInv, TileAversionObelisk te) {
super(playerInv, te);
}
@@ -20,10 +19,10 @@ public class ContainerAversionObelisk extends AbstractMachineContainer {
x = 62;
for (int col = 0; col < 4; col++) {
final int index = (row * 4) + col;
addSlotToContainer(new Slot(tileEntity, index, x, y) {
addSlotToContainer(new Slot(getInv(), index, x, y) {
@Override
public boolean isItemValid(ItemStack itemStack) {
return tileEntity.isItemValidForSlot(index, itemStack);
return getInv().isItemValidForSlot(index, itemStack);
}
});
x += 18;
@@ -5,7 +5,7 @@ import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import crazypants.enderio.machine.gui.AbstractMachineContainer;
public class ContainerWeatherObelisk extends AbstractMachineContainer {
public class ContainerWeatherObelisk extends AbstractMachineContainer<TileWeatherObelisk> {
public static final int MAX_SCALE = 31;
@@ -15,10 +15,10 @@ public class ContainerWeatherObelisk extends AbstractMachineContainer {
@Override
protected void addMachineSlots(InventoryPlayer playerInv) {
addSlotToContainer(new Slot(tileEntity, 0, 80, 62) {
addSlotToContainer(new Slot(getInv(), 0, 80, 62) {
@Override
public boolean isItemValid(ItemStack itemStack) {
return tileEntity.isItemValidForSlot(0, itemStack);
return getInv().isItemValidForSlot(0, itemStack);
}
});
}
@@ -10,7 +10,6 @@ import cpw.mods.fml.relauncher.SideOnly;
import crazypants.enderio.GuiHandler;
import crazypants.enderio.ModObject;
import crazypants.enderio.machine.AbstractMachineBlock;
import crazypants.enderio.machine.AbstractMachineEntity;
public class BlockPainter extends AbstractMachineBlock<TileEntityPainter> {
@@ -35,7 +34,7 @@ public class BlockPainter extends AbstractMachineBlock<TileEntityPainter> {
// items, which are then sent to the client for display
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileEntityPainter) {
return new PainterContainer(player.inventory, (AbstractMachineEntity) te);
return new PainterContainer(player.inventory, (TileEntityPainter) te);
}
return null;
}
@@ -3,30 +3,29 @@ package crazypants.enderio.machine.painter;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import crazypants.enderio.machine.AbstractMachineEntity;
import crazypants.enderio.machine.gui.AbstractMachineContainer;
public class PainterContainer extends AbstractMachineContainer {
public class PainterContainer extends AbstractMachineContainer<TileEntityPainter> {
public PainterContainer(InventoryPlayer playerInv, AbstractMachineEntity te) {
public PainterContainer(InventoryPlayer playerInv, TileEntityPainter te) {
super(playerInv, te);
}
@Override
protected void addMachineSlots(InventoryPlayer playerInv) {
addSlotToContainer(new Slot(tileEntity, 0, 67, 34) {
addSlotToContainer(new Slot(getInv(), 0, 67, 34) {
@Override
public boolean isItemValid(ItemStack itemStack) {
return tileEntity.isItemValidForSlot(0, itemStack);
return getInv().isItemValidForSlot(0, itemStack);
}
});
addSlotToContainer(new Slot(tileEntity, 1, 38, 34) {
addSlotToContainer(new Slot(getInv(), 1, 38, 34) {
@Override
public boolean isItemValid(ItemStack itemStack) {
return tileEntity.isItemValidForSlot(1, itemStack);
return getInv().isItemValidForSlot(1, itemStack);
}
});
addSlotToContainer(new Slot(tileEntity, 2, 121, 34) {
addSlotToContainer(new Slot(getInv(), 2, 121, 34) {
@Override
public boolean isItemValid(ItemStack par1ItemStack) {
return false;
@@ -31,7 +31,7 @@ public class BlockSliceAndSplice extends AbstractMachineBlock<TileSliceAndSplice
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileSliceAndSplice) {
return new ContainerSliceAndSplice(player.inventory, (AbstractMachineEntity) te);
return new ContainerSliceAndSplice(player.inventory, (TileSliceAndSplice) te);
}
return null;
}
@@ -5,10 +5,9 @@ import java.awt.Point;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import crazypants.enderio.machine.AbstractMachineEntity;
import crazypants.enderio.machine.gui.AbstractMachineContainer;
public class ContainerSliceAndSplice extends AbstractMachineContainer {
public class ContainerSliceAndSplice extends AbstractMachineContainer<TileSliceAndSplice> {
public static final Point[] INPUT_SLOTS = new Point[] {
new Point(44,40),
@@ -23,7 +22,7 @@ public class ContainerSliceAndSplice extends AbstractMachineContainer {
public static final Point OUTPUT_SLOT = new Point(134, 49);
public ContainerSliceAndSplice(InventoryPlayer playerInv, AbstractMachineEntity te) {
public ContainerSliceAndSplice(InventoryPlayer playerInv, TileSliceAndSplice te) {
super(playerInv, te);
}
@@ -33,16 +32,16 @@ public class ContainerSliceAndSplice extends AbstractMachineContainer {
for(int i=0;i<INPUT_SLOTS.length;i++) {
Point p = INPUT_SLOTS[i];
final int slot = i;
addSlotToContainer(new Slot(tileEntity, i, p.x, p.y) {
addSlotToContainer(new Slot(getInv(), i, p.x, p.y) {
@Override
public boolean isItemValid(ItemStack itemStack) {
return tileEntity.isItemValidForSlot(slot, itemStack);
return getInv().isItemValidForSlot(slot, itemStack);
}
});
}
addSlotToContainer(new Slot(tileEntity, 8, OUTPUT_SLOT.x, OUTPUT_SLOT.y) {
addSlotToContainer(new Slot(getInv(), 8, OUTPUT_SLOT.x, OUTPUT_SLOT.y) {
@Override
public boolean isItemValid(ItemStack par1ItemStack) {
return false;
@@ -14,7 +14,6 @@ import cpw.mods.fml.relauncher.SideOnly;
import crazypants.enderio.GuiHandler;
import crazypants.enderio.ModObject;
import crazypants.enderio.machine.AbstractMachineBlock;
import crazypants.enderio.machine.AbstractMachineEntity;
import crazypants.enderio.xp.PacketDrainPlayerXP;
import crazypants.enderio.xp.PacketExperianceContainer;
@@ -44,7 +43,7 @@ public class BlockSoulBinder extends AbstractMachineBlock<TileSoulBinder> {
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileSoulBinder) {
return new ContainerSoulBinder(player.inventory, (AbstractMachineEntity) te);
return new ContainerSoulBinder(player.inventory, (TileSoulBinder) te);
}
return null;
}
@@ -3,36 +3,35 @@ package crazypants.enderio.machine.soul;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import crazypants.enderio.machine.AbstractMachineEntity;
import crazypants.enderio.machine.gui.AbstractMachineContainer;
public class ContainerSoulBinder extends AbstractMachineContainer {
public class ContainerSoulBinder extends AbstractMachineContainer<TileSoulBinder> {
public ContainerSoulBinder(InventoryPlayer playerInv, AbstractMachineEntity te) {
public ContainerSoulBinder(InventoryPlayer playerInv, TileSoulBinder te) {
super(playerInv, te);
}
@Override
protected void addMachineSlots(InventoryPlayer playerInv) {
addSlotToContainer(new Slot(tileEntity, 0, 38, 34) {
addSlotToContainer(new Slot(getInv(), 0, 38, 34) {
@Override
public boolean isItemValid(ItemStack itemStack) {
return tileEntity.isItemValidForSlot(0, itemStack);
return getInv().isItemValidForSlot(0, itemStack);
}
});
addSlotToContainer(new Slot(tileEntity, 1, 59, 34) {
addSlotToContainer(new Slot(getInv(), 1, 59, 34) {
@Override
public boolean isItemValid(ItemStack itemStack) {
return tileEntity.isItemValidForSlot(1, itemStack);
return getInv().isItemValidForSlot(1, itemStack);
}
});
addSlotToContainer(new Slot(tileEntity, 2, 112, 34) {
addSlotToContainer(new Slot(getInv(), 2, 112, 34) {
@Override
public boolean isItemValid(ItemStack par1ItemStack) {
return false;
}
});
addSlotToContainer(new Slot(tileEntity, 3, 134, 34) {
addSlotToContainer(new Slot(getInv(), 3, 134, 34) {
@Override
public boolean isItemValid(ItemStack par1ItemStack) {
return false;
@@ -3,27 +3,26 @@ package crazypants.enderio.machine.spawner;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import crazypants.enderio.machine.AbstractMachineEntity;
import crazypants.enderio.machine.gui.AbstractMachineContainer;
public class ContainerPoweredSpawner extends AbstractMachineContainer {
public class ContainerPoweredSpawner extends AbstractMachineContainer<TilePoweredSpawner> {
private Slot slotInput;
private Slot slotOutput;
public ContainerPoweredSpawner(InventoryPlayer playerInv, AbstractMachineEntity te) {
public ContainerPoweredSpawner(InventoryPlayer playerInv, TilePoweredSpawner te) {
super(playerInv, te);
}
@Override
protected void addMachineSlots(InventoryPlayer playerInv) {
slotInput = addSlotToContainer(new Slot(tileEntity, 0, 54, 42) {
slotInput = addSlotToContainer(new Slot(getInv(), 0, 54, 42) {
@Override
public boolean isItemValid(ItemStack itemStack) {
return tileEntity.isItemValidForSlot(0, itemStack);
return getInv().isItemValidForSlot(0, itemStack);
}
});
slotOutput = addSlotToContainer(new Slot(tileEntity, 1, 105, 42) {
slotOutput = addSlotToContainer(new Slot(getInv(), 1, 105, 42) {
@Override
public boolean isItemValid(ItemStack itemStack) {
return false;
@@ -3,39 +3,38 @@ package crazypants.enderio.machine.tank;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import crazypants.enderio.machine.AbstractMachineEntity;
import crazypants.enderio.machine.gui.AbstractMachineContainer;
public class ContainerTank extends AbstractMachineContainer {
public class ContainerTank extends AbstractMachineContainer<TileTank> {
public ContainerTank(InventoryPlayer playerInv, AbstractMachineEntity te) {
public ContainerTank(InventoryPlayer playerInv, TileTank te) {
super(playerInv, te);
}
@Override
protected void addMachineSlots(InventoryPlayer playerInv) {
addSlotToContainer(new Slot(tileEntity, 0, 44, 21) {
addSlotToContainer(new Slot(getInv(), 0, 44, 21) {
@Override
public boolean isItemValid(ItemStack itemStack) {
return tileEntity.isItemValidForSlot(0, itemStack);
return getInv().isItemValidForSlot(0, itemStack);
}
});
addSlotToContainer(new Slot(tileEntity, 1, 116, 21) {
addSlotToContainer(new Slot(getInv(), 1, 116, 21) {
@Override
public boolean isItemValid(ItemStack itemStack) {
return tileEntity.isItemValidForSlot(1, itemStack);
return getInv().isItemValidForSlot(1, itemStack);
}
});
addSlotToContainer(new Slot(tileEntity, 2, 44, 52) {
addSlotToContainer(new Slot(getInv(), 2, 44, 52) {
@Override
public boolean isItemValid(ItemStack itemStack) {
return tileEntity.isItemValidForSlot(2, itemStack);
return getInv().isItemValidForSlot(2, itemStack);
}
});
addSlotToContainer(new Slot(tileEntity, 3, 116, 52) {
addSlotToContainer(new Slot(getInv(), 3, 116, 52) {
@Override
public boolean isItemValid(ItemStack itemStack) {
return tileEntity.isItemValidForSlot(3, itemStack);
return getInv().isItemValidForSlot(3, itemStack);
}
});
@@ -11,7 +11,7 @@ import crazypants.enderio.machine.SlotDefinition;
import crazypants.enderio.machine.gui.AbstractMachineContainer;
import crazypants.enderio.machine.transceiver.TileTransceiver;
public class ContainerTransceiver extends AbstractMachineContainer {
public class ContainerTransceiver extends AbstractMachineContainer<TileTransceiver> {
public static final int GUI_WIDTH = 256;
@@ -23,30 +23,25 @@ public class ContainerTransceiver extends AbstractMachineContainer {
static final Point FILTER_OFFSET = new Point(PLAYER_INV_OFFSET.x, 30);
private TileTransceiver trans;
public ContainerTransceiver(InventoryPlayer inventory, TileTransceiver te) {
super(inventory, te);
trans = te;
}
@Override
protected void addMachineSlots(InventoryPlayer playerInv) {
trans = (TileTransceiver) tileEntity;
int i;
for (i = 0; i < 8; i++) {
addSlotToContainer(new Slot(tileEntity, i, 0, 0) {
addSlotToContainer(new Slot(getInv(), i, 0, 0) {
@Override
public boolean isItemValid(ItemStack itemstack) {
return trans.isItemValidForSlot(getSlotIndex(), itemstack);
return getInv().isItemValidForSlot(getSlotIndex(), itemstack);
//return true;
}
});
}
for (; i < 16; i++) {
addSlotToContainer(new Slot(tileEntity, i, 0, 0) {
addSlotToContainer(new Slot(getInv(), i, 0, 0) {
@Override
public boolean isItemValid(ItemStack p_75214_1_) {
return false;
@@ -3,27 +3,26 @@ package crazypants.enderio.machine.vat;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import crazypants.enderio.machine.AbstractMachineEntity;
import crazypants.enderio.machine.gui.AbstractMachineContainer;
public class ContainerVat extends AbstractMachineContainer {
public class ContainerVat extends AbstractMachineContainer<TileVat> {
public ContainerVat(InventoryPlayer playerInv, AbstractMachineEntity te) {
public ContainerVat(InventoryPlayer playerInv, TileVat te) {
super(playerInv, te);
}
@Override
protected void addMachineSlots(InventoryPlayer playerInv) {
addSlotToContainer(new Slot(tileEntity, 0, 56, 12) {
addSlotToContainer(new Slot(getInv(), 0, 56, 12) {
@Override
public boolean isItemValid(ItemStack itemStack) {
return tileEntity.isItemValidForSlot(0, itemStack);
return getInv().isItemValidForSlot(0, itemStack);
}
});
addSlotToContainer(new Slot(tileEntity, 1, 105, 12) {
addSlotToContainer(new Slot(getInv(), 1, 105, 12) {
@Override
public boolean isItemValid(ItemStack itemStack) {
return tileEntity.isItemValidForSlot(1, itemStack);
return getInv().isItemValidForSlot(1, itemStack);
}
});
}
@@ -1,55 +1,56 @@
package crazypants.enderio.teleport;
import java.awt.Point;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import com.enderio.core.client.gui.widget.TemplateSlot;
import com.enderio.core.common.ContainerEnder;
import crazypants.enderio.api.teleport.ITravelAccessable;
import crazypants.enderio.teleport.ContainerTravelAccessable.PasswordInventory;
import crazypants.util.ArrayInventory;
public class ContainerTravelAccessable extends Container {
public class ContainerTravelAccessable extends ContainerEnder<PasswordInventory> {
ITravelAccessable ta;
TileEntity te;
World world;
public ContainerTravelAccessable(InventoryPlayer playerInv, final ITravelAccessable travelAccessable, World world) {
super(playerInv, new PasswordInventory(travelAccessable, world, true));
ta = travelAccessable;
this.world = world;
if(ta instanceof TileEntity) {
if (ta instanceof TileEntity) {
te = ((TileEntity) ta);
}
ArrayInventory arrInv = new PasswordInventory(ta.getPassword(), true);
getInv().te = te;
}
@Override
protected void addSlots(InventoryPlayer playerInv) {
int x = 44;
int y = 73;
for (int i = 0; i < 5; i++) {
addSlotToContainer(new TemplateSlot(arrInv, i, x, y));
addSlotToContainer(new TemplateSlot(getInv(), i, x, y));
x += 18;
}
arrInv = new PasswordInventory(new ItemStack[] {ta.getItemLabel()}, false);
ArrayInventory arrInv = new PasswordInventory(getInv().ta, getInv().world, false);
x = 125;
y = 10;
y = 10;
addSlotToContainer(new TemplateSlot(arrInv, 0, x, y));
// add players inventory
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 9; ++j) {
addSlotToContainer(new Slot(playerInv, j + i * 9 + 9, 8 + j * 18, 103 + i * 18));
}
}
for (int i = 0; i < 9; ++i) {
addSlotToContainer(new Slot(playerInv, i, 8 + i * 18, 161));
}
}
@Override
public Point getPlayerInventoryOffset() {
return new Point(8, 103);
}
@Override
@@ -63,21 +64,29 @@ public class ContainerTravelAccessable extends Container {
return null;
}
private class PasswordInventory extends ArrayInventory {
static class PasswordInventory extends ArrayInventory {
boolean isAuth;
public PasswordInventory(ItemStack[] items, boolean isAuth) {
super(items);
World world;
TileEntity te;
ITravelAccessable ta;
public PasswordInventory(ITravelAccessable ta, World world, boolean isAuth) {
super(isAuth ? ta.getPassword() : new ItemStack[] { ta.getItemLabel() });
this.isAuth = isAuth;
this.world = world;
if (ta instanceof TileEntity) {
te = (TileEntity) ta;
}
this.ta = ta;
}
@Override
public void markDirty() {
super.markDirty();
if(!world.isRemote && te != null) {
if(isAuth) {
ta.clearAuthorisedUsers();
if (!world.isRemote && te != null) {
if (isAuth) {
((ITravelAccessable) te).clearAuthorisedUsers();
}
world.markBlockForUpdate(te.xCoord, te.yCoord, te.zCoord);
}
@@ -90,7 +99,7 @@ public class ContainerTravelAccessable extends Container {
@Override
public ItemStack getStackInSlot(int i) {
if(i < 0 || i >= items.length) {
if (i < 0 || i >= items.length) {
return null;
}
return items[i];
@@ -100,7 +109,7 @@ public class ContainerTravelAccessable extends Container {
public ItemStack decrStackSize(int fromSlot, int amount) {
ItemStack item = items[fromSlot];
items[fromSlot] = null;
if(item == null) {
if (item == null) {
return null;
}
item.stackSize = 0;
@@ -114,13 +123,13 @@ public class ContainerTravelAccessable extends Container {
@Override
public void setInventorySlotContents(int i, ItemStack itemstack) {
if(itemstack != null) {
if (itemstack != null) {
items[i] = itemstack.copy();
items[i].stackSize = 0;
} else {
items[i] = null;
}
ta.setItemLabel(items[i]);
((ITravelAccessable) te).setItemLabel(items[i]);
}
@Override
@@ -134,5 +143,5 @@ public class ContainerTravelAccessable extends Container {
}
}
}
@@ -10,7 +10,7 @@ public class ArrayInventory implements IInventory {
protected ItemStack[] items;
public ArrayInventory(ItemStack[] items) {
public ArrayInventory(ItemStack... items) {
this.items = items;
}