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

someone suggested me to add the ability to place my mods' kettles on campfires to boil the water in them.

these would be a block with two parts: the kettle and campfire, which can be interacted with and broken separately.

while I could think of ways to implement the rendering, I'm not quite sure how to detect when the player broke or interacted with each part of the block. I considered the Forge Multipart lib, but that's outdated right? is there another way to do this?

Edited by A Soulspark

There is no multipart library for 1.16 unfortunately. Best you could do would probably be to have the campfire as a block with some property that determines whether the kettle is on it or not. The kettle could then be an item or a block if you want to place it separately. You would then probably use some right click action to separate the blocks and attach them together. Note that this would still be just a BlockState.

  • Author

Yeah, that sounds close to what I had in mind! But how should I go about detecting what part of the block was interacted with?

For example, in the onBlockActivated method, what information could I use to determine if you right-clicked the kettle or the campfire? you should be able to pick up the kettle by right-clicking it, but not the campfire.

Same problem for the dropping: how do I check if you broke the kettle or the campfire? if you only broke the kettle, it should only remove the kettle, not both parts.

Just now, vemerion said:

Or do you mean that the repo is a good place to look to get inspired on how to implement something similar for their mod

yes

  • Author

well, I think I understand what the mod is doing. it makes a second raycast everytime the block is interacted with to determine what part is being interacted with.

except the way it does that raycast is through a function in BlockState called collisionRayTrace, which doesn't exist in 1.16.

still, I'll try out another method that sounds like it should work (VoxelShape.rayTrace). we'll see!

EDIT: it does! hooray, that made my day ^^
Here's the code for reference:
 

Spoiler

public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
  Vector3d startVec = player.getEyePosition(1);
  Vector3d endVec = startVec.add(player.getLookVec().scale(player.getAttribute(ForgeMod.REACH_DISTANCE.get()).getValue()));
		
  RayTraceResult subHit = KETTLE_SHAPE.rayTrace(startVec, endVec, pos);
  if (subHit == null || subHit.getType() != RayTraceResult.Type.BLOCK) return ActionResultType.PASS;
		
  // code that runs when the kettle was interacted with
}

 

 

Edited by A Soulspark

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.