Posted May 27, 201411 yr Hello forums I'm trying to create a block that has multiple hitboxes, like in the Ender Chest mod by Chickenbones. I do realise that the mod is open src, but I feel like I would understand ray tracing better if someone gave me some tips. After doing some research, I learned that you should use ray tracing to find where the player is looking, but I can't figure out how the actual subHit variable works. If anyone can help or has any tips, it would be appreciated.
May 28, 201411 yr Hi Check out the vanilla raytracing code in EntityRenderer.getMouseOver. MovingObjectPosition is the class used to store information about where the player's line of sight ends. The raytracing on blocks is done in EntityLivingBase.rayTrace --> World.clip -TGG
May 28, 201411 yr Author I've learned the basics of ray tracing now, but I also found that in the method onBlockActivated(), there are 3 floats at the end that return the exact same value as ray tracing does. Should I still use ray tracing though? Also, I've looked at chickenbones' code once again and saw that he didn't use any of these x, y, and z values that the ray tracing returns, as far as I know. His code was something among the lines of if (hit.subHit==0) ... How can I use the subHit variable?
May 28, 201411 yr Hi From memory, MovingObjectPosition.subHit isn't implemented in vanilla. For blocks - sideHit tells you which side, and hitVec tells you the position of where the line-of-sight raytrace intersects the block cube onBlockActivated is given hitVec, with the coordinates adjusted relative to the block position, i.e. from [0,0,0] to [1,1,1] I haven't seen chickenbones' code, but I imagine that overriding Block.collisionRayTrace will give you the flexibility you need. Your block can use the vector information to check against its multiple hitboxes and decide which one (if any) were hit. And set subHit appropriately, I guess, so that onBlockActivated can use it later (never tried that) -TGG
May 29, 201411 yr Author I apologise for the late reply, was sort of busy yesterday. With your tips, I've figured almost everything out. All that's left is the rendering of the wire. Again, thanks.
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.