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
|
|
|
|
*
|
2016-05-16 22:54:42 +02:00
|
|
|
* © 2015-2016 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-11-27 11:37:55 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.tile.FilterSettings;
|
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;
|
2015-04-04 05:20:19 +02:00
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
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
|
|
|
|
|
|
|
public class SlotFilter extends Slot{
|
|
|
|
|
2015-07-29 14:13:47 +02:00
|
|
|
public SlotFilter(IInventory inv, int slot, int x, int y){
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-07-29 14:13:47 +02:00
|
|
|
/**
|
|
|
|
* Gets called when the Filter Slot is clicked
|
|
|
|
* Needs to be called in slotClick() in the Container!
|
2015-10-02 16:48:01 +02:00
|
|
|
*
|
2015-07-29 14:13:47 +02:00
|
|
|
* @param player The player
|
|
|
|
* @return Nothing, as the Item didn't really get "transferred"
|
|
|
|
*/
|
2015-10-10 02:52:53 +02:00
|
|
|
public ItemStack slotClick(EntityPlayer player){
|
2015-07-29 14:13:47 +02:00
|
|
|
ItemStack heldStack = player.inventory.getItemStack();
|
|
|
|
|
|
|
|
//Delete the stack in the inventory
|
2016-11-16 20:31:16 +01:00
|
|
|
if(StackUtil.isValid(this.getStack()) && !StackUtil.isValid(heldStack)){
|
|
|
|
this.putStack(StackUtil.getNull());
|
2015-07-29 14:13:47 +02:00
|
|
|
}
|
|
|
|
//Put the current Item as a filter
|
|
|
|
else{
|
2016-11-16 20:31:16 +01:00
|
|
|
if(StackUtil.isValid(heldStack)){
|
2015-07-29 14:13:47 +02:00
|
|
|
ItemStack stack = heldStack.copy();
|
2016-11-16 16:59:00 +01:00
|
|
|
stack = StackUtil.setStackSize(stack, 1);
|
2015-07-29 14:13:47 +02:00
|
|
|
this.putStack(stack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-25 22:05:45 +01:00
|
|
|
return StackUtil.getNull();
|
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){
|
2016-11-16 20:31:16 +01:00
|
|
|
super.putStack(StackUtil.validateCopy(stack));
|
2015-10-10 02:51:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canTakeStack(EntityPlayer player){
|
|
|
|
return false;
|
|
|
|
}
|
2015-04-04 05:20:19 +02:00
|
|
|
}
|