From 0167e5194ceb21a829008432b73c4320836a6eeb Mon Sep 17 00:00:00 2001 From: Elenterius Date: Fri, 15 Mar 2024 16:58:29 +0100 Subject: [PATCH] fix: fix maw hopper stealing items from villagers & witches Closes: #122 --- .../block/mawhopper/MawHopperBlockEntity.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/github/elenterius/biomancy/block/mawhopper/MawHopperBlockEntity.java b/src/main/java/com/github/elenterius/biomancy/block/mawhopper/MawHopperBlockEntity.java index 9ccaafddb..f478188e5 100644 --- a/src/main/java/com/github/elenterius/biomancy/block/mawhopper/MawHopperBlockEntity.java +++ b/src/main/java/com/github/elenterius/biomancy/block/mawhopper/MawHopperBlockEntity.java @@ -44,16 +44,22 @@ public class MawHopperBlockEntity extends BlockEntity implements GeoBlockEntity public static final int ITEM_TRANSFER_AMOUNT = 16; public static final int DURATION = 11; public static final int DELAY = 8 + 1; + + public static final Predicate CONTAINER_ENTITY_SELECTOR = entity -> + entity.isAlive() + && (EntitySelector.CONTAINER_ENTITY_SELECTOR.test(entity) || entity instanceof Player) + && entity.getCapability(ModCapabilities.ITEM_HANDLER, null).isPresent(); + protected static final RawAnimation IDLE_ANIM = RawAnimation.begin().thenLoop("maw_hopper.idle"); protected static final RawAnimation PUMPING_ANIM = RawAnimation.begin().thenLoop("maw_hopper.pumping"); + private final SingleItemStackHandler inventory; + private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); + private int ticks = BiomancyMod.GLOBAL_RANDOM.nextInt(DURATION); //add random tick offset - private final SingleItemStackHandler inventory; private LazyOptional optionalItemHandler; - private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); - public MawHopperBlockEntity(BlockPos pos, BlockState blockState) { super(ModBlockEntities.MAW_HOPPER.get(), pos, blockState); inventory = new SingleItemStackHandler() { @@ -79,7 +85,7 @@ private static LazyOptional getItemHandler(ServerLevel level, Bloc } } - List list = level.getEntities((Entity) null, new AABB(pos), entity -> entity.getCapability(ModCapabilities.ITEM_HANDLER, direction).isPresent()); + List list = level.getEntities((Entity) null, new AABB(pos), CONTAINER_ENTITY_SELECTOR); if (!list.isEmpty()) { int index = level.random.nextInt(list.size()); return list.get(index).getCapability(ModCapabilities.ITEM_HANDLER, direction);