From 1e9ec4e7aaa53bbe60f0f18e3907dc2c54d8457a Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 27 Dec 2016 12:19:34 +0100 Subject: [PATCH] not how you revert --- .../mod/inventory/ContainerBag.java | 5 +- .../mod/inventory/ContainerFilter.java | 9 ++-- .../mod/inventory/ContainerInputter.java | 5 +- .../ContainerLaserRelayItemWhitelist.java | 5 +- .../inventory/ContainerRangedCollector.java | 5 +- .../mod/inventory/slot/SlotFilter.java | 47 +++++++------------ .../mod/tile/FilterSettings.java | 3 +- .../mod/tile/TileEntityInputter.java | 13 +++-- .../TileEntityLaserRelayItemWhitelist.java | 17 +++---- .../mod/tile/TileEntityRangedCollector.java | 10 ++-- 10 files changed, 56 insertions(+), 63 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerBag.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerBag.java index 91cb03b76..d8755c2c8 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerBag.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerBag.java @@ -192,8 +192,9 @@ public class ContainerBag extends Container implements IButtonReactor{ @Override public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player){ - if(SlotFilter.checkFilter(this, slotId, player)){ - return StackUtil.getNull(); + if(slotId >= 0 && slotId < this.inventorySlots.size() && this.getSlot(slotId) instanceof SlotFilter){ + //Calls the Filter's SlotClick function + return ((SlotFilter)this.getSlot(slotId)).slotClick(player); } else if(clickTypeIn == ClickType.SWAP && dragType == this.inventory.currentItem){ return null; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerFilter.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerFilter.java index 2c9f8687c..a3d857e0d 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerFilter.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerFilter.java @@ -59,7 +59,7 @@ public class ContainerFilter extends Container{ } ItemStack stack = inventory.getCurrentItem(); - if(SlotFilter.isFilter(stack)){ + if(StackUtil.isValid(stack) && stack.getItem() instanceof ItemFilter){ ItemDrill.loadSlotsFromNBT(this.filterInventory.slots, inventory.getCurrentItem()); } } @@ -113,8 +113,9 @@ public class ContainerFilter extends Container{ @Override public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player){ - if(SlotFilter.checkFilter(this, slotId, player)){ - return StackUtil.getNull(); + if(slotId >= 0 && slotId < this.inventorySlots.size() && this.getSlot(slotId) instanceof SlotFilter){ + //Calls the Filter's SlotClick function + return ((SlotFilter)this.getSlot(slotId)).slotClick(player); } else if(clickTypeIn == ClickType.SWAP && dragType == this.inventory.currentItem){ return null; @@ -127,7 +128,7 @@ public class ContainerFilter extends Container{ @Override public void onContainerClosed(EntityPlayer player){ ItemStack stack = this.inventory.getCurrentItem(); - if(SlotFilter.isFilter(stack)){ + if(StackUtil.isValid(stack) && stack.getItem() instanceof ItemFilter){ ItemDrill.writeSlotsToNBT(this.filterInventory.slots, this.inventory.getCurrentItem()); } super.onContainerClosed(player); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerInputter.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerInputter.java index 17af40ce5..40f5f49bd 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerInputter.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerInputter.java @@ -106,8 +106,9 @@ public class ContainerInputter extends Container{ @Override public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player){ - if(SlotFilter.checkFilter(this, slotId, player)){ - return StackUtil.getNull(); + if(slotId >= 0 && slotId < this.inventorySlots.size() && this.getSlot(slotId) instanceof SlotFilter){ + //Calls the Filter's SlotClick function + return ((SlotFilter)this.getSlot(slotId)).slotClick(player); } else{ return super.slotClick(slotId, dragType, clickTypeIn, player); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerLaserRelayItemWhitelist.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerLaserRelayItemWhitelist.java index f6dbfa6c6..485ff092e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerLaserRelayItemWhitelist.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerLaserRelayItemWhitelist.java @@ -94,8 +94,9 @@ public class ContainerLaserRelayItemWhitelist extends Container{ @Override public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player){ - if(SlotFilter.checkFilter(this, slotId, player)){ - return StackUtil.getNull(); + if(slotId >= 0 && slotId < this.inventorySlots.size() && this.getSlot(slotId) instanceof SlotFilter){ + //Calls the Filter's SlotClick function + return ((SlotFilter)this.getSlot(slotId)).slotClick(player); } else{ return super.slotClick(slotId, dragType, clickTypeIn, player); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerRangedCollector.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerRangedCollector.java index ab3d6eae0..342e3a4b6 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerRangedCollector.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerRangedCollector.java @@ -101,8 +101,9 @@ public class ContainerRangedCollector extends Container{ @Override public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player){ - if(SlotFilter.checkFilter(this, slotId, player)){ - return StackUtil.getNull(); + if(slotId >= 0 && slotId < this.inventorySlots.size() && this.getSlot(slotId) instanceof SlotFilter){ + //Calls the Filter's SlotClick function + return ((SlotFilter)this.getSlot(slotId)).slotClick(player); } else{ return super.slotClick(slotId, dragType, clickTypeIn, player); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/slot/SlotFilter.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/slot/SlotFilter.java index 8d6a0630e..4cbb4521f 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/slot/SlotFilter.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/slot/SlotFilter.java @@ -10,10 +10,8 @@ package de.ellpeck.actuallyadditions.mod.inventory.slot; -import de.ellpeck.actuallyadditions.mod.items.ItemFilter; import de.ellpeck.actuallyadditions.mod.util.StackUtil; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; @@ -24,41 +22,30 @@ public class SlotFilter extends Slot{ super(inv, slot, x, y); } - public static boolean checkFilter(Container container, int slotId, EntityPlayer player){ - if(slotId >= 0 && slotId < container.inventorySlots.size()){ - Slot slot = container.getSlot(slotId); - if(slot instanceof SlotFilter){ - ((SlotFilter)slot).slotClick(player); - return true; - } - } - return false; - } - - private void slotClick(EntityPlayer player){ + /** + * Gets called when the Filter Slot is clicked + * Needs to be called in slotClick() in the Container! + * + * @param player The player + * @return Nothing, as the Item didn't really get "transferred" + */ + public ItemStack slotClick(EntityPlayer player){ ItemStack heldStack = player.inventory.getItemStack(); - ItemStack stackInSlot = this.getStack(); - - if(StackUtil.isValid(stackInSlot) && !StackUtil.isValid(heldStack)){ - if(isFilter(stackInSlot)){ - player.inventory.setItemStack(stackInSlot); - } + //Delete the stack in the inventory + if(StackUtil.isValid(this.getStack()) && !StackUtil.isValid(heldStack)){ this.putStack(StackUtil.getNull()); } - else if(StackUtil.isValid(heldStack)){ - if(!isFilter(stackInSlot)){ - this.putStack(StackUtil.setStackSize(heldStack.copy(), 1)); - - if(isFilter(heldStack)){ - player.inventory.setItemStack(StackUtil.addStackSize(heldStack, -1)); - } + //Put the current Item as a filter + else{ + if(StackUtil.isValid(heldStack)){ + ItemStack stack = heldStack.copy(); + stack = StackUtil.setStackSize(stack, 1); + this.putStack(stack); } } - } - public static boolean isFilter(ItemStack stack){ - return StackUtil.isValid(stack) && stack.getItem() instanceof ItemFilter; + return null; } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/FilterSettings.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/FilterSettings.java index dcd25ed67..635a604f0 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/FilterSettings.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/FilterSettings.java @@ -11,7 +11,6 @@ package de.ellpeck.actuallyadditions.mod.tile; import de.ellpeck.actuallyadditions.mod.inventory.ContainerFilter; -import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotFilter; import de.ellpeck.actuallyadditions.mod.items.ItemDrill; import de.ellpeck.actuallyadditions.mod.items.ItemFilter; import de.ellpeck.actuallyadditions.mod.util.StackUtil; @@ -66,7 +65,7 @@ public class FilterSettings{ if(StackUtil.isValid(stack)){ for(int i = startSlot; i < endSlot; i++){ if(StackUtil.isValid(slots[i])){ - if(SlotFilter.isFilter(slots[i])){ + if(slots[i].getItem() instanceof ItemFilter){ ItemStack[] filterSlots = new ItemStack[ContainerFilter.SLOT_AMOUNT]; ItemDrill.loadSlotsFromNBT(filterSlots, slots[i]); if(filterSlots != null && filterSlots.length > 0){ diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityInputter.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityInputter.java index c28359f55..533276ebe 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityInputter.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityInputter.java @@ -231,10 +231,10 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt compound.setInteger("SideToPull", this.sideToPull); compound.setInteger("SlotToPull", this.slotToPullStart); compound.setInteger("SlotToPullEnd", this.slotToPullEnd); - } - this.leftFilter.writeToNBT(compound, "LeftFilter"); - this.rightFilter.writeToNBT(compound, "RightFilter"); + this.leftFilter.writeToNBT(compound, "LeftFilter"); + this.rightFilter.writeToNBT(compound, "RightFilter"); + } } @Override @@ -246,11 +246,10 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt this.sideToPull = compound.getInteger("SideToPull"); this.slotToPullStart = compound.getInteger("SlotToPull"); this.slotToPullEnd = compound.getInteger("SlotToPullEnd"); + + this.leftFilter.readFromNBT(compound, "LeftFilter"); + this.rightFilter.readFromNBT(compound, "RightFilter"); } - - this.leftFilter.readFromNBT(compound, "LeftFilter"); - this.rightFilter.readFromNBT(compound, "RightFilter"); - super.readSyncableNBT(compound, type); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItemWhitelist.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItemWhitelist.java index d7c5eba3d..e0d0a7853 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItemWhitelist.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItemWhitelist.java @@ -11,7 +11,6 @@ package de.ellpeck.actuallyadditions.mod.tile; import de.ellpeck.actuallyadditions.mod.inventory.ContainerFilter; -import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotFilter; import de.ellpeck.actuallyadditions.mod.items.ItemDrill; import de.ellpeck.actuallyadditions.mod.items.ItemFilter; import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor; @@ -181,9 +180,10 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem if(type == NBTType.SAVE_TILE){ TileEntityInventoryBase.saveSlots(this.slots, compound); } - - this.leftFilter.writeToNBT(compound, "LeftFilter"); - this.rightFilter.writeToNBT(compound, "RightFilter"); + if(type != NBTType.SAVE_BLOCK){ + this.leftFilter.writeToNBT(compound, "LeftFilter"); + this.rightFilter.writeToNBT(compound, "RightFilter"); + } } @Override @@ -192,9 +192,10 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem if(type == NBTType.SAVE_TILE){ TileEntityInventoryBase.loadSlots(this.slots, compound); } - - this.leftFilter.readFromNBT(compound, "LeftFilter"); - this.rightFilter.readFromNBT(compound, "RightFilter"); + if(type != NBTType.SAVE_BLOCK){ + this.leftFilter.readFromNBT(compound, "LeftFilter"); + this.rightFilter.readFromNBT(compound, "RightFilter"); + } } @Override @@ -221,7 +222,7 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem if(!FilterSettings.check(copy, this.slots, usedSettings.startSlot, usedSettings.endSlot, true, usedSettings.respectMeta, usedSettings.respectNBT, usedSettings.respectMod, usedSettings.respectOredict)){ for(int k = usedSettings.startSlot; k < usedSettings.endSlot; k++){ if(StackUtil.isValid(this.slots[k])){ - if(SlotFilter.isFilter(this.slots[k])){ + if(this.slots[k].getItem() instanceof ItemFilter){ ItemStack[] filterSlots = new ItemStack[ContainerFilter.SLOT_AMOUNT]; ItemDrill.loadSlotsFromNBT(filterSlots, this.slots[k]); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityRangedCollector.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityRangedCollector.java index 24a8cdc6b..659ad2fd7 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityRangedCollector.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityRangedCollector.java @@ -37,15 +37,17 @@ public class TileEntityRangedCollector extends TileEntityInventoryBase implement @Override public void writeSyncableNBT(NBTTagCompound compound, NBTType type){ super.writeSyncableNBT(compound, type); - - this.filter.writeToNBT(compound, "Filter"); + if(type != NBTType.SAVE_BLOCK){ + this.filter.writeToNBT(compound, "Filter"); + } } @Override public void readSyncableNBT(NBTTagCompound compound, NBTType type){ super.readSyncableNBT(compound, type); - - this.filter.readFromNBT(compound, "Filter"); + if(type != NBTType.SAVE_BLOCK){ + this.filter.readFromNBT(compound, "Filter"); + } } @Override