Fixed structure features and code style
This commit is contained in:
parent
d431f2555c
commit
5a9365e2bb
153 changed files with 2304 additions and 2459 deletions
|
@ -1,15 +1,9 @@
|
|||
package ru.bclib.world.biomes;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
|
@ -21,23 +15,28 @@ import ru.bclib.world.features.ListFeature;
|
|||
import ru.bclib.world.features.ListFeature.StructureInfo;
|
||||
import ru.bclib.world.features.NBTStructureFeature.TerrainMerge;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class BCLBiome {
|
||||
protected WeightedList<BCLBiome> subbiomes = new WeightedList<BCLBiome>();
|
||||
|
||||
|
||||
protected final Biome biome;
|
||||
protected final ResourceLocation mcID;
|
||||
protected BCLBiome edge;
|
||||
protected int edgeSize;
|
||||
|
||||
|
||||
protected BCLBiome biomeParent;
|
||||
protected float maxSubBiomeChance = 1;
|
||||
protected final float genChance;
|
||||
|
||||
|
||||
private final Map<String, Object> customData;
|
||||
private final float fogDensity;
|
||||
private BCLFeature structuresFeature;
|
||||
private Biome actualBiome;
|
||||
|
||||
|
||||
public BCLBiome(BCLBiomeDef definition) {
|
||||
this.mcID = definition.getID();
|
||||
this.readStructureList();
|
||||
|
@ -49,7 +48,7 @@ public class BCLBiome {
|
|||
this.fogDensity = definition.getFodDensity();
|
||||
this.customData = definition.getCustomData();
|
||||
}
|
||||
|
||||
|
||||
public BCLBiome(ResourceLocation id, Biome biome, float fogDensity, float genChance) {
|
||||
this.mcID = id;
|
||||
this.biome = biome;
|
||||
|
@ -58,24 +57,24 @@ public class BCLBiome {
|
|||
this.readStructureList();
|
||||
this.customData = Maps.newHashMap();
|
||||
}
|
||||
|
||||
|
||||
public BCLBiome getEdge() {
|
||||
return edge == null ? this : edge;
|
||||
}
|
||||
|
||||
|
||||
public void setEdge(BCLBiome edge) {
|
||||
this.edge = edge;
|
||||
edge.biomeParent = this;
|
||||
}
|
||||
|
||||
|
||||
public int getEdgeSize() {
|
||||
return edgeSize;
|
||||
}
|
||||
|
||||
|
||||
public void setEdgeSize(int size) {
|
||||
edgeSize = size;
|
||||
}
|
||||
|
||||
|
||||
public void addSubBiome(BCLBiome biome) {
|
||||
biome.biomeParent = this;
|
||||
subbiomes.add(biome, biome.getGenChance());
|
||||
|
@ -84,41 +83,41 @@ public class BCLBiome {
|
|||
public boolean containsSubBiome(BCLBiome biome) {
|
||||
return subbiomes.contains(biome);
|
||||
}
|
||||
|
||||
|
||||
public BCLBiome getSubBiome(Random random) {
|
||||
BCLBiome biome = subbiomes.get(random);
|
||||
return biome == null ? this : biome;
|
||||
}
|
||||
|
||||
|
||||
public BCLBiome getParentBiome() {
|
||||
return this.biomeParent;
|
||||
}
|
||||
|
||||
|
||||
public boolean hasEdge() {
|
||||
return edge != null;
|
||||
}
|
||||
|
||||
|
||||
public boolean hasParentBiome() {
|
||||
return biomeParent != null;
|
||||
}
|
||||
|
||||
|
||||
public boolean isSame(BCLBiome biome) {
|
||||
return biome == this || (biome.hasParentBiome() && biome.getParentBiome() == this);
|
||||
}
|
||||
|
||||
|
||||
public Biome getBiome() {
|
||||
return biome;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return mcID.toString();
|
||||
}
|
||||
|
||||
|
||||
public ResourceLocation getID() {
|
||||
return mcID;
|
||||
}
|
||||
|
||||
|
||||
public float getFogDensity() {
|
||||
return fogDensity;
|
||||
}
|
||||
|
@ -126,7 +125,7 @@ public class BCLBiome {
|
|||
protected void readStructureList() {
|
||||
String ns = mcID.getNamespace();
|
||||
String nm = mcID.getPath();
|
||||
|
||||
|
||||
String path = "/data/" + ns + "/structures/biome/" + nm + "/";
|
||||
InputStream inputstream = StructureHelper.class.getResourceAsStream(path + "structures.json");
|
||||
if (inputstream != null) {
|
||||
|
@ -155,7 +154,7 @@ public class BCLBiome {
|
|||
public Biome getActualBiome() {
|
||||
return this.actualBiome;
|
||||
}
|
||||
|
||||
|
||||
public float getGenChance() {
|
||||
return this.genChance;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
package ru.bclib.world.biomes;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.particles.ParticleOptions;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
@ -32,7 +28,6 @@ import net.minecraft.world.level.levelgen.carver.CarverConfiguration;
|
|||
import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver;
|
||||
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
|
||||
import net.minecraft.world.level.levelgen.feature.configurations.ProbabilityFeatureConfiguration;
|
||||
import net.minecraft.world.level.levelgen.surfacebuilders.ConfiguredSurfaceBuilder;
|
||||
import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilder;
|
||||
import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilderBaseConfiguration;
|
||||
|
@ -42,6 +37,9 @@ import ru.bclib.world.features.BCLFeature;
|
|||
import ru.bclib.world.structures.BCLStructureFeature;
|
||||
import ru.bclib.world.surface.DoubleBlockSurfaceBuilder;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class BCLBiomeDef {
|
||||
public static final int DEF_FOLIAGE_OVERWORLD = ColorUtil.color(110, 143, 64);
|
||||
public static final int DEF_FOLIAGE_NETHER = ColorUtil.color(117, 10, 10);
|
||||
|
@ -55,13 +53,13 @@ public class BCLBiomeDef {
|
|||
private final Map<String, Object> customData = Maps.newHashMap();
|
||||
|
||||
private final ResourceLocation id;
|
||||
|
||||
|
||||
private AmbientParticleSettings particleConfig;
|
||||
private AmbientAdditionsSettings additions;
|
||||
private AmbientMoodSettings mood;
|
||||
private SoundEvent music;
|
||||
private SoundEvent loop;
|
||||
|
||||
|
||||
private int foliageColor = DEF_FOLIAGE_OVERWORLD;
|
||||
private int grassColor = DEF_FOLIAGE_OVERWORLD;
|
||||
private int waterFogColor = 329011;
|
||||
|
@ -78,17 +76,19 @@ public class BCLBiomeDef {
|
|||
private int edgeSize = 32;
|
||||
|
||||
private ConfiguredSurfaceBuilder<?> surface;
|
||||
|
||||
|
||||
/**
|
||||
* Custom biome definition. Can be extended with new parameters.
|
||||
*
|
||||
* @param id - Biome {@link ResourceLocation} (identifier).
|
||||
*/
|
||||
public BCLBiomeDef(ResourceLocation id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Create default definition for The Nether biome.
|
||||
*
|
||||
* @return {@link BCLBiomeDef}.
|
||||
*/
|
||||
public BCLBiomeDef netherBiome() {
|
||||
|
@ -98,8 +98,9 @@ public class BCLBiomeDef {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Create default definition for The End biome.
|
||||
*
|
||||
* @return {@link BCLBiomeDef}.
|
||||
*/
|
||||
public BCLBiomeDef endBiome() {
|
||||
|
@ -111,6 +112,7 @@ public class BCLBiomeDef {
|
|||
|
||||
/**
|
||||
* Used to load biome settings from config.
|
||||
*
|
||||
* @param config - {@link IdConfig}.
|
||||
* @return this {@link BCLBiomeDef}.
|
||||
*/
|
||||
|
@ -123,6 +125,7 @@ public class BCLBiomeDef {
|
|||
|
||||
/**
|
||||
* Set category of the biome.
|
||||
*
|
||||
* @param category - {@link BiomeCategory}.
|
||||
* @return this {@link BCLBiomeDef}.
|
||||
*/
|
||||
|
@ -137,11 +140,7 @@ public class BCLBiomeDef {
|
|||
}
|
||||
|
||||
public BCLBiomeDef setSurface(Block block) {
|
||||
setSurface(SurfaceBuilder.DEFAULT.configured(new SurfaceBuilderBaseConfiguration(
|
||||
block.defaultBlockState(),
|
||||
Blocks.END_STONE.defaultBlockState(),
|
||||
Blocks.END_STONE.defaultBlockState()
|
||||
)));
|
||||
setSurface(SurfaceBuilder.DEFAULT.configured(new SurfaceBuilderBaseConfiguration(block.defaultBlockState(), Blocks.END_STONE.defaultBlockState(), Blocks.END_STONE.defaultBlockState())));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -154,7 +153,7 @@ public class BCLBiomeDef {
|
|||
this.surface = builder;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public BCLBiomeDef setParticles(ParticleOptions particle, float probability) {
|
||||
this.particleConfig = new AmbientParticleSettings(particle, probability);
|
||||
return this;
|
||||
|
@ -184,7 +183,7 @@ public class BCLBiomeDef {
|
|||
this.edgeSize = edgeSize;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public BCLBiomeDef addMobSpawn(EntityType<?> type, int weight, int minGroupSize, int maxGroupSize) {
|
||||
ResourceLocation eID = Registry.ENTITY_TYPE.getKey(type);
|
||||
if (eID != Registry.ENTITY_TYPE.getDefaultKey()) {
|
||||
|
@ -202,7 +201,7 @@ public class BCLBiomeDef {
|
|||
spawns.add(entry);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public BCLBiomeDef addStructureFeature(ConfiguredStructureFeature<?, ?> feature) {
|
||||
structures.add(feature);
|
||||
return this;
|
||||
|
@ -220,7 +219,7 @@ public class BCLBiomeDef {
|
|||
features.add(info);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public BCLBiomeDef addFeature(Decoration featureStep, ConfiguredFeature<?, ?> feature) {
|
||||
FeatureInfo info = new FeatureInfo();
|
||||
info.featureStep = featureStep;
|
||||
|
@ -235,22 +234,22 @@ public class BCLBiomeDef {
|
|||
b = Mth.clamp(b, 0, 255);
|
||||
return ColorUtil.color(r, g, b);
|
||||
}
|
||||
|
||||
|
||||
public BCLBiomeDef setFogColor(int r, int g, int b) {
|
||||
this.fogColor = getColor(r, g, b);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public BCLBiomeDef setFogDensity(float density) {
|
||||
this.fogDensity = density;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public BCLBiomeDef setWaterColor(int r, int g, int b) {
|
||||
this.waterColor = getColor(r, g, b);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public BCLBiomeDef setWaterFogColor(int r, int g, int b) {
|
||||
this.waterFogColor = getColor(r, g, b);
|
||||
return this;
|
||||
|
@ -273,32 +272,32 @@ public class BCLBiomeDef {
|
|||
public BCLBiomeDef setPlantsColor(int r, int g, int b) {
|
||||
return this.setFoliageColor(r, g, b).setGrassColor(r, g, b);
|
||||
}
|
||||
|
||||
|
||||
public BCLBiomeDef setLoop(SoundEvent loop) {
|
||||
this.loop = loop;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public BCLBiomeDef setMood(SoundEvent mood) {
|
||||
this.mood = new AmbientMoodSettings(mood, 6000, 8, 2.0D);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public BCLBiomeDef setAdditions(SoundEvent additions) {
|
||||
this.additions = new AmbientAdditionsSettings(additions, 0.0111);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public BCLBiomeDef setMusic(SoundEvent music) {
|
||||
this.music = music;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Biome build() {
|
||||
MobSpawnSettings.Builder spawnSettings = new MobSpawnSettings.Builder();
|
||||
BiomeGenerationSettings.Builder generationSettings = new BiomeGenerationSettings.Builder();
|
||||
Builder effects = new Builder();
|
||||
|
||||
|
||||
mobs.forEach((spawn) -> {
|
||||
spawnSettings.addSpawn(spawn.type.getCategory(), new MobSpawnSettings.SpawnerData(spawn.type, spawn.weight, spawn.minGroupSize, spawn.maxGroupSize));
|
||||
});
|
||||
|
@ -311,34 +310,24 @@ public class BCLBiomeDef {
|
|||
structures.forEach((structure) -> generationSettings.addStructureStart(structure));
|
||||
features.forEach((info) -> generationSettings.addFeature(info.featureStep, info.feature));
|
||||
carvers.forEach((info) -> generationSettings.addCarver(info.carverStep, info.carver));
|
||||
|
||||
|
||||
effects.skyColor(0).waterColor(waterColor).waterFogColor(waterFogColor).fogColor(fogColor).foliageColorOverride(foliageColor).grassColorOverride(grassColor);
|
||||
if (loop != null) effects.ambientLoopSound(loop);
|
||||
if (mood != null) effects.ambientMoodSound(mood);
|
||||
if (additions != null) effects.ambientAdditionsSound(additions);
|
||||
if (particleConfig != null) effects.ambientParticle(particleConfig);
|
||||
effects.backgroundMusic(music != null ? new Music(music, 600, 2400, true) : Musics.END);
|
||||
|
||||
return new Biome.BiomeBuilder()
|
||||
.precipitation(precipitation)
|
||||
.biomeCategory(category)
|
||||
.depth(depth)
|
||||
.scale(0.2F)
|
||||
.temperature(temperature)
|
||||
.downfall(downfall)
|
||||
.specialEffects(effects.build())
|
||||
.mobSpawnSettings(spawnSettings.build())
|
||||
.generationSettings(generationSettings.build())
|
||||
.build();
|
||||
|
||||
return new Biome.BiomeBuilder().precipitation(precipitation).biomeCategory(category).depth(depth).scale(0.2F).temperature(temperature).downfall(downfall).specialEffects(effects.build()).mobSpawnSettings(spawnSettings.build()).generationSettings(generationSettings.build()).build();
|
||||
}
|
||||
|
||||
|
||||
private static final class SpawnInfo {
|
||||
EntityType<?> type;
|
||||
int weight;
|
||||
int minGroupSize;
|
||||
int maxGroupSize;
|
||||
}
|
||||
|
||||
|
||||
private static final class FeatureInfo {
|
||||
Decoration featureStep;
|
||||
ConfiguredFeature<?, ?> feature;
|
||||
|
@ -348,7 +337,7 @@ public class BCLBiomeDef {
|
|||
Carving carverStep;
|
||||
ConfiguredWorldCarver<CarverConfiguration> carver;
|
||||
}
|
||||
|
||||
|
||||
public ResourceLocation getID() {
|
||||
return id;
|
||||
}
|
||||
|
@ -356,7 +345,7 @@ public class BCLBiomeDef {
|
|||
public float getFodDensity() {
|
||||
return fogDensity;
|
||||
}
|
||||
|
||||
|
||||
public float getGenChance() {
|
||||
return genChance;
|
||||
}
|
||||
|
@ -364,7 +353,7 @@ public class BCLBiomeDef {
|
|||
public int getEdgeSize() {
|
||||
return edgeSize;
|
||||
}
|
||||
|
||||
|
||||
public BCLBiomeDef addCarver(Carving carverStep, ConfiguredWorldCarver<CarverConfiguration> carver) {
|
||||
CarverInfo info = new CarverInfo();
|
||||
info.carverStep = carverStep;
|
||||
|
|
|
@ -8,7 +8,7 @@ import java.lang.reflect.Field;
|
|||
|
||||
public class BCLDecorators {
|
||||
public static final ConfiguredDecorator<?> HEIGHTMAP_SQUARE;
|
||||
|
||||
|
||||
private static final ConfiguredDecorator<?> getDecorator(Field[] fields, int index) {
|
||||
try {
|
||||
return (ConfiguredDecorator<?>) fields[index].get(null);
|
||||
|
@ -18,7 +18,7 @@ public class BCLDecorators {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static {
|
||||
Class<?>[] classes = Features.class.getDeclaredClasses();
|
||||
Field[] fields = classes[1].getDeclaredFields(); // Decorators class
|
||||
|
|
|
@ -2,9 +2,7 @@ package ru.bclib.world.features;
|
|||
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.data.BuiltinRegistries;
|
||||
import net.minecraft.data.worldgen.Features;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.levelgen.GenerationStep;
|
||||
|
@ -15,7 +13,6 @@ import net.minecraft.world.level.levelgen.feature.configurations.CountConfigurat
|
|||
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
|
||||
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
|
||||
import net.minecraft.world.level.levelgen.feature.configurations.OreConfiguration;
|
||||
import net.minecraft.world.level.levelgen.feature.configurations.RangeDecoratorConfiguration;
|
||||
import net.minecraft.world.level.levelgen.placement.ChanceDecoratorConfiguration;
|
||||
import net.minecraft.world.level.levelgen.placement.FeatureDecorator;
|
||||
import net.minecraft.world.level.levelgen.structure.templatesystem.BlockMatchTest;
|
||||
|
@ -28,7 +25,7 @@ public class BCLFeature {
|
|||
private ConfiguredFeature<?, ?> featureConfigured;
|
||||
private GenerationStep.Decoration featureStep;
|
||||
private Feature<?> feature;
|
||||
|
||||
|
||||
public BCLFeature(Feature<?> feature, ConfiguredFeature<?, ?> configuredFeature, GenerationStep.Decoration featureStep) {
|
||||
this.featureConfigured = configuredFeature;
|
||||
this.featureStep = featureStep;
|
||||
|
@ -59,10 +56,7 @@ public class BCLFeature {
|
|||
public static BCLFeature makeOreFeature(ResourceLocation id, Block blockOre, int veins, int veinSize, int offset, int minY, int maxY) {
|
||||
OreConfiguration featureConfig = new OreConfiguration(new BlockMatchTest(Blocks.END_STONE), blockOre.defaultBlockState(), veinSize);
|
||||
OreConfiguration config = new OreConfiguration(ANY_TERRAIN, blockOre.defaultBlockState(), 33);
|
||||
ConfiguredFeature<?, ?> oreFeature = Feature.ORE.configured(featureConfig)
|
||||
.rangeUniform(VerticalAnchor.absolute(minY), VerticalAnchor.absolute(maxY))
|
||||
.squared()
|
||||
.count(veins);
|
||||
ConfiguredFeature<?, ?> oreFeature = Feature.ORE.configured(featureConfig).rangeUniform(VerticalAnchor.absolute(minY), VerticalAnchor.absolute(maxY)).squared().count(veins);
|
||||
return new BCLFeature(Feature.ORE, Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, id, oreFeature), GenerationStep.Decoration.UNDERGROUND_ORES);
|
||||
}
|
||||
|
||||
|
@ -89,11 +83,11 @@ public class BCLFeature {
|
|||
public Feature<?> getFeature() {
|
||||
return feature;
|
||||
}
|
||||
|
||||
|
||||
public ConfiguredFeature<?, ?> getFeatureConfigured() {
|
||||
return featureConfigured;
|
||||
}
|
||||
|
||||
|
||||
public GenerationStep.Decoration getFeatureStep() {
|
||||
return featureStep;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
package ru.bclib.world.features;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.WorldGenLevel;
|
||||
import net.minecraft.world.level.block.Mirror;
|
||||
|
@ -11,6 +8,9 @@ import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlac
|
|||
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
|
||||
import ru.bclib.util.StructureHelper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class ListFeature extends NBTStructureFeature {
|
||||
private final List<StructureInfo> list;
|
||||
private StructureInfo selected;
|
||||
|
@ -24,29 +24,29 @@ public class ListFeature extends NBTStructureFeature {
|
|||
selected = list.get(random.nextInt(list.size()));
|
||||
return selected.getStructure();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean canSpawn(WorldGenLevel world, BlockPos pos, Random random) {
|
||||
int cx = pos.getX() >> 4;
|
||||
int cz = pos.getZ() >> 4;
|
||||
return ((cx + cz) & 1) == 0 && pos.getY() > 58;// && world.getBlockState(pos.below()).is(EndTags.GEN_TERRAIN);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Rotation getRotation(WorldGenLevel world, BlockPos pos, Random random) {
|
||||
return Rotation.getRandom(random);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Mirror getMirror(WorldGenLevel world, BlockPos pos, Random random) {
|
||||
return Mirror.values()[random.nextInt(3)];
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected int getYOffset(StructureTemplate structure, WorldGenLevel world, BlockPos pos, Random random) {
|
||||
return selected.offsetY;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected TerrainMerge getTerrainMerge(WorldGenLevel world, BlockPos pos, Random random) {
|
||||
return selected.terrainMerge;
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
package ru.bclib.world.features;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.BlockPos.MutableBlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
|
@ -17,36 +13,38 @@ import net.minecraft.world.level.biome.Biome;
|
|||
import net.minecraft.world.level.block.Mirror;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
|
||||
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
|
||||
import net.minecraft.world.level.levelgen.structure.BoundingBox;
|
||||
import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings;
|
||||
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
|
||||
import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilderConfiguration;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import ru.bclib.api.BiomeAPI;
|
||||
import ru.bclib.api.TagAPI;
|
||||
import ru.bclib.util.BlocksHelper;
|
||||
import ru.bclib.world.processors.DestructionStructureProcessor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Random;
|
||||
|
||||
public abstract class NBTStructureFeature extends DefaultFeature {
|
||||
protected static final DestructionStructureProcessor DESTRUCTION = new DestructionStructureProcessor();
|
||||
|
||||
|
||||
protected abstract StructureTemplate getStructure(WorldGenLevel world, BlockPos pos, Random random);
|
||||
|
||||
|
||||
protected abstract boolean canSpawn(WorldGenLevel world, BlockPos pos, Random random);
|
||||
|
||||
|
||||
protected abstract Rotation getRotation(WorldGenLevel world, BlockPos pos, Random random);
|
||||
|
||||
|
||||
protected abstract Mirror getMirror(WorldGenLevel world, BlockPos pos, Random random);
|
||||
|
||||
|
||||
protected abstract int getYOffset(StructureTemplate structure, WorldGenLevel world, BlockPos pos, Random random);
|
||||
|
||||
|
||||
protected abstract TerrainMerge getTerrainMerge(WorldGenLevel world, BlockPos pos, Random random);
|
||||
|
||||
|
||||
protected abstract void addStructureData(StructurePlaceSettings data);
|
||||
|
||||
|
||||
protected BlockPos getGround(WorldGenLevel world, BlockPos center) {
|
||||
Biome biome = world.getBiome(center);
|
||||
ResourceLocation id = BiomeAPI.getBiomeID(biome);
|
||||
|
@ -59,7 +57,7 @@ public abstract class NBTStructureFeature extends DefaultFeature {
|
|||
return new BlockPos(center.getX(), y, center.getZ());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected int getAverageY(WorldGenLevel world, BlockPos center) {
|
||||
int y = getYOnSurface(world, center.getX(), center.getZ());
|
||||
y += getYOnSurface(world, center.getX() - 2, center.getZ() - 2);
|
||||
|
@ -68,7 +66,7 @@ public abstract class NBTStructureFeature extends DefaultFeature {
|
|||
y += getYOnSurface(world, center.getX() + 2, center.getZ() + 2);
|
||||
return y / 5;
|
||||
}
|
||||
|
||||
|
||||
protected int getAverageYWG(WorldGenLevel world, BlockPos center) {
|
||||
int y = getYOnSurfaceWG(world, center.getX(), center.getZ());
|
||||
y += getYOnSurfaceWG(world, center.getX() - 2, center.getZ() - 2);
|
||||
|
@ -77,33 +75,33 @@ public abstract class NBTStructureFeature extends DefaultFeature {
|
|||
y += getYOnSurfaceWG(world, center.getX() + 2, center.getZ() + 2);
|
||||
return y / 5;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> context) {
|
||||
WorldGenLevel world = context.level();
|
||||
Random random = context.random();
|
||||
BlockPos center = context.origin();
|
||||
|
||||
|
||||
center = new BlockPos(((center.getX() >> 4) << 4) | 8, 128, ((center.getZ() >> 4) << 4) | 8);
|
||||
center = getGround(world, center);
|
||||
|
||||
|
||||
if (!canSpawn(world, center, random)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
int posY = center.getY() + 1;
|
||||
StructureTemplate structure = getStructure(world, center, random);
|
||||
Rotation rotation = getRotation(world, center, random);
|
||||
Mirror mirror = getMirror(world, center, random);
|
||||
BlockPos offset = StructureTemplate.transform(new BlockPos(structure.getSize()), mirror, rotation, BlockPos.ZERO);
|
||||
center = center.offset(0, getYOffset(structure, world, center, random) + 0.5, 0);
|
||||
|
||||
|
||||
BoundingBox bounds = makeBox(center);
|
||||
StructurePlaceSettings placementData = new StructurePlaceSettings().setRotation(rotation).setMirror(mirror).setBoundingBox(bounds);
|
||||
addStructureData(placementData);
|
||||
center = center.offset(-offset.getX() * 0.5, 0, -offset.getZ() * 0.5);
|
||||
structure.placeInWorld(world, center, center, placementData, random, 4);
|
||||
|
||||
|
||||
TerrainMerge merge = getTerrainMerge(world, center, random);
|
||||
int x1 = center.getX();
|
||||
int z1 = center.getZ();
|
||||
|
@ -111,19 +109,19 @@ public abstract class NBTStructureFeature extends DefaultFeature {
|
|||
int z2 = z1 + offset.getZ();
|
||||
if (merge != TerrainMerge.NONE) {
|
||||
MutableBlockPos mut = new MutableBlockPos();
|
||||
|
||||
|
||||
if (x2 < x1) {
|
||||
int a = x1;
|
||||
x1 = x2;
|
||||
x2 = a;
|
||||
}
|
||||
|
||||
|
||||
if (z2 < z1) {
|
||||
int a = z1;
|
||||
z1 = z2;
|
||||
z2 = a;
|
||||
}
|
||||
|
||||
|
||||
int surfMax = posY - 1;
|
||||
for (int x = x1; x <= x2; x++) {
|
||||
mut.setX(x);
|
||||
|
@ -149,8 +147,7 @@ public abstract class NBTStructureFeature extends DefaultFeature {
|
|||
else {
|
||||
if (stateSt.is(TagAPI.END_GROUND) && state.getMaterial().isSolidBlocking()) {
|
||||
if (merge == TerrainMerge.SURFACE) {
|
||||
SurfaceBuilderConfiguration config = world.getBiome(mut).getGenerationSettings()
|
||||
.getSurfaceBuilderConfig();
|
||||
SurfaceBuilderConfiguration config = world.getBiome(mut).getGenerationSettings().getSurfaceBuilderConfig();
|
||||
BlocksHelper.setWithoutUpdate(world, mut, config.getUnderMaterial());
|
||||
}
|
||||
else {
|
||||
|
@ -165,10 +162,10 @@ public abstract class NBTStructureFeature extends DefaultFeature {
|
|||
}
|
||||
}
|
||||
//BlocksHelper.fixBlocks(world, new BlockPos(x1, center.getY(), z1), new BlockPos(x2, center.getY() + offset.getY(), z2));
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
protected BoundingBox makeBox(BlockPos pos) {
|
||||
int sx = ((pos.getX() >> 4) << 4) - 16;
|
||||
int sz = ((pos.getZ() >> 4) << 4) - 16;
|
||||
|
@ -176,35 +173,34 @@ public abstract class NBTStructureFeature extends DefaultFeature {
|
|||
int ez = sz + 47;
|
||||
return BoundingBox.fromCorners(new Vec3i(sx, 0, sz), new Vec3i(ex, 255, ez));
|
||||
}
|
||||
|
||||
|
||||
protected static StructureTemplate readStructure(ResourceLocation resource) {
|
||||
String ns = resource.getNamespace();
|
||||
String nm = resource.getPath();
|
||||
|
||||
|
||||
try {
|
||||
InputStream inputstream = MinecraftServer.class
|
||||
.getResourceAsStream("/data/" + ns + "/structures/" + nm + ".nbt");
|
||||
InputStream inputstream = MinecraftServer.class.getResourceAsStream("/data/" + ns + "/structures/" + nm + ".nbt");
|
||||
return readStructureFromStream(inputstream);
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private static StructureTemplate readStructureFromStream(InputStream stream) throws IOException {
|
||||
CompoundTag nbttagcompound = NbtIo.readCompressed(stream);
|
||||
|
||||
|
||||
StructureTemplate template = new StructureTemplate();
|
||||
template.load(nbttagcompound);
|
||||
|
||||
|
||||
return template;
|
||||
}
|
||||
|
||||
|
||||
public static enum TerrainMerge {
|
||||
NONE, SURFACE, OBJECT;
|
||||
|
||||
|
||||
public static TerrainMerge getFromString(String type) {
|
||||
if (type.equals("surface")) {
|
||||
return SURFACE;
|
||||
|
|
|
@ -1,34 +1,38 @@
|
|||
package ru.bclib.world.generator;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import ru.bclib.world.biomes.BCLBiome;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class BiomeChunk {
|
||||
protected static final int WIDTH = 16;
|
||||
private static final int SM_WIDTH = WIDTH >> 1;
|
||||
private static final int MASK_OFFSET = SM_WIDTH - 1;
|
||||
protected static final int MASK_WIDTH = WIDTH - 1;
|
||||
|
||||
|
||||
private final BCLBiome[][] biomes;
|
||||
|
||||
|
||||
public BiomeChunk(BiomeMap map, Random random, BiomePicker picker) {
|
||||
BCLBiome[][] PreBio = new BCLBiome[SM_WIDTH][SM_WIDTH];
|
||||
biomes = new BCLBiome[WIDTH][WIDTH];
|
||||
|
||||
for (int x = 0; x < SM_WIDTH; x++)
|
||||
for (int z = 0; z < SM_WIDTH; z++)
|
||||
|
||||
for (int x = 0; x < SM_WIDTH; x++) {
|
||||
for (int z = 0; z < SM_WIDTH; z++) {
|
||||
PreBio[x][z] = picker.getBiome(random);
|
||||
|
||||
for (int x = 0; x < WIDTH; x++)
|
||||
for (int z = 0; z < WIDTH; z++)
|
||||
}
|
||||
}
|
||||
|
||||
for (int x = 0; x < WIDTH; x++) {
|
||||
for (int z = 0; z < WIDTH; z++) {
|
||||
biomes[x][z] = PreBio[offsetXZ(x, random)][offsetXZ(z, random)].getSubBiome(random);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public BCLBiome getBiome(int x, int z) {
|
||||
return biomes[x & MASK_WIDTH][z & MASK_WIDTH];
|
||||
}
|
||||
|
||||
|
||||
private int offsetXZ(int x, Random random) {
|
||||
return ((x + random.nextInt(2)) >> 1) & MASK_OFFSET;
|
||||
}
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
package ru.bclib.world.generator;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.levelgen.WorldgenRandom;
|
||||
import ru.bclib.noise.OpenSimplexNoise;
|
||||
import ru.bclib.util.MHelper;
|
||||
import ru.bclib.world.biomes.BCLBiome;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class BiomeMap {
|
||||
private static final WorldgenRandom RANDOM = new WorldgenRandom();
|
||||
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
package ru.bclib.world.generator;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import ru.bclib.util.WeighTree;
|
||||
import ru.bclib.util.WeightedList;
|
||||
import ru.bclib.world.biomes.BCLBiome;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class BiomePicker {
|
||||
private final Set<ResourceLocation> immutableIDs = Sets.newHashSet();
|
||||
private final List<BCLBiome> biomes = Lists.newArrayList();
|
||||
|
@ -21,7 +20,7 @@ public class BiomePicker {
|
|||
public void addBiome(BCLBiome biome) {
|
||||
immutableIDs.add(biome.getID());
|
||||
biomes.add(biome);
|
||||
biomeCount ++;
|
||||
biomeCount++;
|
||||
}
|
||||
|
||||
public void addBiomeMutable(BCLBiome biome) {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package ru.bclib.world.generator;
|
||||
|
||||
public enum BiomeType {
|
||||
LAND,
|
||||
VOID;
|
||||
LAND, VOID;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ public class DestructionStructureProcessor extends StructureProcessor {
|
|||
}
|
||||
return structureBlockInfo2;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected StructureProcessorType<?> getType() {
|
||||
return StructureProcessorType.RULE;
|
||||
|
|
|
@ -19,7 +19,7 @@ public class TerrainStructureProcessor extends StructureProcessor {
|
|||
}
|
||||
return structureBlockInfo2;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected StructureProcessorType<?> getType() {
|
||||
return StructureProcessorType.RULE;
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package ru.bclib.world.structures;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.fabricmc.fabric.api.structure.v1.FabricStructureBuilder;
|
||||
import net.fabricmc.fabric.mixin.structure.FlatChunkGeneratorConfigAccessor;
|
||||
import net.minecraft.data.BuiltinRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.levelgen.GenerationStep;
|
||||
|
@ -10,6 +9,8 @@ import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
|
|||
import net.minecraft.world.level.levelgen.feature.StructureFeature;
|
||||
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class BCLStructureFeature {
|
||||
private static final Random RANDOM = new Random(354);
|
||||
private final StructureFeature<NoneFeatureConfiguration> structure;
|
||||
|
@ -18,24 +19,22 @@ public class BCLStructureFeature {
|
|||
|
||||
public BCLStructureFeature(ResourceLocation id, StructureFeature<NoneFeatureConfiguration> structure, GenerationStep.Decoration step, int spacing, int separation) {
|
||||
this.featureStep = step;
|
||||
this.structure = FabricStructureBuilder.create(id, structure)
|
||||
.step(step)
|
||||
.defaultConfig(spacing, separation, RANDOM.nextInt(8192))
|
||||
.register();
|
||||
|
||||
this.featureConfigured = this.structure.configured(NoneFeatureConfiguration.NONE);
|
||||
|
||||
this.structure = FabricStructureBuilder.create(id, structure).step(step).defaultConfig(spacing, separation, RANDOM.nextInt(8192)).register();
|
||||
|
||||
this.featureConfigured = this.structure.configured(NoneFeatureConfiguration.NONE);
|
||||
BuiltinRegistries.register(BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE, id, this.featureConfigured);
|
||||
FlatChunkGeneratorConfigAccessor.getStructureToFeatures().put(this.structure, this.featureConfigured);
|
||||
}
|
||||
|
||||
|
||||
public StructureFeature<NoneFeatureConfiguration> getStructure() {
|
||||
return structure;
|
||||
}
|
||||
|
||||
|
||||
public ConfiguredStructureFeature<?, ?> getFeatureConfigured() {
|
||||
return featureConfigured;
|
||||
}
|
||||
|
||||
|
||||
public GenerationStep.Decoration getFeatureStep() {
|
||||
return featureStep;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
package ru.bclib.world.structures;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
|
@ -15,6 +12,8 @@ import net.minecraft.world.level.block.state.BlockState;
|
|||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.levelgen.structure.BoundingBox;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class StructureWorld {
|
||||
private Map<ChunkPos, Part> parts = Maps.newHashMap();
|
||||
private ChunkPos lastPos;
|
||||
|
@ -153,7 +152,7 @@ public class StructureWorld {
|
|||
blocks.forEach((pos, state) -> {
|
||||
int stateID = states.getOrDefault(states, -1);
|
||||
if (stateID < 0) {
|
||||
stateID = id[0] ++;
|
||||
stateID = id[0]++;
|
||||
states.put(state, stateID);
|
||||
stateMap.add(NbtUtils.writeBlockState(state));
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package ru.bclib.world.surface;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
|
@ -14,6 +12,8 @@ import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilderBaseConf
|
|||
import ru.bclib.noise.OpenSimplexNoise;
|
||||
import ru.bclib.util.MHelper;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class DoubleBlockSurfaceBuilder extends SurfaceBuilder<SurfaceBuilderBaseConfiguration> {
|
||||
private static final OpenSimplexNoise NOISE = new OpenSimplexNoise(4141);
|
||||
private SurfaceBuilderBaseConfiguration config1;
|
||||
|
@ -43,7 +43,7 @@ public class DoubleBlockSurfaceBuilder extends SurfaceBuilder<SurfaceBuilderBase
|
|||
BlockState stone = Blocks.END_STONE.defaultBlockState();
|
||||
return this.configured(new SurfaceBuilderBaseConfiguration(config1.getTopMaterial(), stone, stone));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void apply(Random random, ChunkAccess chunkAccess, Biome biome, int x, int z, int height, double noise, BlockState defaultBlock, BlockState defaultFluid, int l, int m, long seed, SurfaceBuilderBaseConfiguration surfaceBuilderConfiguration) {
|
||||
noise = NOISE.eval(x * 0.1, z * 0.1) + MHelper.randRange(-0.4, 0.4, random);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue