Moved vegetation functions
This commit is contained in:
parent
9ae9c318bd
commit
2d8b7fe70a
3 changed files with 84 additions and 18 deletions
50
src/main/java/ru/bclib/api/features/BCLCommonFeatures.java
Normal file
50
src/main/java/ru/bclib/api/features/BCLCommonFeatures.java
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
package ru.bclib.api.features;
|
||||||
|
|
||||||
|
import net.minecraft.data.worldgen.placement.PlacementUtils;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.util.valueproviders.UniformInt;
|
||||||
|
import net.minecraft.world.level.levelgen.GenerationStep.Decoration;
|
||||||
|
import net.minecraft.world.level.levelgen.feature.Feature;
|
||||||
|
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
|
||||||
|
import net.minecraft.world.level.levelgen.placement.BiomeFilter;
|
||||||
|
import net.minecraft.world.level.levelgen.placement.CountOnEveryLayerPlacement;
|
||||||
|
import net.minecraft.world.level.levelgen.placement.CountPlacement;
|
||||||
|
import net.minecraft.world.level.levelgen.placement.InSquarePlacement;
|
||||||
|
import net.minecraft.world.level.levelgen.placement.PlacementModifier;
|
||||||
|
import ru.bclib.world.features.BCLFeature;
|
||||||
|
|
||||||
|
public class BCLCommonFeatures {
|
||||||
|
/**
|
||||||
|
* Will create a basic plant feature.
|
||||||
|
* @param id {@link ResourceLocation} feature ID.
|
||||||
|
* @param feature {@link Feature} with {@link NoneFeatureConfiguration} config.
|
||||||
|
* @param density iterations per chunk.
|
||||||
|
* @return new BCLFeature instance.
|
||||||
|
*/
|
||||||
|
public static BCLFeature makeVegetationFeature(ResourceLocation id, Feature<NoneFeatureConfiguration> feature, int density) {
|
||||||
|
return BCLFeatureBuilder.start(id, feature).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will create a basic plant feature.
|
||||||
|
* @param id {@link ResourceLocation} feature ID.
|
||||||
|
* @param feature {@link Feature} with {@link NoneFeatureConfiguration} config.
|
||||||
|
* @param density iterations per chunk.
|
||||||
|
* @param allHeight if {@code true} will generate plant on all layers, if {@code false} - only on surface.
|
||||||
|
* @return new BCLFeature instance.
|
||||||
|
*/
|
||||||
|
public static BCLFeature makeVegetationFeature(ResourceLocation id, Feature<NoneFeatureConfiguration> feature, int density, boolean allHeight) {
|
||||||
|
if (allHeight) {
|
||||||
|
return BCLFeatureBuilder.start(id, feature).countLayers(density).onlyInBiome().build();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return BCLFeatureBuilder
|
||||||
|
.start(id, feature)
|
||||||
|
.countAverage(density)
|
||||||
|
.squarePlacement()
|
||||||
|
.heightmap()
|
||||||
|
.onlyInBiome()
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,10 +1,14 @@
|
||||||
package ru.bclib.api.features;
|
package ru.bclib.api.features;
|
||||||
|
|
||||||
|
import net.minecraft.data.worldgen.placement.PlacementUtils;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.level.levelgen.GenerationStep.Decoration;
|
import net.minecraft.world.level.levelgen.GenerationStep.Decoration;
|
||||||
import net.minecraft.world.level.levelgen.feature.Feature;
|
import net.minecraft.world.level.levelgen.feature.Feature;
|
||||||
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
|
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
|
||||||
|
import net.minecraft.world.level.levelgen.placement.BiomeFilter;
|
||||||
|
import net.minecraft.world.level.levelgen.placement.CountOnEveryLayerPlacement;
|
||||||
import net.minecraft.world.level.levelgen.placement.CountPlacement;
|
import net.minecraft.world.level.levelgen.placement.CountPlacement;
|
||||||
|
import net.minecraft.world.level.levelgen.placement.InSquarePlacement;
|
||||||
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
||||||
import net.minecraft.world.level.levelgen.placement.PlacementModifier;
|
import net.minecraft.world.level.levelgen.placement.PlacementModifier;
|
||||||
import net.minecraft.world.level.levelgen.placement.RarityFilter;
|
import net.minecraft.world.level.levelgen.placement.RarityFilter;
|
||||||
|
@ -75,13 +79,14 @@ public class BCLFeatureBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate feature in certain iterations (per chunk), count can be different in different chunks.
|
* Generate feature in certain iterations (per chunk).
|
||||||
* Feature will be generated on all layers (example - Nether plants).
|
* Feature will be generated on all layers (example - Nether plants).
|
||||||
* @param average how many times feature will be generated in chunk (in average).
|
* @param count how many times feature will be generated in chunk layers.
|
||||||
* @return same {@link BCLFeatureBuilder} instance.
|
* @return same {@link BCLFeatureBuilder} instance.
|
||||||
*/
|
*/
|
||||||
public BCLFeatureBuilder countLayers(int average) {
|
@SuppressWarnings("deprecation")
|
||||||
return modifier(RarityFilter.onAverageOnceEvery(average));
|
public BCLFeatureBuilder countLayers(int count) {
|
||||||
|
return modifier(CountOnEveryLayerPlacement.of(count));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -93,6 +98,25 @@ public class BCLFeatureBuilder {
|
||||||
return modifier(RarityFilter.onAverageOnceEvery(chunks));
|
return modifier(RarityFilter.onAverageOnceEvery(chunks));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restricts feature generation only to biome where feature was added.
|
||||||
|
* @return same {@link BCLFeatureBuilder} instance.
|
||||||
|
*/
|
||||||
|
public BCLFeatureBuilder onlyInBiome() {
|
||||||
|
return modifier(BiomeFilter.biome());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Are these two things required in 1.18.1?
|
||||||
|
// TODO - add information
|
||||||
|
public BCLFeatureBuilder squarePlacement() {
|
||||||
|
return modifier(InSquarePlacement.spread());
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO - add information
|
||||||
|
public BCLFeatureBuilder heightmap() {
|
||||||
|
return modifier(PlacementUtils.HEIGHTMAP);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a new {@link BCLFeature} instance. Features will be registered during this process.
|
* Builds a new {@link BCLFeature} instance. Features will be registered during this process.
|
||||||
* @param configuration any {@link FeatureConfiguration} for provided {@link Feature}.
|
* @param configuration any {@link FeatureConfiguration} for provided {@link Feature}.
|
||||||
|
|
|
@ -21,6 +21,7 @@ import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
||||||
import net.minecraft.world.level.levelgen.placement.PlacementModifier;
|
import net.minecraft.world.level.levelgen.placement.PlacementModifier;
|
||||||
import net.minecraft.world.level.levelgen.placement.RarityFilter;
|
import net.minecraft.world.level.levelgen.placement.RarityFilter;
|
||||||
import net.minecraft.world.level.levelgen.structure.templatesystem.BlockMatchTest;
|
import net.minecraft.world.level.levelgen.structure.templatesystem.BlockMatchTest;
|
||||||
|
import ru.bclib.api.features.BCLCommonFeatures;
|
||||||
|
|
||||||
public class BCLFeature {
|
public class BCLFeature {
|
||||||
private PlacedFeature placedFeature;
|
private PlacedFeature placedFeature;
|
||||||
|
@ -64,14 +65,16 @@ public class BCLFeature {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Deprecated, use function from {@link BCLCommonFeatures} instead.
|
||||||
* Will create a basic plant feature.
|
* Will create a basic plant feature.
|
||||||
* @param id {@link ResourceLocation} feature ID.
|
* @param id {@link ResourceLocation} feature ID.
|
||||||
* @param feature {@link Feature} with {@link NoneFeatureConfiguration} config.
|
* @param feature {@link Feature} with {@link NoneFeatureConfiguration} config.
|
||||||
* @param density iterations per chunk.
|
* @param density iterations per chunk.
|
||||||
* @return new BCLFeature instance.
|
* @return new BCLFeature instance.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(forRemoval = true)
|
||||||
public static BCLFeature makeVegetationFeature(ResourceLocation id, Feature<NoneFeatureConfiguration> feature, int density) {
|
public static BCLFeature makeVegetationFeature(ResourceLocation id, Feature<NoneFeatureConfiguration> feature, int density) {
|
||||||
return makeVegetationFeature(id, feature, density, false);
|
return BCLCommonFeatures.makeVegetationFeature(id, feature, density);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -82,20 +85,9 @@ public class BCLFeature {
|
||||||
* @param allHeight if {@code true} will generate plant on all layers, if {@code false} - only on surface.
|
* @param allHeight if {@code true} will generate plant on all layers, if {@code false} - only on surface.
|
||||||
* @return new BCLFeature instance.
|
* @return new BCLFeature instance.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(forRemoval = true)
|
||||||
public static BCLFeature makeVegetationFeature(ResourceLocation id, Feature<NoneFeatureConfiguration> feature, int density, boolean allHeight) {
|
public static BCLFeature makeVegetationFeature(ResourceLocation id, Feature<NoneFeatureConfiguration> feature, int density, boolean allHeight) {
|
||||||
if (allHeight) {
|
return BCLCommonFeatures.makeVegetationFeature(id, feature, density, allHeight);
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
PlacementModifier count =CountOnEveryLayerPlacement.of(density);
|
|
||||||
return makeFeature(id, Decoration.VEGETAL_DECORATION, feature, count, BiomeFilter.biome());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return makeFeature(id, Decoration.VEGETAL_DECORATION, feature,
|
|
||||||
CountPlacement.of(UniformInt.of(0, density)),
|
|
||||||
InSquarePlacement.spread(),
|
|
||||||
PlacementUtils.HEIGHTMAP,
|
|
||||||
BiomeFilter.biome()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue