Fixed BCLFeature
This commit is contained in:
parent
ddddfa1492
commit
99840b8ee2
5 changed files with 78 additions and 47 deletions
|
@ -1,6 +1,5 @@
|
|||
package ru.bclib.api;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
@ -445,7 +444,7 @@ public class BiomeAPI {
|
|||
List<List<Supplier<ConfiguredFeature<?, ?>>>> biomeFeatures = getMutableList(accessor.fabric_getFeatures());
|
||||
for (BCLFeature feature: features) {
|
||||
List<Supplier<ConfiguredFeature<?, ?>>> list = getList(feature.getFeatureStep(), biomeFeatures);
|
||||
list.add(feature::getFeatureConfigured);
|
||||
list.add(feature::getPlacedFeature);
|
||||
}
|
||||
accessor.fabric_setFeatures(biomeFeatures);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
package ru.bclib.mixin.common;
|
||||
|
||||
import net.minecraft.world.level.levelgen.placement.ConfiguredDecorator;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(targets = "net.minecraft.data.worldgen.Features$Decorators")
|
||||
public interface FeatureDecoratorsAccessor {
|
||||
@Accessor("HEIGHTMAP_SQUARE")
|
||||
ConfiguredDecorator<?> bclib_getHeightmapSquare();
|
||||
/*@Accessor("HEIGHTMAP_SQUARE")
|
||||
ConfiguredDecorator<?> bclib_getHeightmapSquare();*/
|
||||
}
|
||||
|
|
|
@ -235,7 +235,7 @@ public class BCLBiomeDef {
|
|||
public BCLBiomeDef addFeature(BCLFeature feature) {
|
||||
FeatureInfo info = new FeatureInfo();
|
||||
info.featureStep = feature.getFeatureStep();
|
||||
info.feature = feature.getFeatureConfigured();
|
||||
info.feature = feature.getPlacedFeature();
|
||||
features.add(info);
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,7 @@
|
|||
package ru.bclib.world.features;
|
||||
|
||||
import net.minecraft.data.worldgen.Features;
|
||||
import net.minecraft.world.level.levelgen.placement.ConfiguredDecorator;
|
||||
import ru.bclib.BCLib;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class BCLDecorators {
|
||||
public static final ConfiguredDecorator<?> HEIGHTMAP_SQUARE;
|
||||
/*public static final ConfiguredDecorator<?> HEIGHTMAP_SQUARE;
|
||||
|
||||
private static final ConfiguredDecorator<?> getDecorator(Field[] fields, int index) {
|
||||
try {
|
||||
|
@ -23,5 +17,5 @@ public class BCLDecorators {
|
|||
Class<?>[] classes = Features.class.getDeclaredClasses();
|
||||
Field[] fields = classes[1].getDeclaredFields(); // Decorators class
|
||||
HEIGHTMAP_SQUARE = getDecorator(fields, 17);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
|
|
@ -2,33 +2,38 @@ package ru.bclib.world.features;
|
|||
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.data.BuiltinRegistries;
|
||||
import net.minecraft.data.worldgen.placement.PlacementUtils;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.valueproviders.UniformInt;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.levelgen.GenerationStep.Decoration;
|
||||
import net.minecraft.world.level.levelgen.VerticalAnchor;
|
||||
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.level.levelgen.feature.Feature;
|
||||
import net.minecraft.world.level.levelgen.feature.configurations.CountConfiguration;
|
||||
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
|
||||
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
|
||||
import net.minecraft.world.level.levelgen.feature.configurations.OreConfiguration;
|
||||
import net.minecraft.world.level.levelgen.placement.ChanceDecoratorConfiguration;
|
||||
import net.minecraft.world.level.levelgen.placement.FeatureDecorator;
|
||||
import net.minecraft.world.level.levelgen.heightproviders.UniformHeight;
|
||||
import net.minecraft.world.level.levelgen.placement.BiomeFilter;
|
||||
import net.minecraft.world.level.levelgen.placement.CountPlacement;
|
||||
import net.minecraft.world.level.levelgen.placement.HeightRangePlacement;
|
||||
import net.minecraft.world.level.levelgen.placement.InSquarePlacement;
|
||||
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
||||
import net.minecraft.world.level.levelgen.placement.RarityFilter;
|
||||
import net.minecraft.world.level.levelgen.structure.templatesystem.BlockMatchTest;
|
||||
|
||||
public class BCLFeature {
|
||||
private ConfiguredFeature<?, ?> featureConfigured;
|
||||
private PlacedFeature placedFeature;
|
||||
private Decoration featureStep;
|
||||
private Feature<?> feature;
|
||||
|
||||
public BCLFeature(Feature<?> feature, ConfiguredFeature<?, ?> configuredFeature, Decoration featureStep) {
|
||||
this.featureConfigured = configuredFeature;
|
||||
public BCLFeature(Feature<?> feature, PlacedFeature placedFeature, Decoration featureStep) {
|
||||
this.placedFeature = placedFeature;
|
||||
this.featureStep = featureStep;
|
||||
this.feature = feature;
|
||||
}
|
||||
|
||||
public BCLFeature(ResourceLocation id, Feature<NoneFeatureConfiguration> feature, Decoration featureStep, ConfiguredFeature<?, ?> configuredFeature) {
|
||||
this.featureConfigured = Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, id, configuredFeature);
|
||||
public BCLFeature(ResourceLocation id, Feature<NoneFeatureConfiguration> feature, Decoration featureStep, PlacedFeature placedFeature) {
|
||||
this.placedFeature = Registry.register(BuiltinRegistries.PLACED_FEATURE, id, placedFeature);
|
||||
this.feature = Registry.register(Registry.FEATURE, id, feature);
|
||||
this.featureStep = featureStep;
|
||||
}
|
||||
|
@ -43,10 +48,10 @@ public class BCLFeature {
|
|||
|
||||
/**
|
||||
* Get configured feature.
|
||||
* @return {@link ConfiguredFeature}.
|
||||
* @return {@link PlacedFeature}.
|
||||
*/
|
||||
public ConfiguredFeature<?, ?> getFeatureConfigured() {
|
||||
return featureConfigured;
|
||||
public PlacedFeature getPlacedFeature() {
|
||||
return placedFeature;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -56,7 +61,6 @@ public class BCLFeature {
|
|||
public Decoration getFeatureStep() {
|
||||
return featureStep;
|
||||
}
|
||||
|
||||
/**
|
||||
* Will create a basic plant feature.
|
||||
* @param id {@link ResourceLocation} feature ID.
|
||||
|
@ -65,13 +69,18 @@ public class BCLFeature {
|
|||
* @return new BCLFeature instance.
|
||||
*/
|
||||
public static BCLFeature makeVegetationFeature(ResourceLocation id, Feature<NoneFeatureConfiguration> feature, int density) {
|
||||
ConfiguredFeature<?, ?> configured = feature
|
||||
PlacedFeature configured = feature
|
||||
.configured(FeatureConfiguration.NONE)
|
||||
.decorated(BCLDecorators.HEIGHTMAP_SQUARE)
|
||||
.countRandom(density);
|
||||
.placed(
|
||||
CountPlacement.of(UniformInt.of(0, 4)),
|
||||
InSquarePlacement.spread(),
|
||||
PlacementUtils.HEIGHTMAP,
|
||||
BiomeFilter.biome()
|
||||
);
|
||||
//.decorated(BCLDecorators.HEIGHTMAP_SQUARE)
|
||||
//.countRandom(density);
|
||||
return new BCLFeature(id, feature, Decoration.VEGETAL_DECORATION, configured);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will create a basic ore feature.
|
||||
* @param id {@link ResourceLocation} feature ID.
|
||||
|
@ -84,22 +93,50 @@ public class BCLFeature {
|
|||
* @return new BCLFeature instance.
|
||||
*/
|
||||
public static BCLFeature makeOreFeature(ResourceLocation id, Block blockOre, Block hostBlock, int veins, int veinSize, int minY, int maxY) {
|
||||
return makeOreFeature(id, blockOre, hostBlock, veins, veinSize, minY, maxY, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will create a basic ore feature.
|
||||
*
|
||||
* @param id {@link ResourceLocation} feature ID.
|
||||
* @param blockOre {@link Decoration} feature step.
|
||||
* @param hostBlock {@link Block} to generate feature in.
|
||||
* @param veins iterations per chunk.
|
||||
* @param veinSize size of ore vein.
|
||||
* @param minY minimum height.
|
||||
* @param maxY maximum height.
|
||||
* @param rare when true, this is placed as a rare resource
|
||||
* @return new BCLFeature instance.
|
||||
*/
|
||||
public static BCLFeature makeOreFeature(ResourceLocation id, Block blockOre, Block hostBlock, int veins, int veinSize, int minY, int maxY, boolean rare) {
|
||||
OreConfiguration featureConfig = new OreConfiguration(
|
||||
new BlockMatchTest(hostBlock),
|
||||
blockOre.defaultBlockState(),
|
||||
veinSize
|
||||
);
|
||||
ConfiguredFeature<?, ?> oreFeature = Feature.ORE
|
||||
|
||||
PlacedFeature oreFeature = Feature.ORE
|
||||
.configured(featureConfig)
|
||||
.rangeUniform(
|
||||
VerticalAnchor.absolute(minY),
|
||||
VerticalAnchor.absolute(maxY)
|
||||
)
|
||||
.squared()
|
||||
.count(veins);
|
||||
.placed(
|
||||
InSquarePlacement.spread(),
|
||||
rare ? RarityFilter.onAverageOnceEvery(veins) : CountPlacement.of(veins),
|
||||
HeightRangePlacement.of(
|
||||
UniformHeight.of(
|
||||
VerticalAnchor.absolute(minY),
|
||||
VerticalAnchor.absolute(maxY)
|
||||
)
|
||||
),
|
||||
BiomeFilter.biome());
|
||||
// .rangeUniform(
|
||||
// VerticalAnchor.absolute(minY),
|
||||
// VerticalAnchor.absolute(maxY)
|
||||
// )
|
||||
// .squared()
|
||||
// .count(veins);
|
||||
return new BCLFeature(
|
||||
net.minecraft.world.level.levelgen.feature.Feature.ORE,
|
||||
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, id, oreFeature),
|
||||
Registry.register(BuiltinRegistries.PLACED_FEATURE, id, oreFeature),
|
||||
Decoration.UNDERGROUND_ORES
|
||||
);
|
||||
}
|
||||
|
@ -112,9 +149,10 @@ public class BCLFeature {
|
|||
* @return new BCLFeature instance.
|
||||
*/
|
||||
public static BCLFeature makeChunkFeature(ResourceLocation id, Decoration step, Feature<NoneFeatureConfiguration> feature) {
|
||||
ConfiguredFeature<?, ?> configured = feature
|
||||
PlacedFeature configured = feature
|
||||
.configured(FeatureConfiguration.NONE)
|
||||
.decorated(FeatureDecorator.COUNT.configured(new CountConfiguration(1)));
|
||||
.placed(CountPlacement.of(1));
|
||||
//.decorated(FeatureDecorator.COUNT.configured(new CountConfiguration(1)));
|
||||
return new BCLFeature(id, feature, step, configured);
|
||||
}
|
||||
|
||||
|
@ -127,9 +165,10 @@ public class BCLFeature {
|
|||
* @return new BCLFeature instance.
|
||||
*/
|
||||
public static BCLFeature makeChancedFeature(ResourceLocation id, Decoration step, Feature<NoneFeatureConfiguration> feature, int chance) {
|
||||
ConfiguredFeature<?, ?> configured = feature
|
||||
PlacedFeature configured = feature
|
||||
.configured(FeatureConfiguration.NONE)
|
||||
.decorated(FeatureDecorator.CHANCE.configured(new ChanceDecoratorConfiguration(chance)));
|
||||
.placed(RarityFilter.onAverageOnceEvery(chance));
|
||||
//.decorated(FeatureDecorator.CHANCE.configured(new ChanceDecoratorConfiguration(chance)));
|
||||
return new BCLFeature(id, feature, step, configured);
|
||||
}
|
||||
|
||||
|
@ -142,9 +181,10 @@ public class BCLFeature {
|
|||
* @return new BCLFeature instance.
|
||||
*/
|
||||
public static BCLFeature makeCountFeature(ResourceLocation id, Decoration step, Feature<NoneFeatureConfiguration> feature, int count) {
|
||||
ConfiguredFeature<?, ?> configured = feature
|
||||
PlacedFeature configured = feature
|
||||
.configured(FeatureConfiguration.NONE)
|
||||
.decorated(FeatureDecorator.COUNT.configured(new CountConfiguration(count)));
|
||||
.placed(CountPlacement.of(count));
|
||||
//.decorated(FeatureDecorator.COUNT.configured(new CountConfiguration(count)));
|
||||
return new BCLFeature(id, feature, step, configured);
|
||||
}
|
||||
|
||||
|
@ -156,7 +196,7 @@ public class BCLFeature {
|
|||
* @return new BCLFeature instance.
|
||||
*/
|
||||
public static BCLFeature makeFeatureConfigured(ResourceLocation id, Decoration step, Feature<NoneFeatureConfiguration> feature) {
|
||||
ConfiguredFeature<?, ?> configured = feature.configured(FeatureConfiguration.NONE);
|
||||
PlacedFeature configured = feature.configured(FeatureConfiguration.NONE).placed();
|
||||
return new BCLFeature(id, feature, step, configured);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue