Immutable fix

This commit is contained in:
paulevsGitch 2021-11-28 17:10:59 +03:00
parent 32b7ca1608
commit 80df11526b

View file

@ -1,6 +1,7 @@
package ru.bclib.api; package ru.bclib.api;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
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;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
@ -497,7 +498,7 @@ public class BiomeAPI {
public static <M extends Mob> void addBiomeMobSpawn(Biome biome, EntityType<M> entityType, int weight, int minGroupCount, int maxGroupCount) { public static <M extends Mob> void addBiomeMobSpawn(Biome biome, EntityType<M> entityType, int weight, int minGroupCount, int maxGroupCount) {
MobCategory category = entityType.getCategory(); MobCategory category = entityType.getCategory();
SpawnSettingsAccessor accessor = (SpawnSettingsAccessor) biome.getMobSettings(); SpawnSettingsAccessor accessor = (SpawnSettingsAccessor) biome.getMobSettings();
Map<MobCategory, WeightedRandomList<SpawnerData>> spawners = accessor.fabric_getSpawners(); Map<MobCategory, WeightedRandomList<SpawnerData>> spawners = getMutableMap(accessor.fabric_getSpawners());
List<SpawnerData> mobs = spawners.containsKey(category) ? getMutableList(spawners.get(category).unwrap()) : Lists.newArrayList(); List<SpawnerData> mobs = spawners.containsKey(category) ? getMutableList(spawners.get(category).unwrap()) : Lists.newArrayList();
mobs.add(new SpawnerData(entityType, weight, minGroupCount, maxGroupCount)); mobs.add(new SpawnerData(entityType, weight, minGroupCount, maxGroupCount));
spawners.put(category, WeightedRandomList.create(mobs)); spawners.put(category, WeightedRandomList.create(mobs));
@ -510,4 +511,11 @@ public class BiomeAPI {
} }
return input; return input;
} }
private static <K extends Object, V extends Object> Map<K, V> getMutableMap(Map<K, V> input) {
if (input instanceof ImmutableMap) {
return Maps.newHashMap(input);
}
return input;
}
} }