Posted April 24, 20214 yr 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 April 24, 20214 yr by A Soulspark
April 24, 20214 yr 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.
April 25, 20214 yr 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.
April 25, 20214 yr 14 minutes ago, loordgek said: you want https://github.com/amadornes/MCMultiPart But that mod is for 1.12, so A Soulspark won't be able to use that for their 1.16 mod. 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?
April 25, 20214 yr 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
April 25, 20214 yr 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 April 25, 20214 yr 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.