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

[1.17] How do I make a placed block create a structure?


askod333
 Share

Recommended Posts

Hi everyone,

 

I am almost done with my mod that I only need for myself, I just can't grasp how to code one thing.

I need to code it so when a block is placed by a player, a structure appears instead of the block. I suppose I am meant to use the onBlockAdded method, but I can't understand, how it works. Could someone show me how to code it please? Also, how do I map the structure? Do i use XYZ coordinates?

It would be really helpful if you could give me an example of such code and I would change the values to match the structure. Again, this mod is for my purposes only, I will not upload it anywhere if you are afraid of you doing someone else's work.

Thank you for the response!

Link to comment
Share on other sites

You have two options. You could manually create the structure by placing blocks individually based on the location of the player-placed block (Yes using x, y, z coordinates). Or you could load the structure using an nbt structure file based on the location of the player-placed block. I suppose it mostly depends on how large and complex the structure is. If it is fairly complex or large, Id go with the second option.

Link to comment
Share on other sites

2 hours ago, ForgetFunsize said:

You have two options. You could manually create the structure by placing blocks individually based on the location of the player-placed block (Yes using x, y, z coordinates). Or you could load the structure using an nbt structure file based on the location of the player-placed block. I suppose it mostly depends on how large and complex the structure is. If it is fairly complex or large, Id go with the second option.

It's not large or complex at all, so the first option works for me. Could you show me how to code that? Or explain in detail?

Link to comment
Share on other sites

1 hour ago, askod333 said:

It's not large or complex at all, so the first option works for me. Could you show me how to code that? Or explain in detail?

In your EntityPlaceEvent, you would manually place the blocks for your structure based on the placed block position. Such as world.setBlockAndUpdate(pos, Blocks.WHATEVER_BLOCK.defaultBlockState());. pos being the position you want to set the block. You would call this for as many blocks as you need until your structure is complete.

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.

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

 Share



×
×
  • Create New...

Important Information

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