make filters be consumed when putting them into filter slots

This commit is contained in:
Ellpeck 2016-12-27 12:08:00 +01:00
parent 7303b3b68c
commit 8e3ea19bcd
10 changed files with 67 additions and 60 deletions

View file

@ -192,9 +192,8 @@ public class ContainerBag extends Container implements IButtonReactor{
@Override
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player){
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);
if(SlotFilter.checkFilter(this, slotId, player)){
return StackUtil.getNull();
}
else if(clickTypeIn == ClickType.SWAP && dragType == this.inventory.currentItem){
return null;

View file

@ -59,7 +59,7 @@ public class ContainerFilter extends Container{
}
ItemStack stack = inventory.getCurrentItem();
if(StackUtil.isValid(stack) && stack.getItem() instanceof ItemFilter){
if(SlotFilter.isFilter(stack)){
ItemDrill.loadSlotsFromNBT(this.filterInventory.slots, inventory.getCurrentItem());
}
}
@ -113,9 +113,8 @@ public class ContainerFilter extends Container{
@Override
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player){
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);
if(SlotFilter.checkFilter(this, slotId, player)){
return StackUtil.getNull();
}
else if(clickTypeIn == ClickType.SWAP && dragType == this.inventory.currentItem){
return null;
@ -128,7 +127,7 @@ public class ContainerFilter extends Container{
@Override
public void onContainerClosed(EntityPlayer player){
ItemStack stack = this.inventory.getCurrentItem();
if(StackUtil.isValid(stack) && stack.getItem() instanceof ItemFilter){
if(SlotFilter.isFilter(stack)){
ItemDrill.writeSlotsToNBT(this.filterInventory.slots, this.inventory.getCurrentItem());
}
super.onContainerClosed(player);

View file

@ -106,9 +106,8 @@ public class ContainerInputter extends Container{
@Override
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player){
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);
if(SlotFilter.checkFilter(this, slotId, player)){
return StackUtil.getNull();
}
else{
return super.slotClick(slotId, dragType, clickTypeIn, player);

View file

@ -94,9 +94,8 @@ public class ContainerLaserRelayItemWhitelist extends Container{
@Override
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player){
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);
if(SlotFilter.checkFilter(this, slotId, player)){
return StackUtil.getNull();
}
else{
return super.slotClick(slotId, dragType, clickTypeIn, player);

View file

@ -101,9 +101,8 @@ public class ContainerRangedCollector extends Container{
@Override
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player){
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);
if(SlotFilter.checkFilter(this, slotId, player)){
return StackUtil.getNull();
}
else{
return super.slotClick(slotId, dragType, clickTypeIn, player);

View file

@ -10,8 +10,10 @@
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;
@ -22,30 +24,41 @@ public class SlotFilter extends Slot{
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
* @return Nothing, as the Item didn't really get "transferred"
*/
public ItemStack slotClick(EntityPlayer player){
ItemStack heldStack = player.inventory.getItemStack();
//Delete the stack in the inventory
if(StackUtil.isValid(this.getStack()) && !StackUtil.isValid(heldStack)){
this.putStack(StackUtil.getNull());
}
//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 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;
}
return null;
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);
}
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));
}
}
}
}
public static boolean isFilter(ItemStack stack){
return StackUtil.isValid(stack) && stack.getItem() instanceof ItemFilter;
}
@Override

View file

@ -11,6 +11,7 @@
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;
@ -65,7 +66,7 @@ public class FilterSettings{
if(StackUtil.isValid(stack)){
for(int i = startSlot; i < endSlot; i++){
if(StackUtil.isValid(slots[i])){
if(slots[i].getItem() instanceof ItemFilter){
if(SlotFilter.isFilter(slots[i])){
ItemStack[] filterSlots = new ItemStack[ContainerFilter.SLOT_AMOUNT];
ItemDrill.loadSlotsFromNBT(filterSlots, slots[i]);
if(filterSlots != null && filterSlots.length > 0){

View file

@ -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,10 +246,11 @@ 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);
}

View file

@ -11,6 +11,7 @@
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;
@ -180,10 +181,9 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
if(type == NBTType.SAVE_TILE){
TileEntityInventoryBase.saveSlots(this.slots, compound);
}
if(type != NBTType.SAVE_BLOCK){
this.leftFilter.writeToNBT(compound, "LeftFilter");
this.rightFilter.writeToNBT(compound, "RightFilter");
}
this.leftFilter.writeToNBT(compound, "LeftFilter");
this.rightFilter.writeToNBT(compound, "RightFilter");
}
@Override
@ -192,10 +192,9 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
if(type == NBTType.SAVE_TILE){
TileEntityInventoryBase.loadSlots(this.slots, compound);
}
if(type != NBTType.SAVE_BLOCK){
this.leftFilter.readFromNBT(compound, "LeftFilter");
this.rightFilter.readFromNBT(compound, "RightFilter");
}
this.leftFilter.readFromNBT(compound, "LeftFilter");
this.rightFilter.readFromNBT(compound, "RightFilter");
}
@Override
@ -222,7 +221,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(this.slots[k].getItem() instanceof ItemFilter){
if(SlotFilter.isFilter(this.slots[k])){
ItemStack[] filterSlots = new ItemStack[ContainerFilter.SLOT_AMOUNT];
ItemDrill.loadSlotsFromNBT(filterSlots, this.slots[k]);

View file

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