Jump to content

get hitX/Y/Z from EntityPlayer


Recommended Posts

The Block class has a method removeBlockByPlayer which removes the block when a player breaks it. How to get the hitX, hitY, hitZ coordinates where the player hit the block? The given arguments are World world, EntityPlayer player, int x, int y, int z. I found the method EntityLiving.rayTrace(double reachDistance, float partialTickTime), but i don't know what the parameter partialTickTime is for, and as i set it to 1, I got different results on client and server side.

Link to comment
Share on other sites

With hitX,hitY & hitZ are you reffering to which side of the block the player was hitting it, or?

I'm unsure about exactly what you want to get. If you want the side he hit, I believe you could cast a ray from the player to see what side of the block you hit.


Looking into the code for entityLiving.rayTrace(...);

It returns an "MovingObjectPosition" which has among other things the following properties:


typeOfHit - int which has 0 for Block and 1 for Entity.

sideHit - int which is Bottom = 0, Top = 1, East = 2, West = 3, North = 4, South = 5

                  or -1 if the RayTrace went the full length of it's trace.


Also it contains the entity you hit(if you hit one, else it's null of course). And the coordinates for the block etc.

Check out the code for it, I believe you could use that to solve your problem :)

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

I refer to the exact coordinates the player was hitting. The problem with the rayTrace function is, that i don't know how to use it. It takes two arguments: reachDistance and partialTickTime. I can get the reachDistance, but i have no idea what the partialTickTime is for. When I start it and set partialTickTime to 1, i get different results on server and client side(very different).

Link to comment
Share on other sites

And with exact coordinates you mean which pixel on the block's surface did he point at?

also client doesn't have all the information the server has, the server one should be the correct one :)

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use.