Fixed compiler errors
This commit is contained in:
parent
6c015a9a53
commit
824e78abf7
10 changed files with 165 additions and 112 deletions
|
@ -1,16 +1,17 @@
|
||||||
package ru.bclib.api.biomes;
|
package ru.bclib.api.biomes;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
|
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
|
||||||
import net.minecraft.core.Holder;
|
import net.minecraft.core.Holder;
|
||||||
import net.minecraft.core.HolderSet;
|
import net.minecraft.core.HolderSet;
|
||||||
import net.minecraft.core.Registry;
|
|
||||||
import net.minecraft.core.particles.ParticleOptions;
|
import net.minecraft.core.particles.ParticleOptions;
|
||||||
import net.minecraft.data.BuiltinRegistries;
|
import net.minecraft.data.BuiltinRegistries;
|
||||||
import net.minecraft.data.worldgen.BiomeDefaultFeatures;
|
import net.minecraft.data.worldgen.BiomeDefaultFeatures;
|
||||||
import net.minecraft.resources.ResourceKey;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.sounds.Music;
|
import net.minecraft.sounds.Music;
|
||||||
import net.minecraft.sounds.SoundEvent;
|
import net.minecraft.sounds.SoundEvent;
|
||||||
|
import net.minecraft.tags.TagKey;
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
import net.minecraft.world.entity.EntityType;
|
import net.minecraft.world.entity.EntityType;
|
||||||
import net.minecraft.world.entity.Mob;
|
import net.minecraft.world.entity.Mob;
|
||||||
|
@ -44,13 +45,9 @@ import ru.bclib.world.biomes.BCLBiomeSettings;
|
||||||
import ru.bclib.world.features.BCLFeature;
|
import ru.bclib.world.features.BCLFeature;
|
||||||
import ru.bclib.world.structures.BCLStructureFeature;
|
import ru.bclib.world.structures.BCLStructureFeature;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Supplier;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class BCLBiomeBuilder {
|
public class BCLBiomeBuilder {
|
||||||
|
@ -61,7 +58,7 @@ public class BCLBiomeBuilder {
|
||||||
private static final BCLBiomeBuilder INSTANCE = new BCLBiomeBuilder();
|
private static final BCLBiomeBuilder INSTANCE = new BCLBiomeBuilder();
|
||||||
private static final SurfaceRules.ConditionSource SURFACE_NOISE = SurfaceRules.noiseCondition(Noises.SOUL_SAND_LAYER, -0.012);
|
private static final SurfaceRules.ConditionSource SURFACE_NOISE = SurfaceRules.noiseCondition(Noises.SOUL_SAND_LAYER, -0.012);
|
||||||
|
|
||||||
private List<ConfiguredStructureFeature> structures = new ArrayList<>(16);
|
private List<TagKey<Biome>> structureTags = new ArrayList<>(8);
|
||||||
private BiomeGenerationSettings.Builder generationSettings;
|
private BiomeGenerationSettings.Builder generationSettings;
|
||||||
private BiomeSpecialEffects.Builder effectsBuilder;
|
private BiomeSpecialEffects.Builder effectsBuilder;
|
||||||
private MobSpawnSettings.Builder spawnSettings;
|
private MobSpawnSettings.Builder spawnSettings;
|
||||||
|
@ -91,7 +88,7 @@ public class BCLBiomeBuilder {
|
||||||
INSTANCE.generationSettings = null;
|
INSTANCE.generationSettings = null;
|
||||||
INSTANCE.effectsBuilder = null;
|
INSTANCE.effectsBuilder = null;
|
||||||
INSTANCE.spawnSettings = null;
|
INSTANCE.spawnSettings = null;
|
||||||
INSTANCE.structures.clear();
|
INSTANCE.structureTags.clear();
|
||||||
INSTANCE.temperature = 1.0F;
|
INSTANCE.temperature = 1.0F;
|
||||||
INSTANCE.fogDensity = 1.0F;
|
INSTANCE.fogDensity = 1.0F;
|
||||||
INSTANCE.edgeSize = 0;
|
INSTANCE.edgeSize = 0;
|
||||||
|
@ -546,11 +543,11 @@ public class BCLBiomeBuilder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds new structure feature into the biome.
|
* Adds new structure feature into the biome.
|
||||||
* @param structure {@link ConfiguredStructureFeature} to add.
|
* @param structureTag {@link TagKey} to add.
|
||||||
* @return same {@link BCLBiomeBuilder} instance.
|
* @return same {@link BCLBiomeBuilder} instance.
|
||||||
*/
|
*/
|
||||||
public BCLBiomeBuilder structure(Holder<ConfiguredStructureFeature<?, ?>> structure) {
|
public BCLBiomeBuilder structure(TagKey<Biome> structureTag) {
|
||||||
structures.add(structure.value());
|
structureTags.add(structureTag);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -561,7 +558,7 @@ public class BCLBiomeBuilder {
|
||||||
*/
|
*/
|
||||||
public BCLBiomeBuilder structure(BCLStructureFeature structure) {
|
public BCLBiomeBuilder structure(BCLStructureFeature structure) {
|
||||||
structure.addInternalBiome(biomeID);
|
structure.addInternalBiome(biomeID);
|
||||||
return structure(structure.getFeatureConfigured());
|
return structure(structure.biomeTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -659,7 +656,7 @@ public class BCLBiomeBuilder {
|
||||||
public <T extends BCLBiome> T build(BiFunction<ResourceLocation, Biome, T> biomeConstructor) {
|
public <T extends BCLBiome> T build(BiFunction<ResourceLocation, Biome, T> biomeConstructor) {
|
||||||
return build((id, biome, settings)->biomeConstructor.apply(id, biome));
|
return build((id, biome, settings)->biomeConstructor.apply(id, biome));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finalize biome creation.
|
* Finalize biome creation.
|
||||||
* @param biomeConstructor {@link BiomeSupplier} biome constructor.
|
* @param biomeConstructor {@link BiomeSupplier} biome constructor.
|
||||||
|
@ -674,24 +671,23 @@ public class BCLBiomeBuilder {
|
||||||
|
|
||||||
builder.mobSpawnSettings(getSpawns().build());
|
builder.mobSpawnSettings(getSpawns().build());
|
||||||
builder.specialEffects(getEffects().build());
|
builder.specialEffects(getEffects().build());
|
||||||
|
|
||||||
Map<Decoration, HolderSet<PlacedFeature>> defferedFeatures = new HashMap<>();
|
Map<Decoration, List<Holder<PlacedFeature>>> defferedFeatures = Maps.newHashMap();
|
||||||
BiomeGenerationSettingsAccessor acc = BiomeGenerationSettingsAccessor.class.cast(getGeneration().build());
|
BiomeGenerationSettingsAccessor acc = BiomeGenerationSettingsAccessor.class.cast(getGeneration().build());
|
||||||
if (acc != null) {
|
if (acc != null) {
|
||||||
builder.generationSettings(new BiomeGenerationSettings.Builder().build());
|
builder.generationSettings(new BiomeGenerationSettings.Builder().build());
|
||||||
var decorations = acc.bclib_getFeatures();
|
List<HolderSet<PlacedFeature>> decorations = acc.bclib_getFeatures();
|
||||||
for (Decoration d : Decoration.values()) {
|
for (Decoration d : Decoration.values()) {
|
||||||
int i = d.ordinal();
|
int i = d.ordinal();
|
||||||
if (i >= 0 && i < decorations.size()) {
|
if (i>=0 && i<decorations.size()) {
|
||||||
var features = decorations.get(i);
|
HolderSet<PlacedFeature> features = decorations.get(i);
|
||||||
defferedFeatures.put(d, features.stream().collect(Collectors.toList()));
|
defferedFeatures.put(d, features.stream().collect(Collectors.toList()));
|
||||||
|
} else {
|
||||||
|
defferedFeatures.put(d, Lists.newArrayList());
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
defferedFeatures.put(d, new ArrayList<>(0));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
builder.generationSettings(getGeneration().build());
|
builder.generationSettings(getGeneration().build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -706,7 +702,7 @@ public class BCLBiomeBuilder {
|
||||||
|
|
||||||
final Biome biome = builder.build();
|
final Biome biome = builder.build();
|
||||||
final T res = biomeConstructor.apply(biomeID, biome, settings);
|
final T res = biomeConstructor.apply(biomeID, biome, settings);
|
||||||
res.attachStructures(structures);
|
res.attachStructures(structureTags);
|
||||||
res.setSurface(surfaceRule);
|
res.setSurface(surfaceRule);
|
||||||
res.setFeatures(defferedFeatures);
|
res.setFeatures(defferedFeatures);
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package ru.bclib.api.biomes;
|
package ru.bclib.api.biomes;
|
||||||
|
|
||||||
|
import com.google.common.base.Suppliers;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
@ -39,6 +41,7 @@ import net.minecraft.world.level.levelgen.SurfaceRules.RuleSource;
|
||||||
import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver;
|
import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver;
|
||||||
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
|
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
|
||||||
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
|
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
|
||||||
|
import net.minecraft.world.level.levelgen.feature.Feature;
|
||||||
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
||||||
import net.minecraft.world.level.levelgen.structure.StructureSet;
|
import net.minecraft.world.level.levelgen.structure.StructureSet;
|
||||||
import org.apache.commons.lang3.mutable.MutableInt;
|
import org.apache.commons.lang3.mutable.MutableInt;
|
||||||
|
@ -77,7 +80,7 @@ public class BiomeAPI {
|
||||||
private static final Map<Biome, BCLBiome> CLIENT = Maps.newHashMap();
|
private static final Map<Biome, BCLBiome> CLIENT = Maps.newHashMap();
|
||||||
private static Registry<Biome> biomeRegistry;
|
private static Registry<Biome> biomeRegistry;
|
||||||
|
|
||||||
private static final Map<PlacedFeature, Integer> FEATURE_ORDER = Maps.newHashMap();
|
private static final Map<Holder<PlacedFeature>, Integer> FEATURE_ORDER = Maps.newHashMap();
|
||||||
private static final MutableInt FEATURE_ORDER_ID = new MutableInt(0);
|
private static final MutableInt FEATURE_ORDER_ID = new MutableInt(0);
|
||||||
|
|
||||||
private static final Map<ResourceKey, List<BiConsumer<ResourceLocation, Holder<Biome>>>> MODIFICATIONS = Maps.newHashMap();
|
private static final Map<ResourceKey, List<BiConsumer<ResourceLocation, Holder<Biome>>>> MODIFICATIONS = Maps.newHashMap();
|
||||||
|
@ -113,8 +116,7 @@ public class BiomeAPI {
|
||||||
.map(Entry::getValue)
|
.map(Entry::getValue)
|
||||||
.map(biome -> (BiomeGenerationSettingsAccessor) biome.getGenerationSettings())
|
.map(biome -> (BiomeGenerationSettingsAccessor) biome.getGenerationSettings())
|
||||||
.map(BiomeGenerationSettingsAccessor::bclib_getFeatures)
|
.map(BiomeGenerationSettingsAccessor::bclib_getFeatures)
|
||||||
.forEach(stepFeatureSuppliers -> stepFeatureSuppliers.forEach(step -> step.forEach(featureSupplier -> {
|
.forEach(stepFeatureSuppliers -> stepFeatureSuppliers.forEach(step -> step.forEach(feature -> {
|
||||||
PlacedFeature feature = featureSupplier.value();
|
|
||||||
FEATURE_ORDER.computeIfAbsent(feature, f -> FEATURE_ORDER_ID.getAndIncrement());
|
FEATURE_ORDER.computeIfAbsent(feature, f -> FEATURE_ORDER_ID.getAndIncrement());
|
||||||
})));
|
})));
|
||||||
}
|
}
|
||||||
|
@ -427,7 +429,7 @@ public class BiomeAPI {
|
||||||
|
|
||||||
FabricBiomesData.END_VOID_BIOMES.forEach((key, weight) -> {
|
FabricBiomesData.END_VOID_BIOMES.forEach((key, weight) -> {
|
||||||
if (!hasBiome(key.location())) {
|
if (!hasBiome(key.location())) {
|
||||||
registerEndVoidBiome(BuiltinRegistries.BIOME.get(key), weight);
|
registerEndVoidBiome(BuiltinRegistries.BIOME.getOrCreateHolder(key), weight);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -581,12 +583,12 @@ public class BiomeAPI {
|
||||||
public static void sortBiomeFeatures(Holder<Biome> biome) {
|
public static void sortBiomeFeatures(Holder<Biome> biome) {
|
||||||
BiomeGenerationSettings settings = biome.value().getGenerationSettings();
|
BiomeGenerationSettings settings = biome.value().getGenerationSettings();
|
||||||
BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) settings;
|
BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) settings;
|
||||||
List<List<Supplier<PlacedFeature>>> featureList = CollectionsUtil.getMutable(accessor.bclib_getFeatures());
|
List<HolderSet<PlacedFeature>> featureList = CollectionsUtil.getMutable(accessor.bclib_getFeatures());
|
||||||
final int size = featureList.size();
|
final int size = featureList.size();
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
List<Supplier<PlacedFeature>> features = CollectionsUtil.getMutable(featureList.get(i));
|
List<Holder<PlacedFeature>> features = getFeaturesListCopy(featureList, i);
|
||||||
sortFeatures(features);
|
sortFeatures(features);
|
||||||
featureList.set(i, features);
|
featureList.set(i, HolderSet.direct(features));
|
||||||
}
|
}
|
||||||
accessor.bclib_setFeatures(featureList);
|
accessor.bclib_setFeatures(featureList);
|
||||||
}
|
}
|
||||||
|
@ -652,20 +654,24 @@ public class BiomeAPI {
|
||||||
* Adds new features to existing biome.
|
* Adds new features to existing biome.
|
||||||
* @param biome {@link Biome} to add features in.
|
* @param biome {@link Biome} to add features in.
|
||||||
* @param step a {@link Decoration} step for the feature.
|
* @param step a {@link Decoration} step for the feature.
|
||||||
* @param featureList List of {@link ConfiguredFeature} to add.
|
* @param additionalFeatures List of {@link ConfiguredFeature} to add.
|
||||||
*/
|
*/
|
||||||
private static void addBiomeFeature(Holder<Biome> biome, Decoration step, List<Holder<PlacedFeature>> featureList) {
|
private static void addBiomeFeature(Holder<Biome> biome, Decoration step, List<Holder<PlacedFeature>> additionalFeatures) {
|
||||||
BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.value().getGenerationSettings();
|
BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.value().getGenerationSettings();
|
||||||
List<HolderSet<PlacedFeature>> allFeatures = CollectionsUtil.getMutable(accessor.bclib_getFeatures());
|
List<HolderSet<PlacedFeature>> allFeatures = CollectionsUtil.getMutable(accessor.bclib_getFeatures());
|
||||||
Set<PlacedFeature> set = CollectionsUtil.getMutable(accessor.bclib_getFeatureSet().get());
|
List<Holder<PlacedFeature>> features = getFeaturesListCopy(allFeatures, step);
|
||||||
HolderSet<PlacedFeature> features = getFeaturesList(allFeatures, step);
|
|
||||||
for (var feature : featureList) {
|
for (var feature : additionalFeatures) {
|
||||||
features.
|
if (!features.contains(feature))
|
||||||
features.add(() -> feature);
|
features.add(feature);
|
||||||
set.add(feature);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
allFeatures.set(step.ordinal(), HolderSet.direct(features));
|
||||||
|
final Supplier<List<ConfiguredFeature<?, ?>>> flowerFeatures = Suppliers.memoize(() -> allFeatures.stream().flatMap(HolderSet::stream).map(Holder::value).flatMap(PlacedFeature::getFeatures).filter(configuredFeature -> configuredFeature.feature() == Feature.FLOWER).collect(ImmutableList.toImmutableList()));
|
||||||
|
final Supplier<Set<PlacedFeature>> featureSet = Suppliers.memoize(() -> allFeatures.stream().flatMap(HolderSet::stream).map(Holder::value).collect(Collectors.toSet()));
|
||||||
|
|
||||||
accessor.bclib_setFeatures(allFeatures);
|
accessor.bclib_setFeatures(allFeatures);
|
||||||
accessor.bclib_setFeatureSet(()-> set);
|
accessor.bclib_setFeatureSet(featureSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -676,22 +682,10 @@ public class BiomeAPI {
|
||||||
* @param biome {@link Biome} to add features in.
|
* @param biome {@link Biome} to add features in.
|
||||||
* @param featureMap Map of {@link ConfiguredFeature} to add.
|
* @param featureMap Map of {@link ConfiguredFeature} to add.
|
||||||
*/
|
*/
|
||||||
private static void addStepFeaturesToBiome(Holder<Biome> biome, Map<Decoration, List<Supplier<PlacedFeature>>> featureMap) {
|
private static void addStepFeaturesToBiome(Holder<Biome> biome, Map<Decoration, List<Holder<PlacedFeature>>> featureMap) {
|
||||||
BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.value().getGenerationSettings();
|
|
||||||
List<List<Supplier<PlacedFeature>>> allFeatures = CollectionsUtil.getMutable(accessor.bclib_getFeatures());
|
|
||||||
Set<PlacedFeature> set = CollectionsUtil.getMutable(accessor.bclib_getFeatureSet().get());
|
|
||||||
|
|
||||||
for (Decoration step: featureMap.keySet()) {
|
for (Decoration step: featureMap.keySet()) {
|
||||||
List<Supplier<PlacedFeature>> features = getFeaturesList(allFeatures, step);
|
addBiomeFeature(biome, step, featureMap.get(step));
|
||||||
List<Supplier<PlacedFeature>> featureList = featureMap.get(step);
|
|
||||||
|
|
||||||
for (Supplier<PlacedFeature> feature : featureList) {
|
|
||||||
features.add(feature);
|
|
||||||
set.add(feature.get());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
accessor.bclib_setFeatures(allFeatures);
|
|
||||||
accessor.bclib_setFeatureSet(() -> set);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -700,13 +694,20 @@ public class BiomeAPI {
|
||||||
* @param carver {@link ConfiguredWorldCarver} to add.
|
* @param carver {@link ConfiguredWorldCarver} to add.
|
||||||
* @param stage {@link Carving} stage.
|
* @param stage {@link Carving} stage.
|
||||||
*/
|
*/
|
||||||
public static void addBiomeCarver(Biome biome, ConfiguredWorldCarver carver, Carving stage) {
|
public static void addBiomeCarver(Biome biome, Holder<ConfiguredWorldCarver<?>> carver, Carving stage) {
|
||||||
BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings();
|
BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings();
|
||||||
Map<Carving, HolderSet<ConfiguredWorldCarver<?>>> carvers = CollectionsUtil.getMutable(accessor.bclib_getCarvers());
|
Map<Carving, HolderSet<ConfiguredWorldCarver<?>>> carverMap = CollectionsUtil.getMutable(accessor.bclib_getCarvers());
|
||||||
HolderSet<ConfiguredWorldCarver<?>> carverList = CollectionsUtil.getMutable(carvers.getOrDefault(stage, new ArrayList<>()));
|
HolderSet<ConfiguredWorldCarver<?>> carvers = carverMap.get(stage);
|
||||||
carvers.put(stage, carverList);
|
|
||||||
carverList.add(() -> carver);
|
List<Holder<ConfiguredWorldCarver<?>>> carverList;
|
||||||
accessor.bclib_setCarvers(carvers);
|
if (carvers==null) {
|
||||||
|
carverList = Lists.newArrayList();
|
||||||
|
} else {
|
||||||
|
carverList = carvers.stream().toList();
|
||||||
|
}
|
||||||
|
carverList.add(carver);
|
||||||
|
carverMap.put(stage, HolderSet.direct(carverList));
|
||||||
|
accessor.bclib_setCarvers(carverMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -866,25 +867,24 @@ public class BiomeAPI {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void sortFeatures(List<Supplier<PlacedFeature>> features) {
|
private static void sortFeatures(List<Holder<PlacedFeature>> features) {
|
||||||
initFeatureOrder();
|
initFeatureOrder();
|
||||||
|
|
||||||
Set<PlacedFeature> featuresWithoutDuplicates = Sets.newHashSet();
|
Set<Holder<PlacedFeature>> featuresWithoutDuplicates = Sets.newHashSet();
|
||||||
features.forEach(provider -> featuresWithoutDuplicates.add(provider.get()));
|
features.forEach(holder -> featuresWithoutDuplicates.add(holder));
|
||||||
|
|
||||||
if (featuresWithoutDuplicates.size() != features.size()) {
|
if (featuresWithoutDuplicates.size() != features.size()) {
|
||||||
features.clear();
|
features.clear();
|
||||||
featuresWithoutDuplicates.forEach(feature -> features.add(() -> feature));
|
featuresWithoutDuplicates.forEach(feature -> features.add(feature));
|
||||||
}
|
}
|
||||||
|
|
||||||
features.forEach(provider -> {
|
features.forEach(feature -> {
|
||||||
PlacedFeature feature = provider.get();
|
|
||||||
FEATURE_ORDER.computeIfAbsent(feature, f -> FEATURE_ORDER_ID.getAndIncrement());
|
FEATURE_ORDER.computeIfAbsent(feature, f -> FEATURE_ORDER_ID.getAndIncrement());
|
||||||
});
|
});
|
||||||
|
|
||||||
features.sort((f1, f2) -> {
|
features.sort((f1, f2) -> {
|
||||||
int v1 = FEATURE_ORDER.getOrDefault(f1.get(), 70000);
|
int v1 = FEATURE_ORDER.getOrDefault(f1, 70000);
|
||||||
int v2 = FEATURE_ORDER.getOrDefault(f2.get(), 70000);
|
int v2 = FEATURE_ORDER.getOrDefault(f2, 70000);
|
||||||
return Integer.compare(v1, v2);
|
return Integer.compare(v1, v2);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -906,14 +906,15 @@ public class BiomeAPI {
|
||||||
lists.set(index, list);
|
lists.set(index, list);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static List<Holder<PlacedFeature>> getFeaturesListCopy(List<HolderSet<PlacedFeature>> features, Decoration step) {
|
||||||
|
return getFeaturesListCopy(features, step.ordinal());
|
||||||
|
}
|
||||||
|
|
||||||
private static HolderSet<PlacedFeature> getFeaturesList(List<HolderSet<PlacedFeature>> features, Decoration step) {
|
private static List<Holder<PlacedFeature>> getFeaturesListCopy(List<HolderSet<PlacedFeature>> features, int index) {
|
||||||
int index = step.ordinal();
|
|
||||||
while (features.size() <= index) {
|
while (features.size() <= index) {
|
||||||
features.add(HolderSet.direct(Lists.newArrayList()));
|
features.add(HolderSet.direct(Lists.newArrayList()));
|
||||||
}
|
}
|
||||||
HolderSet<PlacedFeature> mutable = features.get(index);
|
return features.get(index).stream().collect(Collectors.toList());
|
||||||
features.set(index, mutable);
|
|
||||||
return mutable;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ 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.util.valueproviders.UniformInt;
|
||||||
import net.minecraft.world.level.levelgen.GenerationStep.Decoration;
|
import net.minecraft.world.level.levelgen.GenerationStep.Decoration;
|
||||||
|
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.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.BiomeFilter;
|
||||||
|
@ -18,12 +19,12 @@ import ru.bclib.world.features.BCLFeature;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class BCLFeatureBuilder {
|
public class BCLFeatureBuilder <FC extends FeatureConfiguration, F extends Feature<FC>>{
|
||||||
private static final BCLFeatureBuilder INSTANCE = new BCLFeatureBuilder();
|
private static final BCLFeatureBuilder INSTANCE = new BCLFeatureBuilder();
|
||||||
private List<PlacementModifier> modifications = new ArrayList<>(16);
|
private List<PlacementModifier> modifications = new ArrayList<>(16);
|
||||||
private ResourceLocation featureID;
|
private ResourceLocation featureID;
|
||||||
private Decoration decoration;
|
private Decoration decoration;
|
||||||
private Feature<?> feature;
|
private F feature;
|
||||||
|
|
||||||
private BCLFeatureBuilder() {}
|
private BCLFeatureBuilder() {}
|
||||||
|
|
||||||
|
@ -134,10 +135,9 @@ public class BCLFeatureBuilder {
|
||||||
* @param configuration any {@link FeatureConfiguration} for provided {@link Feature}.
|
* @param configuration any {@link FeatureConfiguration} for provided {@link Feature}.
|
||||||
* @return created {@link BCLFeature} instance.
|
* @return created {@link BCLFeature} instance.
|
||||||
*/
|
*/
|
||||||
public <FC extends FeatureConfiguration> BCLFeature build(FC configuration) {
|
public BCLFeature build(FC configuration) {
|
||||||
PlacementModifier [] modifiers = modifications.toArray(new PlacementModifier [modifications.size()]);
|
PlacementModifier [] modifiers = modifications.toArray(new PlacementModifier [modifications.size()]);
|
||||||
PlacedFeature configured = ((Feature<FC>) feature).configured(configuration).placed(modifiers);
|
return new BCLFeature(featureID, feature, decoration, configuration, modifiers);
|
||||||
return new BCLFeature(featureID, feature, decoration, configured);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -146,6 +146,6 @@ public class BCLFeatureBuilder {
|
||||||
* @return created {@link BCLFeature} instance.
|
* @return created {@link BCLFeature} instance.
|
||||||
*/
|
*/
|
||||||
public BCLFeature build() {
|
public BCLFeature build() {
|
||||||
return build(FeatureConfiguration.NONE);
|
return build((FC)FeatureConfiguration.NONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,16 @@ public class TagAPI {
|
||||||
public static TagKey<Block> makeBlockTag(String modID, String name) {
|
public static TagKey<Block> makeBlockTag(String modID, String name) {
|
||||||
return makeTag(Registry.BLOCK, new TagLocation<>(modID, name));
|
return makeTag(Registry.BLOCK, new TagLocation<>(modID, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get or create {@link Block} {@link TagKey} with mod namespace.
|
||||||
|
*
|
||||||
|
* @param id - {@link String} id for the tag;
|
||||||
|
* @return {@link Block} {@link TagKey}.
|
||||||
|
*/
|
||||||
|
public static TagKey<Block> makeBlockTag(ResourceLocation id) {
|
||||||
|
return makeTag(Registry.BLOCK, new TagLocation<>(id));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get or create {@link Item} {@link TagKey} with mod namespace.
|
* Get or create {@link Item} {@link TagKey} with mod namespace.
|
||||||
|
@ -73,6 +83,16 @@ public class TagAPI {
|
||||||
public static TagKey<Item> makeItemTag(String modID, String name) {
|
public static TagKey<Item> makeItemTag(String modID, String name) {
|
||||||
return makeTag(Registry.ITEM, new TagLocation<>(modID, name));
|
return makeTag(Registry.ITEM, new TagLocation<>(modID, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get or create {@link Item} {@link TagKey} with mod namespace.
|
||||||
|
*
|
||||||
|
* @param id - {@link String} id for the tag;
|
||||||
|
* @return {@link Item} {@link TagKey}.
|
||||||
|
*/
|
||||||
|
public static TagKey<Item> makeItemTag(ResourceLocation id) {
|
||||||
|
return makeTag(Registry.ITEM, new TagLocation<>(id));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get or create {@link Block} {@link TagKey}.
|
* Get or create {@link Block} {@link TagKey}.
|
||||||
|
@ -208,6 +228,7 @@ public class TagAPI {
|
||||||
* @return The {@code tagsMap} Parameter.
|
* @return The {@code tagsMap} Parameter.
|
||||||
*/
|
*/
|
||||||
public static <T> Map<ResourceLocation, Tag.Builder> apply(String directory, Map<ResourceLocation, Tag.Builder> tagsMap) {
|
public static <T> Map<ResourceLocation, Tag.Builder> apply(String directory, Map<ResourceLocation, Tag.Builder> tagsMap) {
|
||||||
|
System.out.println("TAG DIRECTORY: " + directory);
|
||||||
final BiConsumer<ResourceLocation, Set<ResourceLocation>> consumer;
|
final BiConsumer<ResourceLocation, Set<ResourceLocation>> consumer;
|
||||||
consumer = (id, ids) -> apply(tagsMap.computeIfAbsent(id, key -> Tag.Builder.tag()), ids);
|
consumer = (id, ids) -> apply(tagsMap.computeIfAbsent(id, key -> Tag.Builder.tag()), ids);
|
||||||
if ("tags/blocks".equals(directory)) {
|
if ("tags/blocks".equals(directory)) {
|
||||||
|
|
|
@ -19,6 +19,7 @@ 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.placement.PlacedFeature;
|
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
||||||
import ru.bclib.BCLib;
|
import ru.bclib.BCLib;
|
||||||
|
import ru.bclib.api.tag.TagAPI;
|
||||||
import ru.bclib.world.features.BCLFeature;
|
import ru.bclib.world.features.BCLFeature;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
|
@ -66,8 +67,8 @@ public abstract class ModIntegration {
|
||||||
public BCLFeature getFeature(String featureID, String placedFeatureID, GenerationStep.Decoration featureStep) {
|
public BCLFeature getFeature(String featureID, String placedFeatureID, GenerationStep.Decoration featureStep) {
|
||||||
ResourceLocation id = getID(featureID);
|
ResourceLocation id = getID(featureID);
|
||||||
Feature<?> feature = Registry.FEATURE.get(id);
|
Feature<?> feature = Registry.FEATURE.get(id);
|
||||||
Holder<PlacedFeature> featureConfigured = BuiltinRegistries.PLACED_FEATURE.getHolder(getFeatureKey(placedFeatureID)).orElse(null);
|
Holder<PlacedFeature> featurePlaced = BuiltinRegistries.PLACED_FEATURE.getHolder(getFeatureKey(placedFeatureID)).orElse(null);
|
||||||
return new BCLFeature(id, feature, featureStep, featureConfigured);
|
return new BCLFeature(id, feature, featureStep, featurePlaced);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BCLFeature getFeature(String name, GenerationStep.Decoration featureStep) {
|
public BCLFeature getFeature(String name, GenerationStep.Decoration featureStep) {
|
||||||
|
@ -203,16 +204,11 @@ public abstract class ModIntegration {
|
||||||
|
|
||||||
public TagKey<Item> getItemTag(String name) {
|
public TagKey<Item> getItemTag(String name) {
|
||||||
ResourceLocation id = getID(name);
|
ResourceLocation id = getID(name);
|
||||||
Tag<Item> tag = ItemTags.getAllTags().getTag(id);
|
return TagAPI.makeItemTag(id);
|
||||||
|
|
||||||
//return tag == null ? (TagKey<Item>) TagRegistry.item(id) : (TagKey<Item>) tag;
|
|
||||||
return tag == null ? (TagKey<Item>) TagFactory.ITEM.create(id) : (TagKey<Item>) tag;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagKey<Block> getBlockTag(String name) {
|
public TagKey<Block> getBlockTag(String name) {
|
||||||
ResourceLocation id = getID(name);
|
ResourceLocation id = getID(name);
|
||||||
Tag<Block> tag = BlockTags.getAllTags().getTag(id);
|
return TagAPI.makeBlockTag(id);
|
||||||
//return tag == null ? (Named<Block>) TagRegistry.block(id) : (Named<Block>) tag;
|
|
||||||
return tag == null ? (TagKey<Block>) TagFactory.BLOCK.create(id) : (TagKey<Block>) tag;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import net.minecraft.world.level.biome.BiomeGenerationSettings;
|
||||||
import net.minecraft.world.level.levelgen.GenerationStep;
|
import net.minecraft.world.level.levelgen.GenerationStep;
|
||||||
import net.minecraft.world.level.levelgen.GenerationStep.Carving;
|
import net.minecraft.world.level.levelgen.GenerationStep.Carving;
|
||||||
import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver;
|
import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver;
|
||||||
|
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
|
||||||
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Mutable;
|
import org.spongepowered.asm.mixin.Mutable;
|
||||||
|
@ -28,7 +29,13 @@ public interface BiomeGenerationSettingsAccessor {
|
||||||
Supplier<Set<PlacedFeature>> bclib_getFeatureSet();
|
Supplier<Set<PlacedFeature>> bclib_getFeatureSet();
|
||||||
|
|
||||||
@Accessor("featureSet")
|
@Accessor("featureSet")
|
||||||
void bclib_setFeatureSet(Supplier<Set<PlacedFeature>> features);
|
void bclib_setFeatureSet(Supplier<Set<PlacedFeature>> featureSet);
|
||||||
|
|
||||||
|
@Accessor("flowerFeatures")
|
||||||
|
Supplier<List<ConfiguredFeature<?, ?>>> bclib_getFlowerFeatures();
|
||||||
|
|
||||||
|
@Accessor("flowerFeatures")
|
||||||
|
void bclib_setFlowerFeatures(Supplier<List<ConfiguredFeature<?, ?>>> flowerFeatures);
|
||||||
|
|
||||||
@Accessor("carvers")
|
@Accessor("carvers")
|
||||||
Map<GenerationStep.Carving, HolderSet<ConfiguredWorldCarver<?>>> bclib_getCarvers();
|
Map<GenerationStep.Carving, HolderSet<ConfiguredWorldCarver<?>>> bclib_getCarvers();
|
||||||
|
|
|
@ -27,7 +27,7 @@ public abstract class RecipeManagerMixin {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "getRecipeFor", at = @At(value = "HEAD"), cancellable = true)
|
@Inject(method = "getRecipeFor", at = @At(value = "HEAD"), cancellable = true)
|
||||||
private <C extends Container, T extends Recipe<C>> void bclib_getRecipeFor(RecipeType<T> type, C inventory, Level world, CallbackInfoReturnable<Optional<T>> info) {
|
private <C extends Container, T extends Recipe<C>> void bclib_getRecipeFor(RecipeType<T> type, C inventory, Level level, CallbackInfoReturnable<Optional<T>> info) {
|
||||||
Collection<Recipe<C>> values = byType(type).values();
|
Collection<Recipe<C>> values = byType(type).values();
|
||||||
List<Recipe<C>> list = new ArrayList<>(values);
|
List<Recipe<C>> list = new ArrayList<>(values);
|
||||||
list.sort((v1, v2) -> {
|
list.sort((v1, v2) -> {
|
||||||
|
@ -35,6 +35,6 @@ public abstract class RecipeManagerMixin {
|
||||||
boolean b2 = v2.getId().getNamespace().equals("minecraft");
|
boolean b2 = v2.getId().getNamespace().equals("minecraft");
|
||||||
return b1 ^ b2 ? (b1 ? 1 : -1) : 0;
|
return b1 ^ b2 ? (b1 ? 1 : -1) : 0;
|
||||||
});
|
});
|
||||||
info.setReturnValue(list.stream().flatMap((recipe) -> Util.toStream(type.tryMatch(recipe, world, inventory))).findFirst());
|
info.setReturnValue(list.stream().flatMap(recipe -> type.tryMatch(recipe, level, inventory).stream()).findFirst());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,12 +4,14 @@ import com.google.gson.JsonObject;
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
|
import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider;
|
||||||
import net.minecraft.core.NonNullList;
|
import net.minecraft.core.NonNullList;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.TagParser;
|
import net.minecraft.nbt.TagParser;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.tags.ItemTags;
|
||||||
import net.minecraft.tags.Tag;
|
import net.minecraft.tags.Tag;
|
||||||
import net.minecraft.tags.TagKey;
|
import net.minecraft.tags.TagKey;
|
||||||
import net.minecraft.util.GsonHelper;
|
import net.minecraft.util.GsonHelper;
|
||||||
|
@ -142,12 +144,13 @@ public class AnvilRecipe implements Recipe<Container>, UnknownReceipBookCategory
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NonNullList<Ingredient> getIngredients() {
|
public NonNullList<Ingredient> getIngredients() {
|
||||||
|
;
|
||||||
NonNullList<Ingredient> defaultedList = NonNullList.create();
|
NonNullList<Ingredient> defaultedList = NonNullList.create();
|
||||||
defaultedList.add(Ingredient.of(CommonItemTags.HAMMERS
|
defaultedList.add(Ingredient.of(Registry.ITEM.stream()
|
||||||
.getValues()
|
.filter(item->item.builtInRegistryHolder().is(CommonItemTags.HAMMERS))
|
||||||
.stream()
|
.filter(hammer -> ((TieredItem) hammer).getTier().getLevel() >= toolLevel)
|
||||||
.filter(hammer -> ((TieredItem) hammer).getTier().getLevel() >= toolLevel)
|
.map(ItemStack::new))
|
||||||
.map(ItemStack::new)));
|
);
|
||||||
defaultedList.add(input);
|
defaultedList.add(input);
|
||||||
return defaultedList;
|
return defaultedList;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,13 @@ package ru.bclib.world.biomes;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
import net.minecraft.core.Holder;
|
import net.minecraft.core.Holder;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.data.BuiltinRegistries;
|
import net.minecraft.data.BuiltinRegistries;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.tags.TagKey;
|
||||||
import net.minecraft.world.level.biome.Biome;
|
import net.minecraft.world.level.biome.Biome;
|
||||||
import net.minecraft.world.level.levelgen.GenerationStep.Decoration;
|
import net.minecraft.world.level.levelgen.GenerationStep.Decoration;
|
||||||
import net.minecraft.world.level.levelgen.SurfaceRules;
|
import net.minecraft.world.level.levelgen.SurfaceRules;
|
||||||
|
@ -18,15 +20,14 @@ import ru.bclib.BCLib;
|
||||||
import ru.bclib.api.biomes.BiomeAPI;
|
import ru.bclib.api.biomes.BiomeAPI;
|
||||||
import ru.bclib.util.WeightedList;
|
import ru.bclib.util.WeightedList;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class BCLBiome extends BCLBiomeSettings {
|
public class BCLBiome extends BCLBiomeSettings {
|
||||||
private final List<ConfiguredStructureFeature> structures = Lists.newArrayList();
|
private final Set<TagKey<Biome>> structureTags = Sets.newHashSet();
|
||||||
private final WeightedList<BCLBiome> subbiomes = new WeightedList<>();
|
private final WeightedList<BCLBiome> subbiomes = new WeightedList<>();
|
||||||
private final Map<String, Object> customData = Maps.newHashMap();
|
private final Map<String, Object> customData = Maps.newHashMap();
|
||||||
private final ResourceLocation biomeID;
|
private final ResourceLocation biomeID;
|
||||||
|
@ -207,15 +208,17 @@ public class BCLBiome extends BCLBiomeSettings {
|
||||||
BCLib.LOGGER.error("Unable to find actual Biome for " + biomeID);
|
BCLib.LOGGER.error("Unable to find actual Biome for " + biomeID);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.structures.isEmpty()) {
|
if (!this.structureTags.isEmpty()) {
|
||||||
//TODO: 1.18.2 This need to be done by BiomeTags now
|
//TODO: 1.18.2 This need to be done by BiomeTags now
|
||||||
structures.forEach(s -> BiomeAPI.addBiomeStructure(BiomeAPI.getBiomeKey(actualBiome), s));
|
structureTags.forEach(tagKey -> {System.out.println("Code to add Tags to Biomes should go here. " + tagKey);});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.surfaceInit != null) {
|
if (this.surfaceInit != null) {
|
||||||
surfaceInit.accept(actualBiome);
|
surfaceInit.accept(actualBiome);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getter for custom data. Will get custom data object or null if object doesn't exists.
|
* Getter for custom data. Will get custom data object or null if object doesn't exists.
|
||||||
|
@ -283,8 +286,8 @@ public class BCLBiome extends BCLBiomeSettings {
|
||||||
* Adds structures to this biome. For internal use only.
|
* Adds structures to this biome. For internal use only.
|
||||||
* Used inside {@link ru.bclib.api.biomes.BCLBiomeBuilder}.
|
* Used inside {@link ru.bclib.api.biomes.BCLBiomeBuilder}.
|
||||||
*/
|
*/
|
||||||
public void attachStructures(List<ConfiguredStructureFeature> structures) {
|
public void attachStructures(List<TagKey<Biome>> structures) {
|
||||||
this.structures.addAll(structures);
|
this.structureTags.addAll(structures);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -303,13 +306,13 @@ public class BCLBiome extends BCLBiomeSettings {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<Decoration, List<Supplier<PlacedFeature>>> features = new HashMap<>(0);
|
private Map<Decoration, List<Holder<PlacedFeature>>> features = Maps.newHashMap();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the biome features.
|
* Sets the biome features.
|
||||||
* @param features the feature list.
|
* @param features the feature list.
|
||||||
*/
|
*/
|
||||||
public void setFeatures(Map<Decoration, List<Supplier<PlacedFeature>>> features) {
|
public void setFeatures(Map<Decoration, List<Holder<PlacedFeature>>> features) {
|
||||||
this.features = features;
|
this.features = features;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,7 +320,7 @@ public class BCLBiome extends BCLBiomeSettings {
|
||||||
* Returns the built-in set of Features for this biome (as they were set with {@link #setFeatures(Map)})
|
* Returns the built-in set of Features for this biome (as they were set with {@link #setFeatures(Map)})
|
||||||
* @return List of all features
|
* @return List of all features
|
||||||
*/
|
*/
|
||||||
public Map<Decoration, List<Supplier<PlacedFeature>>> getFeatures(){
|
public Map<Decoration, List<Holder<PlacedFeature>>> getFeatures(){
|
||||||
return features;
|
return features;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,25 +3,35 @@ package ru.bclib.world.features;
|
||||||
import net.minecraft.core.Holder;
|
import net.minecraft.core.Holder;
|
||||||
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.features.FeatureUtils;
|
||||||
|
import net.minecraft.data.worldgen.placement.PlacementUtils;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
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.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.FeatureConfiguration;
|
||||||
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 java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class BCLFeature {
|
public class BCLFeature {
|
||||||
private Holder<PlacedFeature> placedFeature;
|
private final Holder<PlacedFeature> placedFeature;
|
||||||
private Decoration featureStep;
|
private final Decoration featureStep;
|
||||||
private Feature<?> feature;
|
private final Feature<?> feature;
|
||||||
|
|
||||||
|
|
||||||
|
public<FC extends FeatureConfiguration, F extends Feature<FC>> BCLFeature(ResourceLocation id, F feature, Decoration featureStep, FC configuration, PlacementModifier[] modifiers) {
|
||||||
|
this(id, feature, featureStep, buildPlacedFeature(id, feature, configuration, modifiers));
|
||||||
|
}
|
||||||
|
|
||||||
public BCLFeature(ResourceLocation id, Feature<?> feature, Decoration featureStep, Holder<PlacedFeature> placedFeature) {
|
public BCLFeature(ResourceLocation id, Feature<?> feature, Decoration featureStep, Holder<PlacedFeature> placedFeature) {
|
||||||
this.placedFeature = placedFeature;
|
this.placedFeature = placedFeature;
|
||||||
this.featureStep = featureStep;
|
this.featureStep = featureStep;
|
||||||
this.feature = feature;
|
this.feature = feature;
|
||||||
|
|
||||||
if (!BuiltinRegistries.PLACED_FEATURE.containsKey(id)) {
|
if (!BuiltinRegistries.PLACED_FEATURE.containsKey(id)) {
|
||||||
Registry.register(BuiltinRegistries.PLACED_FEATURE, id, placedFeature.value());
|
Registry.register(BuiltinRegistries.PLACED_FEATURE, id, placedFeature.value());
|
||||||
}
|
}
|
||||||
|
@ -29,6 +39,22 @@ public class BCLFeature {
|
||||||
Registry.register(Registry.FEATURE, id, feature);
|
Registry.register(Registry.FEATURE, id, feature);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static <FC extends FeatureConfiguration, F extends Feature<FC>> Holder<PlacedFeature> buildPlacedFeature(ResourceLocation id, F feature, FC configuration, PlacementModifier[] modifiers) {
|
||||||
|
Holder<ConfiguredFeature<?, ?>> configuredFeature;
|
||||||
|
//TODO: 1.18.2 Check if this cast is working
|
||||||
|
if (!BuiltinRegistries.CONFIGURED_FEATURE.containsKey(id)) {
|
||||||
|
configuredFeature = (Holder<ConfiguredFeature<?, ?>>)(Object)FeatureUtils.register(id.toString(), feature, configuration);
|
||||||
|
} else {
|
||||||
|
configuredFeature = BuiltinRegistries.CONFIGURED_FEATURE.getHolder(ResourceKey.create(BuiltinRegistries.CONFIGURED_FEATURE.key(), id)).orElseThrow();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!BuiltinRegistries.PLACED_FEATURE.containsKey(id)) {
|
||||||
|
return PlacementUtils.register(id.toString(), configuredFeature, modifiers);
|
||||||
|
} else {
|
||||||
|
return BuiltinRegistries.PLACED_FEATURE.getHolder(ResourceKey.create(BuiltinRegistries.PLACED_FEATURE.key(), id)).orElseThrow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static <E> boolean containsObj(Registry<E> registry, E obj) {
|
private static <E> boolean containsObj(Registry<E> registry, E obj) {
|
||||||
Optional<Entry<ResourceKey<E>, E>> optional = registry
|
Optional<Entry<ResourceKey<E>, E>> optional = registry
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue