I am trying to get the EntityItem (Dropped item) that the player is looking at.
Therefor I must raytrace, and in order to raytrace I must call Minecraft.getRenderViewEntity();
I am having an issue where Minecraft.getRenderViewEntity() is not returning all types of entities. Specifically it will not return EntityItem. It works well with every other entity except Dropped items.
Basically this means I can get any entity the player is looking at, EXCEPT dropped items.
I've tried going deep into Minecraft's code, but I cannot find out why it will not return Dropped Item entities. Does anyone know why?
EntityItem hit = null;
EntityPlayer player = e.player;
Vec3d v = player.getLookVec();
double x = player.getLookVec().xCoord;
double y = player.getLookVec().yCoord;
double z = player.getLookVec().zCoord;
List<EntityItem> Items = player.worldObj.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(player.posX - 5, player.posY - 5, player.posZ - 5, player.posX + 5, player.posY + 5, player.posZ + 5));
for(EntityItem i : Items){
AxisAlignedBB AABB = i.getCollisionBoundingBox();
if ((AABB != null && v != null) && (AABB.intersectsWithXY(v) || AABB.intersectsWithXZ(v) || AABB.intersectsWithYZ(v))){
hit = i;
break;
}
}
System.out.println(hit);
I've also tried getting all of the item entities within a radius of the player, and checking if the player's look vector intersects any of the item entities' Collision boxes. It doesn't appear to be working, I assume I have to do some sort of mathematics to the player's look vector, but I don't know exactly what.
Either that, or I'm misinterpreting what the intersectWith() methods do.
You could do a RayTrace to see if the player looks at an EntityItem, use Entity#rayTrace() (EntityPlayer is a subclass of Entity) and check if the returned RayTraceResult's entityHit field isn't null and is an instace of EntityItem.
You could do a RayTrace to see if the player looks at an EntityItem, use Entity#rayTrace() (EntityPlayer is a subclass of Entity) and check if the returned RayTraceResult's entityHit field isn't null and is an instace of EntityItem.
An important thing to note there is that MovingObjectposition was renamed to RayTraceResult.
Yeah I know about that rename, but you asked for 1.10 (at least you marked your thread for that version).
But I have another idea: try to intercept the EntityItem's update method and check if there's a player around. then do a RayTrace on the player's look vector and check if the position is equal to the entity's position.
I am trying to get the EntityItem (Dropped item) that the player is looking at.
Therefor I must raytrace, and in order to raytrace I must call Minecraft.getRenderViewEntity();
I am having an issue where Minecraft.getRenderViewEntity() is not returning all types of entities. Specifically it will not return EntityItem. It works well with every other entity except Dropped items.
Basically this means I can get any entity the player is looking at, EXCEPT dropped items.
I've tried going deep into Minecraft's code, but I cannot find out why it will not return Dropped Item entities. Does anyone know why?
My Github ด้้้้้็็็็็้้้้้็็็็็้้้้้็็็็็้้้้้็็็็็้้้้้็็็็็้้้้้็็็็็้้้้้็็็็็้้้้้дด็็็็็้้้้้็็็็้้้้้็็็็็้้้้้็็็็็้้้้้็็็็็้้้้้
What do you need this for? I think there may be other ways to do whatever you're trying to achieve..
I'm making the dropped item that the player is looking at glow (via Entity.setGlowing(true));
My Github ด้้้้้็็็็็้้้้้็็็็็้้้้้็็็็็้้้้้็็็็็้้้้้็็็็็้้้้้็็็็็้้้้้็็็็็้้้้้дด็็็็็้้้้้็็็็้้้้้็็็็็้้้้้็็็็็้้้้้็็็็็้้้้้
I've also tried getting all of the item entities within a radius of the player, and checking if the player's look vector intersects any of the item entities' Collision boxes. It doesn't appear to be working, I assume I have to do some sort of mathematics to the player's look vector, but I don't know exactly what.
Either that, or I'm misinterpreting what the intersectWith() methods do.
My Github ด้้้้้็็็็็้้้้้็็็็็้้้้้็็็็็้้้้้็็็็็้้้้้็็็็็้้้้้็็็็็้้้้้็็็็็้้้้้дด็็็็็้้้้้็็็็้้้้้็็็็็้้้้้็็็็็้้้้้็็็็็้้้้้
You could do a RayTrace to see if the player looks at an EntityItem, use Entity#rayTrace() (EntityPlayer is a subclass of Entity) and check if the returned RayTraceResult's entityHit field isn't null and is an instace of EntityItem.
Seehttp://www.minecraftforge.net/forum/index.php?topic=29969.msg155311#msg155311
An important thing to note there is that MovingObjectposition was renamed to RayTraceResult.
I've also tried using the code linked there, but it calls Minecraft.getRenderViewEntity()
My Github ด้้้้้็็็็็้้้้้็็็็็้้้้้็็็็็้้้้้็็็็็้้้้้็็็็็้้้้้็็็็็้้้้้็็็็็้้้้้дด็็็็็้้้้้็็็็้้้้้็็็็็้้้้้็็็็็้้้้้็็็็็้้้้้
Yeah I know about that rename, but you asked for 1.10 (at least you marked your thread for that version).
But I have another idea: try to intercept the EntityItem's update method and check if there's a player around. then do a RayTrace on the player's look vector and check if the position is equal to the entity's position.
I figured it out. I used some of the code from the example, except passing in the bounding boxes of EntityItems in a radius of the player.
My Github ด้้้้้็็็็็้้้้้็็็็็้้้้้็็็็็้้้้้็็็็็้้้้้็็็็็้้้้้็็็็็้้้้้็็็็็้้้้้дด็็็็็้้้้้็็็็้้้้้็็็็็้้้้้็็็็็้้้้้็็็็็้้้้้