Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Block with multiple parts (1.16)

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 post
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 post
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 post
Share on other sites
Posted (edited)

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:


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

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.

  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Hey, since yesterday im not able to load in an existing world anymore. I searched for some solutions, but only thing i could find is the productivebees mod, which seems to cause some problems. I havent installed this mod though. Ive attached the debug.log to this post. If you need any additional information or files please let me know!   debug-2.log.gz
    • Doing these things moves the camera. Your code subtracts the camera's position value from the MatrixStack.
    • That is just the modpack, no logs.
    • I created a modpack for me and my friends but we constantly crash after ~5 minutes of playing , Can some one help me please ? Here are the logs and the modpack : https://www.mediafire.com/file/kqnui7c0wzu8t7k/VladPack4-1.16.5.zip/file
    • I wrote a class that stores the BlockPos and BlockState of a specific block that needs to be changed into another block after a certain amount of time. So far I just coded stone bricks being changed into cracked stone bricks. In every worldtickevent I call a method called onTick in which there is a slight chance (1 in 1000) that this change will occur. The class that does this is called DecayHandler.java   DecayHandler.Java :   public class DecayHandler { public BlockState blockState; public BlockPos blockPos; public World world; private Random random; public int decayChance = 1000; private boolean decayed = false; public DecayHandler(BlockState blockState, BlockPos blockPos, World world){ this.blockState = blockState; this.blockPos = blockPos; this.world = world; random = new Random(); } public DecayHandler OnTick(){ //TODO: Refactor in other methods and implement BlockSwapper if(random.nextInt(decayChance) == 0 && !decayed){ System.out.println(this.blockPos + " Decayed"); if(world.setBlockAndUpdate(blockPos, Blocks.CRACKED_STONE_BRICKS.getBlock().defaultBlockState())){ this.blockState = Blocks.CRACKED_STONE_BRICKS.getBlock().defaultBlockState(); decayed = true; return this; } } //WorldDecayData.get(); return null; } }   This code works fine when I load in to a world and place stone bricks down. The stone bricks stay there for a couple of seconds and then they change into cracked stone bricks. The problem occurs when I save and quit to title and rejoin the same world when I placed stone brick that hadn't decayed yet. The game seems to remember what DecayHandlers were running which I guess is logical because I never closed it. So when the world is reloaded again my code stops without error and no longer functions. I can see in the terminal that the last message that was displayed was that a block decayed so I put a breakpoint on it to see what went wrong. By the way, the game keeps running just fine but my code just stops. The part where it seems to go wrong is in this line:  if(world.setBlockAndUpdate(blockPos, Blocks.CRACKED_STONE_BRICKS.getBlock().defaultBlockState())) When I try to step in to every single detail the callstack becomes insanely large and I'm unable to understand what's going on. The only thing I know is that right at the end they put my thread in to parking or something? I really don't understand what was going on. Can someone explain why this is happening? I don't have a clue of what's going on.
  • Topics

  • Who's Online (See full list)

  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.