RFTools

RFTools

74M Downloads

Sensor not correctly detecting entities in a stack

eslachance opened this issue ยท 5 comments

commented

I'm attempting to trigger an action whenever a stack of items is detected, dropped on the floor. Unfortunately, while the sensor easily detects a single entity item in front of it, as soon as the items merge into a stack, the detection stops working correctly.

2016-11-26_13 19 40

I also tried this with Cobblestone.

Note that I'm on the Direwolf20 pack (1.10.2).

commented

Not sure how or if I should solve that because technically a stack of cobble is a single entity. Have to think about that

commented

Users shouldn't need to know how Minecraft is implemented internally to understand the behavior of their tools. As an ordinary user, I would expect it to work the same way that the OP expected it to. As for how the problem can be solved, this seems to work for me (in SensorTileEntity.java):

private boolean checkEntities(BlockPos pos1, EnumFacing dir, Class<? extends Entity> clazz) {
        List<Entity> entities = worldObj.getEntitiesWithinAABB(clazz, getCachedBox(pos1, dir));
        int entityCount = entities.size();
        for (Entity entity : entities) {
            if (entity instanceof EntityItem) {
                int stackSize = getEntityItemStackSize((EntityItem)entity);
                // 1 entity is already included in the result of entities.size().
                entityCount += (stackSize - 1);
            }
        }

        return entityCount >= number;
    }
    
    private int getEntityItemStackSize(EntityItem entityItem) {
        ItemStack stack = entityItem.getEntityItem();
        if (stack == null) {
            return 0;
        }

        return stack.stackSize;
    }
commented

@McJty, would you prefer to have a separate Items mode? That should meet everyone's needs without affecting backward-compatibility; people who want the new behavior can use the Items mode and people who want the old behavior can use the Entities mode.

commented

yes, that might be a good idea yes

commented

@eslachance, your screenshot shows that you tried to use the filter slot in Entities mode. Please note that the only modes in which filters do anything are Block, Fluid, and the proposed Items mode. In the future, we should probably hide the filter slot while other modes are selected so that users aren't misled into thinking it works in every mode.