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;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.particles.ParticleOptions;
|
||||
import net.minecraft.data.BuiltinRegistries;
|
||||
import net.minecraft.data.worldgen.BiomeDefaultFeatures;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.Music;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
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.structures.BCLStructureFeature;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class BCLBiomeBuilder {
|
||||
|
@ -61,7 +58,7 @@ public class BCLBiomeBuilder {
|
|||
private static final BCLBiomeBuilder INSTANCE = new BCLBiomeBuilder();
|
||||
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 BiomeSpecialEffects.Builder effectsBuilder;
|
||||
private MobSpawnSettings.Builder spawnSettings;
|
||||
|
@ -91,7 +88,7 @@ public class BCLBiomeBuilder {
|
|||
INSTANCE.generationSettings = null;
|
||||
INSTANCE.effectsBuilder = null;
|
||||
INSTANCE.spawnSettings = null;
|
||||
INSTANCE.structures.clear();
|
||||
INSTANCE.structureTags.clear();
|
||||
INSTANCE.temperature = 1.0F;
|
||||
INSTANCE.fogDensity = 1.0F;
|
||||
INSTANCE.edgeSize = 0;
|
||||
|
@ -546,11 +543,11 @@ public class BCLBiomeBuilder {
|
|||
|
||||
/**
|
||||
* Adds new structure feature into the biome.
|
||||
* @param structure {@link ConfiguredStructureFeature} to add.
|
||||
* @param structureTag {@link TagKey} to add.
|
||||
* @return same {@link BCLBiomeBuilder} instance.
|
||||
*/
|
||||
public BCLBiomeBuilder structure(Holder<ConfiguredStructureFeature<?, ?>> structure) {
|
||||
structures.add(structure.value());
|
||||
public BCLBiomeBuilder structure(TagKey<Biome> structureTag) {
|
||||
structureTags.add(structureTag);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -561,7 +558,7 @@ public class BCLBiomeBuilder {
|
|||
*/
|
||||
public BCLBiomeBuilder structure(BCLStructureFeature structure) {
|
||||
structure.addInternalBiome(biomeID);
|
||||
return structure(structure.getFeatureConfigured());
|
||||
return structure(structure.biomeTag);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -675,23 +672,22 @@ public class BCLBiomeBuilder {
|
|||
builder.mobSpawnSettings(getSpawns().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());
|
||||
if (acc != null) {
|
||||
builder.generationSettings(new BiomeGenerationSettings.Builder().build());
|
||||
var decorations = acc.bclib_getFeatures();
|
||||
List<HolderSet<PlacedFeature>> decorations = acc.bclib_getFeatures();
|
||||
for (Decoration d : Decoration.values()) {
|
||||
int i = d.ordinal();
|
||||
if (i >= 0 && i < decorations.size()) {
|
||||
var features = decorations.get(i);
|
||||
if (i>=0 && i<decorations.size()) {
|
||||
HolderSet<PlacedFeature> features = decorations.get(i);
|
||||
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());
|
||||
}
|
||||
|
||||
|
@ -706,7 +702,7 @@ public class BCLBiomeBuilder {
|
|||
|
||||
final Biome biome = builder.build();
|
||||
final T res = biomeConstructor.apply(biomeID, biome, settings);
|
||||
res.attachStructures(structures);
|
||||
res.attachStructures(structureTags);
|
||||
res.setSurface(surfaceRule);
|
||||
res.setFeatures(defferedFeatures);
|
||||
return res;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
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.Maps;
|
||||
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.feature.ConfiguredFeature;
|
||||
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.structure.StructureSet;
|
||||
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 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 Map<ResourceKey, List<BiConsumer<ResourceLocation, Holder<Biome>>>> MODIFICATIONS = Maps.newHashMap();
|
||||
|
@ -113,8 +116,7 @@ public class BiomeAPI {
|
|||
.map(Entry::getValue)
|
||||
.map(biome -> (BiomeGenerationSettingsAccessor) biome.getGenerationSettings())
|
||||
.map(BiomeGenerationSettingsAccessor::bclib_getFeatures)
|
||||
.forEach(stepFeatureSuppliers -> stepFeatureSuppliers.forEach(step -> step.forEach(featureSupplier -> {
|
||||
PlacedFeature feature = featureSupplier.value();
|
||||
.forEach(stepFeatureSuppliers -> stepFeatureSuppliers.forEach(step -> step.forEach(feature -> {
|
||||
FEATURE_ORDER.computeIfAbsent(feature, f -> FEATURE_ORDER_ID.getAndIncrement());
|
||||
})));
|
||||
}
|
||||
|
@ -427,7 +429,7 @@ public class BiomeAPI {
|
|||
|
||||
FabricBiomesData.END_VOID_BIOMES.forEach((key, weight) -> {
|
||||
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) {
|
||||
BiomeGenerationSettings settings = biome.value().getGenerationSettings();
|
||||
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();
|
||||
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);
|
||||
featureList.set(i, features);
|
||||
featureList.set(i, HolderSet.direct(features));
|
||||
}
|
||||
accessor.bclib_setFeatures(featureList);
|
||||
}
|
||||
|
@ -652,20 +654,24 @@ public class BiomeAPI {
|
|||
* Adds new features to existing biome.
|
||||
* @param biome {@link Biome} to add features in.
|
||||
* @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();
|
||||
List<HolderSet<PlacedFeature>> allFeatures = CollectionsUtil.getMutable(accessor.bclib_getFeatures());
|
||||
Set<PlacedFeature> set = CollectionsUtil.getMutable(accessor.bclib_getFeatureSet().get());
|
||||
HolderSet<PlacedFeature> features = getFeaturesList(allFeatures, step);
|
||||
for (var feature : featureList) {
|
||||
features.
|
||||
features.add(() -> feature);
|
||||
set.add(feature);
|
||||
List<Holder<PlacedFeature>> features = getFeaturesListCopy(allFeatures, step);
|
||||
|
||||
for (var feature : additionalFeatures) {
|
||||
if (!features.contains(feature))
|
||||
features.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_setFeatureSet(()-> set);
|
||||
accessor.bclib_setFeatureSet(featureSet);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -676,22 +682,10 @@ public class BiomeAPI {
|
|||
* @param biome {@link Biome} to add features in.
|
||||
* @param featureMap Map of {@link ConfiguredFeature} to add.
|
||||
*/
|
||||
private static void addStepFeaturesToBiome(Holder<Biome> biome, Map<Decoration, List<Supplier<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());
|
||||
|
||||
private static void addStepFeaturesToBiome(Holder<Biome> biome, Map<Decoration, List<Holder<PlacedFeature>>> featureMap) {
|
||||
for (Decoration step: featureMap.keySet()) {
|
||||
List<Supplier<PlacedFeature>> features = getFeaturesList(allFeatures, step);
|
||||
List<Supplier<PlacedFeature>> featureList = featureMap.get(step);
|
||||
|
||||
for (Supplier<PlacedFeature> feature : featureList) {
|
||||
features.add(feature);
|
||||
set.add(feature.get());
|
||||
}
|
||||
addBiomeFeature(biome, step, featureMap.get(step));
|
||||
}
|
||||
accessor.bclib_setFeatures(allFeatures);
|
||||
accessor.bclib_setFeatureSet(() -> set);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -700,13 +694,20 @@ public class BiomeAPI {
|
|||
* @param carver {@link ConfiguredWorldCarver} to add.
|
||||
* @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();
|
||||
Map<Carving, HolderSet<ConfiguredWorldCarver<?>>> carvers = CollectionsUtil.getMutable(accessor.bclib_getCarvers());
|
||||
HolderSet<ConfiguredWorldCarver<?>> carverList = CollectionsUtil.getMutable(carvers.getOrDefault(stage, new ArrayList<>()));
|
||||
carvers.put(stage, carverList);
|
||||
carverList.add(() -> carver);
|
||||
accessor.bclib_setCarvers(carvers);
|
||||
Map<Carving, HolderSet<ConfiguredWorldCarver<?>>> carverMap = CollectionsUtil.getMutable(accessor.bclib_getCarvers());
|
||||
HolderSet<ConfiguredWorldCarver<?>> carvers = carverMap.get(stage);
|
||||
|
||||
List<Holder<ConfiguredWorldCarver<?>>> carverList;
|
||||
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();
|
||||
|
||||
Set<PlacedFeature> featuresWithoutDuplicates = Sets.newHashSet();
|
||||
features.forEach(provider -> featuresWithoutDuplicates.add(provider.get()));
|
||||
Set<Holder<PlacedFeature>> featuresWithoutDuplicates = Sets.newHashSet();
|
||||
features.forEach(holder -> featuresWithoutDuplicates.add(holder));
|
||||
|
||||
if (featuresWithoutDuplicates.size() != features.size()) {
|
||||
features.clear();
|
||||
featuresWithoutDuplicates.forEach(feature -> features.add(() -> feature));
|
||||
featuresWithoutDuplicates.forEach(feature -> features.add(feature));
|
||||
}
|
||||
|
||||
features.forEach(provider -> {
|
||||
PlacedFeature feature = provider.get();
|
||||
features.forEach(feature -> {
|
||||
FEATURE_ORDER.computeIfAbsent(feature, f -> FEATURE_ORDER_ID.getAndIncrement());
|
||||
});
|
||||
|
||||
features.sort((f1, f2) -> {
|
||||
int v1 = FEATURE_ORDER.getOrDefault(f1.get(), 70000);
|
||||
int v2 = FEATURE_ORDER.getOrDefault(f2.get(), 70000);
|
||||
int v1 = FEATURE_ORDER.getOrDefault(f1, 70000);
|
||||
int v2 = FEATURE_ORDER.getOrDefault(f2, 70000);
|
||||
return Integer.compare(v1, v2);
|
||||
});
|
||||
}
|
||||
|
@ -907,13 +907,14 @@ public class BiomeAPI {
|
|||
return list;
|
||||
}
|
||||
|
||||
private static HolderSet<PlacedFeature> getFeaturesList(List<HolderSet<PlacedFeature>> features, Decoration step) {
|
||||
int index = step.ordinal();
|
||||
private static List<Holder<PlacedFeature>> getFeaturesListCopy(List<HolderSet<PlacedFeature>> features, Decoration step) {
|
||||
return getFeaturesListCopy(features, step.ordinal());
|
||||
}
|
||||
|
||||
private static List<Holder<PlacedFeature>> getFeaturesListCopy(List<HolderSet<PlacedFeature>> features, int index) {
|
||||
while (features.size() <= index) {
|
||||
features.add(HolderSet.direct(Lists.newArrayList()));
|
||||
}
|
||||
HolderSet<PlacedFeature> mutable = features.get(index);
|
||||
features.set(index, mutable);
|
||||
return mutable;
|
||||
return features.get(index).stream().collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import net.minecraft.data.worldgen.placement.PlacementUtils;
|
|||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.valueproviders.UniformInt;
|
||||
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.configurations.FeatureConfiguration;
|
||||
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.List;
|
||||
|
||||
public class BCLFeatureBuilder {
|
||||
public class BCLFeatureBuilder <FC extends FeatureConfiguration, F extends Feature<FC>>{
|
||||
private static final BCLFeatureBuilder INSTANCE = new BCLFeatureBuilder();
|
||||
private List<PlacementModifier> modifications = new ArrayList<>(16);
|
||||
private ResourceLocation featureID;
|
||||
private Decoration decoration;
|
||||
private Feature<?> feature;
|
||||
private F feature;
|
||||
|
||||
private BCLFeatureBuilder() {}
|
||||
|
||||
|
@ -134,10 +135,9 @@ public class BCLFeatureBuilder {
|
|||
* @param configuration any {@link FeatureConfiguration} for provided {@link Feature}.
|
||||
* @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()]);
|
||||
PlacedFeature configured = ((Feature<FC>) feature).configured(configuration).placed(modifiers);
|
||||
return new BCLFeature(featureID, feature, decoration, configured);
|
||||
return new BCLFeature(featureID, feature, decoration, configuration, modifiers);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -146,6 +146,6 @@ public class BCLFeatureBuilder {
|
|||
* @return created {@link BCLFeature} instance.
|
||||
*/
|
||||
public BCLFeature build() {
|
||||
return build(FeatureConfiguration.NONE);
|
||||
return build((FC)FeatureConfiguration.NONE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,6 +63,16 @@ public class TagAPI {
|
|||
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.
|
||||
*
|
||||
|
@ -74,6 +84,16 @@ public class TagAPI {
|
|||
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}.
|
||||
*
|
||||
|
@ -208,6 +228,7 @@ public class TagAPI {
|
|||
* @return The {@code tagsMap} Parameter.
|
||||
*/
|
||||
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;
|
||||
consumer = (id, ids) -> apply(tagsMap.computeIfAbsent(id, key -> Tag.Builder.tag()), ids);
|
||||
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.placement.PlacedFeature;
|
||||
import ru.bclib.BCLib;
|
||||
import ru.bclib.api.tag.TagAPI;
|
||||
import ru.bclib.world.features.BCLFeature;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
@ -66,8 +67,8 @@ public abstract class ModIntegration {
|
|||
public BCLFeature getFeature(String featureID, String placedFeatureID, GenerationStep.Decoration featureStep) {
|
||||
ResourceLocation id = getID(featureID);
|
||||
Feature<?> feature = Registry.FEATURE.get(id);
|
||||
Holder<PlacedFeature> featureConfigured = BuiltinRegistries.PLACED_FEATURE.getHolder(getFeatureKey(placedFeatureID)).orElse(null);
|
||||
return new BCLFeature(id, feature, featureStep, featureConfigured);
|
||||
Holder<PlacedFeature> featurePlaced = BuiltinRegistries.PLACED_FEATURE.getHolder(getFeatureKey(placedFeatureID)).orElse(null);
|
||||
return new BCLFeature(id, feature, featureStep, featurePlaced);
|
||||
}
|
||||
|
||||
public BCLFeature getFeature(String name, GenerationStep.Decoration featureStep) {
|
||||
|
@ -203,16 +204,11 @@ public abstract class ModIntegration {
|
|||
|
||||
public TagKey<Item> getItemTag(String name) {
|
||||
ResourceLocation id = getID(name);
|
||||
Tag<Item> tag = ItemTags.getAllTags().getTag(id);
|
||||
|
||||
//return tag == null ? (TagKey<Item>) TagRegistry.item(id) : (TagKey<Item>) tag;
|
||||
return tag == null ? (TagKey<Item>) TagFactory.ITEM.create(id) : (TagKey<Item>) tag;
|
||||
return TagAPI.makeItemTag(id);
|
||||
}
|
||||
|
||||
public TagKey<Block> getBlockTag(String name) {
|
||||
ResourceLocation id = getID(name);
|
||||
Tag<Block> tag = BlockTags.getAllTags().getTag(id);
|
||||
//return tag == null ? (Named<Block>) TagRegistry.block(id) : (Named<Block>) tag;
|
||||
return tag == null ? (TagKey<Block>) TagFactory.BLOCK.create(id) : (TagKey<Block>) tag;
|
||||
return TagAPI.makeBlockTag(id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.Carving;
|
||||
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 org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Mutable;
|
||||
|
@ -28,7 +29,13 @@ public interface BiomeGenerationSettingsAccessor {
|
|||
Supplier<Set<PlacedFeature>> bclib_getFeatureSet();
|
||||
|
||||
@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")
|
||||
Map<GenerationStep.Carving, HolderSet<ConfiguredWorldCarver<?>>> bclib_getCarvers();
|
||||
|
|
|
@ -27,7 +27,7 @@ public abstract class RecipeManagerMixin {
|
|||
}
|
||||
|
||||
@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();
|
||||
List<Recipe<C>> list = new ArrayList<>(values);
|
||||
list.sort((v1, v2) -> {
|
||||
|
@ -35,6 +35,6 @@ public abstract class RecipeManagerMixin {
|
|||
boolean b2 = v2.getId().getNamespace().equals("minecraft");
|
||||
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 net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.TagParser;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
|
@ -142,12 +144,13 @@ public class AnvilRecipe implements Recipe<Container>, UnknownReceipBookCategory
|
|||
|
||||
@Override
|
||||
public NonNullList<Ingredient> getIngredients() {
|
||||
;
|
||||
NonNullList<Ingredient> defaultedList = NonNullList.create();
|
||||
defaultedList.add(Ingredient.of(CommonItemTags.HAMMERS
|
||||
.getValues()
|
||||
.stream()
|
||||
.filter(hammer -> ((TieredItem) hammer).getTier().getLevel() >= toolLevel)
|
||||
.map(ItemStack::new)));
|
||||
defaultedList.add(Ingredient.of(Registry.ITEM.stream()
|
||||
.filter(item->item.builtInRegistryHolder().is(CommonItemTags.HAMMERS))
|
||||
.filter(hammer -> ((TieredItem) hammer).getTier().getLevel() >= toolLevel)
|
||||
.map(ItemStack::new))
|
||||
);
|
||||
defaultedList.add(input);
|
||||
return defaultedList;
|
||||
}
|
||||
|
|
|
@ -2,11 +2,13 @@ package ru.bclib.world.biomes;
|
|||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.data.BuiltinRegistries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.levelgen.GenerationStep.Decoration;
|
||||
import net.minecraft.world.level.levelgen.SurfaceRules;
|
||||
|
@ -18,15 +20,14 @@ import ru.bclib.BCLib;
|
|||
import ru.bclib.api.biomes.BiomeAPI;
|
||||
import ru.bclib.util.WeightedList;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
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 Map<String, Object> customData = Maps.newHashMap();
|
||||
private final ResourceLocation biomeID;
|
||||
|
@ -207,9 +208,9 @@ public class BCLBiome extends BCLBiomeSettings {
|
|||
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
|
||||
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) {
|
||||
|
@ -217,6 +218,8 @@ public class BCLBiome extends BCLBiomeSettings {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Getter for custom data. Will get custom data object or null if object doesn't exists.
|
||||
* @param name {@link String} name of data object.
|
||||
|
@ -283,8 +286,8 @@ public class BCLBiome extends BCLBiomeSettings {
|
|||
* Adds structures to this biome. For internal use only.
|
||||
* Used inside {@link ru.bclib.api.biomes.BCLBiomeBuilder}.
|
||||
*/
|
||||
public void attachStructures(List<ConfiguredStructureFeature> structures) {
|
||||
this.structures.addAll(structures);
|
||||
public void attachStructures(List<TagKey<Biome>> 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.
|
||||
* @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;
|
||||
}
|
||||
|
||||
|
@ -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)})
|
||||
* @return List of all features
|
||||
*/
|
||||
public Map<Decoration, List<Supplier<PlacedFeature>>> getFeatures(){
|
||||
public Map<Decoration, List<Holder<PlacedFeature>>> getFeatures(){
|
||||
return features;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,19 +3,29 @@ package ru.bclib.world.features;
|
|||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
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.ResourceLocation;
|
||||
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.configurations.FeatureConfiguration;
|
||||
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
||||
import net.minecraft.world.level.levelgen.placement.PlacementModifier;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
|
||||
public class BCLFeature {
|
||||
private Holder<PlacedFeature> placedFeature;
|
||||
private Decoration featureStep;
|
||||
private Feature<?> feature;
|
||||
private final Holder<PlacedFeature> placedFeature;
|
||||
private final Decoration featureStep;
|
||||
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) {
|
||||
this.placedFeature = placedFeature;
|
||||
|
@ -30,6 +40,22 @@ public class BCLFeature {
|
|||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
Optional<Entry<ResourceKey<E>, E>> optional = registry
|
||||
.entrySet()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue