Skip to content

Commit

Permalink
Fix entities' item_handler_automation capability getting ignored in c…
Browse files Browse the repository at this point in the history
…ertain cases (#995)
  • Loading branch information
bl4ckscor3 authored May 26, 2024
1 parent 309042a commit 039852a
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package net.neoforged.neoforge.items;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -209,10 +210,12 @@ private static Optional<Pair<IItemHandler, Object>> getItemHandlerAt(Level world
// Note: the isAlive check matches what vanilla does for hoppers in EntitySelector.CONTAINER_ENTITY_SELECTOR
List<Entity> list = worldIn.getEntities((Entity) null, new AABB(x - 0.5D, y - 0.5D, z - 0.5D, x + 0.5D, y + 0.5D, z + 0.5D), EntitySelector.ENTITY_STILL_ALIVE);
if (!list.isEmpty()) {
var entity = list.get(worldIn.random.nextInt(list.size()));
var entityCap = entity.getCapability(Capabilities.ItemHandler.ENTITY_AUTOMATION, side);
if (entityCap != null)
return Optional.of(ImmutablePair.of(entityCap, entity));
Collections.shuffle(list);
for (Entity entity : list) {
IItemHandler entityCap = entity.getCapability(Capabilities.ItemHandler.ENTITY_AUTOMATION, side);
if (entityCap != null)
return Optional.of(ImmutablePair.of(entityCap, entity));
}
}

return Optional.empty();
Expand Down

0 comments on commit 039852a

Please sign in to comment.