2020-04-16 23:40:35 +02:00
|
|
|
package de.ellpeck.prettypipes.pipe.modules.insertion;
|
2020-04-16 21:19:40 +02:00
|
|
|
|
|
|
|
import de.ellpeck.prettypipes.Registry;
|
|
|
|
import de.ellpeck.prettypipes.items.IModule;
|
|
|
|
import de.ellpeck.prettypipes.items.ModuleItem;
|
|
|
|
import de.ellpeck.prettypipes.items.ModuleTier;
|
2022-06-30 16:35:01 +02:00
|
|
|
import de.ellpeck.prettypipes.misc.DirectionSelector;
|
2020-04-16 21:19:40 +02:00
|
|
|
import de.ellpeck.prettypipes.misc.ItemFilter;
|
2021-12-02 14:44:26 +01:00
|
|
|
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
2020-05-07 15:48:46 +02:00
|
|
|
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
2022-06-30 16:00:33 +02:00
|
|
|
import net.minecraft.core.Direction;
|
2021-12-02 16:55:04 +01:00
|
|
|
import net.minecraft.world.entity.player.Inventory;
|
|
|
|
import net.minecraft.world.entity.player.Player;
|
2021-12-02 12:31:04 +01:00
|
|
|
import net.minecraft.world.item.ItemStack;
|
2024-02-03 15:17:58 +01:00
|
|
|
import net.neoforged.neoforge.items.IItemHandler;
|
2020-04-16 21:19:40 +02:00
|
|
|
|
|
|
|
public class FilterModuleItem extends ModuleItem {
|
|
|
|
|
|
|
|
public final int filterSlots;
|
2021-03-03 00:10:24 +01:00
|
|
|
private final boolean canPopulateFromInventories;
|
2020-04-16 21:19:40 +02:00
|
|
|
|
|
|
|
public FilterModuleItem(String name, ModuleTier tier) {
|
|
|
|
super(name);
|
|
|
|
this.filterSlots = tier.forTier(5, 9, 18);
|
2020-04-16 22:25:58 +02:00
|
|
|
this.canPopulateFromInventories = tier.forTier(false, false, true);
|
2020-04-16 21:19:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-06-30 16:00:33 +02:00
|
|
|
public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack, Direction direction, IItemHandler destination) {
|
2023-09-26 10:51:43 +02:00
|
|
|
return !this.getDirectionSelector(module, tile).has(direction) || this.getItemFilter(module, tile).isAllowed(stack, direction);
|
2020-04-16 21:19:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-02 14:44:26 +01:00
|
|
|
public boolean isCompatible(ItemStack module, PipeBlockEntity tile, IModule other) {
|
2020-04-16 21:19:40 +02:00
|
|
|
return !(other instanceof FilterModuleItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-02 14:44:26 +01:00
|
|
|
public boolean hasContainer(ItemStack module, PipeBlockEntity tile) {
|
2020-04-16 21:19:40 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-02 16:55:04 +01:00
|
|
|
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeBlockEntity tile, int windowId, Inventory inv, Player player, int moduleIndex) {
|
|
|
|
return new FilterModuleContainer(Registry.filterModuleContainer, windowId, player, tile.getBlockPos(), moduleIndex);
|
2020-04-16 21:19:40 +02:00
|
|
|
}
|
2021-03-03 00:10:24 +01:00
|
|
|
|
|
|
|
@Override
|
2021-12-02 14:44:26 +01:00
|
|
|
public ItemFilter getItemFilter(ItemStack module, PipeBlockEntity tile) {
|
2021-12-02 17:46:56 +01:00
|
|
|
var filter = new ItemFilter(this.filterSlots, module, tile);
|
2021-03-03 00:10:24 +01:00
|
|
|
filter.canPopulateFromInventories = this.canPopulateFromInventories;
|
|
|
|
return filter;
|
|
|
|
}
|
2022-06-30 16:35:01 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public DirectionSelector getDirectionSelector(ItemStack module, PipeBlockEntity tile) {
|
|
|
|
return new DirectionSelector(module, tile);
|
|
|
|
}
|
2023-09-26 10:51:43 +02:00
|
|
|
|
2020-04-16 21:19:40 +02:00
|
|
|
}
|