1
\$\begingroup\$

The title mostly explains it. I have a tile entity that is called Energizer. I want this energizer to check to see if there is an EntityItem on top of it and if so, consume it and create energy. The only problem is, I can't figure out how to check for (and receive) an EntityItem in a certain location (on top of it). I considered using a method that searches for nearby entities and then seeing if they were instanceof EntityItem, but I can't even find a method to do that.

\$\endgroup\$
6
  • \$\begingroup\$ Please consider expanding the question with some more details. For example I'm sure you have an event or a specific method that is called when the EntityItem is placed somewhere. It would be useful for better answers to know the sequence of actions that happens when doing this. \$\endgroup\$ Apr 21, 2015 at 11:07
  • \$\begingroup\$ no, I don't have an event like that, because I am hoping to control this all from only the machine, so that it works with all items without me having to modify them. \$\endgroup\$ Apr 21, 2015 at 16:54
  • \$\begingroup\$ Ok. And have you already considered using a collider on top of your Energizer and use OnTriggerEnter to make the association? (Or something like that if not Unity) \$\endgroup\$ Apr 21, 2015 at 17:20
  • \$\begingroup\$ It's not unity. It's minecraft, so there isnt such a thing as a collider (as far as I know) \$\endgroup\$ Apr 21, 2015 at 17:38
  • \$\begingroup\$ i don't know Minecraft Forge well enough but there must be the way to check the distance between two objects or just get their positions so you can compare distance on the X and Y plane and if EntityItem's Z if higher that your Energizer's. \$\endgroup\$ Apr 21, 2015 at 17:59

1 Answer 1

2
\$\begingroup\$

First off, you want to override ITickable#update() in your Energizer TileEntity. Inside here is where you can scan for nearby EntityItems. With the TileEntity#worldObj member you can use World#getEntitiesWithinAABB(Class, AxisAlignedBB) to find any entities of a given class within the defined bounding box (i.e., right above your tile entity).

@Override
public void update() {
    // Create bounding box for block directly above this tile entity.
    double x = (double)this.pos.getX();
    double y = (double)this.pos.getY() + 1.0d;
    double z = (double)this.pos.getZ();
    AxisAlignedBB scanAbove = new AxisAlignedBB(x, y, z, x, y, z);

    // Find entities above this tile entity.
    List entities = worldObj.getEntitiesWithinAABB(EntityItem.class, scanAbove);

    // TODO: Consume entities.
}

Imports:

import java.util.List;

import net.minecraft.entity.item.EntityItem;
import net.minecraft.util.AxisAlignedBB;
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .