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