diff --git a/src/java/cd4017be/lib/Gui/AdvancedContainer.java b/src/java/cd4017be/lib/Gui/AdvancedContainer.java index 03aee43..0d3c102 100644 --- a/src/java/cd4017be/lib/Gui/AdvancedContainer.java +++ b/src/java/cd4017be/lib/Gui/AdvancedContainer.java @@ -57,6 +57,10 @@ public AdvancedContainer(IStateInteractionHandler handler, StateSynchronizer syn @Override public void detectAndSendChanges() { + if (player.world.isRemote) { + super.detectAndSendChanges(); + return; + } StateSyncServer sss = (StateSyncServer)sync; sss.buffer.clear().writeInt(windowId); sss.setHeader(); @@ -139,13 +143,21 @@ public void addItemSlot(Slot slot, boolean sync) { this.addSlotToContainer(slot); } + @Override + public void putStackInSlot(int slotID, ItemStack stack) { + if (slotsToSync.contains(slotID)) return; + Slot slot = inventorySlots.get(slotID); + if (slot instanceof ISpecialSlot) + ((ISpecialSlot)slot).setStack(stack); + else slot.putStack(stack); + } + @Override @SideOnly(Side.CLIENT) public void setAll(List items) { int m = Math.min(items.size(), inventorySlots.size()); for (int i = 0; i < m; ++i) - if (!slotsToSync.contains(i)) - inventorySlots.get(i).putStack(items.get(i)); + putStackInSlot(i, items.get(i)); } @Override diff --git a/src/java/cd4017be/lib/Gui/GlitchSaveSlot.java b/src/java/cd4017be/lib/Gui/GlitchSaveSlot.java index 526059d..cccafde 100644 --- a/src/java/cd4017be/lib/Gui/GlitchSaveSlot.java +++ b/src/java/cd4017be/lib/Gui/GlitchSaveSlot.java @@ -1,8 +1,10 @@ package cd4017be.lib.Gui; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.ClickType; import net.minecraft.item.ItemStack; import net.minecraftforge.items.IItemHandler; +import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.items.SlotItemHandler; /** @@ -10,7 +12,7 @@ * and/or where vanilla inventory slot interaction would cause bad glitches (requires special hard coded handling in containers). * @author CD4017BE */ -public class GlitchSaveSlot extends SlotItemHandler { +public class GlitchSaveSlot extends SlotItemHandler implements ISpecialSlot { public final int index; public final boolean clientInteract; @@ -45,4 +47,61 @@ public ItemStack decrStackSize(int amount) { @Override public void putStack(ItemStack stack) {} + // new container system + + @Override + public int getSlot() { + return index; + } + + @Override + public boolean insertHereOnly(ItemStack stack) { + return false; + } + + @Override + public ItemStack onClick(int b, ClickType ct, EntityPlayer player, AdvancedContainer container) { + ItemStack item = getStack(); + if (ct == ClickType.CLONE) { + ISpecialSlot.quickSelect(player, item); + return ItemStack.EMPTY; + } else if (ct != ClickType.PICKUP && ct != ClickType.QUICK_MOVE) + return ItemStack.EMPTY; + if (!clientInteract) { + if (player.world.isRemote) + return ItemStack.EMPTY; + container.hardInvUpdate(); + } + boolean boost = ct == ClickType.QUICK_MOVE; + ItemStack curItem = player.inventory.getItemStack(); + if (curItem.getCount() > 0 && (item.isEmpty() || ItemHandlerHelper.canItemStacksStack(item, curItem))) { + if (boost) { + ItemStack rem = insertItem(ItemHandlerHelper.copyStackWithSize(curItem, 65536), true); + int n = 65536 - rem.getCount(), n1 = 0; + if (n <= 0) return ItemStack.EMPTY; + if (b == 0) { + if (n < curItem.getCount()) curItem.shrink(n1 = n); + else { + n1 = curItem.getCount(); + player.inventory.setItemStack(ItemStack.EMPTY); + } + } + if (n1 < n) + n1 += ISpecialSlot.getFromPlayerInv(ItemHandlerHelper.copyStackWithSize(curItem, n - n1), player.inventory); + insertItem(ItemHandlerHelper.copyStackWithSize(curItem, n1), false); + } else { + int n = b == 0 ? curItem.getCount() : 1; + ItemStack rem = insertItem(ItemHandlerHelper.copyStackWithSize(curItem, n), false); + curItem.shrink(n - rem.getCount()); + if (curItem.getCount() <= 0) player.inventory.setItemStack(ItemStack.EMPTY); + } + } else if (item.getCount() > 0) { + int n = boost ? (b == 0 ? item.getMaxStackSize() : 65536) : (b == 0 ? 1 : 8); + if ((item = extractItem(n, true)).getCount() == 0) return ItemStack.EMPTY; + int rem = ISpecialSlot.putInPlayerInv(item.copy(), player.inventory); + extractItem(item.getCount() - rem, false); + } + return ItemStack.EMPTY; + } + }