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

Spawn structure from inventory


Foniks
 Share

Recommended Posts

Hi! I'm able to export and load a structure so that it is generated as part of the world generation. But I'm wondering how I would go about spawning the same structures from inventory. I'm thinking either creating an item that spawns the structure on right click, or placing a block and clicking on that. But what I am not sure about is how to actually spawn the structure from these events.

Any thoughts would be welcome.

Link to comment
Share on other sites

Thanks for the reply. So I should have mentioned that I am on 1.18.2 - which means Place doesn't exist - I think PlaceFeature is the equivalent. What I am unsure about though - I already have structures correctly spawning as part of the world generation. They are of type StructureFeature. When I try to use the PlaceFeature command in the console - these do not appear in the list of potential features to spawn. So I'm wondering if that is going to be the right path to go down...

Link to comment
Share on other sites

Since I don't write mods for 1.18.2 anymore, i use code 1.19 for the following explanation. i hope the classes exists and the code work

first of all you need to call Structure#generate this will return a StructureStart. Before you continue make sure StructureStart#isValid returns true.
Then make sure all Chunks in the BoundingBox of the Structure is fully load. Then call StructureStart#placeInChunk for each Chunk which is inside the Structure BoundingBox,
therefore you can use something like this:

BoundingBox structureBox = structureStart.getBoundingBox();
ChunkPos minPos = new ChunkPos(SectionPos.blockToSectionCoord(structureBox.minX()), SectionPos.blockToSectionCoord(structureBox.minZ()));
ChunkPos maxPos = new ChunkPos(SectionPos.blockToSectionCoord(structureBox.maxX()), SectionPos.blockToSectionCoord(structureBox.maxZ()));
ChunkPos.rangeClosed(minPos, maxPos).forEach((pos) -> {
	// load structure here 
});

Note the BoundingBox of StructureStart#placeInChunk is not the Structure BoundingBox it's the BoundingBox of the Chunk in which you currently generate the Structure,
means you need to create inside the #forEach a BoundingBox for the current chunk pos from the min x, y, z to the max x, y, z
should be looks like this:

new BoundingBox(pos.getMinBlockX(), ServerLevel#getMinBuildHeight(), pos.getMinBlockZ(), pos.getMaxBlockX(), erverLevel#getMaxBuildHeight(), pos.getMaxBlockZ())

 

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
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 Terms of Use.