Posted July 18, 20223 yr 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.
July 19, 20223 yr Author 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...
July 19, 20223 yr 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())
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.