mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-06-28 21:48:19 +02:00
54 lines
1.6 KiB
Java
54 lines
1.6 KiB
Java
|
package de.ellpeck.prettypipes.misc;
|
||
|
|
||
|
import net.minecraft.entity.player.PlayerEntity;
|
||
|
import net.minecraft.inventory.container.Container;
|
||
|
import net.minecraft.inventory.container.Slot;
|
||
|
import net.minecraft.item.ItemStack;
|
||
|
import net.minecraftforge.items.IItemHandler;
|
||
|
import net.minecraftforge.items.SlotItemHandler;
|
||
|
|
||
|
public class SlotFilter extends SlotItemHandler {
|
||
|
public SlotFilter(IItemHandler itemHandler, int index, int xPosition, int yPosition) {
|
||
|
super(itemHandler, index, xPosition, yPosition);
|
||
|
}
|
||
|
|
||
|
public static boolean checkFilter(Container container, int slotId, PlayerEntity 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;
|
||
|
}
|
||
|
|
||
|
private void slotClick(PlayerEntity player) {
|
||
|
ItemStack heldStack = player.inventory.getItemStack();
|
||
|
ItemStack stackInSlot = this.getStack();
|
||
|
|
||
|
if (!stackInSlot.isEmpty() && heldStack.isEmpty()) {
|
||
|
this.putStack(ItemStack.EMPTY);
|
||
|
} else if (!heldStack.isEmpty()) {
|
||
|
ItemStack s = heldStack.copy();
|
||
|
s.setCount(1);
|
||
|
this.putStack(s);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public boolean isItemValid(ItemStack stack) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void putStack(ItemStack stack) {
|
||
|
super.putStack(stack.copy());
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public boolean canTakeStack(PlayerEntity playerIn) {
|
||
|
return false;
|
||
|
}
|
||
|
}
|