Started Feature Migration in BN

This commit is contained in:
Frank 2022-05-28 15:06:50 +02:00
parent 2168787ac2
commit abe18ae923
9 changed files with 142 additions and 34 deletions

View file

@ -1,7 +1,7 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx2G
#Loom
loom_version=0.11-SNAPSHOT
loom_version=0.12-SNAPSHOT
# Fabric Properties
# check these on https://fabricmc.net/versions.html
minecraft_version=1.19-pre3

View file

@ -40,7 +40,12 @@ public class BCLCommonFeatures {
int density,
boolean allHeight) {
if (allHeight) {
return BCLFeatureBuilder.start(id, feature).countLayers(density).squarePlacement().onlyInBiome().build();
return BCLFeatureBuilder
.start(id, feature)
.countLayers(density)
.squarePlacement()
.onlyInBiome()
.buildAndRegister();
} else {
return BCLFeatureBuilder
.start(id, feature)
@ -48,7 +53,7 @@ public class BCLCommonFeatures {
.squarePlacement()
.heightmap()
.onlyInBiome()
.build();
.buildAndRegister();
}
}
@ -63,7 +68,7 @@ public class BCLCommonFeatures {
public static BCLFeature makeChunkFeature(ResourceLocation id,
Decoration decoration,
Feature<NoneFeatureConfiguration> feature) {
return BCLFeatureBuilder.start(id, feature).decoration(decoration).count(1).onlyInBiome().build();
return BCLFeatureBuilder.start(id, feature).decoration(decoration).count(1).onlyInBiome().buildAndRegister();
}
/**
@ -84,7 +89,7 @@ public class BCLCommonFeatures {
.oncePerChunks(chance)
.squarePlacement()
.onlyInBiome()
.build();
.buildAndRegister();
}
/**
@ -105,7 +110,7 @@ public class BCLCommonFeatures {
.count(count)
.squarePlacement()
.onlyInBiome()
.build();
.buildAndRegister();
}
/**
@ -140,7 +145,7 @@ public class BCLCommonFeatures {
builder.modifier(placement).squarePlacement().onlyInBiome();
return builder.build(new OreConfiguration(
return builder.buildAndRegister(new OreConfiguration(
new BlockMatchTest(hostBlock),
blockOre.defaultBlockState(),
veinSize,

View file

@ -132,17 +132,33 @@ public class BCLFeatureBuilder<FC extends FeatureConfiguration, F extends Featur
return modifier(InSquarePlacement.spread());
}
public BCLFeatureBuilder distanceToTopAndBottom10() {
return modifier(PlacementUtils.RANGE_10_10);
}
public BCLFeatureBuilder distanceToTopAndBottom4() {
return modifier(PlacementUtils.RANGE_4_4);
}
public BCLFeatureBuilder heightmap() {
return modifier(PlacementUtils.HEIGHTMAP);
}
public BCLFeatureBuilder heightmapTopSolid() {
return modifier(PlacementUtils.HEIGHTMAP_TOP_SOLID);
}
public BCLFeatureBuilder heightmapWorldSurface() {
return modifier(PlacementUtils.HEIGHTMAP_WORLD_SURFACE);
}
/**
* Builds a new {@link BCLFeature} instance. Features will be registered during this process.
*
* @param configuration any {@link FeatureConfiguration} for provided {@link Feature}.
* @return created {@link BCLFeature} instance.
*/
public BCLFeature build(FC configuration) {
public BCLFeature buildAndRegister(FC configuration) {
PlacementModifier[] modifiers = modifications.toArray(new PlacementModifier[modifications.size()]);
return new BCLFeature(featureID, feature, decoration, configuration, modifiers);
}
@ -153,7 +169,17 @@ public class BCLFeatureBuilder<FC extends FeatureConfiguration, F extends Featur
*
* @return created {@link BCLFeature} instance.
*/
public BCLFeature buildAndRegister() {
return buildAndRegister((FC) FeatureConfiguration.NONE);
}
@Deprecated(forRemoval = true)
public BCLFeature build(FC configuration) {
return buildAndRegister(configuration);
}
@Deprecated(forRemoval = true)
public BCLFeature build() {
return build((FC) FeatureConfiguration.NONE);
return buildAndRegister();
}
}

View file

@ -4,11 +4,13 @@ import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.resources.RegistryOps;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.biome.BiomeSource;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator;
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
import net.minecraft.world.level.levelgen.RandomState;
import net.minecraft.world.level.levelgen.WorldGenSettings;
import net.minecraft.world.level.levelgen.structure.StructureSet;
import net.minecraft.world.level.levelgen.synth.NormalNoise;
@ -116,4 +118,14 @@ public class BCLChunkGenerator extends NoiseBasedChunkGenerator {
public String toString() {
return "BCLib - Chunk Generator (" + Integer.toHexString(hashCode()) + ")";
}
public static RandomState createRandomState(ServerLevel level, ChunkGenerator generator) {
if (generator instanceof NoiseBasedChunkGenerator noiseBasedChunkGenerator) {
return RandomState.create(noiseBasedChunkGenerator.generatorSettings().value(),
level.registryAccess().registryOrThrow(Registry.NOISE_REGISTRY),
level.getSeed());
} else {
return RandomState.create(level.registryAccess(), NoiseGeneratorSettings.OVERWORLD, level.getSeed());
}
}
}

View file

@ -17,7 +17,9 @@ import net.minecraft.world.level.block.state.properties.Property;
import com.google.common.collect.Maps;
import java.util.Map;
import java.util.Optional;
import java.util.Random;
import java.util.function.Predicate;
public class BlocksHelper {
private static final Map<Block, Integer> COLOR_BY_BLOCK = Maps.newHashMap();
@ -201,4 +203,16 @@ public class BlocksHelper {
return false;
}
}
public static Optional<BlockPos> findSurface(LevelAccessor level,
BlockPos startPos,
int minY,
Predicate<BlockState> surface) {
final MutableBlockPos POS = new MutableBlockPos(startPos.getX(), startPos.getY(), startPos.getZ());
for (int y = startPos.getY(); y >= minY; y--) {
POS.setY(y);
if (surface.test(level.getBlockState(POS))) return Optional.of(POS);
}
return Optional.empty();
}
}

View file

@ -8,7 +8,6 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.stream.JsonReader;
import org.apache.logging.log4j.LogManager;
import org.betterx.bclib.BCLib;
import java.io.IOException;
@ -48,7 +47,6 @@ public class ModUtil {
if (mods != null) return mods;
mods = new HashMap<>();
org.apache.logging.log4j.Logger logger = LogManager.getFormatterLogger("BCLib|ModLoader");
PathUtil.fileWalker(PathUtil.MOD_FOLDER.toFile(), false, (ModUtil::accept));
return mods;

View file

@ -0,0 +1,53 @@
package org.betterx.bclib.world.features;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import com.mojang.serialization.Codec;
import org.betterx.bclib.util.BlocksHelper;
import java.util.Optional;
public abstract class SurfaceFeature<T extends FeatureConfiguration> extends Feature<T> {
public static abstract class DefaultConfiguration extends SurfaceFeature<NoneFeatureConfiguration> {
protected DefaultConfiguration() {
super(NoneFeatureConfiguration.CODEC);
}
}
protected SurfaceFeature(Codec<T> codec) {
super(codec);
}
protected abstract boolean isValidSurface(BlockState state);
protected int minHeight(FeaturePlaceContext<T> ctx) {
return ctx.chunkGenerator().getSeaLevel();
}
@Override
public boolean place(FeaturePlaceContext<T> ctx) {
Optional<BlockPos> pos = BlocksHelper.findSurface(ctx.level(),
ctx.origin(),
minHeight(ctx),
this::isValidSurface);
if (pos.isPresent()) {
int y2 = ctx.level().getHeight(Heightmap.Types.WORLD_SURFACE_WG, ctx.origin().getX(), ctx.origin().getZ());
int y3 = ctx.level().getHeight(Heightmap.Types.WORLD_SURFACE, ctx.origin().getX(), ctx.origin().getZ());
System.out.println("Surfaces:" + pos.get().getY() + ", " + y2 + ", " + y3);
generate(pos.get(), ctx);
return true;
}
return false;
}
protected abstract void generate(BlockPos centerPos, FeaturePlaceContext<T> ctx);
}

View file

@ -165,7 +165,6 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource {
public Holder<Biome> getNoiseBiome(int biomeX, int biomeY, int biomeZ, Climate.Sampler var4) {
if (biomeMap == null)
return this.possibleBiomes().stream().findFirst().get();
if (lastWorldHeight != worldHeight) {
lastWorldHeight = worldHeight;
initMap(this.currentSeed);

View file

@ -37,6 +37,7 @@ public class HexBiomeMap implements BiomeMap {
this.picker = picker;
this.scale = HexBiomeChunk.scaleMap(size);
Random random = new Random(seed);
noises[0] = new OpenSimplexNoise(random.nextInt());
noises[1] = new OpenSimplexNoise(random.nextInt());
noiseIterations = (byte) Math.min(Math.ceil(Math.log(scale) / Math.log(2)), 5);