diff --git a/resources/assets/enderio/textures/gui/capacitorBank.png b/resources/assets/enderio/textures/gui/capacitorBank.png index 0b452754..26393e48 100644 Binary files a/resources/assets/enderio/textures/gui/capacitorBank.png and b/resources/assets/enderio/textures/gui/capacitorBank.png differ diff --git a/src/main/java/crazypants/enderio/machine/capbank/ContainerCapBank.java b/src/main/java/crazypants/enderio/machine/capbank/ContainerCapBank.java index c4a6e8d6..8cd37265 100644 --- a/src/main/java/crazypants/enderio/machine/capbank/ContainerCapBank.java +++ b/src/main/java/crazypants/enderio/machine/capbank/ContainerCapBank.java @@ -4,6 +4,7 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemArmor; import net.minecraft.item.ItemStack; @@ -11,12 +12,18 @@ import net.minecraft.util.IIcon; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import crazypants.enderio.machine.capbank.network.InventoryImpl; +import crazypants.util.BaublesUtil; +import crazypants.util.ShadowInventory; public class ContainerCapBank extends Container { private final TileCapBank tileEntity; private final 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) { @@ -25,6 +32,12 @@ public class ContainerCapBank extends Container { inv = new InventoryImpl(); } + baubles = BaublesUtil.instance().getBaubles((EntityPlayer) player); + + if (baubles != null && BaublesUtil.WhoAmI.whoAmI(player.worldObj) == BaublesUtil.WhoAmI.SPCLIENT) { + baubles = new ShadowInventory(baubles); + } + int armorOffset = 21; addSlotToContainer(new Slot(inv, 0, 59 + armorOffset, 59) { @Override @@ -68,7 +81,7 @@ public class ContainerCapBank extends Container { //armor slots for (int i = 0; i < 4; ++i) { final int k = i; - addSlotToContainer(new Slot(playerInv, playerInv.getSizeInventory() - 1 - i, -15 + armorOffset, 30 + i * 18) { + addSlotToContainer(new Slot(playerInv, playerInv.getSizeInventory() - 1 - i, -15 + armorOffset, 12 + i * 18) { @Override public int getSlotStackLimit() { @@ -91,8 +104,23 @@ public class ContainerCapBank extends Container { }); } + if (hasBaublesSlots()) { + for (int i = 0; i < baubles.getSizeInventory(); i++) { + addSlotToContainer(new Slot(baubles, i, -15 + armorOffset, 84 + i * 18) { + @Override + public boolean isItemValid(ItemStack par1ItemStack) { + return inventory.isItemValidForSlot(getSlotIndex(), par1ItemStack); + } + }); + } + } + } + public boolean hasBaublesSlots() { + return baubles != null; + } + public void updateInventory() { if(tileEntity.getNetwork() != null && tileEntity.getNetwork().getInventory() != null) { inv.setCapBank(tileEntity.getNetwork().getInventory().getCapBank()); @@ -111,6 +139,8 @@ public class ContainerCapBank extends Container { int endPlayerSlot = startPlayerSlot + 26; int startHotBarSlot = endPlayerSlot + 1; int endHotBarSlot = startHotBarSlot + 9; + int startBaublesSlot = endHotBarSlot + 1; + int endBaublesSlot = baubles == null ? 0 : startBaublesSlot + baubles.getSizeInventory(); ItemStack copystack = null; Slot slot = (Slot) inventorySlots.get(slotIndex); @@ -119,12 +149,17 @@ public class ContainerCapBank extends Container { ItemStack origStack = slot.getStack(); copystack = origStack.copy(); + // Note: Merging into Baubles slots is disabled because the used vanilla + // merge method does not check if the item can go into the slot or not. + if(slotIndex < 4) { // merge from machine input slots to inventory - if(!mergeItemStackIntoArmor(entityPlayer, origStack, slotIndex)) { - if(!mergeItemStack(origStack, startPlayerSlot, endHotBarSlot, false)) { + if (!mergeItemStackIntoArmor(entityPlayer, origStack, slotIndex) + && /* + * !(baubles != null && mergeItemStack(origStack, + * startBaublesSlot, endBaublesSlot, false)) && + */!mergeItemStack(origStack, startPlayerSlot, endHotBarSlot, false)) { return null; - } } } else { @@ -133,11 +168,22 @@ public class ContainerCapBank extends Container { if(!inv.isItemValidForSlot(0, origStack) || !mergeItemStack(origStack, 0, 4, false)) { if(slotIndex <= endPlayerSlot) { - if(!mergeItemStack(origStack, startHotBarSlot, endHotBarSlot, false)) { + if (/* + * !(baubles != null && mergeItemStack(origStack, + * startBaublesSlot, endBaublesSlot, false)) && + */!mergeItemStack(origStack, startHotBarSlot, endHotBarSlot, false)) { return null; } } else if(slotIndex >= startHotBarSlot && slotIndex <= endHotBarSlot) { - if(!mergeItemStack(origStack, startPlayerSlot, endPlayerSlot, false)) { + if (/* + * !(baubles != null && mergeItemStack(origStack, + * startBaublesSlot, endBaublesSlot, false)) && + */!mergeItemStack(origStack, startPlayerSlot, endPlayerSlot, false)) { + return null; + } + } else if (slotIndex >= startBaublesSlot && slotIndex <= endBaublesSlot) { + if(!mergeItemStack(origStack, startHotBarSlot, endHotBarSlot, false) && + !mergeItemStack(origStack, startPlayerSlot, endPlayerSlot, false)) { return null; } } diff --git a/src/main/java/crazypants/enderio/machine/capbank/GuiCapBank.java b/src/main/java/crazypants/enderio/machine/capbank/GuiCapBank.java index 6a8446a1..c9825f31 100644 --- a/src/main/java/crazypants/enderio/machine/capbank/GuiCapBank.java +++ b/src/main/java/crazypants/enderio/machine/capbank/GuiCapBank.java @@ -246,6 +246,10 @@ public class GuiCapBank extends GuiContainerBase { drawTexturedModalRect(sx, sy, 0, 0, xSize - 21, ySize); + if (container.hasBaublesSlots()) { + drawTexturedModalRect(sx, sy + 83, 197, 83, 24, 76); + } + int i1 = getEnergyStoredScaled(POWER_HEIGHT); drawTexturedModalRect(sx + POWER_X, sy + BOTTOM_POWER_Y - i1, 176 + 21, 0, POWER_WIDTH, i1); diff --git a/src/main/java/crazypants/util/BaublesUtil.java b/src/main/java/crazypants/util/BaublesUtil.java index e7aaec40..1e66dc95 100644 --- a/src/main/java/crazypants/util/BaublesUtil.java +++ b/src/main/java/crazypants/util/BaublesUtil.java @@ -1,12 +1,43 @@ package crazypants.util; +import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; +import net.minecraft.server.MinecraftServer; +import net.minecraft.world.World; import baubles.api.BaublesApi; +import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Loader; +import cpw.mods.fml.relauncher.Side; public class BaublesUtil { + public static enum WhoAmI { + SPCLIENT, MPCLIENT, SPSERVER, MPSERVER, OTHER; + + public static BaublesUtil.WhoAmI whoAmI(World world) { + Side side = FMLCommonHandler.instance().getSide(); + if (side == Side.CLIENT) { + if (Minecraft.getMinecraft().isIntegratedServerRunning()) { + if (world.isRemote) { + return SPCLIENT; + } else { + return SPSERVER; + } + } else { + return MPCLIENT; + } + } else if (side == Side.SERVER) { + if (MinecraftServer.getServer().isDedicatedServer()) { + return MPSERVER; + } else if (Minecraft.getMinecraft().isIntegratedServerRunning()) { + return SPSERVER; + } + } + return OTHER; + } + } + private static final BaublesUtil instance = new BaublesUtil(); private static final boolean baublesLoaded; static { @@ -24,6 +55,11 @@ public class BaublesUtil { return baublesLoaded; } + /** + * Do NOT modify this inventory on the client side of a singleplayer game! + * + * Wrap it in a ShadowInventory if you need to. + */ public IInventory getBaubles(EntityPlayer player) { return hasBaubles() ? getBaublesInvUnsafe(player) : null; } @@ -31,4 +67,5 @@ public class BaublesUtil { private IInventory getBaublesInvUnsafe(EntityPlayer player) { return BaublesApi.getBaubles(player); } + } diff --git a/src/main/java/crazypants/util/ShadowInventory.java b/src/main/java/crazypants/util/ShadowInventory.java new file mode 100644 index 00000000..2cec5834 --- /dev/null +++ b/src/main/java/crazypants/util/ShadowInventory.java @@ -0,0 +1,84 @@ +package crazypants.util; + +import codechicken.lib.inventory.InventoryUtils; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; + +public class ShadowInventory implements IInventory { + private final ItemStack[] items; + private final IInventory master; + + public ShadowInventory(IInventory master) { + this.master = master; + items = new ItemStack[master.getSizeInventory()]; + for (int i = 0; i < master.getSizeInventory(); i++) { + items[i] = master.getStackInSlot(i); + } + } + + @Override + public int getSizeInventory() { + return master.getSizeInventory(); + } + + @Override + public ItemStack getStackInSlot(int p_70301_1_) { + return items[p_70301_1_]; + } + + @Override + public ItemStack decrStackSize(int p_70298_1_, int p_70298_2_) { + return InventoryUtils.decrStackSize(this, p_70298_1_, p_70298_2_); + } + + @Override + public ItemStack getStackInSlotOnClosing(int p_70304_1_) { + return InventoryUtils.getStackInSlotOnClosing(this, p_70304_1_); + } + + @Override + public void setInventorySlotContents(int p_70299_1_, ItemStack p_70299_2_) { + items[p_70299_1_] = p_70299_2_; + } + + @Override + public String getInventoryName() { + return master.getInventoryName(); + } + + @Override + public boolean hasCustomInventoryName() { + return master.hasCustomInventoryName(); + } + + @Override + public int getInventoryStackLimit() { + return master.getInventoryStackLimit(); + } + + @Override + public void markDirty() { + } + + @Override + public boolean isUseableByPlayer(EntityPlayer p_70300_1_) { + return master.isUseableByPlayer(p_70300_1_); + } + + @Override + public void openInventory() { + master.openInventory(); + } + + @Override + public void closeInventory() { + master.closeInventory(); + } + + @Override + public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) { + return master.isItemValidForSlot(p_94041_1_, p_94041_2_); + } + +}