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;
|
2024-03-02 21:23:08 +01:00
|
|
|
import net.minecraft.world.entity.player.Player;
|
|
|
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
|
|
|
import net.minecraft.world.inventory.Slot;
|
|
|
|
import net.minecraft.world.item.ItemStack;
|
2015-04-04 05:20:19 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public class SlotFilter extends SlotItemHandlerUnconditioned {
|
2015-04-04 05:20:19 +02:00
|
|
|
|
2019-05-02 09:10:29 +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);
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public SlotFilter(FilterSettings inv, int slot, int x, int y) {
|
2016-11-27 11:37:55 +01:00
|
|
|
this(inv.filterInventory, slot, x, y);
|
|
|
|
}
|
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
public static boolean checkFilter(AbstractContainerMenu container, int slotId, Player player) {
|
2021-08-22 17:09:06 +02:00
|
|
|
if (slotId >= 0 && slotId < container.slots.size()) {
|
2016-12-03 10:52:03 +01:00
|
|
|
Slot slot = container.getSlot(slotId);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (slot instanceof SlotFilter) {
|
2024-03-05 23:23:49 +01:00
|
|
|
((SlotFilter) slot).slotClick(player, container.getCarried());
|
2016-12-03 10:52:03 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public static boolean isFilter(ItemStack stack) {
|
2024-03-04 22:37:11 +01:00
|
|
|
return !stack.isEmpty() && stack.getItem() instanceof ItemFilter;
|
2016-12-18 17:50:31 +01:00
|
|
|
}
|
|
|
|
|
2024-03-05 23:23:49 +01:00
|
|
|
private void slotClick(Player player, ItemStack cursorItem) {
|
2021-08-22 17:09:06 +02:00
|
|
|
ItemStack stackInSlot = this.getItem();
|
2024-03-16 18:25:35 +01:00
|
|
|
if (!stackInSlot.isEmpty() && cursorItem.isEmpty()) {
|
2019-05-02 09:10:29 +02:00
|
|
|
if (isFilter(stackInSlot)) {
|
2024-03-16 18:25:35 +01:00
|
|
|
player.containerMenu.setCarried(stackInSlot);
|
2016-12-03 10:52:03 +01:00
|
|
|
}
|
2015-07-29 14:13:47 +02:00
|
|
|
|
2022-06-24 21:38:07 +02:00
|
|
|
this.set(ItemStack.EMPTY);
|
2024-03-16 18:25:35 +01:00
|
|
|
} else if (StackUtil.isValid(cursorItem)) {
|
2019-05-02 09:10:29 +02:00
|
|
|
if (!isFilter(stackInSlot)) {
|
2024-03-16 18:25:35 +01:00
|
|
|
ItemStack s = cursorItem.copy();
|
2018-06-23 19:27:08 +02:00
|
|
|
s.setCount(1);
|
2021-08-22 17:09:06 +02:00
|
|
|
this.set(s);
|
2016-12-03 10:52:03 +01:00
|
|
|
|
2024-03-16 18:25:35 +01:00
|
|
|
if (isFilter(cursorItem)) {
|
|
|
|
cursorItem.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
|
2021-08-22 17:09:06 +02:00
|
|
|
public boolean mayPlace(ItemStack stack) {
|
2015-10-10 02:52:53 +02:00
|
|
|
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
|
2021-08-22 17:09:06 +02:00
|
|
|
public void set(ItemStack stack) {
|
|
|
|
super.set(stack.copy());
|
2015-10-10 02:51:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2024-03-02 21:23:08 +01:00
|
|
|
public boolean mayPickup(Player player) {
|
2015-10-10 02:51:06 +02:00
|
|
|
return false;
|
|
|
|
}
|
2015-04-04 05:20:19 +02:00
|
|
|
}
|