From d3b9d575ea213accb92159fec6040ea92e575305 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 29 Jul 2015 14:13:47 +0200 Subject: [PATCH] Made the Slots in the ESD actual filter slots that don't consume Items because people were annoying me with it --- .../inventory/ContainerInputter.java | 25 +++++++++---- .../inventory/slot/SlotFilter.java | 37 +++++++++++++++++-- 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerInputter.java b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerInputter.java index 65794c470..ec571a3c7 100644 --- a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerInputter.java +++ b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerInputter.java @@ -22,12 +22,12 @@ public class ContainerInputter extends Container{ this.tileInputter = (TileEntityInputter)tile; this.isAdvanced = isAdvanced; - this.addSlotToContainer(new Slot(this.tileInputter, 0, 80, 21 + (isAdvanced ? 12 : 0))); + this.addSlotToContainer(new Slot(this.tileInputter, 0, 80, 21+(isAdvanced ? 12 : 0))); if(isAdvanced){ for(int i = 0; i < 2; i++){ for(int x = 0; x < 3; x++){ - for(int y = 0;y < 4; y++){ + for(int y = 0; y < 4; y++){ this.addSlotToContainer(new SlotFilter(this.tileInputter, 1+y+x*4+i*12, 20+i*84+x*18, 6+y*18)); } } @@ -35,12 +35,12 @@ public class ContainerInputter extends Container{ } for(int i = 0; i < 3; i++){ - for (int j = 0; j < 9; j++){ - this.addSlotToContainer(new Slot(inventory, j + i * 9 + 9, 8 + j * 18, 97 + i * 18 + (isAdvanced ? GuiInputter.OFFSET_ADVANCED : 0))); + for(int j = 0; j < 9; j++){ + this.addSlotToContainer(new Slot(inventory, j+i*9+9, 8+j*18, 97+i*18+(isAdvanced ? GuiInputter.OFFSET_ADVANCED : 0))); } } for(int i = 0; i < 9; i++){ - this.addSlotToContainer(new Slot(inventory, i, 8 + i * 18, 155 + (isAdvanced ? GuiInputter.OFFSET_ADVANCED : 0))); + this.addSlotToContainer(new Slot(inventory, i, 8+i*18, 155+(isAdvanced ? GuiInputter.OFFSET_ADVANCED : 0))); } } @@ -49,6 +49,15 @@ public class ContainerInputter extends Container{ return this.tileInputter.isUseableByPlayer(player); } + @Override + public ItemStack slotClick(int par1, int par2, int par3, EntityPlayer player){ + if(par1 >= 0 && par1 < this.inventorySlots.size() && this.getSlot(par1) instanceof SlotFilter){ + //Calls the Filter's SlotClick function + return ((SlotFilter)getSlot(par1)).slotClick(player, par2); + } + else return super.slotClick(par1, par2, par3, player); + } + @Override public ItemStack transferStackInSlot(EntityPlayer player, int slot){ final int inventoryStart = this.isAdvanced ? 25 : 1; @@ -58,7 +67,7 @@ public class ContainerInputter extends Container{ Slot theSlot = (Slot)this.inventorySlots.get(slot); - if (theSlot != null && theSlot.getHasStack()){ + if(theSlot != null && theSlot.getHasStack()){ ItemStack newStack = theSlot.getStack(); ItemStack currentStack = newStack.copy(); @@ -76,10 +85,10 @@ public class ContainerInputter extends Container{ } else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)) return null; - if (newStack.stackSize == 0) theSlot.putStack(null); + if(newStack.stackSize == 0) theSlot.putStack(null); else theSlot.onSlotChanged(); - if (newStack.stackSize == currentStack.stackSize) return null; + if(newStack.stackSize == currentStack.stackSize) return null; theSlot.onPickupFromSlot(player, newStack); return currentStack; diff --git a/src/main/java/ellpeck/actuallyadditions/inventory/slot/SlotFilter.java b/src/main/java/ellpeck/actuallyadditions/inventory/slot/SlotFilter.java index 873ab776e..c19ed8a7f 100644 --- a/src/main/java/ellpeck/actuallyadditions/inventory/slot/SlotFilter.java +++ b/src/main/java/ellpeck/actuallyadditions/inventory/slot/SlotFilter.java @@ -1,17 +1,46 @@ package ellpeck.actuallyadditions.inventory.slot; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; public class SlotFilter extends Slot{ - public SlotFilter(IInventory inventory, int id, int x, int y){ - super(inventory, id, x, y); + public SlotFilter(IInventory inv, int slot, int x, int y){ + super(inv, slot, x, y); + } + + /** + * Gets called when the Filter Slot is clicked + * Needs to be called in slotClick() in the Container! + * @param player The player + * @param button The button pressed (1 is right mouse button!) + * @return Nothing, as the Item didn't really get "transferred" + */ + public ItemStack slotClick(EntityPlayer player, int button){ + ItemStack heldStack = player.inventory.getItemStack(); + + //Delete the stack in the inventory + if(this.getStack() != null && heldStack == null){ + this.putStack(null); + } + //Put the current Item as a filter + else{ + if(heldStack != null){ + ItemStack stack = heldStack.copy(); + stack.stackSize = 1; + this.putStack(stack); + } + } + + return null; } @Override - public int getSlotStackLimit(){ - return 1; + public void putStack(ItemStack stack){ + ItemStack theStack = (stack != null ? stack.copy() : null); + super.putStack(theStack); } }