Feature Builder for Random Feature Select
This commit is contained in:
parent
717f220af1
commit
c1d5ca7b9b
6 changed files with 176 additions and 27 deletions
|
@ -17,7 +17,6 @@ import net.minecraft.core.Holder;
|
|||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.BiomeTags;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.BiomeSource;
|
||||
import net.minecraft.world.level.biome.Climate;
|
||||
|
@ -136,11 +135,12 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource implements BiomeSourc
|
|||
|
||||
|
||||
private static boolean isValidNetherBiome(Holder<Biome> biome, ResourceLocation location) {
|
||||
//return biome.unwrapKey().get().location().toString().contains("gravel_desert");
|
||||
return biome.unwrapKey().get().location().toString().contains("mushroom_forest")
|
||||
|| biome.unwrapKey().get().location().toString().contains("old_fungiwoods");
|
||||
|
||||
return NetherBiomes.canGenerateInNether(biome.unwrapKey().get()) ||
|
||||
biome.is(BiomeTags.IS_NETHER) ||
|
||||
BiomeAPI.wasRegisteredAsNetherBiome(location);
|
||||
// return NetherBiomes.canGenerateInNether(biome.unwrapKey().get()) ||
|
||||
// biome.is(BiomeTags.IS_NETHER) ||
|
||||
// BiomeAPI.wasRegisteredAsNetherBiome(location);
|
||||
}
|
||||
|
||||
private static boolean isValidNonVanillaNetherBiome(Holder<Biome> biome, ResourceLocation location) {
|
||||
|
|
|
@ -28,6 +28,12 @@ import net.minecraft.world.level.levelgen.placement.PlacementModifier;
|
|||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @param <F>
|
||||
* @param <FC>
|
||||
* @deprecated Please use {@link org.betterx.bclib.api.v3.levelgen.features.BCLFeature} instead
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public class BCLFeature<F extends Feature<FC>, FC extends FeatureConfiguration> {
|
||||
public static final Feature<PlaceFacingBlockConfig> PLACE_BLOCK = register(
|
||||
BCLib.makeID("place_block"),
|
||||
|
|
|
@ -25,6 +25,12 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @param <FC>
|
||||
* @param <F>
|
||||
* @deprecated please use {@link org.betterx.bclib.api.v3.levelgen.features.BCLFeatureBuilder} instead
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public class BCLFeatureBuilder<FC extends FeatureConfiguration, F extends Feature<FC>> {
|
||||
private final List<PlacementModifier> modifications = new ArrayList<>(5);
|
||||
private final ResourceLocation featureID;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.betterx.bclib.api.v3.levelgen.features;
|
||||
|
||||
import org.betterx.bclib.BCLib;
|
||||
import org.betterx.bclib.api.v2.levelgen.features.BCLFeature;
|
||||
import org.betterx.bclib.api.v2.levelgen.features.config.PillarFeatureConfig;
|
||||
import org.betterx.bclib.api.v2.levelgen.features.config.PlaceFacingBlockConfig;
|
||||
|
@ -13,6 +14,7 @@ import org.betterx.bclib.api.v2.levelgen.structures.StructurePlacementType;
|
|||
import org.betterx.bclib.api.v2.levelgen.structures.StructureWorldNBT;
|
||||
import org.betterx.bclib.api.v2.poi.BCLPoiType;
|
||||
import org.betterx.bclib.blocks.BlockProperties;
|
||||
import org.betterx.bclib.util.Triple;
|
||||
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Holder;
|
||||
|
@ -109,6 +111,26 @@ public abstract class BCLFeatureBuilder<F extends Feature<FC>, FC extends Featur
|
|||
);
|
||||
}
|
||||
|
||||
public static AsRandomSelect startRandomSelect(
|
||||
ResourceLocation featureID
|
||||
) {
|
||||
return new AsRandomSelect(
|
||||
featureID,
|
||||
(RandomSelectorFeature) Feature.RANDOM_SELECTOR
|
||||
);
|
||||
}
|
||||
|
||||
public static AsMultiPlaceRandomSelect startRandomSelect(
|
||||
ResourceLocation featureID,
|
||||
BiFunction<BCLInlinePlacedBuilder<SimpleBlockFeature, SimpleBlockConfiguration>, Integer, Holder<PlacedFeature>> placementModFunction
|
||||
) {
|
||||
return new AsMultiPlaceRandomSelect(
|
||||
featureID,
|
||||
(RandomSelectorFeature) Feature.RANDOM_SELECTOR,
|
||||
placementModFunction
|
||||
);
|
||||
}
|
||||
|
||||
public static NetherForrestVegetation startNetherVegetation(
|
||||
ResourceLocation featureID
|
||||
) {
|
||||
|
@ -781,6 +803,142 @@ public abstract class BCLFeatureBuilder<F extends Feature<FC>, FC extends Featur
|
|||
return new SimpleBlockConfiguration(new WeightedStateProvider(stateBuilder.build()));
|
||||
}
|
||||
}
|
||||
|
||||
public static class AsRandomSelect extends BCLFeatureBuilder<RandomSelectorFeature, RandomFeatureConfiguration> {
|
||||
private List<WeightedPlacedFeature> features = new LinkedList<>();
|
||||
private Holder<PlacedFeature> defaultFeature;
|
||||
|
||||
private AsRandomSelect(ResourceLocation featureID, RandomSelectorFeature feature) {
|
||||
super(featureID, feature);
|
||||
}
|
||||
|
||||
|
||||
public AsRandomSelect add(Holder<PlacedFeature> feature, float weight) {
|
||||
features.add(new WeightedPlacedFeature(feature, weight));
|
||||
return this;
|
||||
}
|
||||
|
||||
public AsRandomSelect defaultFeature(Holder<PlacedFeature> feature) {
|
||||
defaultFeature = feature;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RandomFeatureConfiguration createConfiguration() {
|
||||
return new RandomFeatureConfiguration(features, defaultFeature);
|
||||
}
|
||||
}
|
||||
|
||||
public static class AsMultiPlaceRandomSelect extends BCLFeatureBuilder<RandomSelectorFeature, RandomFeatureConfiguration> {
|
||||
private List<Triple<BlockStateProvider, Float, Integer>> features = new LinkedList<>();
|
||||
|
||||
private final BiFunction<BCLInlinePlacedBuilder<SimpleBlockFeature, SimpleBlockConfiguration>, Integer, Holder<PlacedFeature>> modFunction;
|
||||
|
||||
private AsMultiPlaceRandomSelect(
|
||||
ResourceLocation featureID,
|
||||
RandomSelectorFeature feature,
|
||||
BiFunction<BCLInlinePlacedBuilder<SimpleBlockFeature, SimpleBlockConfiguration>, Integer, Holder<PlacedFeature>> mod
|
||||
) {
|
||||
super(featureID, feature);
|
||||
this.modFunction = mod;
|
||||
}
|
||||
|
||||
private static int featureCounter = 0;
|
||||
private static int lastID = 0;
|
||||
|
||||
public AsMultiPlaceRandomSelect addAllStates(Block block, int weight) {
|
||||
return addAllStates(block, weight, lastID + 1);
|
||||
}
|
||||
|
||||
public AsMultiPlaceRandomSelect addAll(int weight, Block... blocks) {
|
||||
return addAll(weight, lastID + 1, blocks);
|
||||
}
|
||||
|
||||
public AsMultiPlaceRandomSelect addAllStatesFor(IntegerProperty prop, Block block, int weight) {
|
||||
return addAllStatesFor(prop, block, weight, lastID + 1);
|
||||
}
|
||||
|
||||
public AsMultiPlaceRandomSelect add(Block block, float weight) {
|
||||
return add(BlockStateProvider.simple(block), weight);
|
||||
}
|
||||
|
||||
public AsMultiPlaceRandomSelect add(BlockState state, float weight) {
|
||||
return add(BlockStateProvider.simple(state), weight);
|
||||
}
|
||||
|
||||
public AsMultiPlaceRandomSelect add(BlockStateProvider provider, float weight) {
|
||||
return add(provider, weight, lastID + 1);
|
||||
}
|
||||
|
||||
|
||||
public AsMultiPlaceRandomSelect addAllStates(Block block, int weight, int id) {
|
||||
Set<BlockState> states = BCLPoiType.getBlockStates(block);
|
||||
SimpleWeightedRandomList.Builder<BlockState> builder = SimpleWeightedRandomList.builder();
|
||||
states.forEach(s -> builder.add(block.defaultBlockState(), 1));
|
||||
|
||||
this.add(new WeightedStateProvider(builder.build()), weight, id);
|
||||
return this;
|
||||
}
|
||||
|
||||
public AsMultiPlaceRandomSelect addAll(int weight, int id, Block... blocks) {
|
||||
SimpleWeightedRandomList.Builder<BlockState> builder = SimpleWeightedRandomList.builder();
|
||||
for (Block block : blocks) {
|
||||
builder.add(block.defaultBlockState(), 1);
|
||||
}
|
||||
|
||||
this.add(new WeightedStateProvider(builder.build()), weight, id);
|
||||
return this;
|
||||
}
|
||||
|
||||
public AsMultiPlaceRandomSelect addAllStatesFor(IntegerProperty prop, Block block, int weight, int id) {
|
||||
Collection<Integer> values = prop.getPossibleValues();
|
||||
SimpleWeightedRandomList.Builder<BlockState> builder = SimpleWeightedRandomList.builder();
|
||||
values.forEach(s -> builder.add(block.defaultBlockState().setValue(prop, s), 1));
|
||||
this.add(new WeightedStateProvider(builder.build()), weight, id);
|
||||
return this;
|
||||
}
|
||||
|
||||
public AsMultiPlaceRandomSelect add(Block block, float weight, int id) {
|
||||
return add(BlockStateProvider.simple(block), weight, id);
|
||||
}
|
||||
|
||||
public AsMultiPlaceRandomSelect add(BlockState state, float weight, int id) {
|
||||
return add(BlockStateProvider.simple(state), weight, id);
|
||||
}
|
||||
|
||||
public AsMultiPlaceRandomSelect add(BlockStateProvider provider, float weight, int id) {
|
||||
features.add(new Triple<>(provider, weight, id));
|
||||
lastID = Math.max(lastID, id);
|
||||
return this;
|
||||
}
|
||||
|
||||
private Holder<PlacedFeature> place(BlockStateProvider p, int id) {
|
||||
var builder = BCLFeatureBuilder
|
||||
.start(BCLib.makeID("temp_select_feature" + (featureCounter++)), p)
|
||||
.inlinePlace();
|
||||
return modFunction.apply(builder, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RandomFeatureConfiguration createConfiguration() {
|
||||
if (modFunction == null) {
|
||||
throw new IllegalStateException("AsMultiPlaceRandomSelect needs a placement.modification Function");
|
||||
}
|
||||
float sum = this.features.stream().map(p -> p.second).reduce(0.0f, (p, v) -> p + v);
|
||||
List<WeightedPlacedFeature> features = this.features.stream()
|
||||
.map(p -> new WeightedPlacedFeature(
|
||||
this.place(p.first, p.third),
|
||||
p.second / sum
|
||||
))
|
||||
.toList();
|
||||
|
||||
|
||||
return new RandomFeatureConfiguration(
|
||||
features.subList(0, features.size() - 1),
|
||||
features.get(features.size() - 1).feature
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ public class BCLInlinePlacedBuilder<F extends Feature<FC>, FC extends FeatureCon
|
|||
*
|
||||
* @return created {@link PlacedFeature} instance.
|
||||
*/
|
||||
@Override
|
||||
public Holder<PlacedFeature> build() {
|
||||
return build(cFeature);
|
||||
}
|
||||
|
|
|
@ -11,12 +11,9 @@ import net.minecraft.data.worldgen.placement.PlacementUtils;
|
|||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.valueproviders.IntProvider;
|
||||
import net.minecraft.util.valueproviders.UniformInt;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.levelgen.blockpredicates.BlockPredicate;
|
||||
import net.minecraft.world.level.levelgen.feature.Feature;
|
||||
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
|
||||
import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvider;
|
||||
import net.minecraft.world.level.levelgen.placement.*;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
|
||||
|
@ -443,23 +440,4 @@ abstract class CommonPlacedFeatureBuilder<F extends Feature<FC>, FC extends Feat
|
|||
public BCLFeatureBuilder.RandomPatch inRandomPatch(ResourceLocation id) {
|
||||
return BCLFeatureBuilder.startRandomPatch(id, build());
|
||||
}
|
||||
|
||||
public BCLFeatureBuilder.AsSequence then(ResourceLocation id) {
|
||||
return BCLFeatureBuilder.startSequence(id).add(build());
|
||||
}
|
||||
|
||||
public BCLFeatureBuilder.ForSimpleBlock putBlock(ResourceLocation id, Block block) {
|
||||
return BCLFeatureBuilder.start(id, block);
|
||||
}
|
||||
|
||||
public BCLFeatureBuilder.ForSimpleBlock putBlock(ResourceLocation id, BlockState state) {
|
||||
return BCLFeatureBuilder.start(id, state);
|
||||
}
|
||||
|
||||
public BCLFeatureBuilder.ForSimpleBlock putBlock(
|
||||
ResourceLocation id,
|
||||
BlockStateProvider provider
|
||||
) {
|
||||
return BCLFeatureBuilder.start(id, provider);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue