MinecraftScripterAI
Discord ↗
Link Copied to Clipboard
×
"create a structure and generator"
/* To create a structure and generator in Minecraft Forge, you need to follow these steps: */ 1. /* Create a structure class */ /* This class should extend Structure<?> and define the structure's size, rules, and other properties. */ public class MyStructure extends Structure<NoFeatureConfig> { public MyStructure(Codec<NoFeatureConfig> codec) { super(codec); } @Override public StructureStartFactory<NoFeatureConfig> getStartFactory() { return MyStructureStart::new; } } 2. /* Create a structure start class */ /* This class should extend StructureStart and handle the generation of the structure's components. */ public class MyStructureStart extends StructureStart<NoFeatureConfig> { public MyStructureStart(Structure<NoFeatureConfig> structure, int chunkX, int chunkZ, BoundingBox boundingBox, int references, long seed) { super(structure, chunkX, chunkZ, boundingBox, references, seed); } @Override public void generatePieces(RegistryAccess registry, ChunkGenerator generator, StructureManager manager, int chunkX, int chunkZ, Biome biome, NoFeatureConfig config) { // Add your structure's pieces here } } 3. /* Register the structure */ /* In your mod's registration class, register the structure using the DeferredRegister. */ public static final RegistryObject<Structure<NoFeatureConfig>> MY_STRUCTURE = STRUCTURES.register("my_structure", () -> new MyStructure(NoFeatureConfig.CODEC)); 4. /* Add the structure to the world generation */ /* In your mod's setup method, add the structure to the world generation settings. */ public static void setup() { /* Add the structure to the world generation settings */ WorldGenRegistries.NOISE_GENERATOR_SETTINGS.entrySet().forEach(settings -> { settings.getValue().structureSettings().structures().put(MY_STRUCTURE.get(), new StructureSeparationSettings(10, 5, 123456789)); }); } 5. /* Create a structure generator */ /* This class should extend StructurePiece and handle the placement and construction of the structure's components. */ public class MyStructureGenerator extends StructurePiece { public MyStructureGenerator(StructurePieceType type, CompoundTag tag) { super(type, tag); } public MyStructureGenerator(StructurePieceType type, int index, BoundingBox boundingBox) { super(type, index); this.boundingBox = boundingBox; } @Override public boolean postProcess(WorldGenLevel world, StructureFeatureManager manager, ChunkGenerator generator, Random random, BoundingBox boundingBox, ChunkPos chunkPos, BlockPos blockPos) { // Generate the structure's components here return true; } } 6. /* Register the structure generator */ /* In your mod's registration class, register the structure generator using the DeferredRegister. */ public static final RegistryObject<StructurePieceType> MY_STRUCTURE_GENERATOR = STRUCTURE_PIECE_TYPES.register("my_structure_generator", () -> StructurePieceType.setPieceId(MyStructureGenerator::new));