2015-08-29 14:33:25 +02:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("SlotFilter.java") is part of the Actually Additions mod for Minecraft.
|
2015-08-29 14:33:25 +02:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2017-01-01 16:23:26 +01:00
|
|
|
* © 2015-2017 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.inventory.slot;
|
2015-04-04 05:20:19 +02:00
|
|
|
|
2016-12-03 10:52:03 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.items.ItemFilter;
|
2016-11-27 11:37:55 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.tile.FilterSettings;
|
2018-06-23 01:39:30 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
|
2016-11-16 16:59:00 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
2015-07-29 14:13:47 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2016-12-03 10:52:03 +01:00
|
|
|
import net.minecraft.inventory.Container;
|
2015-04-04 05:20:19 +02:00
|
|
|
import net.minecraft.inventory.Slot;
|
2015-07-29 14:13:47 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2015-04-04 05:20:19 +02:00
|
|
|
|
2016-12-04 00:10:52 +01:00
|
|
|
public class SlotFilter extends SlotItemHandlerUnconditioned{
|
2015-04-04 05:20:19 +02:00
|
|
|
|
2018-06-23 01:39:30 +02:00
|
|
|
public SlotFilter(ItemStackHandlerAA inv, int slot, int x, int y){
|
2015-07-29 14:13:47 +02:00
|
|
|
super(inv, slot, x, y);
|
|
|
|
}
|
|
|
|
|
2016-11-27 11:37:55 +01:00
|
|
|
public SlotFilter(FilterSettings inv, int slot, int x, int y){
|
|
|
|
this(inv.filterInventory, slot, x, y);
|
|
|
|
}
|
|
|
|
|
2016-12-03 10:52:03 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-12-18 17:50:31 +01:00
|
|
|
public static boolean isFilter(ItemStack stack){
|
|
|
|
return StackUtil.isValid(stack) && stack.getItem() instanceof ItemFilter;
|
|
|
|
}
|
|
|
|
|
2016-12-03 10:52:03 +01:00
|
|
|
private void slotClick(EntityPlayer player){
|
2015-07-29 14:13:47 +02:00
|
|
|
ItemStack heldStack = player.inventory.getItemStack();
|
2016-12-03 10:52:03 +01:00
|
|
|
ItemStack stackInSlot = this.getStack();
|
|
|
|
|
|
|
|
if(StackUtil.isValid(stackInSlot) && !StackUtil.isValid(heldStack)){
|
|
|
|
if(isFilter(stackInSlot)){
|
|
|
|
player.inventory.setItemStack(stackInSlot);
|
|
|
|
}
|
2015-07-29 14:13:47 +02:00
|
|
|
|
2017-11-02 22:49:53 +01:00
|
|
|
this.putStack(StackUtil.getEmpty());
|
2015-07-29 14:13:47 +02:00
|
|
|
}
|
2016-12-03 10:52:03 +01:00
|
|
|
else if(StackUtil.isValid(heldStack)){
|
|
|
|
if(!isFilter(stackInSlot)){
|
2018-06-23 19:27:08 +02:00
|
|
|
ItemStack s = heldStack.copy();
|
|
|
|
s.setCount(1);
|
|
|
|
this.putStack(s);
|
2016-12-03 10:52:03 +01:00
|
|
|
|
|
|
|
if(isFilter(heldStack)){
|
2018-06-23 19:27:08 +02:00
|
|
|
heldStack.shrink(1);
|
2016-12-03 10:52:03 +01:00
|
|
|
}
|
2015-07-29 14:13:47 +02:00
|
|
|
}
|
|
|
|
}
|
2016-12-03 10:52:03 +01:00
|
|
|
}
|
2015-07-29 14:13:47 +02:00
|
|
|
|
2015-04-04 05:20:19 +02:00
|
|
|
@Override
|
2015-10-10 02:52:53 +02:00
|
|
|
public boolean isItemValid(ItemStack stack){
|
|
|
|
return false;
|
2015-04-04 05:20:19 +02:00
|
|
|
}
|
2015-06-12 19:12:06 +02:00
|
|
|
|
2015-10-10 02:51:06 +02:00
|
|
|
@Override
|
2015-10-10 02:52:53 +02:00
|
|
|
public void putStack(ItemStack stack){
|
2018-06-23 01:39:30 +02:00
|
|
|
super.putStack(stack.copy());
|
2015-10-10 02:51:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canTakeStack(EntityPlayer player){
|
|
|
|
return false;
|
|
|
|
}
|
2015-04-04 05:20:19 +02:00
|
|
|
}
|