mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-02-16 10:30:53 +00:00
implement biome replacements in all bindings
This commit is contained in:
@@ -127,10 +127,6 @@ public interface INMSBinding {
|
||||
|
||||
boolean registerBiome(String dimensionId, IrisBiomeCustom biome, boolean replace);
|
||||
|
||||
default boolean registerReplacement(String dimensionId, String key, Biome biome) {
|
||||
throw new IllegalStateException("Unsupported registerReplacement");
|
||||
}
|
||||
|
||||
boolean dumpRegistry(File... folders);
|
||||
|
||||
void injectBukkit();
|
||||
|
||||
@@ -36,9 +36,11 @@ import java.util.stream.Collectors;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||
import com.volmit.iris.engine.object.IrisBiomeReplacement;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import net.minecraft.nbt.*;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.server.commands.data.BlockDataAccessor;
|
||||
import com.volmit.iris.core.nms.container.IPackRepository;
|
||||
import com.volmit.iris.util.io.IO;
|
||||
@@ -133,6 +135,7 @@ public class NMSBinding implements INMSBinding {
|
||||
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||
private final AtomicCache<RegistryAccess> registryAccess = new AtomicCache<>();
|
||||
private final AtomicCache<RegistryOps<JsonElement>> registryOps = new AtomicCache<>();
|
||||
private final AtomicCache<Method> byIdRef = new AtomicCache<>();
|
||||
private Field biomeStorageCache = null;
|
||||
|
||||
@@ -318,6 +321,10 @@ public class NMSBinding implements INMSBinding {
|
||||
return registryAccess.aquire(() -> (RegistryAccess) getFor(RegistryAccess.Frozen.class, ((CraftServer) Bukkit.getServer()).getHandle().getServer()));
|
||||
}
|
||||
|
||||
private RegistryOps<JsonElement> registryOps() {
|
||||
return registryOps.aquire(() -> RegistryOps.create(JsonOps.INSTANCE, registry()));
|
||||
}
|
||||
|
||||
private Registry<net.minecraft.world.level.biome.Biome> getCustomBiomeRegistry() {
|
||||
return registry().registry(Registry.BIOME_REGISTRY).orElse(null);
|
||||
}
|
||||
@@ -654,17 +661,31 @@ public class NMSBinding implements INMSBinding {
|
||||
|
||||
@Override
|
||||
public boolean registerBiome(String dimensionId, IrisBiomeCustom biome, boolean replace) {
|
||||
if (biome instanceof IrisBiomeReplacement replacement)
|
||||
return registerReplacement(dimensionId, replacement.getId(), replacement.getBiome(), replace);
|
||||
var biomeBase = decode(net.minecraft.world.level.biome.Biome.CODEC, biome.generateJson()).map(Holder::value).orElse(null);
|
||||
if (biomeBase == null) return false;
|
||||
return register(Registry.BIOME_REGISTRY, new ResourceLocation(dimensionId, biome.getId()), biomeBase, replace);
|
||||
}
|
||||
|
||||
private boolean registerReplacement(String dimensionId, String key, Biome biome, boolean replace) {
|
||||
var registry = getCustomBiomeRegistry();
|
||||
var location = new ResourceLocation(dimensionId, key);
|
||||
if (registry.containsKey(location)) return false;
|
||||
|
||||
var base = registry.get(new ResourceLocation(biome.getKey().toString()));
|
||||
if (base == null) throw new IllegalArgumentException("Base biome not found: " + biome.getKey());
|
||||
var json = encode(net.minecraft.world.level.biome.Biome.NETWORK_CODEC, base);
|
||||
var clone = decode(net.minecraft.world.level.biome.Biome.NETWORK_CODEC, json.toString()).orElse(null);
|
||||
return register(Registry.BIOME_REGISTRY, location, clone, false);
|
||||
}
|
||||
|
||||
private <T> Optional<T> decode(Codec<T> codec, String json) {
|
||||
return codec.decode(JsonOps.INSTANCE, GsonHelper.parse(json)).get().left().map(Pair::getFirst);
|
||||
return codec.decode(registryOps(), GsonHelper.parse(json)).result().map(Pair::getFirst);
|
||||
}
|
||||
|
||||
private <T> Optional<JsonElement> encode(Codec<T> codec, T value) {
|
||||
return codec.encode(value, JsonOps.INSTANCE, new JsonObject()).result();
|
||||
return codec.encodeStart(registryOps(), value).result();
|
||||
}
|
||||
|
||||
private <T> boolean register(ResourceKey<Registry<T>> registryKey, ResourceLocation location, T value, boolean replace) {
|
||||
|
||||
@@ -38,13 +38,16 @@ import com.google.gson.JsonNull;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||
import com.volmit.iris.core.nms.container.IPackRepository;
|
||||
import com.volmit.iris.engine.object.IrisBiomeReplacement;
|
||||
import com.volmit.iris.util.io.IO;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import net.minecraft.nbt.*;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.server.commands.data.BlockDataAccessor;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.gson.JsonElement;
|
||||
@@ -135,6 +138,7 @@ public class NMSBinding implements INMSBinding {
|
||||
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||
private final AtomicCache<RegistryAccess> registryAccess = new AtomicCache<>();
|
||||
private final AtomicCache<RegistryOps<JsonElement>> registryOps = new AtomicCache<>();
|
||||
private final AtomicCache<Method> byIdRef = new AtomicCache<>();
|
||||
private Field biomeStorageCache = null;
|
||||
|
||||
@@ -320,6 +324,10 @@ public class NMSBinding implements INMSBinding {
|
||||
return registryAccess.aquire(() -> (RegistryAccess) getFor(RegistryAccess.Frozen.class, ((CraftServer) Bukkit.getServer()).getHandle().getServer()));
|
||||
}
|
||||
|
||||
private RegistryOps<JsonElement> registryOps() {
|
||||
return registryOps.aquire(() -> RegistryOps.create(JsonOps.INSTANCE, registry()));
|
||||
}
|
||||
|
||||
private Registry<net.minecraft.world.level.biome.Biome> getCustomBiomeRegistry() {
|
||||
return registry().registry(Registries.BIOME).orElse(null);
|
||||
}
|
||||
@@ -657,17 +665,31 @@ public class NMSBinding implements INMSBinding {
|
||||
|
||||
@Override
|
||||
public boolean registerBiome(String dimensionId, IrisBiomeCustom biome, boolean replace) {
|
||||
if (biome instanceof IrisBiomeReplacement replacement)
|
||||
return registerReplacement(dimensionId, replacement.getId(), replacement.getBiome(), replace);
|
||||
var biomeBase = decode(net.minecraft.world.level.biome.Biome.CODEC, biome.generateJson()).map(Holder::value).orElse(null);
|
||||
if (biomeBase == null) return false;
|
||||
return register(Registries.BIOME, new ResourceLocation(dimensionId, biome.getId()), biomeBase, replace);
|
||||
}
|
||||
|
||||
private boolean registerReplacement(String dimensionId, String key, Biome biome, boolean replace) {
|
||||
var registry = getCustomBiomeRegistry();
|
||||
var location = new ResourceLocation(dimensionId, key);
|
||||
if (registry.containsKey(location)) return false;
|
||||
|
||||
var base = registry.get(new ResourceLocation(biome.getKey().toString()));
|
||||
if (base == null) throw new IllegalArgumentException("Base biome not found: " + biome.getKey());
|
||||
var json = encode(net.minecraft.world.level.biome.Biome.NETWORK_CODEC, base);
|
||||
var clone = decode(net.minecraft.world.level.biome.Biome.NETWORK_CODEC, json.toString()).orElse(null);
|
||||
return register(Registries.BIOME, location, clone, false);
|
||||
}
|
||||
|
||||
private <T> Optional<T> decode(Codec<T> codec, String json) {
|
||||
return codec.decode(JsonOps.INSTANCE, GsonHelper.parse(json)).get().left().map(Pair::getFirst);
|
||||
return codec.decode(registryOps(), GsonHelper.parse(json)).result().map(Pair::getFirst);
|
||||
}
|
||||
|
||||
private <T> Optional<JsonElement> encode(Codec<T> codec, T value) {
|
||||
return codec.encode(value, JsonOps.INSTANCE, new JsonObject()).result();
|
||||
return codec.encodeStart(registryOps(), value).result();
|
||||
}
|
||||
|
||||
private <T> boolean register(ResourceKey<Registry<T>> registryKey, ResourceLocation location, T value, boolean replace) {
|
||||
|
||||
@@ -36,14 +36,18 @@ import java.util.stream.Collectors;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||
import com.volmit.iris.engine.object.IrisBiomeReplacement;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import net.minecraft.nbt.*;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.server.commands.data.BlockDataAccessor;
|
||||
import com.volmit.iris.core.nms.container.IPackRepository;
|
||||
import com.volmit.iris.util.io.IO;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.biome.BiomeGenerationSettings;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.gson.JsonElement;
|
||||
@@ -135,6 +139,7 @@ public class NMSBinding implements INMSBinding {
|
||||
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||
private final AtomicCache<RegistryAccess> registryAccess = new AtomicCache<>();
|
||||
private final AtomicCache<RegistryOps<JsonElement>> registryOps = new AtomicCache<>();
|
||||
private final AtomicCache<Method> byIdRef = new AtomicCache<>();
|
||||
private Field biomeStorageCache = null;
|
||||
|
||||
@@ -320,6 +325,10 @@ public class NMSBinding implements INMSBinding {
|
||||
return registryAccess.aquire(() -> (RegistryAccess) getFor(RegistryAccess.Frozen.class, ((CraftServer) Bukkit.getServer()).getHandle().getServer()));
|
||||
}
|
||||
|
||||
private RegistryOps<JsonElement> registryOps() {
|
||||
return registryOps.aquire(() -> RegistryOps.create(JsonOps.INSTANCE, registry()));
|
||||
}
|
||||
|
||||
private Registry<net.minecraft.world.level.biome.Biome> getCustomBiomeRegistry() {
|
||||
return registry().registry(Registries.BIOME).orElse(null);
|
||||
}
|
||||
@@ -666,17 +675,39 @@ public class NMSBinding implements INMSBinding {
|
||||
|
||||
@Override
|
||||
public boolean registerBiome(String dimensionId, IrisBiomeCustom biome, boolean replace) {
|
||||
if (biome instanceof IrisBiomeReplacement replacement)
|
||||
return registerReplacement(dimensionId, replacement.getId(), replacement.getBiome(), replace);
|
||||
var biomeBase = decode(net.minecraft.world.level.biome.Biome.CODEC, biome.generateJson()).map(Holder::value).orElse(null);
|
||||
if (biomeBase == null) return false;
|
||||
return register(Registries.BIOME, new ResourceLocation(dimensionId, biome.getId()), biomeBase, replace);
|
||||
}
|
||||
|
||||
private boolean registerReplacement(String dimensionId, String key, Biome biome, boolean replace) {
|
||||
var registry = getCustomBiomeRegistry();
|
||||
var location = new ResourceLocation(dimensionId, key);
|
||||
if (registry.containsKey(location)) return false;
|
||||
|
||||
var base = registry.get(new ResourceLocation(biome.getKey().toString()));
|
||||
if (base == null) throw new IllegalArgumentException("Base biome not found: " + biome.getKey());
|
||||
var clone = new net.minecraft.world.level.biome.Biome.BiomeBuilder()
|
||||
.hasPrecipitation(base.climateSettings.hasPrecipitation())
|
||||
.temperature(base.climateSettings.temperature())
|
||||
.temperatureAdjustment(base.climateSettings.temperatureModifier())
|
||||
.downfall(base.climateSettings.downfall())
|
||||
.generationSettings(BiomeGenerationSettings.EMPTY)
|
||||
.mobSpawnSettings(MobSpawnSettings.EMPTY)
|
||||
.specialEffects(base.getSpecialEffects())
|
||||
.build();
|
||||
|
||||
return register(Registries.BIOME, location, clone, false);
|
||||
}
|
||||
|
||||
private <T> Optional<T> decode(Codec<T> codec, String json) {
|
||||
return codec.decode(JsonOps.INSTANCE, GsonHelper.parse(json)).get().left().map(Pair::getFirst);
|
||||
return codec.decode(registryOps(), GsonHelper.parse(json)).result().map(Pair::getFirst);
|
||||
}
|
||||
|
||||
private <T> Optional<JsonElement> encode(Codec<T> codec, T value) {
|
||||
return codec.encode(value, JsonOps.INSTANCE, new JsonObject()).result();
|
||||
return codec.encodeStart(registryOps(), value).result();
|
||||
}
|
||||
|
||||
private <T> boolean register(ResourceKey<Registry<T>> registryKey, ResourceLocation location, T value, boolean replace) {
|
||||
|
||||
@@ -35,6 +35,7 @@ import com.volmit.iris.core.nms.container.IPackRepository;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.object.IrisBiomeCustom;
|
||||
import com.volmit.iris.engine.object.IrisBiomeReplacement;
|
||||
import com.volmit.iris.engine.object.IrisDimension;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
@@ -64,6 +65,7 @@ import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.nbt.*;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
@@ -76,7 +78,9 @@ import net.minecraft.server.level.progress.ChunkProgressListener;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.RandomSequences;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.biome.BiomeGenerationSettings;
|
||||
import net.minecraft.world.level.biome.BiomeSource;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
@@ -137,6 +141,7 @@ public class NMSBinding implements INMSBinding {
|
||||
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||
private final AtomicCache<RegistryAccess> registryAccess = new AtomicCache<>();
|
||||
private final AtomicCache<RegistryOps<JsonElement>> registryOps = new AtomicCache<>();
|
||||
private final AtomicCache<Method> byIdRef = new AtomicCache<>();
|
||||
private Field biomeStorageCache = null;
|
||||
|
||||
@@ -322,6 +327,10 @@ public class NMSBinding implements INMSBinding {
|
||||
return registryAccess.aquire(() -> (RegistryAccess) getFor(RegistryAccess.Frozen.class, ((CraftServer) Bukkit.getServer()).getHandle().getServer()));
|
||||
}
|
||||
|
||||
private RegistryOps<JsonElement> registryOps() {
|
||||
return registryOps.aquire(() -> RegistryOps.create(JsonOps.INSTANCE, registry()));
|
||||
}
|
||||
|
||||
private Registry<net.minecraft.world.level.biome.Biome> getCustomBiomeRegistry() {
|
||||
return registry().registry(Registries.BIOME).orElse(null);
|
||||
}
|
||||
@@ -653,17 +662,39 @@ public class NMSBinding implements INMSBinding {
|
||||
|
||||
@Override
|
||||
public boolean registerBiome(String dimensionId, IrisBiomeCustom biome, boolean replace) {
|
||||
if (biome instanceof IrisBiomeReplacement replacement)
|
||||
return registerReplacement(dimensionId, replacement.getId(), replacement.getBiome(), replace);
|
||||
var biomeBase = decode(net.minecraft.world.level.biome.Biome.CODEC, biome.generateJson()).map(Holder::value).orElse(null);
|
||||
if (biomeBase == null) return false;
|
||||
return register(Registries.BIOME, new ResourceLocation(dimensionId, biome.getId()), biomeBase, replace);
|
||||
}
|
||||
|
||||
private boolean registerReplacement(String dimensionId, String key, Biome biome, boolean replace) {
|
||||
var registry = getCustomBiomeRegistry();
|
||||
var location = new ResourceLocation(dimensionId, key);
|
||||
if (registry.containsKey(location)) return false;
|
||||
|
||||
var base = registry.get(new ResourceLocation(biome.getKey().toString()));
|
||||
if (base == null) throw new IllegalArgumentException("Base biome not found: " + biome.getKey());
|
||||
var clone = new net.minecraft.world.level.biome.Biome.BiomeBuilder()
|
||||
.hasPrecipitation(base.climateSettings.hasPrecipitation())
|
||||
.temperature(base.climateSettings.temperature())
|
||||
.temperatureAdjustment(base.climateSettings.temperatureModifier())
|
||||
.downfall(base.climateSettings.downfall())
|
||||
.generationSettings(BiomeGenerationSettings.EMPTY)
|
||||
.mobSpawnSettings(MobSpawnSettings.EMPTY)
|
||||
.specialEffects(base.getSpecialEffects())
|
||||
.build();
|
||||
|
||||
return register(Registries.BIOME, location, clone, false);
|
||||
}
|
||||
|
||||
private <T> Optional<T> decode(Codec<T> codec, String json) {
|
||||
return codec.decode(JsonOps.INSTANCE, GsonHelper.parse(json)).get().left().map(Pair::getFirst);
|
||||
return codec.decode(registryOps(), GsonHelper.parse(json)).result().map(Pair::getFirst);
|
||||
}
|
||||
|
||||
private <T> Optional<JsonElement> encode(Codec<T> codec, T value) {
|
||||
return codec.encode(value, JsonOps.INSTANCE, new JsonObject()).result();
|
||||
return codec.encodeStart(registryOps(), value).result();
|
||||
}
|
||||
|
||||
private <T> boolean register(ResourceKey<Registry<T>> registryKey, ResourceLocation location, T value, boolean replace) {
|
||||
|
||||
@@ -36,9 +36,11 @@ import java.util.stream.Collectors;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||
import com.volmit.iris.engine.object.IrisBiomeReplacement;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import net.minecraft.nbt.*;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.server.commands.data.BlockDataAccessor;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import com.volmit.iris.core.nms.container.IPackRepository;
|
||||
@@ -66,6 +68,8 @@ import net.minecraft.server.level.progress.ChunkProgressListener;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.RandomSequences;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.biome.BiomeGenerationSettings;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import net.minecraft.world.level.storage.LevelStorageSource;
|
||||
@@ -138,6 +142,7 @@ public class NMSBinding implements INMSBinding {
|
||||
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||
private final AtomicCache<RegistryAccess> registryAccess = new AtomicCache<>();
|
||||
private final AtomicCache<RegistryOps<JsonElement>> registryOps = new AtomicCache<>();
|
||||
private final AtomicCache<Method> byIdRef = new AtomicCache<>();
|
||||
private Field biomeStorageCache = null;
|
||||
|
||||
@@ -323,6 +328,10 @@ public class NMSBinding implements INMSBinding {
|
||||
return registryAccess.aquire(() -> (RegistryAccess) getFor(RegistryAccess.Frozen.class, ((CraftServer) Bukkit.getServer()).getHandle().getServer()));
|
||||
}
|
||||
|
||||
private RegistryOps<JsonElement> registryOps() {
|
||||
return registryOps.aquire(() -> RegistryOps.create(JsonOps.INSTANCE, registry()));
|
||||
}
|
||||
|
||||
private Registry<net.minecraft.world.level.biome.Biome> getCustomBiomeRegistry() {
|
||||
return registry().registry(Registries.BIOME).orElse(null);
|
||||
}
|
||||
@@ -659,17 +668,39 @@ public class NMSBinding implements INMSBinding {
|
||||
|
||||
@Override
|
||||
public boolean registerBiome(String dimensionId, IrisBiomeCustom biome, boolean replace) {
|
||||
if (biome instanceof IrisBiomeReplacement replacement)
|
||||
return registerReplacement(dimensionId, replacement.getId(), replacement.getBiome(), replace);
|
||||
var biomeBase = decode(net.minecraft.world.level.biome.Biome.CODEC, biome.generateJson()).map(Holder::value).orElse(null);
|
||||
if (biomeBase == null) return false;
|
||||
return register(Registries.BIOME, new ResourceLocation(dimensionId, biome.getId()), biomeBase, replace);
|
||||
}
|
||||
|
||||
private boolean registerReplacement(String dimensionId, String key, Biome biome, boolean replace) {
|
||||
var registry = getCustomBiomeRegistry();
|
||||
var location = new ResourceLocation(dimensionId, key);
|
||||
if (registry.containsKey(location)) return false;
|
||||
|
||||
var base = registry.get(new ResourceLocation(biome.getKey().toString()));
|
||||
if (base == null) throw new IllegalArgumentException("Base biome not found: " + biome.getKey());
|
||||
var clone = new net.minecraft.world.level.biome.Biome.BiomeBuilder()
|
||||
.hasPrecipitation(base.climateSettings.hasPrecipitation())
|
||||
.temperature(base.climateSettings.temperature())
|
||||
.temperatureAdjustment(base.climateSettings.temperatureModifier())
|
||||
.downfall(base.climateSettings.downfall())
|
||||
.generationSettings(BiomeGenerationSettings.EMPTY)
|
||||
.mobSpawnSettings(MobSpawnSettings.EMPTY)
|
||||
.specialEffects(base.getSpecialEffects())
|
||||
.build();
|
||||
|
||||
return register(Registries.BIOME, location, clone, false);
|
||||
}
|
||||
|
||||
private <T> Optional<T> decode(Codec<T> codec, String json) {
|
||||
return codec.decode(JsonOps.INSTANCE, GsonHelper.parse(json)).get().left().map(Pair::getFirst);
|
||||
return codec.decode(registryOps(), GsonHelper.parse(json)).result().map(Pair::getFirst);
|
||||
}
|
||||
|
||||
private <T> Optional<JsonElement> encode(Codec<T> codec, T value) {
|
||||
return codec.encode(value, JsonOps.INSTANCE, new JsonObject()).result();
|
||||
return codec.encodeStart(registryOps(), value).result();
|
||||
}
|
||||
|
||||
private <T> boolean register(ResourceKey<Registry<T>> registryKey, ResourceLocation location, T value, boolean replace) {
|
||||
|
||||
@@ -58,6 +58,7 @@ import net.bytebuddy.implementation.bytecode.member.MethodInvocation;
|
||||
import net.bytebuddy.matcher.ElementMatchers;
|
||||
import net.minecraft.core.IdMapper;
|
||||
import net.minecraft.core.MappedRegistry;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.progress.ChunkProgressListener;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
@@ -65,6 +66,7 @@ import net.minecraft.world.RandomSequences;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelHeightAccessor;
|
||||
import net.minecraft.world.level.biome.BiomeGenerationSettings;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
import net.minecraft.world.level.chunk.ProtoChunk;
|
||||
import net.minecraft.world.level.chunk.UpgradeData;
|
||||
@@ -149,6 +151,7 @@ public class NMSBinding implements INMSBinding {
|
||||
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||
private final AtomicCache<RegistryAccess> registryAccess = new AtomicCache<>();
|
||||
private final AtomicCache<RegistryOps<JsonElement>> registryOps = new AtomicCache<>();
|
||||
private final AtomicCache<Method> byIdRef = new AtomicCache<>();
|
||||
private Field biomeStorageCache = null;
|
||||
|
||||
@@ -334,6 +337,10 @@ public class NMSBinding implements INMSBinding {
|
||||
return registryAccess.aquire(() -> (RegistryAccess) getFor(RegistryAccess.Frozen.class, ((CraftServer) Bukkit.getServer()).getHandle().getServer()));
|
||||
}
|
||||
|
||||
private RegistryOps<JsonElement> registryOps() {
|
||||
return registryOps.aquire(() -> RegistryOps.create(JsonOps.INSTANCE, registry()));
|
||||
}
|
||||
|
||||
private Registry<net.minecraft.world.level.biome.Biome> getCustomBiomeRegistry() {
|
||||
return registry().registry(Registries.BIOME).orElse(null);
|
||||
}
|
||||
@@ -672,14 +679,13 @@ public class NMSBinding implements INMSBinding {
|
||||
@Override
|
||||
public boolean registerBiome(String dimensionId, IrisBiomeCustom biome, boolean replace) {
|
||||
if (biome instanceof IrisBiomeReplacement replacement)
|
||||
return registerReplacement(dimensionId, replacement.getId(), replacement.getBiome());
|
||||
return registerReplacement(dimensionId, replacement.getId(), replacement.getBiome(), replace);
|
||||
var biomeBase = decode(net.minecraft.world.level.biome.Biome.CODEC, biome.generateJson()).map(Holder::value).orElse(null);
|
||||
if (biomeBase == null) return false;
|
||||
return register(Registries.BIOME, new ResourceLocation(dimensionId, biome.getId()), biomeBase, replace);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean registerReplacement(String dimensionId, String key, Biome biome) {
|
||||
private boolean registerReplacement(String dimensionId, String key, Biome biome, boolean replace) {
|
||||
var registry = getCustomBiomeRegistry();
|
||||
var location = new ResourceLocation(dimensionId, key);
|
||||
if (registry.containsKey(location)) return false;
|
||||
@@ -691,20 +697,20 @@ public class NMSBinding implements INMSBinding {
|
||||
.temperature(base.climateSettings.temperature())
|
||||
.temperatureAdjustment(base.climateSettings.temperatureModifier())
|
||||
.downfall(base.climateSettings.downfall())
|
||||
.generationSettings(base.getGenerationSettings())
|
||||
.specialEffects(base.getSpecialEffects())
|
||||
.generationSettings(BiomeGenerationSettings.EMPTY)
|
||||
.mobSpawnSettings(MobSpawnSettings.EMPTY)
|
||||
.specialEffects(base.getSpecialEffects())
|
||||
.build();
|
||||
|
||||
return register(Registries.BIOME, location, clone, false);
|
||||
}
|
||||
|
||||
private <T> Optional<T> decode(Codec<T> codec, String json) {
|
||||
return codec.decode(JsonOps.INSTANCE, GsonHelper.parse(json)).get().left().map(Pair::getFirst);
|
||||
return codec.decode(registryOps(), GsonHelper.parse(json)).result().map(Pair::getFirst);
|
||||
}
|
||||
|
||||
private <T> Optional<JsonElement> encode(Codec<T> codec, T value) {
|
||||
return codec.encode(value, JsonOps.INSTANCE, new JsonObject()).result();
|
||||
return codec.encodeStart(registryOps(), value).result();
|
||||
}
|
||||
|
||||
private <T> boolean register(ResourceKey<Registry<T>> registryKey, ResourceLocation location, T value, boolean replace) {
|
||||
|
||||
@@ -45,6 +45,7 @@ import com.mojang.serialization.JsonOps;
|
||||
import com.volmit.iris.core.nms.container.IPackRepository;
|
||||
import com.volmit.iris.core.nms.datapack.DataVersion;
|
||||
import com.volmit.iris.engine.object.IrisBiomeCustom;
|
||||
import com.volmit.iris.engine.object.IrisBiomeReplacement;
|
||||
import com.volmit.iris.engine.object.IrisDimension;
|
||||
import com.volmit.iris.util.format.C;
|
||||
import com.volmit.iris.util.io.IO;
|
||||
@@ -60,6 +61,7 @@ import com.volmit.iris.util.scheduling.J;
|
||||
import net.minecraft.core.*;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.progress.ChunkProgressListener;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
@@ -81,6 +83,8 @@ import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.item.component.CustomData;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.biome.BiomeGenerationSettings;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.chunk.status.ChunkStatus;
|
||||
@@ -146,6 +150,7 @@ public class NMSBinding implements INMSBinding {
|
||||
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||
private final AtomicCache<RegistryAccess> registryAccess = new AtomicCache<>();
|
||||
private final AtomicCache<RegistryOps<JsonElement>> registryOps = new AtomicCache<>();
|
||||
private final AtomicCache<Method> byIdRef = new AtomicCache<>();
|
||||
private Field biomeStorageCache = null;
|
||||
|
||||
@@ -323,6 +328,10 @@ public class NMSBinding implements INMSBinding {
|
||||
return registryAccess.aquire(() -> (RegistryAccess) getFor(RegistryAccess.Frozen.class, ((CraftServer) Bukkit.getServer()).getHandle().getServer()));
|
||||
}
|
||||
|
||||
private RegistryOps<JsonElement> registryOps() {
|
||||
return registryOps.aquire(() -> RegistryOps.create(JsonOps.INSTANCE, registry()));
|
||||
}
|
||||
|
||||
private Registry<net.minecraft.world.level.biome.Biome> getCustomBiomeRegistry() {
|
||||
return registry().registry(Registries.BIOME).orElse(null);
|
||||
}
|
||||
@@ -708,17 +717,39 @@ public class NMSBinding implements INMSBinding {
|
||||
|
||||
@Override
|
||||
public boolean registerBiome(String dimensionId, IrisBiomeCustom biome, boolean replace) {
|
||||
if (biome instanceof IrisBiomeReplacement replacement)
|
||||
return registerReplacement(dimensionId, replacement.getId(), replacement.getBiome(), replace);
|
||||
var biomeBase = decode(net.minecraft.world.level.biome.Biome.CODEC, biome.generateJson()).map(Holder::value).orElse(null);
|
||||
if (biomeBase == null) return false;
|
||||
return register(Registries.BIOME, new ResourceLocation(dimensionId, biome.getId()), biomeBase, replace);
|
||||
}
|
||||
|
||||
private boolean registerReplacement(String dimensionId, String key, Biome biome, boolean replace) {
|
||||
var registry = getCustomBiomeRegistry();
|
||||
var location = new ResourceLocation(dimensionId, key);
|
||||
if (registry.containsKey(location)) return false;
|
||||
|
||||
var base = registry.get(new ResourceLocation(biome.getKey().toString()));
|
||||
if (base == null) throw new IllegalArgumentException("Base biome not found: " + biome.getKey());
|
||||
var clone = new net.minecraft.world.level.biome.Biome.BiomeBuilder()
|
||||
.hasPrecipitation(base.climateSettings.hasPrecipitation())
|
||||
.temperature(base.climateSettings.temperature())
|
||||
.temperatureAdjustment(base.climateSettings.temperatureModifier())
|
||||
.downfall(base.climateSettings.downfall())
|
||||
.generationSettings(BiomeGenerationSettings.EMPTY)
|
||||
.mobSpawnSettings(MobSpawnSettings.EMPTY)
|
||||
.specialEffects(base.getSpecialEffects())
|
||||
.build();
|
||||
|
||||
return register(Registries.BIOME, location, clone, false);
|
||||
}
|
||||
|
||||
private <T> Optional<T> decode(Codec<T> codec, String json) {
|
||||
return codec.decode(JsonOps.INSTANCE, GsonHelper.parse(json)).result().map(Pair::getFirst);
|
||||
return codec.decode(registryOps(), GsonHelper.parse(json)).result().map(Pair::getFirst);
|
||||
}
|
||||
|
||||
private <T> Optional<JsonElement> encode(Codec<T> codec, T value) {
|
||||
return codec.encode(value, JsonOps.INSTANCE, new JsonObject()).result();
|
||||
return codec.encodeStart(registryOps(), value).result();
|
||||
}
|
||||
|
||||
private <T> boolean register(ResourceKey<Registry<T>> registryKey, ResourceLocation location, T value, boolean replace) {
|
||||
|
||||
@@ -41,6 +41,7 @@ import com.volmit.iris.core.nms.container.BiomeColor;
|
||||
import com.volmit.iris.core.nms.container.IPackRepository;
|
||||
import com.volmit.iris.core.nms.datapack.DataVersion;
|
||||
import com.volmit.iris.engine.object.IrisBiomeCustom;
|
||||
import com.volmit.iris.engine.object.IrisBiomeReplacement;
|
||||
import com.volmit.iris.engine.object.IrisDimension;
|
||||
import com.volmit.iris.util.format.C;
|
||||
import com.volmit.iris.util.io.IO;
|
||||
@@ -55,6 +56,7 @@ import com.volmit.iris.util.scheduling.J;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.nbt.*;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.server.commands.data.BlockDataAccessor;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ChunkMap;
|
||||
@@ -65,6 +67,8 @@ import net.minecraft.world.RandomSequences;
|
||||
import net.minecraft.world.item.component.CustomData;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.biome.BiomeGenerationSettings;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.chunk.status.ChunkStatus;
|
||||
import net.minecraft.world.level.chunk.status.WorldGenContext;
|
||||
@@ -133,6 +137,7 @@ public class NMSBinding implements INMSBinding {
|
||||
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||
private final AtomicCache<RegistryAccess> registryAccess = new AtomicCache<>();
|
||||
private final AtomicCache<RegistryOps<JsonElement>> registryOps = new AtomicCache<>();
|
||||
private final AtomicCache<Method> byIdRef = new AtomicCache<>();
|
||||
private Field biomeStorageCache = null;
|
||||
|
||||
@@ -310,6 +315,10 @@ public class NMSBinding implements INMSBinding {
|
||||
return registryAccess.aquire(() -> (RegistryAccess) getFor(RegistryAccess.Frozen.class, ((CraftServer) Bukkit.getServer()).getHandle().getServer()));
|
||||
}
|
||||
|
||||
private RegistryOps<JsonElement> registryOps() {
|
||||
return registryOps.aquire(() -> RegistryOps.create(JsonOps.INSTANCE, registry()));
|
||||
}
|
||||
|
||||
private Registry<net.minecraft.world.level.biome.Biome> getCustomBiomeRegistry() {
|
||||
return registry().registry(Registries.BIOME).orElse(null);
|
||||
}
|
||||
@@ -703,17 +712,39 @@ public class NMSBinding implements INMSBinding {
|
||||
|
||||
@Override
|
||||
public boolean registerBiome(String dimensionId, IrisBiomeCustom biome, boolean replace) {
|
||||
if (biome instanceof IrisBiomeReplacement replacement)
|
||||
return registerReplacement(dimensionId, replacement.getId(), replacement.getBiome(), replace);
|
||||
var biomeBase = decode(net.minecraft.world.level.biome.Biome.CODEC, biome.generateJson()).map(Holder::value).orElse(null);
|
||||
if (biomeBase == null) return false;
|
||||
return register(Registries.BIOME, ResourceLocation.fromNamespaceAndPath(dimensionId, biome.getId()), biomeBase, replace);
|
||||
}
|
||||
|
||||
private boolean registerReplacement(String dimensionId, String key, Biome biome, boolean replace) {
|
||||
var registry = getCustomBiomeRegistry();
|
||||
var location = ResourceLocation.fromNamespaceAndPath(dimensionId, key);
|
||||
if (registry.containsKey(location)) return false;
|
||||
|
||||
var base = registry.get(ResourceLocation.parse(biome.getKey().toString()));
|
||||
if (base == null) throw new IllegalArgumentException("Base biome not found: " + biome.getKey());
|
||||
var clone = new net.minecraft.world.level.biome.Biome.BiomeBuilder()
|
||||
.hasPrecipitation(base.climateSettings.hasPrecipitation())
|
||||
.temperature(base.climateSettings.temperature())
|
||||
.temperatureAdjustment(base.climateSettings.temperatureModifier())
|
||||
.downfall(base.climateSettings.downfall())
|
||||
.generationSettings(BiomeGenerationSettings.EMPTY)
|
||||
.mobSpawnSettings(MobSpawnSettings.EMPTY)
|
||||
.specialEffects(base.getSpecialEffects())
|
||||
.build();
|
||||
|
||||
return register(Registries.BIOME, location, clone, false);
|
||||
}
|
||||
|
||||
private <T> Optional<T> decode(Codec<T> codec, String json) {
|
||||
return codec.decode(JsonOps.INSTANCE, GsonHelper.parse(json)).result().map(Pair::getFirst);
|
||||
return codec.decode(registryOps(), GsonHelper.parse(json)).result().map(Pair::getFirst);
|
||||
}
|
||||
|
||||
private <T> Optional<JsonElement> encode(Codec<T> codec, T value) {
|
||||
return codec.encode(value, JsonOps.INSTANCE, new JsonObject()).result();
|
||||
return codec.encodeStart(registryOps(), value).result();
|
||||
}
|
||||
|
||||
private <T> boolean register(ResourceKey<Registry<T>> registryKey, ResourceLocation location, T value, boolean replace) {
|
||||
|
||||
Reference in New Issue
Block a user