Search code examples
coordinatesminecraftminecraft-forgespawning

How to get the coordinates of an item that the player is holding in Minecraft? Using MinecraftForge


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,


Solution

  • 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/