mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-21 19:55:00 +00:00
minor cleanup and improved safeguard for missing dimension types
This commit is contained in:
parent
2008975a8a
commit
6724b0f4c5
@ -63,6 +63,7 @@ import com.volmit.iris.util.scheduling.J;
|
||||
import com.volmit.iris.util.scheduling.Queue;
|
||||
import com.volmit.iris.util.scheduling.ShurikenQueue;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import lombok.NonNull;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.serializer.ComponentSerializer;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
@ -748,25 +749,11 @@ public class Iris extends VolmitPlugin implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
IrisDimension dim;
|
||||
if (id == null || id.isEmpty()) {
|
||||
dim = IrisData.loadAnyDimension(IrisSettings.get().getGenerator().getDefaultWorldType());
|
||||
} else {
|
||||
dim = IrisData.loadAnyDimension(id);
|
||||
}
|
||||
if (id == null || id.isEmpty()) id = IrisSettings.get().getGenerator().getDefaultWorldType();
|
||||
Iris.debug("Generator ID: " + id + " requested by bukkit/plugin");
|
||||
|
||||
IrisDimension dim = loadDimension(worldName, id);
|
||||
if (dim == null) {
|
||||
Iris.warn("Unable to find dimension type " + id + " Looking for online packs...");
|
||||
|
||||
service(StudioSVC.class).downloadSearch(new VolmitSender(Bukkit.getConsoleSender()), id, true);
|
||||
dim = IrisData.loadAnyDimension(id);
|
||||
|
||||
if (dim == null) {
|
||||
throw new RuntimeException("Can't find dimension " + id + "!");
|
||||
} else {
|
||||
Iris.info("Resolved missing dimension, proceeding with generation.");
|
||||
}
|
||||
throw new RuntimeException("Can't find dimension " + id + "!");
|
||||
}
|
||||
|
||||
Iris.debug("Assuming IrisDimension: " + dim.getName());
|
||||
@ -791,6 +778,24 @@ public class Iris extends VolmitPlugin implements Listener {
|
||||
return new BukkitChunkGenerator(w, false, ff, dim.getLoadKey());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static IrisDimension loadDimension(@NonNull String worldName, @NonNull String id) {
|
||||
var data = IrisData.get(new File(Bukkit.getWorldContainer(), String.join(File.separator, worldName, "iris", "pack")));
|
||||
var dimension = data.getDimensionLoader().load(id);
|
||||
if (dimension == null) dimension = IrisData.loadAnyDimension(id);
|
||||
if (dimension == null) {
|
||||
Iris.warn("Unable to find dimension type " + id + " Looking for online packs...");
|
||||
Iris.service(StudioSVC.class).downloadSearch(new VolmitSender(Bukkit.getConsoleSender()), id, true);
|
||||
dimension = IrisData.loadAnyDimension(id);
|
||||
|
||||
if (dimension != null) {
|
||||
Iris.info("Resolved missing dimension, proceeding.");
|
||||
}
|
||||
}
|
||||
|
||||
return dimension;
|
||||
}
|
||||
|
||||
public void splash() {
|
||||
if (!IrisSettings.get().getGeneral().isSplashLogoStartup()) {
|
||||
return;
|
||||
|
@ -21,6 +21,7 @@ package com.volmit.iris.core.nms;
|
||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||
import com.volmit.iris.core.nms.datapack.DataVersion;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.platform.PlatformChunkGenerator;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.mantle.Mantle;
|
||||
@ -89,9 +90,9 @@ public interface INMSBinding {
|
||||
MCABiomeContainer newBiomeContainer(int min, int max);
|
||||
|
||||
default World createWorld(WorldCreator c) {
|
||||
if (missingDimensionTypes(c.generator()))
|
||||
throw new IllegalStateException("Missing dimenstion types to create world");
|
||||
|
||||
if (c.generator() instanceof PlatformChunkGenerator gen
|
||||
&& missingDimensionTypes(gen.getTarget().getDimension().getDimensionTypeKey()))
|
||||
throw new IllegalStateException("Missing dimension types to create world");
|
||||
return c.createWorld();
|
||||
}
|
||||
|
||||
@ -127,7 +128,7 @@ public interface INMSBinding {
|
||||
|
||||
KList<String> getStructureKeys();
|
||||
|
||||
boolean missingDimensionTypes(@Nullable ChunkGenerator generator);
|
||||
boolean missingDimensionTypes(String... keys);
|
||||
|
||||
default boolean injectBukkit() {
|
||||
return true;
|
||||
|
@ -120,7 +120,12 @@ public class NMSBinding1X implements INMSBinding {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean missingDimensionTypes(@Nullable ChunkGenerator generator) {
|
||||
public KList<String> getLevelStems() {
|
||||
return new KList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean missingDimensionTypes(String... keys) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,15 @@
|
||||
package com.volmit.iris.core.safeguard;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.core.nms.v1X.NMSBinding1X;
|
||||
import com.volmit.iris.engine.object.IrisDimension;
|
||||
import com.volmit.iris.util.agent.Agent;
|
||||
import com.volmit.iris.util.collection.KSet;
|
||||
import com.volmit.iris.util.misc.ServerProperties;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import javax.tools.JavaCompiler;
|
||||
@ -184,6 +189,31 @@ public class ServerBootSFG {
|
||||
}
|
||||
|
||||
private static boolean missingDimensionTypes() {
|
||||
return INMS.get().missingDimensionTypes(null);
|
||||
return INMS.get().missingDimensionTypes(getDimensionTypes().toArray(String[]::new));
|
||||
}
|
||||
|
||||
private static KSet<String> getDimensionTypes() {
|
||||
var bukkit = YamlConfiguration.loadConfiguration(ServerProperties.BUKKIT_YML);
|
||||
var worlds = bukkit.getConfigurationSection("worlds");
|
||||
if (worlds == null) return new KSet<>();
|
||||
|
||||
var types = new KSet<String>();
|
||||
for (String world : worlds.getKeys(false)) {
|
||||
var gen = worlds.getString(world + ".generator");
|
||||
if (gen == null) continue;
|
||||
|
||||
String loadKey;
|
||||
if (gen.equalsIgnoreCase("iris")) {
|
||||
loadKey = IrisSettings.get().getGenerator().getDefaultWorldType();
|
||||
} else if (gen.startsWith("Iris:")) {
|
||||
loadKey = gen.substring(5);
|
||||
} else continue;
|
||||
|
||||
IrisDimension dimension = Iris.loadDimension(world, loadKey);
|
||||
if (dimension == null) continue;
|
||||
types.add(dimension.getDimensionTypeKey());
|
||||
}
|
||||
|
||||
return types;
|
||||
}
|
||||
}
|
||||
|
@ -97,7 +97,6 @@ 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 KMap<World.Environment, LevelStem> stems = new KMap<>();
|
||||
private final AtomicCache<Method> byIdRef = new AtomicCache<>();
|
||||
private Field biomeStorageCache = null;
|
||||
|
||||
@ -643,16 +642,11 @@ public class NMSBinding implements INMSBinding {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean missingDimensionTypes(ChunkGenerator generator) {
|
||||
if (generator == null)
|
||||
return registry().registryOrThrow(Registries.DIMENSION_TYPE)
|
||||
.keySet()
|
||||
.stream()
|
||||
.noneMatch(loc -> loc.getNamespace().equals("iris"));
|
||||
if (!(generator instanceof PlatformChunkGenerator pcg))
|
||||
return false;
|
||||
var dimensionKey = new ResourceLocation("iris", pcg.getTarget().getDimension().getDimensionTypeKey());
|
||||
return !registry().registryOrThrow(Registries.DIMENSION_TYPE).containsKey(dimensionKey);
|
||||
public boolean missingDimensionTypes(String... keys) {
|
||||
var type = registry().registryOrThrow(Registries.DIMENSION_TYPE);
|
||||
return !Arrays.stream(keys)
|
||||
.map(key -> new ResourceLocation("iris", key))
|
||||
.allMatch(type::containsKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -96,7 +96,6 @@ 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 KMap<World.Environment, LevelStem> stems = new KMap<>();
|
||||
private final AtomicCache<Method> byIdRef = new AtomicCache<>();
|
||||
private Field biomeStorageCache = null;
|
||||
|
||||
@ -625,16 +624,11 @@ public class NMSBinding implements INMSBinding {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean missingDimensionTypes(ChunkGenerator generator) {
|
||||
if (generator == null)
|
||||
return registry().registryOrThrow(Registries.DIMENSION_TYPE)
|
||||
.keySet()
|
||||
.stream()
|
||||
.noneMatch(loc -> loc.getNamespace().equals("iris"));
|
||||
if (!(generator instanceof PlatformChunkGenerator pcg))
|
||||
return false;
|
||||
var dimensionKey = new ResourceLocation("iris", pcg.getTarget().getDimension().getDimensionTypeKey());
|
||||
return !registry().registryOrThrow(Registries.DIMENSION_TYPE).containsKey(dimensionKey);
|
||||
public boolean missingDimensionTypes(String... keys) {
|
||||
var type = registry().registryOrThrow(Registries.DIMENSION_TYPE);
|
||||
return !Arrays.stream(keys)
|
||||
.map(key -> new ResourceLocation("iris", key))
|
||||
.allMatch(type::containsKey);
|
||||
}
|
||||
|
||||
private static Field getField(Class<?> clazz, Class<?> fieldType) throws NoSuchFieldException {
|
||||
|
@ -96,7 +96,6 @@ 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 KMap<World.Environment, LevelStem> stems = new KMap<>();
|
||||
private final AtomicCache<Method> byIdRef = new AtomicCache<>();
|
||||
private Field biomeStorageCache = null;
|
||||
|
||||
@ -647,16 +646,11 @@ public class NMSBinding implements INMSBinding {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean missingDimensionTypes(ChunkGenerator generator) {
|
||||
if (generator == null)
|
||||
return registry().registryOrThrow(Registries.DIMENSION_TYPE)
|
||||
.keySet()
|
||||
.stream()
|
||||
.noneMatch(loc -> loc.getNamespace().equals("iris"));
|
||||
if (!(generator instanceof PlatformChunkGenerator pcg))
|
||||
return false;
|
||||
var dimensionKey = new ResourceLocation("iris", pcg.getTarget().getDimension().getDimensionTypeKey());
|
||||
return !registry().registryOrThrow(Registries.DIMENSION_TYPE).containsKey(dimensionKey);
|
||||
public boolean missingDimensionTypes(String... keys) {
|
||||
var type = registry().registryOrThrow(Registries.DIMENSION_TYPE);
|
||||
return !Arrays.stream(keys)
|
||||
.map(key -> new ResourceLocation("iris", key))
|
||||
.allMatch(type::containsKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -97,7 +97,6 @@ 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 KMap<World.Environment, LevelStem> stems = new KMap<>();
|
||||
private final AtomicCache<Method> byIdRef = new AtomicCache<>();
|
||||
private Field biomeStorageCache = null;
|
||||
|
||||
@ -665,16 +664,11 @@ public class NMSBinding implements INMSBinding {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean missingDimensionTypes(ChunkGenerator generator) {
|
||||
if (generator == null)
|
||||
return registry().registryOrThrow(Registries.DIMENSION_TYPE)
|
||||
.keySet()
|
||||
.stream()
|
||||
.noneMatch(loc -> loc.getNamespace().equals("iris"));
|
||||
if (!(generator instanceof PlatformChunkGenerator pcg))
|
||||
return false;
|
||||
var dimensionKey = new ResourceLocation("iris", pcg.getTarget().getDimension().getDimensionTypeKey());
|
||||
return !registry().registryOrThrow(Registries.DIMENSION_TYPE).containsKey(dimensionKey);
|
||||
public boolean missingDimensionTypes(String... keys) {
|
||||
var type = registry().registryOrThrow(Registries.DIMENSION_TYPE);
|
||||
return !Arrays.stream(keys)
|
||||
.map(key -> new ResourceLocation("iris", key))
|
||||
.allMatch(type::containsKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -100,7 +100,6 @@ 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 KMap<World.Environment, LevelStem> stems = new KMap<>();
|
||||
private final AtomicCache<Method> byIdRef = new AtomicCache<>();
|
||||
private Field biomeStorageCache = null;
|
||||
|
||||
@ -675,16 +674,11 @@ public class NMSBinding implements INMSBinding {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean missingDimensionTypes(ChunkGenerator generator) {
|
||||
if (generator == null)
|
||||
return registry().registryOrThrow(Registries.DIMENSION_TYPE)
|
||||
.keySet()
|
||||
.stream()
|
||||
.noneMatch(loc -> loc.getNamespace().equals("iris"));
|
||||
if (!(generator instanceof PlatformChunkGenerator pcg))
|
||||
return false;
|
||||
var dimensionKey = ResourceLocation.fromNamespaceAndPath("iris", pcg.getTarget().getDimension().getDimensionTypeKey());
|
||||
return !registry().registryOrThrow(Registries.DIMENSION_TYPE).containsKey(dimensionKey);
|
||||
public boolean missingDimensionTypes(String... keys) {
|
||||
var type = registry().registryOrThrow(Registries.DIMENSION_TYPE);
|
||||
return !Arrays.stream(keys)
|
||||
.map(key -> ResourceLocation.fromNamespaceAndPath("iris", key))
|
||||
.allMatch(type::containsKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -97,7 +97,6 @@ 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 KMap<World.Environment, LevelStem> stems = new KMap<>();
|
||||
private final AtomicCache<Method> byIdRef = new AtomicCache<>();
|
||||
private Field biomeStorageCache = null;
|
||||
|
||||
@ -672,16 +671,11 @@ public class NMSBinding implements INMSBinding {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean missingDimensionTypes(ChunkGenerator generator) {
|
||||
if (generator == null)
|
||||
return registry().lookupOrThrow(Registries.DIMENSION_TYPE)
|
||||
.keySet()
|
||||
.stream()
|
||||
.noneMatch(loc -> loc.getNamespace().equals("iris"));
|
||||
if (!(generator instanceof PlatformChunkGenerator pcg))
|
||||
return false;
|
||||
var dimensionKey = ResourceLocation.fromNamespaceAndPath("iris", pcg.getTarget().getDimension().getDimensionTypeKey());
|
||||
return !registry().lookupOrThrow(Registries.DIMENSION_TYPE).containsKey(dimensionKey);
|
||||
public boolean missingDimensionTypes(String... keys) {
|
||||
var type = registry().lookupOrThrow(Registries.DIMENSION_TYPE);
|
||||
return !Arrays.stream(keys)
|
||||
.map(key -> ResourceLocation.fromNamespaceAndPath("iris", key))
|
||||
.allMatch(type::containsKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -11,6 +11,7 @@ import com.volmit.iris.engine.platform.PlatformChunkGenerator;
|
||||
import com.volmit.iris.util.agent.Agent;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.collection.KSet;
|
||||
import com.volmit.iris.util.format.C;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.json.JSONObject;
|
||||
@ -77,7 +78,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.Color;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -97,7 +97,6 @@ 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 KMap<World.Environment, LevelStem> stems = new KMap<>();
|
||||
private final AtomicCache<Method> byIdRef = new AtomicCache<>();
|
||||
private Field biomeStorageCache = null;
|
||||
|
||||
@ -672,16 +671,11 @@ public class NMSBinding implements INMSBinding {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean missingDimensionTypes(ChunkGenerator generator) {
|
||||
if (generator == null)
|
||||
return registry().lookupOrThrow(Registries.DIMENSION_TYPE)
|
||||
.keySet()
|
||||
.stream()
|
||||
.noneMatch(loc -> loc.getNamespace().equals("iris"));
|
||||
if (!(generator instanceof PlatformChunkGenerator pcg))
|
||||
return false;
|
||||
var dimensionKey = ResourceLocation.fromNamespaceAndPath("iris", pcg.getTarget().getDimension().getDimensionTypeKey());
|
||||
return !registry().lookupOrThrow(Registries.DIMENSION_TYPE).containsKey(dimensionKey);
|
||||
public boolean missingDimensionTypes(String... keys) {
|
||||
var type = registry().lookupOrThrow(Registries.DIMENSION_TYPE);
|
||||
return !Arrays.stream(keys)
|
||||
.map(key -> ResourceLocation.fromNamespaceAndPath("iris", key))
|
||||
.allMatch(type::containsKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -706,10 +700,6 @@ public class NMSBinding implements INMSBinding {
|
||||
return false;
|
||||
}
|
||||
|
||||
private ResourceLocation createIrisKey(ResourceKey<LevelStem> key) {
|
||||
return ResourceLocation.fromNamespaceAndPath("iris", key.location().getPath());
|
||||
}
|
||||
|
||||
public LevelStem levelStem(RegistryAccess access, ChunkGenerator raw) {
|
||||
if (!(raw instanceof PlatformChunkGenerator gen))
|
||||
throw new IllegalStateException("Generator is not platform chunk generator!");
|
||||
|
Loading…
x
Reference in New Issue
Block a user