Skip to content

Commit

Permalink
Add CustomMossPatchFeature
Browse files Browse the repository at this point in the history
Fix Some Other Features
  • Loading branch information
FirstMegaGame4 committed Dec 3, 2023
1 parent e97e20f commit 194ecd1
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -91,14 +90,12 @@ public Feature<DifferedDripstoneClusterFeature.Config> getFeature() {
}

public PlacedFeature createPlacedFeature(IntProvider countRange) {

List<PlacementModifier> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -73,20 +72,16 @@ public Feature<RandomPatchFeatureConfig> getFeature() {
BlockStateProvider provider;

if (this.noised.get()) {
List<BlockState> 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<BlockState> builder = DataPool.builder();
this.flowers.forEach((block, integer) -> builder.add(block.getDefaultState(), integer));

provider = new WeightedBlockStateProvider(builder);
}

Expand All @@ -107,15 +102,13 @@ public CustomFlowerFeature setRarity(int rarity) {
}

public PlacedFeature createPlacedFeature(int count, int rarity) {

List<PlacementModifier> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -82,14 +81,12 @@ public Feature<DifferedLargeDripstoneFeature.Config> getFeature() {
}

public PlacedFeature createPlacedFeature(IntProvider countRange) {

List<PlacementModifier> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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> identifier = new AtomicReference<>();
private final BiList<PlacedFeature, String> additionalPlacedFeatures = new BiArrayList<>();

private final int count;
private final Direction searchDirection;
private final int maxSteps;
private final TagKey<Block> replaceable;
private final BlockState ground;
private final BiList<BlockState, Integer> 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<Block> replaceable, BlockState ground, BiList<BlockState, Integer> 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<VegetationPatchFeatureConfig> getFeature() {
return Feature.VEGETATION_PATCH;
}

@Override
public ConfiguredFeature<?, ?> getConfiguredFeature() {

DataPool.Builder<BlockState> 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<PlacedFeature, String> getAdditionalPlacedFeatures() {
return this.additionalPlacedFeatures;
}

@Override
public void addDefaultToBiomes(Predicate<BiomeSelectionContext> ctx) {
this.addAdditionalToBiomes(ctx, "");
}

@Override
public void addAdditionalToBiomes(Predicate<BiomeSelectionContext> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -57,13 +57,11 @@ public Feature<OreFeatureConfig> getFeature() {
}

public PlacedFeature createPlacedFeature(int veinNumber, int minHeight, int maxHeight) {

List<PlacementModifier> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -112,16 +111,14 @@ public Feature<SimpleRandomFeatureConfig> getFeature() {
}

public PlacedFeature createPlacedFeature(IntProvider countRange, IntProvider numberRange, IntProvider spreadXZ, IntProvider spreadY) {

List<PlacementModifier> 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
Expand Down
Loading

0 comments on commit 194ecd1

Please sign in to comment.