StructurePlacerAPI
This simple library provides a convenient way for one-time placement of structures in the Minecraft world, bypassing standard world generation. It's perfect for creating items that trigger portals or other constructions, as well as implementing "lucky block" mechanics.
Installation
Add the dependency to your build.gradle file:
repositories {
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
content {
includeGroup "maven.modrinth"
}
}
}
dependencies {
modImplementation "maven.modrinth:structureplacerapi:<version>"
}
If you need to include the API in your jar file, add the include line:
repositories {
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
content {
includeGroup "maven.modrinth"
}
}
}
dependencies {
modImplementation "maven.modrinth:structureplacerapi:<version>"
include "maven.modrinth:structureplacerapi:<version>"
}
The library size is less than 15 KB!
Usage
Creating a Structure
Create an NBT structure using Minecraft's structure blocks, as demonstrated in this video: https://www.youtube.com/watch?v=umhuRXinD3o
File Placement
Place the structure.nbt file in your mod's data folder: data/yourmodid/structures
Creating a Placement Object
To place a structure, create a StructurePlacerAPI object with the following parameters:
StructurePlacerAPI(ServerWorld world, Identifier templateName, BlockPos blockPos, BlockMirror mirror, BlockRotation rotation, boolean ignoreEntities, float integrity, BlockPos offset)
Parameters
- world - the world where the structure will be placed
- templateName - structure identifier in MOD_ID:structure_name format
- blockPos - block position for structure placement
- mirror - structure mirroring (use BlockMirror.#value)
- rotation - structure rotation (use BlockRotation.#value)
- ignoreEntities - whether to ignore entities in the structure
- integrity - structure integrity (from 0.0f to 1.0f)
- offset - structure position offset
Placing the Structure
After creating the object, execute:
placer.loadStructure();
Terrain Restoration
Starting from version 1.1.0, terrain restoration is available:
placer.loadAndRestoreStructure(int restore_ticks);
For animated restoration:
placer.loadAndRestoreStructureAnimated(int restore_ticks, int blocks_per_tick, boolean random);
- blocks_per_tick - number of blocks restored per tick
- random - random order of block restoration
Usage Example
Permanent structure:
StructurePlacer placer = new StructurePlacer((ServerWorld) caster.getWorld(), new Identifier(MOD_ID, "frost_light"), caster.getBlockPos(), BlockMirror.NONE, BlockRotation.CLOCKWISE_90, true, 1.0f, new BlockPos(-4, -3, -3));
placer.loadStructure();
With terrain restoration:
StructurePlacer placer = new StructurePlacer((ServerWorld) caster.getWorld(), new Identifier(MOD_ID, "frost_light"), caster.getBlockPos(), BlockMirror.NONE, BlockRotation.CLOCKWISE_90, true, 1.0f, new BlockPos(-4, -3, -3));
placer.loadAndRestoreStructureAnimated(200, 2, true);
Important Note
Ensure the code runs on the server side:
if(!world.isClient){
// code to execute
}
License
The library is distributed under the CC0 license.