I am using Minecraft Forge and I want to know how to get the coordinates of a Block or an Item that the player is holding or looking at. Or It can also be just a block that the player just broke. In any case, I need to get those coordinates to be able to change them in a way that makes y=Sin(x) and I would keep looping and spawning copies of the same item so that it plots the Sinus function. I would really appreaciate your help.. I am stuck with this for days. Best,
Asked
Active
Viewed 1,553 times
1 Answers
0
To get the block a player is looking at:
MovingObjectPosition mop = Minecraft.getMinecraft().renderViewEntity.rayTrace(200, 1.0F);
if(mop != null)
{
int blockHitSide = mop.sideHit;
Block blockLookingAt = worldObj.getBlock(mop.blockX, mop.blockY, mop.blockZ) ;
}
The block variable would be blockLookingAt
Also, you may want to check out http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/modification-development/

Ben Morris
- 606
- 5
- 24
-
I tried to use renderViewEntity but it didn't want to work, I don't know why they don't let me use it. Therefore I used objectMOuseOver instead: MovingObjectPosition mop= Minecraft.getMinecraft().objectMouseOver; int x=mop.getBlockPos().getX(); int y=mop.getBlockPos().getY(); int c=y - 20*x; int i; for(i=x;i<(i+100);){ y=20*i + c; i+=2; x=i; _______________ Is there something wrong with this? What should I write now to set the mop position to the new x and y every time inside the loop? I am trying to make it move in a "y=20x +c" motion Thank you so much for your answer by the way. – SaraFatih Jan 30 '16 at 21:59