PrivateconstructorOptionalsaveMode: StructureSaveModeOptionaloptions: StructureCreateOptionsThis function can't be called in read-only mode.
This function can't be called in early-execution mode.
import { StructureSaveMode, world } from "@minecraft/server";
import { Vector3Builder, Vector3Utils } from "@minecraft/math";
const player = world.getAllPlayers()[0];
const from = player.location;
const to = Vector3Utils.add(from, new Vector3Builder(15, 15, 15));
world.structureManager.createFromWorld("mystructure:test", player.dimension, from, to, {
saveMode: StructureSaveMode.World,
});
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
Optionaloptions: StructurePlaceOptionsThis function can't be called in read-only mode.
This function can throw errors.
minecraftcommon.ArgumentOutOfBoundsError
This function can't be called in early-execution mode.
import { world, StructureAnimationMode, StructureSaveMode, BlockPermutation } from "@minecraft/server";
import { MinecraftBlockTypes } from "@minecraft/vanilla-data";
function getRandomStructure() {
// Return existing mystructure:random structure
if (world.structureManager.getWorldStructureIds().includes("mystructure:random")) {
return world.structureManager.get("mystructure:random");
}
// Create a new mystructure:random structure otherwise
const structure = world.structureManager.createEmpty(
"mystructure:random",
{ x: 10, y: 10, z: 10 },
StructureSaveMode.World
);
const concretes = [
MinecraftBlockTypes.RedConcrete,
MinecraftBlockTypes.YellowConcrete,
MinecraftBlockTypes.BlueConcrete,
];
for (let x = 0; x < 10; x++) {
for (let y = 0; y < 10; y++) {
for (let z = 0; z < 10; z++) {
const permutation = BlockPermutation.resolve(concretes[Math.floor(Math.random() * concretes.length)]);
structure.setBlockPermutation({ x, y, z }, permutation);
}
}
}
return structure;
}
const structure = getRandomStructure();
const player = world.getPlayers()[0];
// Place structure on player's location
world.structureManager.place(structure, player.dimension, player.location, {
animationMode: StructureAnimationMode.Blocks,
animationSeconds: 15,
});
Optionaloptions: JigsawPlaceOptionsThis function can't be called in read-only mode.
This function can't be called in early-execution mode.
Optionaloptions: JigsawStructurePlaceOptionsThis function can't be called in read-only mode.
This function can't be called in early-execution mode.
import { world } from "@minecraft/server";
// Command for /place structure minecraft:trail_ruins 10 20 30
function placeTrailRuins() {
const overworld = world.getDimension("overworld");
// Spawn trail ruins structure in overworld
world.structureManager.placeJigsawStructure("minecraft:trail_ruins", overworld, { x: 10, y: 20, z: 30 });
}
import { world } from "@minecraft/server";
// Command for /place structure minecraft:trial_chambers 10 20 30 true true
function placeTrialChambers() {
const overworld = world.getDimension("overworld");
// Spawn trial chambers structure in overworld
world.structureManager.placeJigsawStructure(
"minecraft:trial_chambers",
overworld,
{ x: 10, y: 20, z: 30 },
{ ignoreStartHeight: true, keepJigsaws: true }
);
}
Remarks
Write Privilege
This function can't be called in read-only mode.
Throws
This function can throw errors.
minecraftcommon.EngineError
minecraftcommon.InvalidArgumentError
World Ready
This function can't be called in early-execution mode.
Example: randomStructure.js