Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

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

 

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

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

  • 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. :D

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.