Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

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

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.