Keep Track of unbound Structures
This commit is contained in:
parent
c75450b6c5
commit
bca140dc1b
2 changed files with 31 additions and 2 deletions
|
@ -28,6 +28,8 @@ public abstract class BCLStructure<S extends Structure> {
|
||||||
private final Function<Structure.StructureSettings, S> structureBuilder;
|
private final Function<Structure.StructureSettings, S> structureBuilder;
|
||||||
private final TerrainAdjustment terrainAdjustment;
|
private final TerrainAdjustment terrainAdjustment;
|
||||||
|
|
||||||
|
private Bound<S> registered;
|
||||||
|
|
||||||
protected Unbound(
|
protected Unbound(
|
||||||
@NotNull ResourceLocation id,
|
@NotNull ResourceLocation id,
|
||||||
@NotNull GenerationStep.Decoration step,
|
@NotNull GenerationStep.Decoration step,
|
||||||
|
@ -48,12 +50,14 @@ public abstract class BCLStructure<S extends Structure> {
|
||||||
BCLStructure.registerStructureType(id, codec)
|
BCLStructure.registerStructureType(id, codec)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
registered = null;
|
||||||
this.structureBuilder = structureBuilder;
|
this.structureBuilder = structureBuilder;
|
||||||
this.terrainAdjustment = terrainAdjustment;
|
this.terrainAdjustment = terrainAdjustment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Bound<S> register(BootstapContext<Structure> bootstrapContext) {
|
public Bound<S> register(BootstapContext<Structure> bootstrapContext) {
|
||||||
|
if (registered != null) return registered;
|
||||||
S baseStructure = structureBuilder.apply(structure(
|
S baseStructure = structureBuilder.apply(structure(
|
||||||
bootstrapContext,
|
bootstrapContext,
|
||||||
this.biomeTag,
|
this.biomeTag,
|
||||||
|
@ -61,7 +65,8 @@ public abstract class BCLStructure<S extends Structure> {
|
||||||
terrainAdjustment
|
terrainAdjustment
|
||||||
));
|
));
|
||||||
Holder.Reference<Structure> structure = bootstrapContext.register(structureKey, baseStructure);
|
Holder.Reference<Structure> structure = bootstrapContext.register(structureKey, baseStructure);
|
||||||
return new Bound<>(
|
BCLStructureBuilder.UNBOUND_STRUCTURES.remove(this);
|
||||||
|
registered = new Bound<>(
|
||||||
this.id,
|
this.id,
|
||||||
this.structureKey,
|
this.structureKey,
|
||||||
this.structureSetKey,
|
this.structureSetKey,
|
||||||
|
@ -73,6 +78,7 @@ public abstract class BCLStructure<S extends Structure> {
|
||||||
baseStructure,
|
baseStructure,
|
||||||
structure
|
structure
|
||||||
);
|
);
|
||||||
|
return registered;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,11 +249,16 @@ public abstract class BCLStructure<S extends Structure> {
|
||||||
return biomes;
|
return biomes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean registeredSet = false;
|
||||||
|
|
||||||
public void registerSet(BootstapContext<StructureSet> bootstrapContext) {
|
public void registerSet(BootstapContext<StructureSet> bootstrapContext) {
|
||||||
|
if (registeredSet) return;
|
||||||
|
registeredSet = true;
|
||||||
bootstrapContext.register(structureSetKey, new StructureSet(
|
bootstrapContext.register(structureSetKey, new StructureSet(
|
||||||
bootstrapContext.lookup(Registries.STRUCTURE).getOrThrow(structureKey),
|
bootstrapContext.lookup(Registries.STRUCTURE).getOrThrow(structureKey),
|
||||||
spreadConfig
|
spreadConfig
|
||||||
));
|
));
|
||||||
|
BCLStructureBuilder.UNBOUND_STRUCTURE_SETS.remove(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract Bound<S> register(BootstapContext<Structure> bootstrapContext);
|
public abstract Bound<S> register(BootstapContext<Structure> bootstrapContext);
|
||||||
|
|
|
@ -3,19 +3,24 @@ package org.betterx.bclib.api.v2.levelgen.structures;
|
||||||
import org.betterx.worlds.together.tag.v3.TagManager;
|
import org.betterx.worlds.together.tag.v3.TagManager;
|
||||||
|
|
||||||
import com.mojang.serialization.Codec;
|
import com.mojang.serialization.Codec;
|
||||||
|
import net.minecraft.data.worldgen.BootstapContext;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.tags.TagKey;
|
import net.minecraft.tags.TagKey;
|
||||||
import net.minecraft.world.level.biome.Biome;
|
import net.minecraft.world.level.biome.Biome;
|
||||||
import net.minecraft.world.level.levelgen.GenerationStep;
|
import net.minecraft.world.level.levelgen.GenerationStep;
|
||||||
import net.minecraft.world.level.levelgen.structure.Structure;
|
import net.minecraft.world.level.levelgen.structure.Structure;
|
||||||
|
import net.minecraft.world.level.levelgen.structure.StructureSet;
|
||||||
import net.minecraft.world.level.levelgen.structure.TerrainAdjustment;
|
import net.minecraft.world.level.levelgen.structure.TerrainAdjustment;
|
||||||
import net.minecraft.world.level.levelgen.structure.placement.RandomSpreadStructurePlacement;
|
import net.minecraft.world.level.levelgen.structure.placement.RandomSpreadStructurePlacement;
|
||||||
import net.minecraft.world.level.levelgen.structure.placement.RandomSpreadType;
|
import net.minecraft.world.level.levelgen.structure.placement.RandomSpreadType;
|
||||||
import net.minecraft.world.level.levelgen.structure.placement.StructurePlacement;
|
import net.minecraft.world.level.levelgen.structure.placement.StructurePlacement;
|
||||||
|
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class BCLStructureBuilder<S extends Structure> {
|
public class BCLStructureBuilder<S extends Structure> {
|
||||||
|
static final ConcurrentLinkedQueue<BCLStructure.Unbound<?>> UNBOUND_STRUCTURES = new ConcurrentLinkedQueue<>();
|
||||||
|
static final ConcurrentLinkedQueue<BCLStructure.Unbound<?>> UNBOUND_STRUCTURE_SETS = new ConcurrentLinkedQueue<>();
|
||||||
|
|
||||||
private final ResourceLocation structureID;
|
private final ResourceLocation structureID;
|
||||||
private final Function<Structure.StructureSettings, S> structureBuilder;
|
private final Function<Structure.StructureSettings, S> structureBuilder;
|
||||||
|
@ -98,7 +103,7 @@ public class BCLStructureBuilder<S extends Structure> {
|
||||||
if (codec == null) codec(Structure.simpleCodec(structureBuilder));
|
if (codec == null) codec(Structure.simpleCodec(structureBuilder));
|
||||||
if (biomeTag == null) biomeTag(structureID.getNamespace(), structureID.getPath());
|
if (biomeTag == null) biomeTag(structureID.getNamespace(), structureID.getPath());
|
||||||
|
|
||||||
return new BCLStructure.Unbound<>(
|
var res = new BCLStructure.Unbound<>(
|
||||||
structureID,
|
structureID,
|
||||||
step,
|
step,
|
||||||
placement,
|
placement,
|
||||||
|
@ -107,5 +112,18 @@ public class BCLStructureBuilder<S extends Structure> {
|
||||||
structureBuilder,
|
structureBuilder,
|
||||||
terrainAdjustment
|
terrainAdjustment
|
||||||
);
|
);
|
||||||
|
UNBOUND_STRUCTURES.add(res);
|
||||||
|
UNBOUND_STRUCTURE_SETS.add(res);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void registerUnbound(BootstapContext<Structure> context) {
|
||||||
|
UNBOUND_STRUCTURES.forEach(s -> s.register(context));
|
||||||
|
UNBOUND_STRUCTURES.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void registerUnboundSets(BootstapContext<StructureSet> context) {
|
||||||
|
UNBOUND_STRUCTURE_SETS.forEach(s -> s.registerSet(context));
|
||||||
|
UNBOUND_STRUCTURE_SETS.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue