Test for new Structure Builder
This commit is contained in:
parent
4fee0429f7
commit
1d359519b4
4 changed files with 21 additions and 38 deletions
|
@ -23,7 +23,7 @@ import java.util.Map;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class BCLStructure<S extends Structure> {
|
public abstract class BCLStructure<S extends Structure> {
|
||||||
public static class Unbound<S extends Structure> extends BCLStructure<S> {
|
public static class Unbound<S extends Structure> extends BCLStructure<S> {
|
||||||
private final Function<Structure.StructureSettings, S> structureBuilder;
|
private final Function<Structure.StructureSettings, S> structureBuilder;
|
||||||
private final TerrainAdjustment terrainAdjustment;
|
private final TerrainAdjustment terrainAdjustment;
|
||||||
|
@ -101,6 +101,10 @@ public class BCLStructure<S extends Structure> {
|
||||||
public Holder<Structure> getStructure() {
|
public Holder<Structure> getStructure() {
|
||||||
return structure;
|
return structure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Bound<S> register(BootstapContext<Structure> bootstrapContext) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -118,8 +122,7 @@ public class BCLStructure<S extends Structure> {
|
||||||
public final Codec<S> STRUCTURE_CODEC;
|
public final Codec<S> STRUCTURE_CODEC;
|
||||||
|
|
||||||
private static HolderSet<Biome> biomes(BootstapContext<Structure> bootstrapContext, TagKey<Biome> tagKey) {
|
private static HolderSet<Biome> biomes(BootstapContext<Structure> bootstrapContext, TagKey<Biome> tagKey) {
|
||||||
//TODO:1.19.3 Refactor
|
return bootstrapContext.lookup(Registries.BIOME).getOrThrow(tagKey);
|
||||||
return null; //BuiltInRegistries.BIOME.getOrCreateTag(tagKey);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Structure.StructureSettings structure(
|
private static Structure.StructureSettings structure(
|
||||||
|
@ -246,4 +249,6 @@ public class BCLStructure<S extends Structure> {
|
||||||
spreadConfig
|
spreadConfig
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract Bound<S> register(BootstapContext<Structure> bootstrapContext);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class TestBiomes extends FabricTagProvider<Biome> {
|
||||||
.skyColor(0x0000AA)
|
.skyColor(0x0000AA)
|
||||||
.addNetherClimateParamater(-1, 1)
|
.addNetherClimateParamater(-1, 1)
|
||||||
.surface(Blocks.LIGHT_BLUE_CONCRETE)
|
.surface(Blocks.LIGHT_BLUE_CONCRETE)
|
||||||
.structure(TestStructure.TEST_STRUCTURE_TAG)
|
.structure(TestStructure.TEST.biomeTag)
|
||||||
.endLandBiome()
|
.endLandBiome()
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ public class TestPlacedFeatures {
|
||||||
.onHeightmap(Heightmap.Types.WORLD_SURFACE)
|
.onHeightmap(Heightmap.Types.WORLD_SURFACE)
|
||||||
.decoration(GenerationStep.Decoration.VEGETAL_DECORATION)
|
.decoration(GenerationStep.Decoration.VEGETAL_DECORATION)
|
||||||
.isEmptyAndOn(BlockPredicate.matchesBlocks(Blocks.YELLOW_CONCRETE))
|
.isEmptyAndOn(BlockPredicate.matchesBlocks(Blocks.YELLOW_CONCRETE))
|
||||||
|
.onlyInBiome()
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public static void bootstrap(BootstapContext<PlacedFeature> bootstrapContext) {
|
public static void bootstrap(BootstapContext<PlacedFeature> bootstrapContext) {
|
||||||
|
|
|
@ -1,25 +1,23 @@
|
||||||
package org.betterx.datagen.bclib.tests;
|
package org.betterx.datagen.bclib.tests;
|
||||||
|
|
||||||
import org.betterx.bclib.BCLib;
|
import org.betterx.bclib.BCLib;
|
||||||
|
import org.betterx.bclib.api.v2.levelgen.structures.BCLStructure;
|
||||||
|
import org.betterx.bclib.api.v2.levelgen.structures.BCLStructureBuilder;
|
||||||
import org.betterx.bclib.util.BlocksHelper;
|
import org.betterx.bclib.util.BlocksHelper;
|
||||||
import org.betterx.bclib.util.MHelper;
|
import org.betterx.bclib.util.MHelper;
|
||||||
import org.betterx.worlds.together.tag.v3.TagManager;
|
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.HolderSet;
|
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.core.registries.BuiltInRegistries;
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.data.worldgen.BootstapContext;
|
import net.minecraft.data.worldgen.BootstapContext;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.tags.TagKey;
|
|
||||||
import net.minecraft.util.RandomSource;
|
import net.minecraft.util.RandomSource;
|
||||||
import net.minecraft.world.level.ChunkPos;
|
import net.minecraft.world.level.ChunkPos;
|
||||||
import net.minecraft.world.level.LevelHeightAccessor;
|
import net.minecraft.world.level.LevelHeightAccessor;
|
||||||
import net.minecraft.world.level.StructureManager;
|
import net.minecraft.world.level.StructureManager;
|
||||||
import net.minecraft.world.level.WorldGenLevel;
|
import net.minecraft.world.level.WorldGenLevel;
|
||||||
import net.minecraft.world.level.biome.Biome;
|
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||||
import net.minecraft.world.level.levelgen.GenerationStep;
|
import net.minecraft.world.level.levelgen.GenerationStep;
|
||||||
|
@ -29,10 +27,7 @@ import net.minecraft.world.level.levelgen.structure.*;
|
||||||
import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceSerializationContext;
|
import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceSerializationContext;
|
||||||
import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceType;
|
import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceType;
|
||||||
import net.minecraft.world.level.levelgen.structure.pieces.StructurePiecesBuilder;
|
import net.minecraft.world.level.levelgen.structure.pieces.StructurePiecesBuilder;
|
||||||
import net.minecraft.world.level.levelgen.structure.placement.RandomSpreadStructurePlacement;
|
|
||||||
import net.minecraft.world.level.levelgen.structure.placement.RandomSpreadType;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
class TestStructurePiece extends StructurePiece {
|
class TestStructurePiece extends StructurePiece {
|
||||||
|
@ -90,15 +85,12 @@ class TestStructurePiece extends StructurePiece {
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TestStructure extends Structure {
|
public class TestStructure extends Structure {
|
||||||
static final TagKey<Biome> TEST_STRUCTURE_TAG = TagManager.BIOMES.makeTag(BCLib.makeID("test_structure"));
|
public static final BCLStructure<TestStructure> TEST = BCLStructureBuilder
|
||||||
static final ResourceKey<StructureType<?>> TYPE_KEY = ResourceKey.create(
|
.start(BCLib.makeID("test_structure"), TestStructure::new)
|
||||||
Registries.STRUCTURE_TYPE,
|
.adjustment(TerrainAdjustment.BEARD_THIN)
|
||||||
BCLib.makeID("test_type")
|
.randomPlacement(16, 8)
|
||||||
);
|
.step(GenerationStep.Decoration.SURFACE_STRUCTURES)
|
||||||
static final StructureType<TestStructure> TYPE = () -> Structure.simpleCodec(TestStructure::new);
|
.build();
|
||||||
|
|
||||||
static final ResourceKey<Structure> KEY = ResourceKey.create(Registries.STRUCTURE, BCLib.makeID("test_structure"));
|
|
||||||
static final ResourceKey<StructureSet> SET_KEY = ResourceKey.create(Registries.STRUCTURE_SET, KEY.location());
|
|
||||||
|
|
||||||
protected TestStructure(StructureSettings structureSettings) {
|
protected TestStructure(StructureSettings structureSettings) {
|
||||||
super(structureSettings);
|
super(structureSettings);
|
||||||
|
@ -155,35 +147,20 @@ public class TestStructure extends Structure {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StructureType<?> type() {
|
public StructureType<?> type() {
|
||||||
return TYPE;
|
return TEST.structureType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void bootstrap(BootstapContext<Structure> bootstrapContext) {
|
public static void bootstrap(BootstapContext<Structure> bootstrapContext) {
|
||||||
BCLib.LOGGER.info("Bootstrap Structure");
|
BCLib.LOGGER.info("Bootstrap Structure");
|
||||||
//registerBase();
|
TEST.register(bootstrapContext);
|
||||||
HolderSet<Biome> biomes = bootstrapContext.lookup(Registries.BIOME).getOrThrow(TEST_STRUCTURE_TAG);
|
|
||||||
|
|
||||||
bootstrapContext.register(KEY, new TestStructure(new Structure.StructureSettings(
|
|
||||||
biomes,
|
|
||||||
Map.of(),
|
|
||||||
GenerationStep.Decoration.SURFACE_STRUCTURES,
|
|
||||||
TerrainAdjustment.BEARD_THIN
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void bootstrapSet(BootstapContext<StructureSet> bootstrapContext) {
|
public static void bootstrapSet(BootstapContext<StructureSet> bootstrapContext) {
|
||||||
BCLib.LOGGER.info("Bootstrap StructureSet");
|
BCLib.LOGGER.info("Bootstrap StructureSet");
|
||||||
var structure = bootstrapContext.lookup(Registries.STRUCTURE).getOrThrow(KEY);
|
TEST.registerSet(bootstrapContext);
|
||||||
bootstrapContext.register(SET_KEY, new StructureSet(structure, new RandomSpreadStructurePlacement(
|
|
||||||
10,
|
|
||||||
8,
|
|
||||||
RandomSpreadType.LINEAR,
|
|
||||||
13323129 + 10 + 8 + KEY.location().toString().hashCode() % 10000
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerBase() {
|
public static void registerBase() {
|
||||||
Registry.register(BuiltInRegistries.STRUCTURE_PIECE, TestStructurePiece.KEY, TestStructurePiece.INSTANCE);
|
Registry.register(BuiltInRegistries.STRUCTURE_PIECE, TestStructurePiece.KEY, TestStructurePiece.INSTANCE);
|
||||||
Registry.register(BuiltInRegistries.STRUCTURE_TYPE, TYPE_KEY, TYPE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue