diff --git a/gradle.properties b/gradle.properties index 66888b8b..3bcf7ed1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/src/main/java/org/betterx/bclib/api/features/BCLCommonFeatures.java b/src/main/java/org/betterx/bclib/api/features/BCLCommonFeatures.java index 7e901bf9..8b648723 100644 --- a/src/main/java/org/betterx/bclib/api/features/BCLCommonFeatures.java +++ b/src/main/java/org/betterx/bclib/api/features/BCLCommonFeatures.java @@ -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 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, diff --git a/src/main/java/org/betterx/bclib/api/features/BCLFeatureBuilder.java b/src/main/java/org/betterx/bclib/api/features/BCLFeatureBuilder.java index e678eda9..68127ddb 100644 --- a/src/main/java/org/betterx/bclib/api/features/BCLFeatureBuilder.java +++ b/src/main/java/org/betterx/bclib/api/features/BCLFeatureBuilder.java @@ -132,17 +132,33 @@ public class BCLFeatureBuilder COLOR_BY_BLOCK = Maps.newHashMap(); @@ -201,4 +203,16 @@ public class BlocksHelper { return false; } } + + public static Optional findSurface(LevelAccessor level, + BlockPos startPos, + int minY, + Predicate 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(); + } } diff --git a/src/main/java/org/betterx/bclib/util/ModUtil.java b/src/main/java/org/betterx/bclib/util/ModUtil.java index 32e068a4..25e6d7dc 100644 --- a/src/main/java/org/betterx/bclib/util/ModUtil.java +++ b/src/main/java/org/betterx/bclib/util/ModUtil.java @@ -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; diff --git a/src/main/java/org/betterx/bclib/world/features/SurfaceFeature.java b/src/main/java/org/betterx/bclib/world/features/SurfaceFeature.java new file mode 100644 index 00000000..28ecc45c --- /dev/null +++ b/src/main/java/org/betterx/bclib/world/features/SurfaceFeature.java @@ -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 extends Feature { + public static abstract class DefaultConfiguration extends SurfaceFeature { + protected DefaultConfiguration() { + super(NoneFeatureConfiguration.CODEC); + } + } + + protected SurfaceFeature(Codec codec) { + super(codec); + } + + protected abstract boolean isValidSurface(BlockState state); + + protected int minHeight(FeaturePlaceContext ctx) { + return ctx.chunkGenerator().getSeaLevel(); + } + + @Override + public boolean place(FeaturePlaceContext ctx) { + Optional 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 ctx); +} diff --git a/src/main/java/org/betterx/bclib/world/generator/BCLibNetherBiomeSource.java b/src/main/java/org/betterx/bclib/world/generator/BCLibNetherBiomeSource.java index 3e4e8791..2ddee4ac 100644 --- a/src/main/java/org/betterx/bclib/world/generator/BCLibNetherBiomeSource.java +++ b/src/main/java/org/betterx/bclib/world/generator/BCLibNetherBiomeSource.java @@ -34,23 +34,23 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource { public static final Codec CODEC = RecordCodecBuilder .create(instance -> instance .group(RegistryOps - .retrieveRegistry(Registry.BIOME_REGISTRY) - .forGetter(source -> source.biomeRegistry), - Codec - .LONG - .fieldOf("seed") - .stable() - .forGetter(source -> { - return source.currentSeed; - }), - Codec - .INT - .optionalFieldOf("version") - .stable() - .forGetter(source -> Optional.of(source.biomeSourceVersion)) - ) + .retrieveRegistry(Registry.BIOME_REGISTRY) + .forGetter(source -> source.biomeRegistry), + Codec + .LONG + .fieldOf("seed") + .stable() + .forGetter(source -> { + return source.currentSeed; + }), + Codec + .INT + .optionalFieldOf("version") + .stable() + .forGetter(source -> Optional.of(source.biomeSourceVersion)) + ) .apply(instance, instance.stable(BCLibNetherBiomeSource::new)) - ); + ); private BiomeMap biomeMap; private final BiomePicker biomePicker; @@ -104,10 +104,10 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource { protected BCLBiomeSource cloneForDatapack(Set> datapackBiomes) { datapackBiomes.addAll(getBclBiomes(this.biomeRegistry)); return new BCLibNetherBiomeSource(this.biomeRegistry, - datapackBiomes.stream().toList(), - this.currentSeed, - Optional.of(biomeSourceVersion), - true); + datapackBiomes.stream().toList(), + this.currentSeed, + Optional.of(biomeSourceVersion), + true); } /** @@ -165,7 +165,6 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource { public Holder 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); @@ -198,8 +197,8 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource { ); } else { this.biomeMap = mapConstructor.apply(seed, - GeneratorOptions.getBiomeSizeNether(), - biomePicker); + GeneratorOptions.getBiomeSizeNether(), + biomePicker); } } diff --git a/src/main/java/org/betterx/bclib/world/generator/map/hex/HexBiomeMap.java b/src/main/java/org/betterx/bclib/world/generator/map/hex/HexBiomeMap.java index dbdc6eb9..741ed66c 100644 --- a/src/main/java/org/betterx/bclib/world/generator/map/hex/HexBiomeMap.java +++ b/src/main/java/org/betterx/bclib/world/generator/map/hex/HexBiomeMap.java @@ -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);