[Changes] Adapted BCLFeatureBuilder for DataGen pass

This commit is contained in:
Frank 2022-11-30 03:15:54 +01:00
parent 7b726d958d
commit 2e60364029
8 changed files with 376 additions and 243 deletions

View file

@ -2,6 +2,7 @@ package org.betterx.bclib.api.v3.levelgen.features;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.data.worldgen.BootstapContext;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource; import net.minecraft.util.RandomSource;
@ -17,6 +18,22 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
public class BCLConfigureFeature<F extends Feature<FC>, FC extends FeatureConfiguration> { public class BCLConfigureFeature<F extends Feature<FC>, FC extends FeatureConfiguration> {
public static class Unregistered<F extends Feature<FC>, FC extends FeatureConfiguration> extends BCLConfigureFeature<F, FC> {
Unregistered(ResourceLocation id, Holder<ConfiguredFeature<FC, F>> configuredFeature) {
super(id, configuredFeature, false);
}
@Override
public BCLConfigureFeature<F, FC> register(BootstapContext<ConfiguredFeature<?, ?>> bootstrapContext) {
Holder<ConfiguredFeature<FC, F>> holder = BCLFeatureBuilder.register(
bootstrapContext,
id,
configuredFeature.value()
);
return new BCLConfigureFeature<>(id, holder, true);
}
}
private static final Map<Holder<ConfiguredFeature<?, ?>>, BCLConfigureFeature<?, ?>> KNOWN = new HashMap<>(); private static final Map<Holder<ConfiguredFeature<?, ?>>, BCLConfigureFeature<?, ?>> KNOWN = new HashMap<>();
public final ResourceLocation id; public final ResourceLocation id;
@ -111,4 +128,8 @@ public class BCLConfigureFeature<F extends Feature<FC>, FC extends FeatureConfig
) { ) {
return placeUnboundInWorld(feature, config, level, pos, random, true); return placeUnboundInWorld(feature, config, level, pos, random, true);
} }
public BCLConfigureFeature<F, FC> register(BootstapContext<ConfiguredFeature<?, ?>> bootstrapContext) {
return this;
}
} }

View file

@ -13,6 +13,7 @@ import org.betterx.bclib.api.v3.levelgen.features.features.PlaceBlockFeature;
import org.betterx.bclib.api.v3.levelgen.features.features.SequenceFeature; import org.betterx.bclib.api.v3.levelgen.features.features.SequenceFeature;
import org.betterx.bclib.api.v3.levelgen.features.features.TemplateFeature; import org.betterx.bclib.api.v3.levelgen.features.features.TemplateFeature;
import org.betterx.bclib.blocks.BlockProperties; import org.betterx.bclib.blocks.BlockProperties;
import org.betterx.bclib.util.FullReferenceHolder;
import org.betterx.bclib.util.Triple; import org.betterx.bclib.util.Triple;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
@ -48,195 +49,181 @@ public abstract class BCLFeatureBuilder<F extends Feature<FC>, FC extends Featur
@FunctionalInterface @FunctionalInterface
public interface HolderBuilder<F extends Feature<FC>, FC extends FeatureConfiguration> { public interface HolderBuilder<F extends Feature<FC>, FC extends FeatureConfiguration> {
Holder<ConfiguredFeature<FC, F>> apply( Holder<ConfiguredFeature<FC, F>> apply(
Context ctx,
ResourceLocation id, ResourceLocation id,
ConfiguredFeature<FC, F> feature ConfiguredFeature<FC, F> feature
); );
} }
public record Context(BootstapContext<ConfiguredFeature<?, ?>> bootstrapContext) { @FunctionalInterface
/** public interface FeatureBuilder<F extends Feature<FC>, FC extends FeatureConfiguration, B extends BCLConfigureFeature<F, FC>> {
* Starts a new {@link BCLFeature} builder. B create(ResourceLocation id, Holder<ConfiguredFeature<FC, F>> configuredFeature);
*
* @param featureID {@link ResourceLocation} feature identifier.
* @param feature {@link Feature} to construct.
* @return {@link BCLFeatureBuilder} instance.
*/
public <F extends Feature<FC>, FC extends FeatureConfiguration> WithConfiguration<F, FC> start(
ResourceLocation featureID,
F feature
) {
return new WithConfiguration<>(this, featureID, feature);
}
public ForSimpleBlock start(
ResourceLocation featureID,
Block block
) {
return start(featureID, BlockStateProvider.simple(block));
}
public ForSimpleBlock start(
ResourceLocation featureID,
BlockState state
) {
return start(featureID, BlockStateProvider.simple(state));
}
public ForSimpleBlock start(
ResourceLocation featureID,
BlockStateProvider provider
) {
return new ForSimpleBlock(
this,
featureID,
(SimpleBlockFeature) Feature.SIMPLE_BLOCK,
provider
);
}
public WeightedBlock startWeighted(ResourceLocation featureID) {
return new WeightedBlock(
this,
featureID,
(SimpleBlockFeature) Feature.SIMPLE_BLOCK
);
}
public WeightedBlockPatch startWeightedRandomPatch(ResourceLocation featureID) {
return new WeightedBlockPatch(
this,
featureID,
(RandomPatchFeature) Feature.RANDOM_PATCH
);
}
public WeightedBlockPatch startBonemealPatch(
ResourceLocation featureID
) {
return startWeightedRandomPatch(featureID).likeDefaultBonemeal();
}
public RandomPatch startRandomPatch(
ResourceLocation featureID,
Holder<PlacedFeature> featureToPlace
) {
return new RandomPatch(
this,
featureID,
(RandomPatchFeature) Feature.RANDOM_PATCH,
featureToPlace
);
}
public AsRandomSelect startRandomSelect(
ResourceLocation featureID
) {
return new AsRandomSelect(
this,
featureID,
(RandomSelectorFeature) Feature.RANDOM_SELECTOR
);
}
public AsMultiPlaceRandomSelect startRandomSelect(
ResourceLocation featureID,
AsMultiPlaceRandomSelect.Placer placementModFunction
) {
return new AsMultiPlaceRandomSelect(
this,
featureID,
(RandomSelectorFeature) Feature.RANDOM_SELECTOR,
placementModFunction
);
}
public NetherForrestVegetation startNetherVegetation(
ResourceLocation featureID
) {
return new NetherForrestVegetation(
this,
featureID,
(NetherForestVegetationFeature) Feature.NETHER_FOREST_VEGETATION
);
}
public NetherForrestVegetation startBonemealNetherVegetation(ResourceLocation featureID) {
return new NetherForrestVegetation(
this,
featureID,
(NetherForestVegetationFeature) Feature.NETHER_FOREST_VEGETATION
).spreadHeight(1).spreadWidth(3);
}
public WithTemplates startWithTemplates(ResourceLocation featureID) {
return new WithTemplates(
this,
featureID,
(TemplateFeature<TemplateFeatureConfig>) BCLFeature.TEMPLATE
);
}
public AsBlockColumn<BlockColumnFeature> startColumn(ResourceLocation featureID) {
return new AsBlockColumn<>(
this,
featureID,
(BlockColumnFeature) Feature.BLOCK_COLUMN
);
}
public AsPillar startPillar(
ResourceLocation featureID,
PillarFeatureConfig.KnownTransformers transformer
) {
return new AsPillar(
this,
featureID,
(PillarFeature) BCLFeature.PILLAR,
transformer
);
}
public AsSequence startSequence(ResourceLocation featureID) {
return new AsSequence(
this,
featureID,
(SequenceFeature) BCLFeature.SEQUENCE
);
}
public AsOre startOre(ResourceLocation featureID) {
return new AsOre(
this,
featureID,
(OreFeature) Feature.ORE
);
}
public FacingBlock startFacing(ResourceLocation featureID) {
return new FacingBlock(
this,
featureID,
(PlaceBlockFeature<PlaceFacingBlockConfig>) BCLFeature.PLACE_BLOCK
);
}
} }
/**
* Starts a new {@link BCLFeature} builder.
*
* @param featureID {@link ResourceLocation} feature identifier.
* @param feature {@link Feature} to construct.
* @return {@link BCLFeatureBuilder} instance.
*/
public static <F extends Feature<FC>, FC extends FeatureConfiguration> WithConfiguration<F, FC> start(
ResourceLocation featureID,
F feature
) {
return new WithConfiguration<>(featureID, feature);
}
public static ForSimpleBlock start(
ResourceLocation featureID,
Block block
) {
return start(featureID, BlockStateProvider.simple(block));
}
public static ForSimpleBlock start(
ResourceLocation featureID,
BlockState state
) {
return start(featureID, BlockStateProvider.simple(state));
}
public static ForSimpleBlock start(
ResourceLocation featureID,
BlockStateProvider provider
) {
return new ForSimpleBlock(
featureID,
(SimpleBlockFeature) Feature.SIMPLE_BLOCK,
provider
);
}
public static WeightedBlock startWeighted(ResourceLocation featureID) {
return new WeightedBlock(
featureID,
(SimpleBlockFeature) Feature.SIMPLE_BLOCK
);
}
public static WeightedBlockPatch startWeightedRandomPatch(ResourceLocation featureID) {
return new WeightedBlockPatch(
featureID,
(RandomPatchFeature) Feature.RANDOM_PATCH
);
}
public static WeightedBlockPatch startBonemealPatch(
ResourceLocation featureID
) {
return startWeightedRandomPatch(featureID).likeDefaultBonemeal();
}
public static RandomPatch startRandomPatch(
ResourceLocation featureID,
Holder<PlacedFeature> featureToPlace
) {
return new RandomPatch(
featureID,
(RandomPatchFeature) Feature.RANDOM_PATCH,
featureToPlace
);
}
public static AsRandomSelect startRandomSelect(
ResourceLocation featureID
) {
return new AsRandomSelect(
featureID,
(RandomSelectorFeature) Feature.RANDOM_SELECTOR
);
}
public static AsMultiPlaceRandomSelect startRandomSelect(
ResourceLocation featureID,
AsMultiPlaceRandomSelect.Placer placementModFunction
) {
return new AsMultiPlaceRandomSelect(
featureID,
(RandomSelectorFeature) Feature.RANDOM_SELECTOR,
placementModFunction
);
}
public static NetherForrestVegetation startNetherVegetation(
ResourceLocation featureID
) {
return new NetherForrestVegetation(
featureID,
(NetherForestVegetationFeature) Feature.NETHER_FOREST_VEGETATION
);
}
public static NetherForrestVegetation startBonemealNetherVegetation(ResourceLocation featureID) {
return new NetherForrestVegetation(
featureID,
(NetherForestVegetationFeature) Feature.NETHER_FOREST_VEGETATION
).spreadHeight(1).spreadWidth(3);
}
public static WithTemplates startWithTemplates(ResourceLocation featureID) {
return new WithTemplates(
featureID,
(TemplateFeature<TemplateFeatureConfig>) BCLFeature.TEMPLATE
);
}
public static AsBlockColumn<BlockColumnFeature> startColumn(ResourceLocation featureID) {
return new AsBlockColumn<>(
featureID,
(BlockColumnFeature) Feature.BLOCK_COLUMN
);
}
public static AsPillar startPillar(
ResourceLocation featureID,
PillarFeatureConfig.KnownTransformers transformer
) {
return new AsPillar(
featureID,
(PillarFeature) BCLFeature.PILLAR,
transformer
);
}
public static AsSequence startSequence(ResourceLocation featureID) {
return new AsSequence(
featureID,
(SequenceFeature) BCLFeature.SEQUENCE
);
}
public static AsOre startOre(ResourceLocation featureID) {
return new AsOre(
featureID,
(OreFeature) Feature.ORE
);
}
public static FacingBlock startFacing(ResourceLocation featureID) {
return new FacingBlock(
featureID,
(PlaceBlockFeature<PlaceFacingBlockConfig>) BCLFeature.PLACE_BLOCK
);
}
protected final ResourceLocation featureID; protected final ResourceLocation featureID;
private final F feature; private final F feature;
protected final Context ctx; private BCLFeatureBuilder(ResourceLocation featureID, F feature) {
private BCLFeatureBuilder(Context ctx, ResourceLocation featureID, F feature) {
this.featureID = featureID; this.featureID = featureID;
this.feature = feature; this.feature = feature;
this.ctx = ctx;
} }
/** /**
* Internally used by the builder. Normally you should not have to call this method directly as it is * Internally used by the builder. Normally you should not have to call this method directly as it is
* handled by {@link #buildAndRegister()} * handled by {@link #buildAndRegister(BootstapContext)}
* *
* @param id The ID to register this feature with * @param id The ID to register this feature with
* @param cFeature The configured Feature * @param cFeature The configured Feature
@ -245,41 +232,64 @@ public abstract class BCLFeatureBuilder<F extends Feature<FC>, FC extends Featur
* @return The Holder for the new Feature * @return The Holder for the new Feature
*/ */
public static <F extends Feature<FC>, FC extends FeatureConfiguration> Holder<ConfiguredFeature<FC, F>> register( public static <F extends Feature<FC>, FC extends FeatureConfiguration> Holder<ConfiguredFeature<FC, F>> register(
Context ctx, BootstapContext<ConfiguredFeature<?, ?>> ctx,
ResourceLocation id, ResourceLocation id,
ConfiguredFeature<FC, F> cFeature ConfiguredFeature<FC, F> cFeature
) { ) {
ResourceKey<ConfiguredFeature<?, ?>> key = ResourceKey.create(Registries.CONFIGURED_FEATURE, id); ResourceKey<ConfiguredFeature<?, ?>> key = ResourceKey.create(Registries.CONFIGURED_FEATURE, id);
return (Holder<ConfiguredFeature<FC, F>>) (Object) ctx.bootstrapContext.register(key, cFeature); return (Holder<ConfiguredFeature<FC, F>>) (Object) ctx.register(key, cFeature);
} }
public abstract FC createConfiguration(); public abstract FC createConfiguration();
protected BCLConfigureFeature<F, FC> buildAndRegister(HolderBuilder<F, FC> holderBuilder) { protected BCLConfigureFeature<F, FC> buildAndCreateHolder(HolderBuilder<F, FC> holderBuilder) {
return buildAndCreateHolder(
(featureID, holder) -> new BCLConfigureFeature<>(featureID, holder, true),
holderBuilder
);
}
protected <B extends BCLConfigureFeature<F, FC>> B buildAndCreateHolder(
FeatureBuilder<F, FC, B> featureBuilder,
HolderBuilder<F, FC> holderBuilder
) {
FC config = createConfiguration(); FC config = createConfiguration();
if (config == null) { if (config == null) {
throw new IllegalStateException("Feature configuration for " + featureID + " can not be null!"); throw new IllegalStateException("Feature configuration for " + featureID + " can not be null!");
} }
ConfiguredFeature<FC, F> cFeature = new ConfiguredFeature<>(feature, config); ConfiguredFeature<FC, F> cFeature = new ConfiguredFeature<>(feature, config);
Holder<ConfiguredFeature<FC, F>> holder = holderBuilder.apply(this.ctx, featureID, cFeature); Holder<ConfiguredFeature<FC, F>> holder = holderBuilder.apply(featureID, cFeature);
return new BCLConfigureFeature<>(featureID, holder, true); return featureBuilder.create(featureID, holder);
} }
public BCLConfigureFeature<F, FC> buildAndRegister() { public BCLConfigureFeature<F, FC> buildAndRegister(BootstapContext<ConfiguredFeature<?, ?>> bootstrapCtx) {
return buildAndRegister(BCLFeatureBuilder::register); return buildAndCreateHolder((featureID, cFeature) -> register(bootstrapCtx, featureID, cFeature));
} }
public BCLConfigureFeature<F, FC> build() { public BCLConfigureFeature<F, FC> buildInline() {
return buildAndRegister((ctx, id, cFeature) -> Holder.direct(cFeature)); return buildAndCreateHolder(
(featureID, cFeature) -> Holder.direct(cFeature)
);
}
public BCLConfigureFeature.Unregistered<F, FC> build() {
return buildAndCreateHolder(
(featureID, holder) -> new BCLConfigureFeature.Unregistered<>(featureID, holder),
(featureID, cFeature) -> (FullReferenceHolder<ConfiguredFeature<FC, F>>) (Object) FullReferenceHolder.create(
Registries.CONFIGURED_FEATURE,
featureID,
cFeature
)
);
} }
public BCLInlinePlacedBuilder<F, FC> inlinePlace() { public BCLInlinePlacedBuilder<F, FC> inlinePlace() {
BCLConfigureFeature<F, FC> f = build(); BCLConfigureFeature<F, FC> f = buildInline();
return BCLInlinePlacedBuilder.place(ctx, f); return BCLInlinePlacedBuilder.place(f);
} }
public Holder<PlacedFeature> inlinePlace(BCLInlinePlacedBuilder<F, FC> placer) { public Holder<PlacedFeature> inlinePlace(BCLInlinePlacedBuilder<F, FC> placer) {
BCLConfigureFeature<F, FC> f = build(); BCLConfigureFeature<F, FC> f = buildInline();
return placer.build(f); return placer.build(f);
} }
@ -288,8 +298,8 @@ public abstract class BCLFeatureBuilder<F extends Feature<FC>, FC extends Featur
private int size = 6; private int size = 6;
private float discardChanceOnAirExposure = 0; private float discardChanceOnAirExposure = 0;
private AsOre(Context ctx, ResourceLocation featureID, OreFeature feature) { private AsOre(ResourceLocation featureID, OreFeature feature) {
super(ctx, featureID, feature); super(featureID, feature);
} }
public AsOre add(Block containedIn, Block ore) { public AsOre add(Block containedIn, Block ore) {
@ -338,12 +348,11 @@ public abstract class BCLFeatureBuilder<F extends Feature<FC>, FC extends Featur
private BlockPredicate allowedPlacement = BlockPredicate.ONLY_IN_AIR_PREDICATE; private BlockPredicate allowedPlacement = BlockPredicate.ONLY_IN_AIR_PREDICATE;
private AsPillar( private AsPillar(
@NotNull Context ctx,
@NotNull ResourceLocation featureID, @NotNull ResourceLocation featureID,
@NotNull PillarFeature feature, @NotNull PillarFeature feature,
@NotNull PillarFeatureConfig.KnownTransformers transformer @NotNull PillarFeatureConfig.KnownTransformers transformer
) { ) {
super(ctx, featureID, feature); super(featureID, feature);
this.transformer = transformer; this.transformer = transformer;
} }
@ -415,11 +424,10 @@ public abstract class BCLFeatureBuilder<F extends Feature<FC>, FC extends Featur
private final List<Holder<PlacedFeature>> features = new LinkedList<>(); private final List<Holder<PlacedFeature>> features = new LinkedList<>();
private AsSequence( private AsSequence(
@NotNull Context ctx,
@NotNull ResourceLocation featureID, @NotNull ResourceLocation featureID,
@NotNull SequenceFeature feature @NotNull SequenceFeature feature
) { ) {
super(ctx, featureID, feature); super(featureID, feature);
} }
@ -445,11 +453,10 @@ public abstract class BCLFeatureBuilder<F extends Feature<FC>, FC extends Featur
private boolean prioritizeTip = false; private boolean prioritizeTip = false;
private AsBlockColumn( private AsBlockColumn(
@NotNull Context ctx,
@NotNull ResourceLocation featureID, @NotNull ResourceLocation featureID,
@NotNull FF feature @NotNull FF feature
) { ) {
super(ctx, featureID, feature); super(featureID, feature);
} }
public AsBlockColumn<FF> add(int height, Block block) { public AsBlockColumn<FF> add(int height, Block block) {
@ -561,11 +568,10 @@ public abstract class BCLFeatureBuilder<F extends Feature<FC>, FC extends Featur
private final List<StructureWorldNBT> templates = new LinkedList<>(); private final List<StructureWorldNBT> templates = new LinkedList<>();
private WithTemplates( private WithTemplates(
@NotNull Context ctx,
@NotNull ResourceLocation featureID, @NotNull ResourceLocation featureID,
@NotNull TemplateFeature<TemplateFeatureConfig> feature @NotNull TemplateFeature<TemplateFeatureConfig> feature
) { ) {
super(ctx, featureID, feature); super(featureID, feature);
} }
public WithTemplates add( public WithTemplates add(
@ -591,11 +597,10 @@ public abstract class BCLFeatureBuilder<F extends Feature<FC>, FC extends Featur
private int spreadHeight = 4; private int spreadHeight = 4;
private NetherForrestVegetation( private NetherForrestVegetation(
@NotNull Context ctx,
@NotNull ResourceLocation featureID, @NotNull ResourceLocation featureID,
@NotNull NetherForestVegetationFeature feature @NotNull NetherForestVegetationFeature feature
) { ) {
super(ctx, featureID, feature); super(featureID, feature);
} }
public NetherForrestVegetation spreadWidth(int v) { public NetherForrestVegetation spreadWidth(int v) {
@ -661,12 +666,11 @@ public abstract class BCLFeatureBuilder<F extends Feature<FC>, FC extends Featur
private int ySpread = 3; private int ySpread = 3;
private RandomPatch( private RandomPatch(
@NotNull Context ctx,
@NotNull ResourceLocation featureID, @NotNull ResourceLocation featureID,
@NotNull RandomPatchFeature feature, @NotNull RandomPatchFeature feature,
@NotNull Holder<PlacedFeature> featureToPlace @NotNull Holder<PlacedFeature> featureToPlace
) { ) {
super(ctx, featureID, feature); super(featureID, feature);
this.featureToPlace = featureToPlace; this.featureToPlace = featureToPlace;
} }
@ -707,11 +711,10 @@ public abstract class BCLFeatureBuilder<F extends Feature<FC>, FC extends Featur
private FC configuration; private FC configuration;
private WithConfiguration( private WithConfiguration(
@NotNull Context ctx,
@NotNull ResourceLocation featureID, @NotNull ResourceLocation featureID,
@NotNull F feature @NotNull F feature
) { ) {
super(ctx, featureID, feature); super(featureID, feature);
} }
public WithConfiguration<F, FC> configuration(FC config) { public WithConfiguration<F, FC> configuration(FC config) {
@ -742,11 +745,10 @@ public abstract class BCLFeatureBuilder<F extends Feature<FC>, FC extends Featur
private List<Direction> directions = PlaceFacingBlockConfig.HORIZONTAL; private List<Direction> directions = PlaceFacingBlockConfig.HORIZONTAL;
private FacingBlock( private FacingBlock(
@NotNull Context ctx,
@NotNull ResourceLocation featureID, @NotNull ResourceLocation featureID,
@NotNull PlaceBlockFeature<PlaceFacingBlockConfig> feature @NotNull PlaceBlockFeature<PlaceFacingBlockConfig> feature
) { ) {
super(ctx, featureID, feature); super(featureID, feature);
} }
@ -820,12 +822,11 @@ public abstract class BCLFeatureBuilder<F extends Feature<FC>, FC extends Featur
private final BlockStateProvider provider; private final BlockStateProvider provider;
private ForSimpleBlock( private ForSimpleBlock(
@NotNull Context ctx,
@NotNull ResourceLocation featureID, @NotNull ResourceLocation featureID,
@NotNull SimpleBlockFeature feature, @NotNull SimpleBlockFeature feature,
@NotNull BlockStateProvider provider @NotNull BlockStateProvider provider
) { ) {
super(ctx, featureID, feature); super(featureID, feature);
this.provider = provider; this.provider = provider;
} }
@ -844,11 +845,10 @@ public abstract class BCLFeatureBuilder<F extends Feature<FC>, FC extends Featur
private int ySpread = 3; private int ySpread = 3;
protected WeightedBlockPatch( protected WeightedBlockPatch(
@NotNull Context ctx,
@NotNull ResourceLocation featureID, @NotNull ResourceLocation featureID,
@NotNull RandomPatchFeature feature @NotNull RandomPatchFeature feature
) { ) {
super(ctx, featureID, feature); super(featureID, feature);
} }
public WeightedBlockPatch isEmpty() { public WeightedBlockPatch isEmpty() {
@ -903,7 +903,7 @@ public abstract class BCLFeatureBuilder<F extends Feature<FC>, FC extends Featur
@Override @Override
public RandomPatchConfiguration createConfiguration() { public RandomPatchConfiguration createConfiguration() {
BCLInlinePlacedBuilder<Feature<SimpleBlockConfiguration>, SimpleBlockConfiguration> blockFeature = ctx BCLInlinePlacedBuilder<Feature<SimpleBlockConfiguration>, SimpleBlockConfiguration> blockFeature = BCLFeatureBuilder
.start( .start(
new ResourceLocation(featureID.getNamespace(), "tmp_" + featureID.getPath()), new ResourceLocation(featureID.getNamespace(), "tmp_" + featureID.getPath()),
Feature.SIMPLE_BLOCK Feature.SIMPLE_BLOCK
@ -920,11 +920,10 @@ public abstract class BCLFeatureBuilder<F extends Feature<FC>, FC extends Featur
public static class WeightedBlock extends WeightedBaseBlock<SimpleBlockFeature, SimpleBlockConfiguration, WeightedBlock> { public static class WeightedBlock extends WeightedBaseBlock<SimpleBlockFeature, SimpleBlockConfiguration, WeightedBlock> {
private WeightedBlock( private WeightedBlock(
@NotNull Context ctx,
@NotNull ResourceLocation featureID, @NotNull ResourceLocation featureID,
@NotNull SimpleBlockFeature feature @NotNull SimpleBlockFeature feature
) { ) {
super(ctx, featureID, feature); super(featureID, feature);
} }
@Override @Override
@ -965,11 +964,10 @@ public abstract class BCLFeatureBuilder<F extends Feature<FC>, FC extends Featur
SimpleWeightedRandomList.Builder<BlockState> stateBuilder = SimpleWeightedRandomList.builder(); SimpleWeightedRandomList.Builder<BlockState> stateBuilder = SimpleWeightedRandomList.builder();
protected WeightedBaseBlock( protected WeightedBaseBlock(
@NotNull Context ctx,
@NotNull ResourceLocation featureID, @NotNull ResourceLocation featureID,
@NotNull F feature @NotNull F feature
) { ) {
super(ctx, featureID, feature); super(featureID, feature);
} }
public W add(Block block, int weight) { public W add(Block block, int weight) {
@ -999,11 +997,10 @@ public abstract class BCLFeatureBuilder<F extends Feature<FC>, FC extends Featur
private Holder<PlacedFeature> defaultFeature; private Holder<PlacedFeature> defaultFeature;
private AsRandomSelect( private AsRandomSelect(
@NotNull Context ctx,
@NotNull ResourceLocation featureID, @NotNull ResourceLocation featureID,
@NotNull RandomSelectorFeature feature @NotNull RandomSelectorFeature feature
) { ) {
super(ctx, featureID, feature); super(featureID, feature);
} }
@ -1036,12 +1033,11 @@ public abstract class BCLFeatureBuilder<F extends Feature<FC>, FC extends Featur
private final Placer modFunction; private final Placer modFunction;
private AsMultiPlaceRandomSelect( private AsMultiPlaceRandomSelect(
@NotNull Context ctx,
@NotNull ResourceLocation featureID, @NotNull ResourceLocation featureID,
@NotNull RandomSelectorFeature feature, @NotNull RandomSelectorFeature feature,
@NotNull Placer mod @NotNull Placer mod
) { ) {
super(ctx, featureID, feature); super(featureID, feature);
this.modFunction = mod; this.modFunction = mod;
} }
@ -1115,7 +1111,7 @@ public abstract class BCLFeatureBuilder<F extends Feature<FC>, FC extends Featur
} }
private Holder<PlacedFeature> place(BlockStateProvider p, int id) { private Holder<PlacedFeature> place(BlockStateProvider p, int id) {
var builder = ctx var builder = BCLFeatureBuilder
.start(BCLib.makeID("temp_select_feature" + (featureCounter++)), p) .start(BCLib.makeID("temp_select_feature" + (featureCounter++)), p)
.inlinePlace(); .inlinePlace();
return modFunction.place(builder, id); return modFunction.place(builder, id);

View file

@ -11,10 +11,8 @@ import net.minecraft.world.level.levelgen.placement.PlacementModifier;
public class BCLInlinePlacedBuilder<F extends Feature<FC>, FC extends FeatureConfiguration> extends CommonPlacedFeatureBuilder<F, FC, BCLInlinePlacedBuilder<F, FC>> { public class BCLInlinePlacedBuilder<F extends Feature<FC>, FC extends FeatureConfiguration> extends CommonPlacedFeatureBuilder<F, FC, BCLInlinePlacedBuilder<F, FC>> {
private final BCLConfigureFeature<F, FC> cFeature; private final BCLConfigureFeature<F, FC> cFeature;
protected final BCLFeatureBuilder.Context ctx;
private BCLInlinePlacedBuilder(BCLFeatureBuilder.Context ctx, BCLConfigureFeature<F, FC> cFeature) { private BCLInlinePlacedBuilder(BCLConfigureFeature<F, FC> cFeature) {
this.ctx = ctx;
this.cFeature = cFeature; this.cFeature = cFeature;
} }
@ -25,11 +23,10 @@ public class BCLInlinePlacedBuilder<F extends Feature<FC>, FC extends FeatureCon
* @return {@link CommonPlacedFeatureBuilder} instance. * @return {@link CommonPlacedFeatureBuilder} instance.
*/ */
public static <F extends Feature<FC>, FC extends FeatureConfiguration> BCLInlinePlacedBuilder<F, FC> place( public static <F extends Feature<FC>, FC extends FeatureConfiguration> BCLInlinePlacedBuilder<F, FC> place(
BCLFeatureBuilder.Context ctx,
ResourceLocation featureID, ResourceLocation featureID,
Holder<ConfiguredFeature<FC, F>> holder Holder<ConfiguredFeature<FC, F>> holder
) { ) {
return place(ctx, BCLConfigureFeature.create(holder)); return place(BCLConfigureFeature.create(holder));
} }
@ -40,10 +37,9 @@ public class BCLInlinePlacedBuilder<F extends Feature<FC>, FC extends FeatureCon
* @return {@link CommonPlacedFeatureBuilder} instance. * @return {@link CommonPlacedFeatureBuilder} instance.
*/ */
static <F extends Feature<FC>, FC extends FeatureConfiguration> BCLInlinePlacedBuilder<F, FC> place( static <F extends Feature<FC>, FC extends FeatureConfiguration> BCLInlinePlacedBuilder<F, FC> place(
BCLFeatureBuilder.Context ctx,
BCLConfigureFeature<F, FC> cFeature BCLConfigureFeature<F, FC> cFeature
) { ) {
return new BCLInlinePlacedBuilder(ctx, cFeature); return new BCLInlinePlacedBuilder(cFeature);
} }
/** /**
@ -87,7 +83,7 @@ public class BCLInlinePlacedBuilder<F extends Feature<FC>, FC extends FeatureCon
public BCLFeatureBuilder.RandomPatch inRandomPatch(ResourceLocation id) { public BCLFeatureBuilder.RandomPatch inRandomPatch(ResourceLocation id) {
return ctx.startRandomPatch(id, build()); return BCLFeatureBuilder.startRandomPatch(id, build());
} }
public BCLFeatureBuilder.RandomPatch randomBonemealDistribution(ResourceLocation id) { public BCLFeatureBuilder.RandomPatch randomBonemealDistribution(ResourceLocation id) {

View file

@ -81,7 +81,7 @@ public class BCLPlacedFeatureBuilder<F extends Feature<FC>, FC extends FeatureCo
); );
Holder<ConfiguredFeature<FC, F>> holder = (Holder<ConfiguredFeature<FC, F>>) (Object) ctx.bootstrapContext Holder<ConfiguredFeature<FC, F>> holder = (Holder<ConfiguredFeature<FC, F>>) (Object) ctx.bootstrapContext
.lookup(Registries.CONFIGURED_FEATURE) .lookup(Registries.CONFIGURED_FEATURE)
.getOrThrow(key); .get(key);
var cFeature = new BCLConfigureFeature<F, FC>(configuredFeature, holder, false); var cFeature = new BCLConfigureFeature<F, FC>(configuredFeature, holder, false);
return new BCLPlacedFeatureBuilder<F, FC>(ctx, configuredFeature, cFeature); return new BCLPlacedFeatureBuilder<F, FC>(ctx, configuredFeature, cFeature);
} }

View file

@ -27,7 +27,7 @@ public class BCLibDatagen implements DataGeneratorEntrypoint {
BCLib.LOGGER.info("Datagen buildRegistry"); BCLib.LOGGER.info("Datagen buildRegistry");
registryBuilder.add(Registries.CONFIGURED_FEATURE, TestConfiguredFeatures::bootstrap); registryBuilder.add(Registries.CONFIGURED_FEATURE, TestConfiguredFeatures::bootstrap);
registryBuilder.add(Registries.PLACED_FEATURE, TestPlacedFeatures::bootstrap); registryBuilder.add(Registries.PLACED_FEATURE, TestPlacedFeatures::bootstrap);
registryBuilder.add(Registries.BIOME, TestBiomes::bootstrap); //registryBuilder.add(Registries.BIOME, TestBiomes::bootstrap);
registryBuilder.add(Registries.NOISE_SETTINGS, NoiseDatagen::bootstrap); registryBuilder.add(Registries.NOISE_SETTINGS, NoiseDatagen::bootstrap);
} }
} }

View file

@ -11,19 +11,17 @@ import net.minecraft.world.level.levelgen.feature.RandomPatchFeature;
import net.minecraft.world.level.levelgen.feature.configurations.RandomPatchConfiguration; import net.minecraft.world.level.levelgen.feature.configurations.RandomPatchConfiguration;
public class TestConfiguredFeatures { public class TestConfiguredFeatures {
static BCLConfigureFeature<RandomPatchFeature, RandomPatchConfiguration> YELLOW_FEATURE; static BCLConfigureFeature<RandomPatchFeature, RandomPatchConfiguration> YELLOW_FEATURE = BCLFeatureBuilder
.startBonemealPatch(BCLib.makeID("yellow_feature"))
.add(Blocks.YELLOW_STAINED_GLASS, 30)
.add(Blocks.YELLOW_CONCRETE_POWDER, 30)
.add(Blocks.YELLOW_GLAZED_TERRACOTTA, 5)
.build();
public static void bootstrap(BootstapContext<ConfiguredFeature<?, ?>> bootstrapContext) { public static void bootstrap(BootstapContext<ConfiguredFeature<?, ?>> bootstrapContext) {
BCLib.LOGGER.info("Bootstrap CONFIGUREDFeatures"); BCLib.LOGGER.info("Bootstrap CONFIGUREDFeatures");
if (BCLibDatagen.ADD_TESTS && BCLib.isDevEnvironment()) { if (BCLibDatagen.ADD_TESTS && BCLib.isDevEnvironment()) {
BCLFeatureBuilder.Context builder = new BCLFeatureBuilder.Context(bootstrapContext); YELLOW_FEATURE = YELLOW_FEATURE.register(bootstrapContext);
YELLOW_FEATURE = builder
.startBonemealPatch(BCLib.makeID("yellow_feature"))
.add(Blocks.YELLOW_STAINED_GLASS, 30)
.add(Blocks.YELLOW_CONCRETE_POWDER, 30)
.add(Blocks.YELLOW_GLAZED_TERRACOTTA, 5)
.buildAndRegister();
} }
} }
} }

View file

@ -18,14 +18,12 @@ public class TestPlacedFeatures {
if (BCLibDatagen.ADD_TESTS && BCLib.isDevEnvironment()) { if (BCLibDatagen.ADD_TESTS && BCLib.isDevEnvironment()) {
final BCLPlacedFeatureBuilder.Context buildContext = new BCLPlacedFeatureBuilder.Context(bootstrapContext); final BCLPlacedFeatureBuilder.Context buildContext = new BCLPlacedFeatureBuilder.Context(bootstrapContext);
YELLOW_PLACED = BCLPlacedFeatureBuilder.<RandomPatchFeature, RandomPatchConfiguration>place( YELLOW_PLACED = TestConfiguredFeatures.YELLOW_FEATURE
buildContext, .place(buildContext)
BCLib.makeID("yellow_feature") .decoration(GenerationStep.Decoration.VEGETAL_DECORATION)
) .vanillaNetherGround(8)
.decoration(GenerationStep.Decoration.VEGETAL_DECORATION) .isEmptyAndOnNetherGround()
.vanillaNetherGround(8) .buildAndRegister();
.isEmptyAndOnNetherGround()
.buildAndRegister();
} }
} }
} }

View file

@ -0,0 +1,124 @@
package org.betterx.bclib.util;
import com.mojang.datafixers.util.Either;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderOwner;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Stream;
import org.jetbrains.annotations.Nullable;
public class FullReferenceHolder<T> implements Holder<T> {
private Set<TagKey<T>> tags = Set.of();
@Nullable
private ResourceKey<T> key;
@Nullable
private T value;
private ResourceKey<Registry<T>> owner;
private FullReferenceHolder(
ResourceKey<Registry<T>> owner,
@Nullable ResourceKey<T> resourceKey,
@Nullable T object
) {
this.owner = owner;
this.key = resourceKey;
this.value = object;
}
public static <T> FullReferenceHolder<T> create(
ResourceKey<Registry<T>> owner,
ResourceKey<T> resourceKey,
@Nullable T object
) {
return new FullReferenceHolder(owner, resourceKey, object);
}
public static <T> FullReferenceHolder<T> create(
ResourceKey<Registry<T>> owner,
ResourceLocation id,
@Nullable T object
) {
return new FullReferenceHolder(owner, ResourceKey.create(owner, id), object);
}
public ResourceKey<T> key() {
if (this.key == null) {
throw new IllegalStateException("Trying to access unbound value '" + this.value + "' from registry " + this.owner);
} else {
return this.key;
}
}
@Override
public T value() {
if (this.value == null) {
throw new IllegalStateException("Trying to access unbound value '" + this.key + "' from registry " + this.owner);
} else {
return this.value;
}
}
@Override
public boolean is(ResourceLocation resourceLocation) {
return this.key().location().equals(resourceLocation);
}
@Override
public boolean is(ResourceKey<T> resourceKey) {
return this.key() == resourceKey;
}
@Override
public boolean is(TagKey<T> tagKey) {
return this.tags.contains(tagKey);
}
@Override
public Stream<TagKey<T>> tags() {
return this.tags.stream();
}
@Override
public boolean is(Predicate<ResourceKey<T>> predicate) {
return predicate.test(this.key());
}
@Override
public boolean canSerializeIn(HolderOwner<T> holderOwner) {
return true;
}
@Override
public Either<ResourceKey<T>, T> unwrap() {
return Either.left(this.key());
}
@Override
public Optional<ResourceKey<T>> unwrapKey() {
return Optional.of(this.key());
}
@Override
public Kind kind() {
return Holder.Kind.REFERENCE;
}
@Override
public boolean isBound() {
return this.key != null && this.value != null;
}
@Override
public String toString() {
return "FullReference{" + this.key + "=" + this.value + "}";
}
}