From 194ecd13cd86d90021a4d1e9327b6138a19e12ae Mon Sep 17 00:00:00 2001 From: FirstMegaGame4 <84094287+FirstMegaGame4@users.noreply.github.com> Date: Sun, 3 Dec 2023 20:43:44 +0100 Subject: [PATCH] Add CustomMossPatchFeature Fix Some Other Features --- .../CustomDripstoneClusterFeature.java | 17 +- .../defaults/CustomFlowerFeature.java | 27 ++- .../defaults/CustomLargeDripstoneFeature.java | 17 +- .../defaults/CustomMossPatchFeature.java | 154 ++++++++++++++++++ .../features/defaults/CustomOreFeature.java | 14 +- .../CustomPointedDripstoneFeature.java | 21 +-- .../defaults/CustomRandomPatchFeature.java | 19 +-- 7 files changed, 201 insertions(+), 68 deletions(-) create mode 100644 src/main/java/com/mmodding/mmodding_lib/library/worldgen/features/defaults/CustomMossPatchFeature.java diff --git a/src/main/java/com/mmodding/mmodding_lib/library/worldgen/features/defaults/CustomDripstoneClusterFeature.java b/src/main/java/com/mmodding/mmodding_lib/library/worldgen/features/defaults/CustomDripstoneClusterFeature.java index 195a968..1f930d3 100644 --- a/src/main/java/com/mmodding/mmodding_lib/library/worldgen/features/defaults/CustomDripstoneClusterFeature.java +++ b/src/main/java/com/mmodding/mmodding_lib/library/worldgen/features/defaults/CustomDripstoneClusterFeature.java @@ -3,6 +3,7 @@ import com.mmodding.mmodding_lib.library.utils.BiArrayList; import com.mmodding.mmodding_lib.library.utils.BiList; import com.mmodding.mmodding_lib.library.utils.IdentifierUtils; +import com.mmodding.mmodding_lib.library.utils.ListUtils; import com.mmodding.mmodding_lib.library.worldgen.MModdingFeatures; import com.mmodding.mmodding_lib.library.worldgen.features.differeds.DifferedDripstoneClusterFeature; import net.minecraft.block.Block; @@ -22,8 +23,6 @@ import org.quiltmc.qsl.worldgen.biome.api.BiomeModifications; import org.quiltmc.qsl.worldgen.biome.api.BiomeSelectionContext; -import java.util.ArrayList; -import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Predicate; @@ -91,14 +90,12 @@ public Feature getFeature() { } public PlacedFeature createPlacedFeature(IntProvider countRange) { - - List placementModifiers = new ArrayList<>(); - placementModifiers.add(CountPlacementModifier.create(countRange)); - placementModifiers.add(InSquarePlacementModifier.getInstance()); - placementModifiers.add(PlacedFeatureUtil.BOTTOM_TO_MAX_TERRAIN_HEIGHT_RANGE); - placementModifiers.add(BiomePlacementModifier.getInstance()); - - return new PlacedFeature(Holder.createDirect(this.getConfiguredFeature()), placementModifiers); + return new PlacedFeature(Holder.createDirect(this.getConfiguredFeature()), ListUtils.builder(placementModifiers -> { + placementModifiers.add(CountPlacementModifier.create(countRange)); + placementModifiers.add(InSquarePlacementModifier.getInstance()); + placementModifiers.add(PlacedFeatureUtil.BOTTOM_TO_MAX_TERRAIN_HEIGHT_RANGE); + placementModifiers.add(BiomePlacementModifier.getInstance()); + })); } @Override diff --git a/src/main/java/com/mmodding/mmodding_lib/library/worldgen/features/defaults/CustomFlowerFeature.java b/src/main/java/com/mmodding/mmodding_lib/library/worldgen/features/defaults/CustomFlowerFeature.java index 4147b2e..c1c6a40 100644 --- a/src/main/java/com/mmodding/mmodding_lib/library/worldgen/features/defaults/CustomFlowerFeature.java +++ b/src/main/java/com/mmodding/mmodding_lib/library/worldgen/features/defaults/CustomFlowerFeature.java @@ -3,6 +3,7 @@ import com.mmodding.mmodding_lib.library.utils.BiArrayList; import com.mmodding.mmodding_lib.library.utils.BiList; import com.mmodding.mmodding_lib.library.utils.IdentifierUtils; +import com.mmodding.mmodding_lib.library.utils.ListUtils; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.util.Holder; @@ -24,9 +25,7 @@ import org.quiltmc.qsl.worldgen.biome.api.BiomeModifications; import org.quiltmc.qsl.worldgen.biome.api.BiomeSelectionContext; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; @@ -48,7 +47,7 @@ public class CustomFlowerFeature implements CustomFeature, FeatureRegistrable { public CustomFlowerFeature(int tries, int spreadHorizontally, int spreadVertically, Block... noisedFlowers) { this.flowers = new BiArrayList<>(); - Arrays.stream(noisedFlowers).toList().forEach(block -> flowers.add(block, 0)); + Arrays.stream(noisedFlowers).toList().forEach(block -> this.flowers.add(block, 0)); this.tries = tries; this.spreadXZ = spreadHorizontally; this.spreadY = spreadVertically; @@ -73,20 +72,16 @@ public Feature getFeature() { BlockStateProvider provider; if (this.noised.get()) { - List flowerStates = new ArrayList<>(); - this.flowers.forEachFirst(block -> flowerStates.add(block.getDefaultState())); - provider = new NoiseBlockStateProvider( 2345L, new DoublePerlinNoiseSampler.NoiseParameters(0, 1.0), 0.05f, - flowerStates + ListUtils.builder(flowerStates -> this.flowers.forEachFirst(block -> flowerStates.add(block.getDefaultState()))) ); } else { DataPool.Builder builder = DataPool.builder(); this.flowers.forEach((block, integer) -> builder.add(block.getDefaultState(), integer)); - provider = new WeightedBlockStateProvider(builder); } @@ -107,15 +102,13 @@ public CustomFlowerFeature setRarity(int rarity) { } public PlacedFeature createPlacedFeature(int count, int rarity) { - - List placementModifiers = new ArrayList<>(); - if (count != 0) placementModifiers.add(CountPlacementModifier.create(count)); - if (rarity != 0) placementModifiers.add(RarityFilterPlacementModifier.create(rarity)); - placementModifiers.add(InSquarePlacementModifier.getInstance()); - placementModifiers.add(PlacedFeatureUtil.MOTION_BLOCKING_HEIGHTMAP); - placementModifiers.add(BiomePlacementModifier.getInstance()); - - return new PlacedFeature(Holder.createDirect(this.getConfiguredFeature()), placementModifiers); + return new PlacedFeature(Holder.createDirect(this.getConfiguredFeature()), ListUtils.builder(placementModifiers -> { + if (count != 0) placementModifiers.add(CountPlacementModifier.create(count)); + if (rarity != 0) placementModifiers.add(RarityFilterPlacementModifier.create(rarity)); + placementModifiers.add(InSquarePlacementModifier.getInstance()); + placementModifiers.add(PlacedFeatureUtil.MOTION_BLOCKING_HEIGHTMAP); + placementModifiers.add(BiomePlacementModifier.getInstance()); + })); } @Override diff --git a/src/main/java/com/mmodding/mmodding_lib/library/worldgen/features/defaults/CustomLargeDripstoneFeature.java b/src/main/java/com/mmodding/mmodding_lib/library/worldgen/features/defaults/CustomLargeDripstoneFeature.java index b44cce7..541a71d 100644 --- a/src/main/java/com/mmodding/mmodding_lib/library/worldgen/features/defaults/CustomLargeDripstoneFeature.java +++ b/src/main/java/com/mmodding/mmodding_lib/library/worldgen/features/defaults/CustomLargeDripstoneFeature.java @@ -3,6 +3,7 @@ import com.mmodding.mmodding_lib.library.utils.BiArrayList; import com.mmodding.mmodding_lib.library.utils.BiList; import com.mmodding.mmodding_lib.library.utils.IdentifierUtils; +import com.mmodding.mmodding_lib.library.utils.ListUtils; import com.mmodding.mmodding_lib.library.worldgen.MModdingFeatures; import com.mmodding.mmodding_lib.library.worldgen.features.differeds.DifferedLargeDripstoneFeature; import net.minecraft.block.Block; @@ -22,8 +23,6 @@ import org.quiltmc.qsl.worldgen.biome.api.BiomeModifications; import org.quiltmc.qsl.worldgen.biome.api.BiomeSelectionContext; -import java.util.ArrayList; -import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Predicate; @@ -82,14 +81,12 @@ public Feature getFeature() { } public PlacedFeature createPlacedFeature(IntProvider countRange) { - - List placementModifiers = new ArrayList<>(); - placementModifiers.add(CountPlacementModifier.create(countRange)); - placementModifiers.add(InSquarePlacementModifier.getInstance()); - placementModifiers.add(PlacedFeatureUtil.BOTTOM_TO_MAX_TERRAIN_HEIGHT_RANGE); - placementModifiers.add(BiomePlacementModifier.getInstance()); - - return new PlacedFeature(Holder.createDirect(this.getConfiguredFeature()), placementModifiers); + return new PlacedFeature(Holder.createDirect(this.getConfiguredFeature()), ListUtils.builder(placementModifiers -> { + placementModifiers.add(CountPlacementModifier.create(countRange)); + placementModifiers.add(InSquarePlacementModifier.getInstance()); + placementModifiers.add(PlacedFeatureUtil.BOTTOM_TO_MAX_TERRAIN_HEIGHT_RANGE); + placementModifiers.add(BiomePlacementModifier.getInstance()); + })); } @Override diff --git a/src/main/java/com/mmodding/mmodding_lib/library/worldgen/features/defaults/CustomMossPatchFeature.java b/src/main/java/com/mmodding/mmodding_lib/library/worldgen/features/defaults/CustomMossPatchFeature.java new file mode 100644 index 0000000..8236486 --- /dev/null +++ b/src/main/java/com/mmodding/mmodding_lib/library/worldgen/features/defaults/CustomMossPatchFeature.java @@ -0,0 +1,154 @@ +package com.mmodding.mmodding_lib.library.worldgen.features.defaults; + +import com.mmodding.mmodding_lib.library.utils.BiArrayList; +import com.mmodding.mmodding_lib.library.utils.BiList; +import com.mmodding.mmodding_lib.library.utils.IdentifierUtils; +import com.mmodding.mmodding_lib.library.utils.ListUtils; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.tag.TagKey; +import net.minecraft.util.Holder; +import net.minecraft.util.Identifier; +import net.minecraft.util.collection.DataPool; +import net.minecraft.util.math.Direction; +import net.minecraft.util.math.VerticalSurfaceType; +import net.minecraft.util.math.intprovider.ConstantIntProvider; +import net.minecraft.util.math.intprovider.IntProvider; +import net.minecraft.util.registry.Registry; +import net.minecraft.util.registry.RegistryKey; +import net.minecraft.world.gen.GenerationStep; +import net.minecraft.world.gen.YOffset; +import net.minecraft.world.gen.blockpredicate.BlockPredicate; +import net.minecraft.world.gen.decorator.*; +import net.minecraft.world.gen.feature.*; +import net.minecraft.world.gen.feature.util.PlacedFeatureUtil; +import net.minecraft.world.gen.stateprovider.BlockStateProvider; +import net.minecraft.world.gen.stateprovider.WeightedBlockStateProvider; +import org.quiltmc.qsl.worldgen.biome.api.BiomeModifications; +import org.quiltmc.qsl.worldgen.biome.api.BiomeSelectionContext; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Predicate; + +public class CustomMossPatchFeature implements CustomFeature, FeatureRegistrable { + + private final AtomicBoolean registered = new AtomicBoolean(); + private final AtomicReference identifier = new AtomicReference<>(); + private final BiList additionalPlacedFeatures = new BiArrayList<>(); + + private final int count; + private final Direction searchDirection; + private final int maxSteps; + private final TagKey replaceable; + private final BlockState ground; + private final BiList vegetationStates; + private final VerticalSurfaceType verticalSurfaceType; + private final IntProvider depth; + private final float extraBottomBlockChance; + private final int verticalRange; + private final float vegetationChance; + private final IntProvider horizontalRadius; + private final float extraEdgeColumnChance; + + public CustomMossPatchFeature(int count, Direction searchDirection, int maxSteps, TagKey replaceable, BlockState ground, BiList vegetationStates, VerticalSurfaceType verticalSurfaceType, IntProvider depth, float extraBottomBlockChance, int verticalRange, float vegetationChance, IntProvider horizontalRadius, float extraEdgeColumnChance) { + this.count = count; + this.searchDirection = searchDirection; + this.maxSteps = maxSteps; + this.replaceable = replaceable; + this.ground = ground; + this.vegetationStates = vegetationStates; + this.verticalSurfaceType = verticalSurfaceType; + this.depth = depth; + this.extraBottomBlockChance = extraBottomBlockChance; + this.verticalRange = verticalRange; + this.vegetationChance = vegetationChance; + this.horizontalRadius = horizontalRadius; + this.extraEdgeColumnChance = extraEdgeColumnChance; + } + + @Override + public Feature getFeature() { + return Feature.VEGETATION_PATCH; + } + + @Override + public ConfiguredFeature getConfiguredFeature() { + + DataPool.Builder builder = DataPool.builder(); + DataPool.of(builder); + this.vegetationStates.forEach(builder::add); + BlockStateProvider provider = new WeightedBlockStateProvider(builder); + + return new ConfiguredFeature<>(this.getFeature(), new VegetationPatchFeatureConfig( + this.replaceable, + BlockStateProvider.of(this.ground), + PlacedFeatureUtil.placedInline(Feature.SIMPLE_BLOCK, new SimpleBlockFeatureConfig(provider)), + this.verticalSurfaceType, + this.depth, + this.extraBottomBlockChance, + this.verticalRange, + this.vegetationChance, + this.horizontalRadius, + this.extraEdgeColumnChance) + ); + } + + public PlacedFeature createPlacedFeature(int count, Direction searchDirection, int maxSteps) { + return new PlacedFeature(Holder.createDirect(this.getConfiguredFeature()), ListUtils.builder(placementModifiers -> { + placementModifiers.add(CountPlacementModifier.create(count)); + placementModifiers.add(InSquarePlacementModifier.getInstance()); + placementModifiers.add(PlacedFeatureUtil.BOTTOM_TO_MAX_TERRAIN_HEIGHT_RANGE); + placementModifiers.add(EnvironmentScanPlacementModifier.create(searchDirection, BlockPredicate.solid(), BlockPredicate.IS_AIR, maxSteps)); + placementModifiers.add(RandomOffsetPlacementModifier.vertical(ConstantIntProvider.create(1))); + placementModifiers.add(BiomePlacementModifier.getInstance()); + })); + } + + @Override + public PlacedFeature getDefaultPlacedFeature() { + return this.createPlacedFeature(this.count, this.searchDirection, this.maxSteps); + } + + public CustomMossPatchFeature addPlacedFeature(int count, Direction searchDirection, int maxSteps, String idExt) { + this.additionalPlacedFeatures.add(this.createPlacedFeature(count, searchDirection, maxSteps), idExt); + return this; + } + + @Override + public BiList getAdditionalPlacedFeatures() { + return this.additionalPlacedFeatures; + } + + @Override + public void addDefaultToBiomes(Predicate ctx) { + this.addAdditionalToBiomes(ctx, ""); + } + + @Override + public void addAdditionalToBiomes(Predicate ctx, String idExt) { + if (this.registered.get()) { + BiomeModifications.addFeature( + ctx, GenerationStep.Feature.VEGETAL_DECORATION, + RegistryKey.of(Registry.PLACED_FEATURE_KEY, IdentifierUtils.extend(this.identifier.get(), idExt)) + ); + } + } + + @Override + public void setIdentifier(Identifier identifier) { + this.identifier.set(identifier); + } + + @Override + public boolean isNotRegistered() { + return !this.registered.get(); + } + + @Override + public void setRegistered() { + this.registered.set(true); + } +} diff --git a/src/main/java/com/mmodding/mmodding_lib/library/worldgen/features/defaults/CustomOreFeature.java b/src/main/java/com/mmodding/mmodding_lib/library/worldgen/features/defaults/CustomOreFeature.java index 09b1911..ec59eda 100644 --- a/src/main/java/com/mmodding/mmodding_lib/library/worldgen/features/defaults/CustomOreFeature.java +++ b/src/main/java/com/mmodding/mmodding_lib/library/worldgen/features/defaults/CustomOreFeature.java @@ -3,6 +3,7 @@ import com.mmodding.mmodding_lib.library.utils.BiArrayList; import com.mmodding.mmodding_lib.library.utils.BiList; import com.mmodding.mmodding_lib.library.utils.IdentifierUtils; +import com.mmodding.mmodding_lib.library.utils.ListUtils; import net.minecraft.util.Holder; import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; @@ -14,7 +15,6 @@ import org.quiltmc.qsl.worldgen.biome.api.BiomeModifications; import org.quiltmc.qsl.worldgen.biome.api.BiomeSelectionContext; -import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; @@ -57,13 +57,11 @@ public Feature getFeature() { } public PlacedFeature createPlacedFeature(int veinNumber, int minHeight, int maxHeight) { - - List placementModifiers = new ArrayList<>(); - placementModifiers.add(CountPlacementModifier.create(veinNumber)); - placementModifiers.add(InSquarePlacementModifier.getInstance()); - placementModifiers.add(HeightRangePlacementModifier.createUniform(YOffset.fixed(minHeight), YOffset.fixed(maxHeight))); - - return new PlacedFeature(Holder.createDirect(this.getConfiguredFeature()), placementModifiers); + return new PlacedFeature(Holder.createDirect(this.getConfiguredFeature()), ListUtils.builder(placementModifiers -> { + placementModifiers.add(CountPlacementModifier.create(veinNumber)); + placementModifiers.add(InSquarePlacementModifier.getInstance()); + placementModifiers.add(HeightRangePlacementModifier.createUniform(YOffset.fixed(minHeight), YOffset.fixed(maxHeight))); + })); } @Override diff --git a/src/main/java/com/mmodding/mmodding_lib/library/worldgen/features/defaults/CustomPointedDripstoneFeature.java b/src/main/java/com/mmodding/mmodding_lib/library/worldgen/features/defaults/CustomPointedDripstoneFeature.java index 5c20f26..012875d 100644 --- a/src/main/java/com/mmodding/mmodding_lib/library/worldgen/features/defaults/CustomPointedDripstoneFeature.java +++ b/src/main/java/com/mmodding/mmodding_lib/library/worldgen/features/defaults/CustomPointedDripstoneFeature.java @@ -3,6 +3,7 @@ import com.mmodding.mmodding_lib.library.utils.BiArrayList; import com.mmodding.mmodding_lib.library.utils.BiList; import com.mmodding.mmodding_lib.library.utils.IdentifierUtils; +import com.mmodding.mmodding_lib.library.utils.ListUtils; import com.mmodding.mmodding_lib.library.worldgen.MModdingFeatures; import com.mmodding.mmodding_lib.library.worldgen.features.differeds.DifferedPointedDripstoneFeature; import net.minecraft.block.Block; @@ -23,8 +24,6 @@ import org.quiltmc.qsl.worldgen.biome.api.BiomeModifications; import org.quiltmc.qsl.worldgen.biome.api.BiomeSelectionContext; -import java.util.ArrayList; -import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Predicate; @@ -112,16 +111,14 @@ public Feature getFeature() { } public PlacedFeature createPlacedFeature(IntProvider countRange, IntProvider numberRange, IntProvider spreadXZ, IntProvider spreadY) { - - List placementModifiers = new ArrayList<>(); - placementModifiers.add(CountPlacementModifier.create(countRange)); - placementModifiers.add(InSquarePlacementModifier.getInstance()); - placementModifiers.add(PlacedFeatureUtil.BOTTOM_TO_MAX_TERRAIN_HEIGHT_RANGE); - placementModifiers.add(CountPlacementModifier.create(numberRange)); - placementModifiers.add(RandomOffsetPlacementModifier.create(spreadXZ, spreadY)); - placementModifiers.add(BiomePlacementModifier.getInstance()); - - return new PlacedFeature(Holder.createDirect(this.getConfiguredFeature()), placementModifiers); + return new PlacedFeature(Holder.createDirect(this.getConfiguredFeature()), ListUtils.builder(placementModifiers -> { + placementModifiers.add(CountPlacementModifier.create(countRange)); + placementModifiers.add(InSquarePlacementModifier.getInstance()); + placementModifiers.add(PlacedFeatureUtil.BOTTOM_TO_MAX_TERRAIN_HEIGHT_RANGE); + placementModifiers.add(CountPlacementModifier.create(numberRange)); + placementModifiers.add(RandomOffsetPlacementModifier.create(spreadXZ, spreadY)); + placementModifiers.add(BiomePlacementModifier.getInstance()); + })); } @Override diff --git a/src/main/java/com/mmodding/mmodding_lib/library/worldgen/features/defaults/CustomRandomPatchFeature.java b/src/main/java/com/mmodding/mmodding_lib/library/worldgen/features/defaults/CustomRandomPatchFeature.java index aa225ef..d8f82b8 100644 --- a/src/main/java/com/mmodding/mmodding_lib/library/worldgen/features/defaults/CustomRandomPatchFeature.java +++ b/src/main/java/com/mmodding/mmodding_lib/library/worldgen/features/defaults/CustomRandomPatchFeature.java @@ -3,6 +3,7 @@ import com.mmodding.mmodding_lib.library.utils.BiArrayList; import com.mmodding.mmodding_lib.library.utils.BiList; import com.mmodding.mmodding_lib.library.utils.IdentifierUtils; +import com.mmodding.mmodding_lib.library.utils.ListUtils; import net.minecraft.util.Holder; import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; @@ -14,8 +15,6 @@ import org.quiltmc.qsl.worldgen.biome.api.BiomeModifications; import org.quiltmc.qsl.worldgen.biome.api.BiomeSelectionContext; -import java.util.ArrayList; -import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; @@ -62,15 +61,13 @@ public CustomRandomPatchFeature setRarity(int rarity) { } public PlacedFeature createPlacedFeature(int count, int rarity) { - - List placementModifiers = new ArrayList<>(); - if (count != 0) placementModifiers.add(CountPlacementModifier.create(count)); - if (rarity != 0) placementModifiers.add(RarityFilterPlacementModifier.create(rarity)); - placementModifiers.add(InSquarePlacementModifier.getInstance()); - placementModifiers.add(PlacedFeatureUtil.WORLD_SURFACE_WG_HEIGHTMAP); - placementModifiers.add(BiomePlacementModifier.getInstance()); - - return new PlacedFeature(Holder.createDirect(this.getConfiguredFeature()), placementModifiers); + return new PlacedFeature(Holder.createDirect(this.getConfiguredFeature()), ListUtils.builder(placementModifiers -> { + if (count != 0) placementModifiers.add(CountPlacementModifier.create(count)); + if (rarity != 0) placementModifiers.add(RarityFilterPlacementModifier.create(rarity)); + placementModifiers.add(InSquarePlacementModifier.getInstance()); + placementModifiers.add(PlacedFeatureUtil.WORLD_SURFACE_WG_HEIGHTMAP); + placementModifiers.add(BiomePlacementModifier.getInstance()); + })); } @Override