Jump to content

[1.7.2] Block subHits


RSQ

Recommended Posts

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

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.

Guest
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.

Announcements



×
×
  • Create New...

Important Information

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