Made Filters be consumed when placing them into filter slots

This commit is contained in:
Ellpeck 2016-12-03 10:52:03 +01:00
parent b8fb63378c
commit 348b3521f6
10 changed files with 68 additions and 62 deletions

View file

@ -191,9 +191,8 @@ public class ContainerBag extends Container implements IButtonReactor{
@Override @Override
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player){ public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player){
if(slotId >= 0 && slotId < this.inventorySlots.size() && this.getSlot(slotId) instanceof SlotFilter){ if(SlotFilter.checkFilter(this, slotId, player)){
//Calls the Filter's SlotClick function return StackUtil.getNull();
return ((SlotFilter)this.getSlot(slotId)).slotClick(player);
} }
else if(clickTypeIn == ClickType.SWAP && dragType == this.inventory.currentItem){ else if(clickTypeIn == ClickType.SWAP && dragType == this.inventory.currentItem){
return null; return null;

View file

@ -58,7 +58,7 @@ public class ContainerFilter extends Container{
} }
ItemStack stack = inventory.getCurrentItem(); ItemStack stack = inventory.getCurrentItem();
if(StackUtil.isValid(stack) && stack.getItem() instanceof ItemFilter){ if(SlotFilter.isFilter(stack)){
ItemDrill.loadSlotsFromNBT(this.filterInventory, inventory.getCurrentItem()); ItemDrill.loadSlotsFromNBT(this.filterInventory, inventory.getCurrentItem());
} }
} }
@ -112,9 +112,8 @@ public class ContainerFilter extends Container{
@Override @Override
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player){ public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player){
if(slotId >= 0 && slotId < this.inventorySlots.size() && this.getSlot(slotId) instanceof SlotFilter){ if(SlotFilter.checkFilter(this, slotId, player)){
//Calls the Filter's SlotClick function return StackUtil.getNull();
return ((SlotFilter)this.getSlot(slotId)).slotClick(player);
} }
else if(clickTypeIn == ClickType.SWAP && dragType == this.inventory.currentItem){ else if(clickTypeIn == ClickType.SWAP && dragType == this.inventory.currentItem){
return null; return null;
@ -127,7 +126,7 @@ public class ContainerFilter extends Container{
@Override @Override
public void onContainerClosed(EntityPlayer player){ public void onContainerClosed(EntityPlayer player){
ItemStack stack = this.inventory.getCurrentItem(); ItemStack stack = this.inventory.getCurrentItem();
if(StackUtil.isValid(stack) && stack.getItem() instanceof ItemFilter){ if(SlotFilter.isFilter(stack)){
ItemDrill.writeSlotsToNBT(this.filterInventory, this.inventory.getCurrentItem()); ItemDrill.writeSlotsToNBT(this.filterInventory, this.inventory.getCurrentItem());
} }
super.onContainerClosed(player); super.onContainerClosed(player);

View file

@ -106,9 +106,8 @@ public class ContainerInputter extends Container{
@Override @Override
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player){ public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player){
if(slotId >= 0 && slotId < this.inventorySlots.size() && this.getSlot(slotId) instanceof SlotFilter){ if(SlotFilter.checkFilter(this, slotId, player)){
//Calls the Filter's SlotClick function return StackUtil.getNull();
return ((SlotFilter)this.getSlot(slotId)).slotClick(player);
} }
else{ else{
return super.slotClick(slotId, dragType, clickTypeIn, player); return super.slotClick(slotId, dragType, clickTypeIn, player);

View file

@ -94,9 +94,8 @@ public class ContainerLaserRelayItemWhitelist extends Container{
@Override @Override
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player){ public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player){
if(slotId >= 0 && slotId < this.inventorySlots.size() && this.getSlot(slotId) instanceof SlotFilter){ if(SlotFilter.checkFilter(this, slotId, player)){
//Calls the Filter's SlotClick function return StackUtil.getNull();
return ((SlotFilter)this.getSlot(slotId)).slotClick(player);
} }
else{ else{
return super.slotClick(slotId, dragType, clickTypeIn, player); return super.slotClick(slotId, dragType, clickTypeIn, player);

View file

@ -101,9 +101,8 @@ public class ContainerRangedCollector extends Container{
@Override @Override
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player){ public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player){
if(slotId >= 0 && slotId < this.inventorySlots.size() && this.getSlot(slotId) instanceof SlotFilter){ if(SlotFilter.checkFilter(this, slotId, player)){
//Calls the Filter's SlotClick function return StackUtil.getNull();
return ((SlotFilter)this.getSlot(slotId)).slotClick(player);
} }
else{ else{
return super.slotClick(slotId, dragType, clickTypeIn, player); return super.slotClick(slotId, dragType, clickTypeIn, player);

View file

@ -10,9 +10,12 @@
package de.ellpeck.actuallyadditions.mod.inventory.slot; package de.ellpeck.actuallyadditions.mod.inventory.slot;
import de.ellpeck.actuallyadditions.mod.items.ItemFilter;
import de.ellpeck.actuallyadditions.mod.tile.FilterSettings; import de.ellpeck.actuallyadditions.mod.tile.FilterSettings;
import de.ellpeck.actuallyadditions.mod.util.StackUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ClickType;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot; import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -27,30 +30,41 @@ public class SlotFilter extends Slot{
this(inv.filterInventory, slot, x, y); this(inv.filterInventory, slot, x, y);
} }
/** public static boolean checkFilter(Container container, int slotId, EntityPlayer player){
* Gets called when the Filter Slot is clicked if(slotId >= 0 && slotId < container.inventorySlots.size()){
* Needs to be called in slotClick() in the Container! Slot slot = container.getSlot(slotId);
* if(slot instanceof SlotFilter){
* @param player The player ((SlotFilter)slot).slotClick(player);
* @return Nothing, as the Item didn't really get "transferred" return true;
*/ }
public ItemStack slotClick(EntityPlayer player){ }
ItemStack heldStack = player.inventory.getItemStack(); return false;
}
private void 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()); this.putStack(StackUtil.getNull());
} }
//Put the current Item as a filter else if(StackUtil.isValid(heldStack)){
else{ if(!isFilter(stackInSlot)){
if(StackUtil.isValid(heldStack)){ this.putStack(StackUtil.setStackSize(heldStack.copy(), 1));
ItemStack stack = heldStack.copy();
stack = StackUtil.setStackSize(stack, 1); if(isFilter(heldStack)){
this.putStack(stack); player.inventory.setItemStack(StackUtil.addStackSize(heldStack, -1));
}
}
} }
} }
return StackUtil.getNull(); public static boolean isFilter(ItemStack stack){
return StackUtil.isValid(stack) && stack.getItem() instanceof ItemFilter;
} }
@Override @Override

View file

@ -11,6 +11,7 @@
package de.ellpeck.actuallyadditions.mod.tile; package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.inventory.ContainerFilter; 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.ItemDrill;
import de.ellpeck.actuallyadditions.mod.items.ItemFilter; import de.ellpeck.actuallyadditions.mod.items.ItemFilter;
import de.ellpeck.actuallyadditions.mod.util.StackUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil;
@ -70,7 +71,7 @@ public class FilterSettings{
if(areEqualEnough(slot, stack, meta, nbt, mod, oredict)){ if(areEqualEnough(slot, stack, meta, nbt, mod, oredict)){
return whitelist; return whitelist;
} }
else if(slot.getItem() instanceof ItemFilter){ else if(SlotFilter.isFilter(slot)){
IInventory inv = new InventoryBasic("Filter", false, ContainerFilter.SLOT_AMOUNT); IInventory inv = new InventoryBasic("Filter", false, ContainerFilter.SLOT_AMOUNT);
ItemDrill.loadSlotsFromNBT(inv, slot); ItemDrill.loadSlotsFromNBT(inv, slot);
for(int k = 0; k < inv.getSizeInventory(); k++){ for(int k = 0; k < inv.getSizeInventory(); k++){

View file

@ -21,7 +21,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.NonNullList;
import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
@ -234,11 +233,11 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
compound.setInteger("SideToPull", this.sideToPull); compound.setInteger("SideToPull", this.sideToPull);
compound.setInteger("SlotToPull", this.slotToPullStart); compound.setInteger("SlotToPull", this.slotToPullStart);
compound.setInteger("SlotToPullEnd", this.slotToPullEnd); compound.setInteger("SlotToPullEnd", this.slotToPullEnd);
}
this.leftFilter.writeToNBT(compound, "LeftFilter"); this.leftFilter.writeToNBT(compound, "LeftFilter");
this.rightFilter.writeToNBT(compound, "RightFilter"); this.rightFilter.writeToNBT(compound, "RightFilter");
} }
}
@Override @Override
public void readSyncableNBT(NBTTagCompound compound, NBTType type){ public void readSyncableNBT(NBTTagCompound compound, NBTType type){
@ -249,10 +248,11 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
this.sideToPull = compound.getInteger("SideToPull"); this.sideToPull = compound.getInteger("SideToPull");
this.slotToPullStart = compound.getInteger("SlotToPull"); this.slotToPullStart = compound.getInteger("SlotToPull");
this.slotToPullEnd = compound.getInteger("SlotToPullEnd"); this.slotToPullEnd = compound.getInteger("SlotToPullEnd");
}
this.leftFilter.readFromNBT(compound, "LeftFilter"); this.leftFilter.readFromNBT(compound, "LeftFilter");
this.rightFilter.readFromNBT(compound, "RightFilter"); this.rightFilter.readFromNBT(compound, "RightFilter");
}
super.readSyncableNBT(compound, type); super.readSyncableNBT(compound, type);
} }

View file

@ -11,8 +11,8 @@
package de.ellpeck.actuallyadditions.mod.tile; package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.inventory.ContainerFilter; 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.ItemDrill;
import de.ellpeck.actuallyadditions.mod.items.ItemFilter;
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor; import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
import de.ellpeck.actuallyadditions.mod.util.StackUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
@ -44,20 +44,18 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
@Override @Override
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){ public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
super.writeSyncableNBT(compound, type); super.writeSyncableNBT(compound, type);
if(type != NBTType.SAVE_BLOCK){
this.leftFilter.writeToNBT(compound, "LeftFilter"); this.leftFilter.writeToNBT(compound, "LeftFilter");
this.rightFilter.writeToNBT(compound, "RightFilter"); this.rightFilter.writeToNBT(compound, "RightFilter");
} }
}
@Override @Override
public void readSyncableNBT(NBTTagCompound compound, NBTType type){ public void readSyncableNBT(NBTTagCompound compound, NBTType type){
super.readSyncableNBT(compound, type); super.readSyncableNBT(compound, type);
if(type != NBTType.SAVE_BLOCK){
this.leftFilter.readFromNBT(compound, "LeftFilter"); this.leftFilter.readFromNBT(compound, "LeftFilter");
this.rightFilter.readFromNBT(compound, "RightFilter"); this.rightFilter.readFromNBT(compound, "RightFilter");
} }
}
@Override @Override
public void onButtonPressed(int buttonID, EntityPlayer player){ public void onButtonPressed(int buttonID, EntityPlayer player){
@ -84,7 +82,7 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
for(int k = 0; k < usedSettings.filterInventory.getSizeInventory(); k++){ for(int k = 0; k < usedSettings.filterInventory.getSizeInventory(); k++){
ItemStack slot = usedSettings.filterInventory.getStackInSlot(k); ItemStack slot = usedSettings.filterInventory.getStackInSlot(k);
if(StackUtil.isValid(slot)){ if(StackUtil.isValid(slot)){
if(slot.getItem() instanceof ItemFilter){ if(SlotFilter.isFilter(slot)){
IInventory inv = new InventoryBasic("Filter", false, ContainerFilter.SLOT_AMOUNT); IInventory inv = new InventoryBasic("Filter", false, ContainerFilter.SLOT_AMOUNT);
ItemDrill.loadSlotsFromNBT(inv, slot); ItemDrill.loadSlotsFromNBT(inv, slot);

View file

@ -36,18 +36,16 @@ public class TileEntityRangedCollector extends TileEntityInventoryBase implement
@Override @Override
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){ public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
super.writeSyncableNBT(compound, type); super.writeSyncableNBT(compound, type);
if(type != NBTType.SAVE_BLOCK){
this.filter.writeToNBT(compound, "Filter"); this.filter.writeToNBT(compound, "Filter");
} }
}
@Override @Override
public void readSyncableNBT(NBTTagCompound compound, NBTType type){ public void readSyncableNBT(NBTTagCompound compound, NBTType type){
super.readSyncableNBT(compound, type); super.readSyncableNBT(compound, type);
if(type != NBTType.SAVE_BLOCK){
this.filter.readFromNBT(compound, "Filter"); this.filter.readFromNBT(compound, "Filter");
} }
}
@Override @Override
public void updateEntity(){ public void updateEntity(){