From ebec0bee6cb731ace2ec29801c8fc58cf8a696c9 Mon Sep 17 00:00:00 2001 From: Henry Loenwind Date: Tue, 28 Apr 2015 16:41:14 +0200 Subject: [PATCH] Even more Baubles * Baubles slots are now displayed in the Capacitor Bank. So the Magnet can be charged directly. --- .../enderio/textures/gui/capacitorBank.png | Bin 2409 -> 2480 bytes .../machine/capbank/ContainerCapBank.java | 58 ++++++++++-- .../enderio/machine/capbank/GuiCapBank.java | 4 + .../java/crazypants/util/BaublesUtil.java | 37 ++++++++ .../java/crazypants/util/ShadowInventory.java | 84 ++++++++++++++++++ 5 files changed, 177 insertions(+), 6 deletions(-) create mode 100644 src/main/java/crazypants/util/ShadowInventory.java diff --git a/resources/assets/enderio/textures/gui/capacitorBank.png b/resources/assets/enderio/textures/gui/capacitorBank.png index 0b45275482323d7d7f04dbe5f013f7f9e55c9e6b..26393e48a0bb0771855db7142d78015f0192905f 100644 GIT binary patch literal 2480 zcmcIl|3A~)A3vKl^W9w0T+=K!ii>V4`I4n!i>9g1lCY&B!Xl(*w%u|+-DG`nv$+^0 zU+$G8xe~*@H{tqLSSpQtU0bwLj8VI9pU>xq&*u;Lobx!3a~`kP>%6``U+4U|m*Quj zYoQAOFd&nNK>)y@BMhLB&=#6l9tmy82!B5!(5%cNaalG*(K$&vcnSbR@ydevEnTUE zh}ucyJwDna2&@radv|L+bW_KZOx(FY_2rDzYu}MUjP`4lVr>L3=9oxDBtiOM9*aUhRsNJ7#odIEDq45Ypi07y-Wx^M}cVbc=UL!oFCdjeaoa zV3<^vdn1^3HsgGcQgrH_#NVXmI`ZhQK34CSMRPBHj0x4={D^q}rMU=eJpN~C=kX@_ z;_vZB*>hA%5roX%;7B2!i4 z5zQxg{|#nCO-;7kz$|g>^jcyXI@f>;Q&mUT)zoYrn3-+;JZMn1S z%XA63OkS#-kkZpX4s|sR`e#%6_l$Hji0K+@{>|!O7|@pm(w8^k4Of8)DpNgj+@1D2su`eb*h;nPe!c0MNK^Rf7gA|fpx5W5+b{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6zox37va-0gx~Q(Qq_(P}zACGsIJdDhud%GEp{lmEWuB_^GBxQP+H%MB z6|Wg7-|%t$zm4JlfBELt=H|ARw)VE>j<&YWw)T$p&aSTR?(Sp9j{X1tALyP@Fd71M z3jr(c-D#kVQWE4B3`~9_888HYXIBLVJZFJNWHAE+-(C=AbpJhJEl^OR#5JNMI6tkV zJh3R1p&&6cuS72|wM4;0&p^*G>BYAiVEJ<1)5S5QBJS<%%;MV$BCbn!WX^h5y(=wy zR!QfS|Nmcyu$VLHh8c5GzGN-ltlewmo(99jhEV018{VV5#W9H?R;>x*u6 zjf;Dgj2Ul$q4u_LI$n{K-6H%8uClxf~$Y*qUxikSRcro znDnvpLSF%Q00S!sIdqy?YdHA7oucU=KBh;Ettjb$+g0-Z{JLRqx5eRX0c~-{rLT3tE9!|_A53X z!46-azYU-J?hPZ*rJ@0M>#kj#UHg3&`${f`=(O)^D;*d;IcNL|-0Od~c?*jTgCOgU z{7yX;PZvg@3^2s1xjFtYc{RJvYf!WhlnPSR<&SA(FcCiVMoeOQ@aijEpx|>bR)mHV z1FO$@AI8T;SyQ7NLAo>4Shy}QZJWcl>CiT-IB};?q!TSa*48E_jRvL-Zv-?LZnlG% zw^kn4pAoe*3~cW-SteG6-wqCYCeK-_HIenfoufh@bJ#OKt~w&tpuSf5(P5dem7<{7 zZ%A!-U_4<5VqWmG#bNN{xleRLJ9QNJf!1g+oaRdmV>lP5D|o(qqS$(`9L68pUUvLw z6(h~WXL>LbQ@AZU6cc{&cTHApYB*`H;WxGR*L|%8nx7c8`I7hV4rgFhIO@dcu`z%l mNJpeWgnLkOy9*e7Kl49eO533JNb5VOGV*lwb6Mw<&;$T6Ygt(U 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_); + } + +}