1

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.

Andrew Graber
  • 131
  • 2
  • 9
  • 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. – Steak Overflow Apr 21 '15 at 11:07
  • 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. – Andrew Graber Apr 21 '15 at 16:54
  • 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) – Steak Overflow Apr 21 '15 at 17:20
  • It's not unity. It's minecraft, so there isnt such a thing as a collider (as far as I know) – Andrew Graber Apr 21 '15 at 17:38
  • 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. – Steak Overflow Apr 21 '15 at 17:59
  • That's the problem. I don't know how to get the entity. Maybe someone with more Forge knowledge has an idea of how I can do this? I've been trying to look at AE2's annihilation plane to see how that is handled and I tracked an onEntityCollision method all the way back to his IPart class, but it just has a comment that says "this method is called when an entity collides with the part" i can't find where it is actually called and how it knows when they collide – Andrew Graber Apr 21 '15 at 18:10

1 Answers1

2

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;
scope
  • 69
  • 9