Jump to content

Block with multiple parts (1.16)


A Soulspark

Recommended Posts

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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