Merge branch '1.18' of github.com-quiqueck:paulevsGitch/BCLib into 1.18
This commit is contained in:
commit
6b5348de88
3 changed files with 92 additions and 12 deletions
|
@ -40,9 +40,9 @@ import ru.bclib.config.Configs;
|
|||
import ru.bclib.mixin.common.BiomeGenerationSettingsAccessor;
|
||||
import ru.bclib.mixin.common.MobSpawnSettingsAccessor;
|
||||
import ru.bclib.mixin.common.StructureSettingsAccessor;
|
||||
import ru.bclib.util.CollectionsUtil;
|
||||
import ru.bclib.util.MHelper;
|
||||
import ru.bclib.world.biomes.BCLBiome;
|
||||
import ru.bclib.world.biomes.BCLBiomeDef;
|
||||
import ru.bclib.world.biomes.FabricBiomesData;
|
||||
import ru.bclib.world.features.BCLFeature;
|
||||
import ru.bclib.world.generator.BiomePicker;
|
||||
|
@ -425,7 +425,7 @@ public class BiomeAPI {
|
|||
Set<Biome> biomes = source.possibleBiomes();
|
||||
|
||||
biomes.forEach(biome -> {
|
||||
ResourceLocation biomeID = getBiomeID(biome);
|
||||
ResourceLocation biomeID = getBiomeID(biome);
|
||||
boolean modify = isDatapackBiome(biomeID);
|
||||
if (biome != BuiltinRegistries.BIOME.get(biomeID)) {
|
||||
modify = true;
|
||||
|
@ -459,13 +459,24 @@ public class BiomeAPI {
|
|||
* @param step a {@link Decoration} step for the feature.
|
||||
*/
|
||||
public static void addBiomeFeature(Biome biome, PlacedFeature feature, Decoration step) {
|
||||
// BiomeModificationContextImpl ctx = new BiomeModificationContextImpl(,,biome);
|
||||
// ctx.getGenerationSettings().addFeature(step, feature.);
|
||||
BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings();
|
||||
List<List<Supplier<PlacedFeature>>> biomeFeatures = getMutableList(accessor.bcl_getFeatures());
|
||||
List<Supplier<PlacedFeature>> list = getList(step, biomeFeatures);
|
||||
list.add(() -> feature);
|
||||
accessor.bcl_setFeatures(biomeFeatures);
|
||||
List<List<Supplier<PlacedFeature>>> allFeatures = CollectionsUtil.getMutable(accessor.bclib_getFeatures());
|
||||
Set<PlacedFeature> set = CollectionsUtil.getMutable(accessor.bclib_getFeatureSet());
|
||||
List<Supplier<PlacedFeature>> features = getFeaturesList(allFeatures, step);
|
||||
features.add(() -> feature);
|
||||
set.add(feature);
|
||||
accessor.bclib_setFeatures(allFeatures);
|
||||
accessor.bclib_setFeatureSet(set);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds new features to existing biome.
|
||||
* @param biomeID {@link ResourceLocation} of the {@link Biome} to add features in.
|
||||
* @param feature {@link ConfiguredFeature} to add.
|
||||
* @param step a {@link Decoration} step for the feature.
|
||||
*/
|
||||
private static void addBiomeFeature(ResourceLocation biomeID, PlacedFeature feature, Decoration step) {
|
||||
addBiomeFeature(BuiltinRegistries.BIOME.get(biomeID), feature, step);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -474,9 +485,16 @@ public class BiomeAPI {
|
|||
* @param features array of {@link BCLFeature} to add.
|
||||
*/
|
||||
public static void addBiomeFeatures(Biome biome, BCLFeature... features) {
|
||||
BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings();
|
||||
List<List<Supplier<PlacedFeature>>> allFeatures = CollectionsUtil.getMutable(accessor.bclib_getFeatures());
|
||||
Set<PlacedFeature> set = CollectionsUtil.getMutable(accessor.bclib_getFeatureSet());
|
||||
for (BCLFeature feature: features) {
|
||||
addBiomeFeature(biome, feature.getPlacedFeature(), feature.getDecoration());
|
||||
List<Supplier<PlacedFeature>> featureList = getFeaturesList(allFeatures, feature.getDecoration());
|
||||
featureList.add(() -> feature.getPlacedFeature());
|
||||
set.add(feature.getPlacedFeature());
|
||||
}
|
||||
accessor.bclib_setFeatures(allFeatures);
|
||||
accessor.bclib_setFeatureSet(set);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -603,6 +621,16 @@ public class BiomeAPI {
|
|||
return input;
|
||||
}
|
||||
|
||||
private static List<Supplier<PlacedFeature>> getFeaturesList(List<List<Supplier<PlacedFeature>>> features, Decoration step) {
|
||||
int index = step.ordinal();
|
||||
while (features.size() <= index) {
|
||||
features.add(Lists.newArrayList());
|
||||
}
|
||||
List<Supplier<PlacedFeature>> mutable = CollectionsUtil.getMutable(features.get(index));
|
||||
features.set(index, mutable);
|
||||
return mutable;
|
||||
}
|
||||
|
||||
private static <K extends Object, V extends Object> Map<K, V> getMutableMap(Map<K, V> input) {
|
||||
if (/*input instanceof ImmutableMap*/ !(input instanceof HashMap ||input instanceof EnumMap)) {
|
||||
return Maps.newHashMap(input);
|
||||
|
|
|
@ -7,15 +7,21 @@ import org.spongepowered.asm.mixin.Mutable;
|
|||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Mixin(BiomeGenerationSettings.class)
|
||||
public interface BiomeGenerationSettingsAccessor {
|
||||
@Accessor("features")
|
||||
List<List<Supplier<PlacedFeature>>> bcl_getFeatures();
|
||||
List<List<Supplier<PlacedFeature>>> bclib_getFeatures();
|
||||
|
||||
@Accessor("features")
|
||||
@Mutable
|
||||
void bcl_setFeatures(List<List<Supplier<PlacedFeature>>> value);
|
||||
}
|
||||
void bclib_setFeatures(List<List<Supplier<PlacedFeature>>> value);
|
||||
|
||||
@Accessor("featureSet")
|
||||
Set<PlacedFeature> bclib_getFeatureSet();
|
||||
|
||||
@Accessor("featureSet")
|
||||
void bclib_setFeatureSet(Set<PlacedFeature> features);
|
||||
}
|
||||
|
|
46
src/main/java/ru/bclib/util/CollectionsUtil.java
Normal file
46
src/main/java/ru/bclib/util/CollectionsUtil.java
Normal file
|
@ -0,0 +1,46 @@
|
|||
package ru.bclib.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class CollectionsUtil {
|
||||
/**
|
||||
* Will return mutable copy of list.
|
||||
* @param list {@link List} to make mutable.
|
||||
* @return {@link ArrayList} or original {@link List} if it is mutable.
|
||||
*/
|
||||
public static <E extends Object> List<E> getMutable(List<E> list) {
|
||||
if (list instanceof ArrayList) {
|
||||
return list;
|
||||
}
|
||||
return new ArrayList<>(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will return mutable copy of set.
|
||||
* @param set {@link Set} to make mutable.
|
||||
* @return {@link HashSet} or original {@link Set} if it is mutable.
|
||||
*/
|
||||
public static <E extends Object> Set<E> getMutable(Set<E> set) {
|
||||
if (set instanceof HashSet) {
|
||||
return set;
|
||||
}
|
||||
return new HashSet<>(set);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will return mutable copy of map.
|
||||
* @param map {@link Map} to make mutable.
|
||||
* @return {@link HashMap} or original {@link Map} if it is mutable.
|
||||
*/
|
||||
public static <K extends Object, V extends Object> Map<K, V> getMutable(Map<K, V> map) {
|
||||
if (map instanceof HashMap) {
|
||||
return map;
|
||||
}
|
||||
return new HashMap<>(map);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue