implement complete world height isolation

This commit is contained in:
Julian Krings 2025-04-16 21:52:30 +02:00
parent 9c151abac7
commit 3415e7c7af
No known key found for this signature in database
GPG Key ID: 208C6E08C3B718D2
13 changed files with 322 additions and 266 deletions

View File

@ -26,7 +26,6 @@ import com.volmit.iris.core.nms.datapack.IDataFixer;
import com.volmit.iris.engine.object.IrisBiome; import com.volmit.iris.engine.object.IrisBiome;
import com.volmit.iris.engine.object.IrisBiomeCustom; import com.volmit.iris.engine.object.IrisBiomeCustom;
import com.volmit.iris.engine.object.IrisDimension; import com.volmit.iris.engine.object.IrisDimension;
import com.volmit.iris.engine.object.IrisRange;
import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.collection.KSet; import com.volmit.iris.util.collection.KSet;
@ -34,8 +33,8 @@ import com.volmit.iris.util.format.C;
import com.volmit.iris.util.misc.ServerProperties; import com.volmit.iris.util.misc.ServerProperties;
import com.volmit.iris.util.plugin.VolmitSender; import com.volmit.iris.util.plugin.VolmitSender;
import com.volmit.iris.util.scheduling.J; import com.volmit.iris.util.scheduling.J;
import lombok.Data;
import lombok.NonNull; import lombok.NonNull;
import lombok.SneakyThrows;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
@ -45,12 +44,12 @@ import org.jetbrains.annotations.Nullable;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicIntegerArray;
import java.util.stream.Stream; import java.util.stream.Stream;
import static com.volmit.iris.core.nms.datapack.IDataFixer.Dimension.*;
public class ServerConfigurator { public class ServerConfigurator {
public static void configure() { public static void configure() {
IrisSettings.IrisSettingsAutoconfiguration s = IrisSettings.get().getAutoConfiguration(); IrisSettings.IrisSettingsAutoconfiguration s = IrisSettings.get().getAutoConfiguration();
@ -112,14 +111,16 @@ public class ServerConfigurator {
KList<File> folders = getDatapacksFolder(); KList<File> folders = getDatapacksFolder();
KMap<String, KSet<String>> biomes = new KMap<>(); KMap<String, KSet<String>> biomes = new KMap<>();
allPacks().flatMap(height::merge) try (Stream<IrisData> stream = allPacks()) {
stream.flatMap(height::merge)
.parallel() .parallel()
.forEach(dim -> { .forEach(dim -> {
Iris.verbose(" Checking Dimension " + dim.getLoadFile().getPath()); Iris.verbose(" Checking Dimension " + dim.getLoadFile().getPath());
dim.installBiomes(fixer, dim::getLoader, folders, biomes.computeIfAbsent(dim.getLoadKey(), k -> new KSet<>())); dim.installBiomes(fixer, dim::getLoader, folders, biomes.computeIfAbsent(dim.getLoadKey(), k -> new KSet<>()));
dim.installDimensionType(fixer, folders);
}); });
}
IrisDimension.writeShared(folders, height); IrisDimension.writeShared(folders, height);
Iris.info("Data Packs Setup!"); Iris.info("Data Packs Setup!");
if (fullInstall) if (fullInstall)
@ -127,7 +128,8 @@ public class ServerConfigurator {
} }
private static void verifyDataPacksPost(boolean allowRestarting) { private static void verifyDataPacksPost(boolean allowRestarting) {
boolean bad = allPacks() try (Stream<IrisData> stream = allPacks()) {
boolean bad = stream
.map(data -> { .map(data -> {
Iris.verbose("Checking Pack: " + data.getDataFolder().getPath()); Iris.verbose("Checking Pack: " + data.getDataFolder().getPath());
var loader = data.getDimensionLoader(); var loader = data.getDimensionLoader();
@ -140,6 +142,7 @@ public class ServerConfigurator {
.toList() .toList()
.contains(true); .contains(true);
if (!bad) return; if (!bad) return;
}
if (allowRestarting) { if (allowRestarting) {
@ -239,20 +242,24 @@ public class ServerConfigurator {
return path.substring(worldContainer.length(), path.length() - l); return path.substring(worldContainer.length(), path.length() - l);
} }
@SneakyThrows
private static Stream<File> listFiles(File parent) { private static Stream<File> listFiles(File parent) {
var files = parent.listFiles(); if (!parent.isDirectory()) return Stream.empty();
return files == null ? Stream.empty() : Arrays.stream(files); return Files.walk(parent.toPath()).map(Path::toFile);
} }
@Data
public static class DimensionHeight { public static class DimensionHeight {
private final IDataFixer fixer; private final IDataFixer fixer;
private IrisRange overworld = new IrisRange(); private final AtomicIntegerArray[] dimensions = new AtomicIntegerArray[3];
private IrisRange nether = new IrisRange();
private IrisRange end = new IrisRange(); public DimensionHeight(IDataFixer fixer) {
private int logicalOverworld = 0; this.fixer = fixer;
private int logicalNether = 0; for (int i = 0; i < 3; i++) {
private int logicalEnd = 0; dimensions[i] = new AtomicIntegerArray(new int[]{
Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE
});
}
}
public Stream<IrisDimension> merge(IrisData data) { public Stream<IrisDimension> merge(IrisData data) {
Iris.verbose("Checking Pack: " + data.getDataFolder().getPath()); Iris.verbose("Checking Pack: " + data.getDataFolder().getPath());
@ -263,25 +270,29 @@ public class ServerConfigurator {
} }
public void merge(IrisDimension dimension) { public void merge(IrisDimension dimension) {
overworld.merge(dimension.getDimensionHeight()); AtomicIntegerArray array = dimensions[dimension.getBaseDimension().ordinal()];
nether.merge(dimension.getDimensionHeight()); array.updateAndGet(0, min -> Math.min(min, dimension.getMinHeight()));
end.merge(dimension.getDimensionHeight()); array.updateAndGet(1, max -> Math.max(max, dimension.getMaxHeight()));
array.updateAndGet(2, logical -> Math.max(logical, dimension.getLogicalHeight()));
logicalOverworld = Math.max(logicalOverworld, dimension.getLogicalHeight());
logicalNether = Math.max(logicalNether, dimension.getLogicalHeightNether());
logicalEnd = Math.max(logicalEnd, dimension.getLogicalHeightEnd());
} }
public String overworldType() { public String[] jsonStrings() {
return fixer.createDimension(OVERRWORLD, overworld, logicalOverworld).toString(4); var dims = IDataFixer.Dimension.values();
var arr = new String[3];
for (int i = 0; i < 3; i++) {
arr[i] = jsonString(dims[i]);
}
return arr;
} }
public String netherType() { public String jsonString(IDataFixer.Dimension dimension) {
return fixer.createDimension(NETHER, nether, logicalNether).toString(4); var data = dimensions[dimension.ordinal()];
} int minY = data.get(0);
int maxY = data.get(1);
public String endType() { int logicalHeight = data.get(2);
return fixer.createDimension(THE_END, end, logicalEnd).toString(4); if (minY == Integer.MAX_VALUE || maxY == Integer.MIN_VALUE || Integer.MIN_VALUE == logicalHeight)
return null;
return fixer.createDimension(dimension, minY, maxY, logicalHeight).toString(4);
} }
} }
} }

View File

@ -1,7 +1,6 @@
package com.volmit.iris.core.nms.datapack; package com.volmit.iris.core.nms.datapack;
import com.volmit.iris.engine.object.IrisBiomeCustom; import com.volmit.iris.engine.object.IrisBiomeCustom;
import com.volmit.iris.engine.object.IrisRange;
import com.volmit.iris.util.json.JSONObject; import com.volmit.iris.util.json.JSONObject;
public interface IDataFixer { public interface IDataFixer {
@ -12,17 +11,17 @@ public interface IDataFixer {
JSONObject rawDimension(Dimension dimension); JSONObject rawDimension(Dimension dimension);
default JSONObject createDimension(Dimension dimension, IrisRange height, int logicalHeight) { default JSONObject createDimension(Dimension dimension, int minY, int maxY, int logicalHeight) {
JSONObject obj = rawDimension(dimension); JSONObject obj = rawDimension(dimension);
obj.put("min_y", height.getMin()); obj.put("min_y", minY);
obj.put("height", height.getMax() - height.getMin()); obj.put("height", maxY - minY);
obj.put("logical_height", logicalHeight); obj.put("logical_height", logicalHeight);
return obj; return obj;
} }
enum Dimension { enum Dimension {
OVERRWORLD, OVERWORLD,
NETHER, NETHER,
THE_END END
} }
} }

View File

@ -7,7 +7,7 @@ import java.util.Map;
public class DataFixerV1192 implements IDataFixer { public class DataFixerV1192 implements IDataFixer {
private static final Map<Dimension, String> DIMENSIONS = Map.of( private static final Map<Dimension, String> DIMENSIONS = Map.of(
Dimension.OVERRWORLD, """ Dimension.OVERWORLD, """
{ {
"ambient_light": 0.0, "ambient_light": 0.0,
"bed_works": true, "bed_works": true,
@ -48,7 +48,7 @@ public class DataFixerV1192 implements IDataFixer {
"respawn_anchor_works": true, "respawn_anchor_works": true,
"ultrawarm": true "ultrawarm": true
}""", }""",
Dimension.THE_END, """ Dimension.END, """
{ {
"ambient_light": 0.0, "ambient_light": 0.0,
"bed_works": false, "bed_works": false,

View File

@ -25,11 +25,13 @@ import com.volmit.iris.core.loader.IrisData;
import com.volmit.iris.core.loader.IrisRegistrant; import com.volmit.iris.core.loader.IrisRegistrant;
import com.volmit.iris.core.nms.INMS; import com.volmit.iris.core.nms.INMS;
import com.volmit.iris.core.nms.datapack.IDataFixer; import com.volmit.iris.core.nms.datapack.IDataFixer;
import com.volmit.iris.core.nms.datapack.IDataFixer.Dimension;
import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.engine.data.cache.AtomicCache;
import com.volmit.iris.engine.object.annotations.*; import com.volmit.iris.engine.object.annotations.*;
import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.collection.KSet; import com.volmit.iris.util.collection.KSet;
import com.volmit.iris.util.data.DataProvider; import com.volmit.iris.util.data.DataProvider;
import com.volmit.iris.util.data.Varint;
import com.volmit.iris.util.io.IO; import com.volmit.iris.util.io.IO;
import com.volmit.iris.util.json.JSONObject; import com.volmit.iris.util.json.JSONObject;
import com.volmit.iris.util.math.Position2; import com.volmit.iris.util.math.Position2;
@ -45,6 +47,8 @@ import org.bukkit.Material;
import org.bukkit.World.Environment; import org.bukkit.World.Environment;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -74,10 +78,6 @@ public class IrisDimension extends IrisRegistrant {
@MaxNumber(2032) @MaxNumber(2032)
@Desc("Maximum height at which players can be teleported to through gameplay.") @Desc("Maximum height at which players can be teleported to through gameplay.")
private int logicalHeight = 256; private int logicalHeight = 256;
@Desc("Maximum height at which players can be teleported to through gameplay.")
private int logicalHeightEnd = 256;
@Desc("Maximum height at which players can be teleported to through gameplay.")
private int logicalHeightNether = 256;
@RegistryListResource(IrisJigsawStructure.class) @RegistryListResource(IrisJigsawStructure.class)
@Desc("If defined, Iris will place the given jigsaw structure where minecraft should place the overworld stronghold.") @Desc("If defined, Iris will place the given jigsaw structure where minecraft should place the overworld stronghold.")
private String stronghold; private String stronghold;
@ -166,10 +166,6 @@ public class IrisDimension extends IrisRegistrant {
private int fluidHeight = 63; private int fluidHeight = 63;
@Desc("Define the min and max Y bounds of this dimension. Please keep in mind that Iris internally generates from 0 to (max - min). \n\nFor example at -64 to 320, Iris is internally generating to 0 to 384, then on outputting chunks, it shifts it down by the min height (64 blocks). The default is -64 to 320. \n\nThe fluid height is placed at (fluid height + min height). So a fluid height of 63 would actually show up in the world at 1.") @Desc("Define the min and max Y bounds of this dimension. Please keep in mind that Iris internally generates from 0 to (max - min). \n\nFor example at -64 to 320, Iris is internally generating to 0 to 384, then on outputting chunks, it shifts it down by the min height (64 blocks). The default is -64 to 320. \n\nThe fluid height is placed at (fluid height + min height). So a fluid height of 63 would actually show up in the world at 1.")
private IrisRange dimensionHeight = new IrisRange(-64, 320); private IrisRange dimensionHeight = new IrisRange(-64, 320);
@Desc("Define the min and max Y bounds of this dimension. Please keep in mind that Iris internally generates from 0 to (max - min). \n\nFor example at -64 to 320, Iris is internally generating to 0 to 384, then on outputting chunks, it shifts it down by the min height (64 blocks). The default is -64 to 320. \n\nThe fluid height is placed at (fluid height + min height). So a fluid height of 63 would actually show up in the world at 1.")
private IrisRange dimensionHeightEnd = new IrisRange(-64, 320);
@Desc("Define the min and max Y bounds of this dimension. Please keep in mind that Iris internally generates from 0 to (max - min). \n\nFor example at -64 to 320, Iris is internally generating to 0 to 384, then on outputting chunks, it shifts it down by the min height (64 blocks). The default is -64 to 320. \n\nThe fluid height is placed at (fluid height + min height). So a fluid height of 63 would actually show up in the world at 1.")
private IrisRange dimensionHeightNether = new IrisRange(-64, 320);
@RegistryListResource(IrisBiome.class) @RegistryListResource(IrisBiome.class)
@Desc("Keep this either undefined or empty. Setting any biome name into this will force iris to only generate the specified biome. Great for testing.") @Desc("Keep this either undefined or empty. Setting any biome name into this will force iris to only generate the specified biome. Great for testing.")
private String focus = ""; private String focus = "";
@ -410,6 +406,40 @@ public class IrisDimension extends IrisRegistrant {
}); });
} }
public Dimension getBaseDimension() {
return switch (getEnvironment()) {
case NETHER -> Dimension.NETHER;
case THE_END -> Dimension.END;
default -> Dimension.OVERWORLD;
};
}
public String getDimensionTypeKey() {
return getDimensionTypeKey(getBaseDimension(), getMinHeight(), getMaxHeight(), getLogicalHeight());
}
public void installDimensionType(IDataFixer fixer, KList<File> folders) {
String key = getDimensionTypeKey();
String json = fixer.createDimension(
getBaseDimension(),
getMinHeight(),
getMaxHeight(),
getLogicalHeight()
).toString(4);
Iris.verbose(" Installing Data Pack Dimension Type: \"iris:" + key + '"');
for (File datapacks : folders) {
File output = new File(datapacks, "iris/data/iris/dimension_type/" + key + ".json");
output.getParentFile().mkdirs();
try {
IO.writeAll(output, json);
} catch (IOException e) {
Iris.reportError(e);
e.printStackTrace();
}
}
}
@Override @Override
public String getFolderName() { public String getFolderName() {
return "dimensions"; return "dimensions";
@ -426,11 +456,12 @@ public class IrisDimension extends IrisRegistrant {
} }
public static void writeShared(KList<File> folders, DimensionHeight height) { public static void writeShared(KList<File> folders, DimensionHeight height) {
Iris.verbose(" Installing Data Pack Dimension Types: \"iris:overworld\", \"iris:the_nether\", \"iris:the_end\""); Iris.verbose(" Installing Data Pack Vanilla Dimension Types");
String[] jsonStrings = height.jsonStrings();
for (File datapacks : folders) { for (File datapacks : folders) {
write(datapacks, "overworld", height.overworldType()); write(datapacks, "overworld", jsonStrings[0]);
write(datapacks, "the_nether", height.netherType()); write(datapacks, "the_nether", jsonStrings[1]);
write(datapacks, "the_end", height.endType()); write(datapacks, "the_end", jsonStrings[2]);
} }
String raw = """ String raw = """
@ -454,18 +485,24 @@ public class IrisDimension extends IrisRegistrant {
} }
} }
private static void write(File datapacks, String type, String json) { public static String getDimensionTypeKey(Dimension dimension, int minY, int maxY, int logicalHeight) {
File dimType = new File(datapacks, "iris/data/iris/dimension_type/" + type + ".json"); var stream = new ByteArrayOutputStream(13);
File dimTypeVanilla = new File(datapacks, "iris/data/minecraft/dimension_type/" + type + ".json"); try (var dos = new DataOutputStream(stream)) {
dos.writeByte(dimension.ordinal());
dimType.getParentFile().mkdirs(); Varint.writeUnsignedVarInt(logicalHeight, dos);
try { Varint.writeUnsignedVarInt(maxY - minY, dos);
IO.writeAll(dimType, json); Varint.writeSignedVarInt(minY, dos);
} catch (IOException e) { } catch (IOException e) {
Iris.reportError(e); throw new RuntimeException("This is impossible", e);
e.printStackTrace();
} }
return IO.encode(stream.toByteArray()).replace("=", ".").toLowerCase();
}
private static void write(File datapacks, String type, String json) {
if (json == null) return;
File dimTypeVanilla = new File(datapacks, "iris/data/minecraft/dimension_type/" + type + ".json");
if (IrisSettings.get().getGeneral().adjustVanillaHeight || dimTypeVanilla.exists()) { if (IrisSettings.get().getGeneral().adjustVanillaHeight || dimTypeVanilla.exists()) {
dimTypeVanilla.getParentFile().mkdirs(); dimTypeVanilla.getParentFile().mkdirs();
try { try {

View File

@ -24,6 +24,7 @@ import com.volmit.iris.core.nms.INMS;
import com.volmit.iris.core.nms.container.AutoClosing; import com.volmit.iris.core.nms.container.AutoClosing;
import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.core.service.StudioSVC;
import com.volmit.iris.engine.IrisEngine; import com.volmit.iris.engine.IrisEngine;
import com.volmit.iris.engine.data.cache.AtomicCache;
import com.volmit.iris.engine.data.chunk.TerrainChunk; import com.volmit.iris.engine.data.chunk.TerrainChunk;
import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.framework.EngineTarget; import com.volmit.iris.engine.framework.EngineTarget;
@ -86,6 +87,7 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
private final boolean studio; private final boolean studio;
private final AtomicInteger a = new AtomicInteger(0); private final AtomicInteger a = new AtomicInteger(0);
private final CompletableFuture<Integer> spawnChunks = new CompletableFuture<>(); private final CompletableFuture<Integer> spawnChunks = new CompletableFuture<>();
private final AtomicCache<EngineTarget> targetCache = new AtomicCache<>();
private Engine engine; private Engine engine;
private Looper hotloader; private Looper hotloader;
private StudioMode lastMode; private StudioMode lastMode;
@ -158,6 +160,18 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
} }
private void setupEngine() { private void setupEngine() {
lastMode = StudioMode.NORMAL;
engine = new IrisEngine(getTarget(), studio);
populators.clear();
targetCache.reset();
}
@NotNull
@Override
public EngineTarget getTarget() {
if (engine != null) return engine.getTarget();
return targetCache.aquire(() -> {
IrisData data = IrisData.get(dataLocation); IrisData data = IrisData.get(dataLocation);
IrisDimension dimension = data.getDimensionLoader().load(dimensionKey); IrisDimension dimension = data.getDimensionLoader().load(dimensionKey);
@ -186,9 +200,8 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
} }
} }
lastMode = StudioMode.NORMAL; return new EngineTarget(world, dimension, data);
engine = new IrisEngine(new EngineTarget(world, dimension, data), studio); });
populators.clear();
} }
@Override @Override

View File

@ -24,21 +24,23 @@ import com.volmit.iris.engine.framework.EngineTarget;
import com.volmit.iris.engine.framework.Hotloadable; import com.volmit.iris.engine.framework.Hotloadable;
import com.volmit.iris.util.data.DataProvider; import com.volmit.iris.util.data.DataProvider;
import org.bukkit.World; import org.bukkit.World;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer; import java.util.function.Consumer;
public interface PlatformChunkGenerator extends Hotloadable, DataProvider { public interface PlatformChunkGenerator extends Hotloadable, DataProvider {
@Nullable
Engine getEngine(); Engine getEngine();
@Override @Override
default IrisData getData() { default IrisData getData() {
return getEngine().getData(); return getTarget().getData();
} }
default EngineTarget getTarget() { @NotNull
return getEngine().getTarget(); EngineTarget getTarget();
}
void injectChunkReplacement(World world, int x, int z, Consumer<Runnable> jobs); void injectChunkReplacement(World world, int x, int z, Consumer<Runnable> jobs);

View File

@ -7,6 +7,7 @@ import com.volmit.iris.core.nms.INMSBinding;
import com.volmit.iris.core.nms.container.BiomeColor; import com.volmit.iris.core.nms.container.BiomeColor;
import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.engine.data.cache.AtomicCache;
import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.platform.PlatformChunkGenerator;
import com.volmit.iris.util.agent.Agent; import com.volmit.iris.util.agent.Agent;
import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.collection.KMap;
@ -22,7 +23,6 @@ import com.volmit.iris.util.nbt.mca.palette.*;
import com.volmit.iris.util.nbt.tag.CompoundTag; import com.volmit.iris.util.nbt.tag.CompoundTag;
import com.volmit.iris.util.scheduling.J; import com.volmit.iris.util.scheduling.J;
import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntMap;
import lombok.SneakyThrows;
import net.bytebuddy.ByteBuddy; import net.bytebuddy.ByteBuddy;
import net.bytebuddy.asm.Advice; import net.bytebuddy.asm.Advice;
import net.bytebuddy.matcher.ElementMatchers; import net.bytebuddy.matcher.ElementMatchers;
@ -49,7 +49,6 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkAccess; import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.ChunkStatus; import net.minecraft.world.level.chunk.ChunkStatus;
import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.dimension.LevelStem; import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.FlatLevelSource; import net.minecraft.world.level.levelgen.FlatLevelSource;
import net.minecraft.world.level.levelgen.flat.FlatLayerInfo; import net.minecraft.world.level.levelgen.flat.FlatLayerInfo;
@ -78,6 +77,7 @@ import org.jetbrains.annotations.NotNull;
import java.awt.Color; import java.awt.Color;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.*; import java.util.*;
@ -700,18 +700,13 @@ public class NMSBinding implements INMSBinding {
return new ResourceLocation("iris", key.location().getPath()); return new ResourceLocation("iris", key.location().getPath());
} }
public LevelStem levelStem(RegistryAccess access, World.Environment env) { public LevelStem levelStem(RegistryAccess access, ChunkGenerator raw) {
if (env == World.Environment.CUSTOM) if (!(raw instanceof PlatformChunkGenerator gen))
env = World.Environment.NORMAL; throw new IllegalStateException("Generator is not platform chunk generator!");
return stems.computeIfAbsent(env, key -> new LevelStem(dimensionType(access, key), chunkGenerator(access)));
}
private Holder.Reference<DimensionType> dimensionType(RegistryAccess access, World.Environment env) { var dimensionKey = new ResourceLocation("iris", gen.getTarget().getDimension().getDimensionTypeKey());
return access.registryOrThrow(Registries.DIMENSION_TYPE).getHolderOrThrow(ResourceKey.create(Registries.DIMENSION_TYPE, new ResourceLocation("iris", switch (env) { var dimensionType = access.lookupOrThrow(Registries.DIMENSION_TYPE).getOrThrow(ResourceKey.create(Registries.DIMENSION_TYPE, dimensionKey));
case NORMAL, CUSTOM -> "overworld"; return new LevelStem(dimensionType, chunkGenerator(access));
case NETHER -> "the_nether";
case THE_END -> "the_end";
})));
} }
private net.minecraft.world.level.chunk.ChunkGenerator chunkGenerator(RegistryAccess access) { private net.minecraft.world.level.chunk.ChunkGenerator chunkGenerator(RegistryAccess access) {
@ -722,7 +717,6 @@ public class NMSBinding implements INMSBinding {
} }
private static class ServerLevelAdvice { private static class ServerLevelAdvice {
@SneakyThrows
@Advice.OnMethodEnter @Advice.OnMethodEnter
static void enter( static void enter(
@Advice.Argument(0) MinecraftServer server, @Advice.Argument(0) MinecraftServer server,
@ -734,15 +728,20 @@ public class NMSBinding implements INMSBinding {
if (gen == null || !gen.getClass().getPackageName().startsWith("com.volmit.iris")) if (gen == null || !gen.getClass().getPackageName().startsWith("com.volmit.iris"))
return; return;
try {
Object bindings = Class.forName("com.volmit.iris.core.nms.INMS", true, Bukkit.getPluginManager().getPlugin("Iris") Object bindings = Class.forName("com.volmit.iris.core.nms.INMS", true, Bukkit.getPluginManager().getPlugin("Iris")
.getClass() .getClass()
.getClassLoader()) .getClassLoader())
.getDeclaredMethod("get") .getDeclaredMethod("get")
.invoke(null); .invoke(null);
levelStem = (LevelStem) bindings.getClass() levelStem = (LevelStem) bindings.getClass()
.getDeclaredMethod("levelStem", RegistryAccess.class, World.Environment.class) .getDeclaredMethod("levelStem", RegistryAccess.class, ChunkGenerator.class)
.invoke(bindings, server.registryAccess(), env); .invoke(bindings, server.registryAccess(), gen);
levelData.customDimensions = null; levelData.customDimensions = null;
} catch (Throwable e) {
throw new RuntimeException("Iris failed to replace the levelStem", e instanceof InvocationTargetException ex ? ex.getCause() : e);
}
} }
} }
} }

View File

@ -2,6 +2,7 @@ package com.volmit.iris.core.nms.v1_20_R2;
import java.awt.Color; import java.awt.Color;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.*; import java.util.*;
@ -11,11 +12,11 @@ import java.util.concurrent.atomic.AtomicInteger;
import com.mojang.datafixers.util.Pair; import com.mojang.datafixers.util.Pair;
import com.volmit.iris.core.nms.container.BiomeColor; import com.volmit.iris.core.nms.container.BiomeColor;
import com.volmit.iris.engine.platform.PlatformChunkGenerator;
import com.volmit.iris.util.agent.Agent; import com.volmit.iris.util.agent.Agent;
import com.volmit.iris.util.format.C; import com.volmit.iris.util.format.C;
import com.volmit.iris.util.misc.ServerProperties; import com.volmit.iris.util.misc.ServerProperties;
import com.volmit.iris.util.scheduling.J; import com.volmit.iris.util.scheduling.J;
import lombok.SneakyThrows;
import net.bytebuddy.ByteBuddy; import net.bytebuddy.ByteBuddy;
import net.bytebuddy.asm.Advice; import net.bytebuddy.asm.Advice;
import net.bytebuddy.matcher.ElementMatchers; import net.bytebuddy.matcher.ElementMatchers;
@ -32,7 +33,6 @@ import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.biome.Biomes; import net.minecraft.world.level.biome.Biomes;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.EntityBlock; import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.dimension.LevelStem; import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.FlatLevelSource; import net.minecraft.world.level.levelgen.FlatLevelSource;
import net.minecraft.world.level.levelgen.flat.FlatLayerInfo; import net.minecraft.world.level.levelgen.flat.FlatLayerInfo;
@ -704,18 +704,13 @@ public class NMSBinding implements INMSBinding {
return new ResourceLocation("iris", key.location().getPath()); return new ResourceLocation("iris", key.location().getPath());
} }
public LevelStem levelStem(RegistryAccess access, World.Environment env) { public LevelStem levelStem(RegistryAccess access, ChunkGenerator raw) {
if (env == World.Environment.CUSTOM) if (!(raw instanceof PlatformChunkGenerator gen))
env = World.Environment.NORMAL; throw new IllegalStateException("Generator is not platform chunk generator!");
return stems.computeIfAbsent(env, key -> new LevelStem(dimensionType(access, key), chunkGenerator(access)));
}
private Holder.Reference<DimensionType> dimensionType(RegistryAccess access, World.Environment env) { var dimensionKey = new ResourceLocation("iris", gen.getTarget().getDimension().getDimensionTypeKey());
return access.registryOrThrow(Registries.DIMENSION_TYPE).getHolderOrThrow(ResourceKey.create(Registries.DIMENSION_TYPE, new ResourceLocation("iris", switch (env) { var dimensionType = access.lookupOrThrow(Registries.DIMENSION_TYPE).getOrThrow(ResourceKey.create(Registries.DIMENSION_TYPE, dimensionKey));
case NORMAL, CUSTOM -> "overworld"; return new LevelStem(dimensionType, chunkGenerator(access));
case NETHER -> "the_nether";
case THE_END -> "the_end";
})));
} }
private net.minecraft.world.level.chunk.ChunkGenerator chunkGenerator(RegistryAccess access) { private net.minecraft.world.level.chunk.ChunkGenerator chunkGenerator(RegistryAccess access) {
@ -726,7 +721,6 @@ public class NMSBinding implements INMSBinding {
} }
private static class ServerLevelAdvice { private static class ServerLevelAdvice {
@SneakyThrows
@Advice.OnMethodEnter @Advice.OnMethodEnter
static void enter( static void enter(
@Advice.Argument(0) MinecraftServer server, @Advice.Argument(0) MinecraftServer server,
@ -738,15 +732,20 @@ public class NMSBinding implements INMSBinding {
if (gen == null || !gen.getClass().getPackageName().startsWith("com.volmit.iris")) if (gen == null || !gen.getClass().getPackageName().startsWith("com.volmit.iris"))
return; return;
try {
Object bindings = Class.forName("com.volmit.iris.core.nms.INMS", true, Bukkit.getPluginManager().getPlugin("Iris") Object bindings = Class.forName("com.volmit.iris.core.nms.INMS", true, Bukkit.getPluginManager().getPlugin("Iris")
.getClass() .getClass()
.getClassLoader()) .getClassLoader())
.getDeclaredMethod("get") .getDeclaredMethod("get")
.invoke(null); .invoke(null);
levelStem = (LevelStem) bindings.getClass() levelStem = (LevelStem) bindings.getClass()
.getDeclaredMethod("levelStem", RegistryAccess.class, World.Environment.class) .getDeclaredMethod("levelStem", RegistryAccess.class, ChunkGenerator.class)
.invoke(bindings, server.registryAccess(), env); .invoke(bindings, server.registryAccess(), gen);
levelData.customDimensions = null; levelData.customDimensions = null;
} catch (Throwable e) {
throw new RuntimeException("Iris failed to replace the levelStem", e instanceof InvocationTargetException ex ? ex.getCause() : e);
}
} }
} }
} }

View File

@ -2,6 +2,7 @@ package com.volmit.iris.core.nms.v1_20_R3;
import java.awt.Color; import java.awt.Color;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.*; import java.util.*;
@ -11,11 +12,11 @@ import java.util.concurrent.atomic.AtomicInteger;
import com.mojang.datafixers.util.Pair; import com.mojang.datafixers.util.Pair;
import com.volmit.iris.core.nms.container.BiomeColor; import com.volmit.iris.core.nms.container.BiomeColor;
import com.volmit.iris.engine.platform.PlatformChunkGenerator;
import com.volmit.iris.util.agent.Agent; import com.volmit.iris.util.agent.Agent;
import com.volmit.iris.util.format.C; import com.volmit.iris.util.format.C;
import com.volmit.iris.util.misc.ServerProperties; import com.volmit.iris.util.misc.ServerProperties;
import com.volmit.iris.util.scheduling.J; import com.volmit.iris.util.scheduling.J;
import lombok.SneakyThrows;
import net.bytebuddy.ByteBuddy; import net.bytebuddy.ByteBuddy;
import net.bytebuddy.asm.Advice; import net.bytebuddy.asm.Advice;
import net.bytebuddy.matcher.ElementMatchers; import net.bytebuddy.matcher.ElementMatchers;
@ -32,7 +33,6 @@ import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.biome.Biomes; import net.minecraft.world.level.biome.Biomes;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.EntityBlock; import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.dimension.LevelStem; import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.FlatLevelSource; import net.minecraft.world.level.levelgen.FlatLevelSource;
import net.minecraft.world.level.levelgen.flat.FlatLayerInfo; import net.minecraft.world.level.levelgen.flat.FlatLayerInfo;
@ -705,18 +705,13 @@ public class NMSBinding implements INMSBinding {
return new ResourceLocation("iris", key.location().getPath()); return new ResourceLocation("iris", key.location().getPath());
} }
public LevelStem levelStem(RegistryAccess access, World.Environment env) { public LevelStem levelStem(RegistryAccess access, ChunkGenerator raw) {
if (env == World.Environment.CUSTOM) if (!(raw instanceof PlatformChunkGenerator gen))
env = World.Environment.NORMAL; throw new IllegalStateException("Generator is not platform chunk generator!");
return stems.computeIfAbsent(env, key -> new LevelStem(dimensionType(access, key), chunkGenerator(access)));
}
private Holder.Reference<DimensionType> dimensionType(RegistryAccess access, World.Environment env) { var dimensionKey = new ResourceLocation("iris", gen.getTarget().getDimension().getDimensionTypeKey());
return access.registryOrThrow(Registries.DIMENSION_TYPE).getHolderOrThrow(ResourceKey.create(Registries.DIMENSION_TYPE, new ResourceLocation("iris", switch (env) { var dimensionType = access.lookupOrThrow(Registries.DIMENSION_TYPE).getOrThrow(ResourceKey.create(Registries.DIMENSION_TYPE, dimensionKey));
case NORMAL, CUSTOM -> "overworld"; return new LevelStem(dimensionType, chunkGenerator(access));
case NETHER -> "the_nether";
case THE_END -> "the_end";
})));
} }
private net.minecraft.world.level.chunk.ChunkGenerator chunkGenerator(RegistryAccess access) { private net.minecraft.world.level.chunk.ChunkGenerator chunkGenerator(RegistryAccess access) {
@ -727,7 +722,6 @@ public class NMSBinding implements INMSBinding {
} }
private static class ServerLevelAdvice { private static class ServerLevelAdvice {
@SneakyThrows
@Advice.OnMethodEnter @Advice.OnMethodEnter
static void enter( static void enter(
@Advice.Argument(0) MinecraftServer server, @Advice.Argument(0) MinecraftServer server,
@ -739,15 +733,20 @@ public class NMSBinding implements INMSBinding {
if (gen == null || !gen.getClass().getPackageName().startsWith("com.volmit.iris")) if (gen == null || !gen.getClass().getPackageName().startsWith("com.volmit.iris"))
return; return;
try {
Object bindings = Class.forName("com.volmit.iris.core.nms.INMS", true, Bukkit.getPluginManager().getPlugin("Iris") Object bindings = Class.forName("com.volmit.iris.core.nms.INMS", true, Bukkit.getPluginManager().getPlugin("Iris")
.getClass() .getClass()
.getClassLoader()) .getClassLoader())
.getDeclaredMethod("get") .getDeclaredMethod("get")
.invoke(null); .invoke(null);
levelStem = (LevelStem) bindings.getClass() levelStem = (LevelStem) bindings.getClass()
.getDeclaredMethod("levelStem", RegistryAccess.class, World.Environment.class) .getDeclaredMethod("levelStem", RegistryAccess.class, ChunkGenerator.class)
.invoke(bindings, server.registryAccess(), env); .invoke(bindings, server.registryAccess(), gen);
levelData.customDimensions = null; levelData.customDimensions = null;
} catch (Throwable e) {
throw new RuntimeException("Iris failed to replace the levelStem", e instanceof InvocationTargetException ex ? ex.getCause() : e);
}
} }
} }
} }

View File

@ -2,6 +2,7 @@ package com.volmit.iris.core.nms.v1_20_R4;
import java.awt.Color; import java.awt.Color;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.*; import java.util.*;
@ -12,12 +13,12 @@ import java.util.concurrent.atomic.AtomicInteger;
import com.mojang.datafixers.util.Pair; import com.mojang.datafixers.util.Pair;
import com.volmit.iris.core.nms.container.BiomeColor; import com.volmit.iris.core.nms.container.BiomeColor;
import com.volmit.iris.core.nms.datapack.DataVersion; import com.volmit.iris.core.nms.datapack.DataVersion;
import com.volmit.iris.engine.platform.PlatformChunkGenerator;
import com.volmit.iris.util.agent.Agent; import com.volmit.iris.util.agent.Agent;
import com.volmit.iris.util.format.C; import com.volmit.iris.util.format.C;
import com.volmit.iris.util.misc.ServerProperties; import com.volmit.iris.util.misc.ServerProperties;
import com.volmit.iris.util.nbt.tag.CompoundTag; import com.volmit.iris.util.nbt.tag.CompoundTag;
import com.volmit.iris.util.scheduling.J; import com.volmit.iris.util.scheduling.J;
import lombok.SneakyThrows;
import net.bytebuddy.ByteBuddy; import net.bytebuddy.ByteBuddy;
import net.bytebuddy.asm.Advice; import net.bytebuddy.asm.Advice;
import net.bytebuddy.matcher.ElementMatchers; import net.bytebuddy.matcher.ElementMatchers;
@ -46,7 +47,6 @@ import net.minecraft.world.level.biome.Biomes;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.EntityBlock; import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.chunk.status.ChunkStatus; import net.minecraft.world.level.chunk.status.ChunkStatus;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.dimension.LevelStem; import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.FlatLevelSource; import net.minecraft.world.level.levelgen.FlatLevelSource;
import net.minecraft.world.level.levelgen.flat.FlatLayerInfo; import net.minecraft.world.level.levelgen.flat.FlatLayerInfo;
@ -733,18 +733,13 @@ public class NMSBinding implements INMSBinding {
return new ResourceLocation("iris", key.location().getPath()); return new ResourceLocation("iris", key.location().getPath());
} }
public LevelStem levelStem(RegistryAccess access, World.Environment env) { public LevelStem levelStem(RegistryAccess access, ChunkGenerator raw) {
if (env == World.Environment.CUSTOM) if (!(raw instanceof PlatformChunkGenerator gen))
env = World.Environment.NORMAL; throw new IllegalStateException("Generator is not platform chunk generator!");
return stems.computeIfAbsent(env, key -> new LevelStem(dimensionType(access, key), chunkGenerator(access)));
}
private Holder.Reference<DimensionType> dimensionType(RegistryAccess access, World.Environment env) { var dimensionKey = new ResourceLocation("iris", gen.getTarget().getDimension().getDimensionTypeKey());
return access.registryOrThrow(Registries.DIMENSION_TYPE).getHolderOrThrow(ResourceKey.create(Registries.DIMENSION_TYPE, new ResourceLocation("iris", switch (env) { var dimensionType = access.lookupOrThrow(Registries.DIMENSION_TYPE).getOrThrow(ResourceKey.create(Registries.DIMENSION_TYPE, dimensionKey));
case NORMAL, CUSTOM -> "overworld"; return new LevelStem(dimensionType, chunkGenerator(access));
case NETHER -> "the_nether";
case THE_END -> "the_end";
})));
} }
private net.minecraft.world.level.chunk.ChunkGenerator chunkGenerator(RegistryAccess access) { private net.minecraft.world.level.chunk.ChunkGenerator chunkGenerator(RegistryAccess access) {
@ -755,7 +750,6 @@ public class NMSBinding implements INMSBinding {
} }
private static class ServerLevelAdvice { private static class ServerLevelAdvice {
@SneakyThrows
@Advice.OnMethodEnter @Advice.OnMethodEnter
static void enter( static void enter(
@Advice.Argument(0) MinecraftServer server, @Advice.Argument(0) MinecraftServer server,
@ -767,15 +761,20 @@ public class NMSBinding implements INMSBinding {
if (gen == null || !gen.getClass().getPackageName().startsWith("com.volmit.iris")) if (gen == null || !gen.getClass().getPackageName().startsWith("com.volmit.iris"))
return; return;
try {
Object bindings = Class.forName("com.volmit.iris.core.nms.INMS", true, Bukkit.getPluginManager().getPlugin("Iris") Object bindings = Class.forName("com.volmit.iris.core.nms.INMS", true, Bukkit.getPluginManager().getPlugin("Iris")
.getClass() .getClass()
.getClassLoader()) .getClassLoader())
.getDeclaredMethod("get") .getDeclaredMethod("get")
.invoke(null); .invoke(null);
levelStem = (LevelStem) bindings.getClass() levelStem = (LevelStem) bindings.getClass()
.getDeclaredMethod("levelStem", RegistryAccess.class, World.Environment.class) .getDeclaredMethod("levelStem", RegistryAccess.class, ChunkGenerator.class)
.invoke(bindings, server.registryAccess(), env); .invoke(bindings, server.registryAccess(), gen);
levelData.customDimensions = null; levelData.customDimensions = null;
} catch (Throwable e) {
throw new RuntimeException("Iris failed to replace the levelStem", e instanceof InvocationTargetException ex ? ex.getCause() : e);
}
} }
} }
} }

View File

@ -2,6 +2,7 @@ package com.volmit.iris.core.nms.v1_21_R1;
import java.awt.Color; import java.awt.Color;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.*; import java.util.*;
@ -12,11 +13,11 @@ import java.util.concurrent.atomic.AtomicInteger;
import com.mojang.datafixers.util.Pair; import com.mojang.datafixers.util.Pair;
import com.volmit.iris.core.nms.container.BiomeColor; import com.volmit.iris.core.nms.container.BiomeColor;
import com.volmit.iris.core.nms.datapack.DataVersion; import com.volmit.iris.core.nms.datapack.DataVersion;
import com.volmit.iris.engine.platform.PlatformChunkGenerator;
import com.volmit.iris.util.agent.Agent; import com.volmit.iris.util.agent.Agent;
import com.volmit.iris.util.format.C; import com.volmit.iris.util.format.C;
import com.volmit.iris.util.misc.ServerProperties; import com.volmit.iris.util.misc.ServerProperties;
import com.volmit.iris.util.scheduling.J; import com.volmit.iris.util.scheduling.J;
import lombok.SneakyThrows;
import net.bytebuddy.ByteBuddy; import net.bytebuddy.ByteBuddy;
import net.bytebuddy.asm.Advice; import net.bytebuddy.asm.Advice;
import net.bytebuddy.matcher.ElementMatchers; import net.bytebuddy.matcher.ElementMatchers;
@ -37,7 +38,6 @@ import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.EntityBlock; import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.chunk.status.ChunkStatus; import net.minecraft.world.level.chunk.status.ChunkStatus;
import net.minecraft.world.level.chunk.status.WorldGenContext; import net.minecraft.world.level.chunk.status.WorldGenContext;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.dimension.LevelStem; import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.FlatLevelSource; import net.minecraft.world.level.levelgen.FlatLevelSource;
import net.minecraft.world.level.levelgen.flat.FlatLayerInfo; import net.minecraft.world.level.levelgen.flat.FlatLayerInfo;
@ -733,18 +733,15 @@ public class NMSBinding implements INMSBinding {
return ResourceLocation.fromNamespaceAndPath("iris", key.location().getPath()); return ResourceLocation.fromNamespaceAndPath("iris", key.location().getPath());
} }
public LevelStem levelStem(RegistryAccess access, World.Environment env) {
if (env == World.Environment.CUSTOM)
env = World.Environment.NORMAL;
return stems.computeIfAbsent(env, key -> new LevelStem(dimensionType(access, key), chunkGenerator(access)));
}
private Holder.Reference<DimensionType> dimensionType(RegistryAccess access, World.Environment env) {
return access.registryOrThrow(Registries.DIMENSION_TYPE).getHolderOrThrow(ResourceKey.create(Registries.DIMENSION_TYPE, ResourceLocation.fromNamespaceAndPath("iris", switch (env) { public LevelStem levelStem(RegistryAccess access, ChunkGenerator raw) {
case NORMAL, CUSTOM -> "overworld"; if (!(raw instanceof PlatformChunkGenerator gen))
case NETHER -> "the_nether"; throw new IllegalStateException("Generator is not platform chunk generator!");
case THE_END -> "the_end";
}))); var dimensionKey = ResourceLocation.fromNamespaceAndPath("iris", gen.getTarget().getDimension().getDimensionTypeKey());
var dimensionType = access.lookupOrThrow(Registries.DIMENSION_TYPE).getOrThrow(ResourceKey.create(Registries.DIMENSION_TYPE, dimensionKey));
return new LevelStem(dimensionType, chunkGenerator(access));
} }
private net.minecraft.world.level.chunk.ChunkGenerator chunkGenerator(RegistryAccess access) { private net.minecraft.world.level.chunk.ChunkGenerator chunkGenerator(RegistryAccess access) {
@ -755,7 +752,6 @@ public class NMSBinding implements INMSBinding {
} }
private static class ServerLevelAdvice { private static class ServerLevelAdvice {
@SneakyThrows
@Advice.OnMethodEnter @Advice.OnMethodEnter
static void enter( static void enter(
@Advice.Argument(0) MinecraftServer server, @Advice.Argument(0) MinecraftServer server,
@ -767,15 +763,20 @@ public class NMSBinding implements INMSBinding {
if (gen == null || !gen.getClass().getPackageName().startsWith("com.volmit.iris")) if (gen == null || !gen.getClass().getPackageName().startsWith("com.volmit.iris"))
return; return;
try {
Object bindings = Class.forName("com.volmit.iris.core.nms.INMS", true, Bukkit.getPluginManager().getPlugin("Iris") Object bindings = Class.forName("com.volmit.iris.core.nms.INMS", true, Bukkit.getPluginManager().getPlugin("Iris")
.getClass() .getClass()
.getClassLoader()) .getClassLoader())
.getDeclaredMethod("get") .getDeclaredMethod("get")
.invoke(null); .invoke(null);
levelStem = (LevelStem) bindings.getClass() levelStem = (LevelStem) bindings.getClass()
.getDeclaredMethod("levelStem", RegistryAccess.class, World.Environment.class) .getDeclaredMethod("levelStem", RegistryAccess.class, ChunkGenerator.class)
.invoke(bindings, server.registryAccess(), env); .invoke(bindings, server.registryAccess(), gen);
levelData.customDimensions = null; levelData.customDimensions = null;
} catch (Throwable e) {
throw new RuntimeException("Iris failed to replace the levelStem", e instanceof InvocationTargetException ex ? ex.getCause() : e);
}
} }
} }
} }

View File

@ -2,6 +2,7 @@ package com.volmit.iris.core.nms.v1_21_R2;
import java.awt.Color; import java.awt.Color;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.*; import java.util.*;
@ -11,11 +12,11 @@ import java.util.concurrent.atomic.AtomicInteger;
import com.volmit.iris.core.nms.container.BiomeColor; import com.volmit.iris.core.nms.container.BiomeColor;
import com.volmit.iris.core.nms.datapack.DataVersion; import com.volmit.iris.core.nms.datapack.DataVersion;
import com.volmit.iris.engine.platform.PlatformChunkGenerator;
import com.volmit.iris.util.agent.Agent; import com.volmit.iris.util.agent.Agent;
import com.volmit.iris.util.format.C; import com.volmit.iris.util.format.C;
import com.volmit.iris.util.misc.ServerProperties; import com.volmit.iris.util.misc.ServerProperties;
import com.volmit.iris.util.scheduling.J; import com.volmit.iris.util.scheduling.J;
import lombok.SneakyThrows;
import net.bytebuddy.ByteBuddy; import net.bytebuddy.ByteBuddy;
import net.bytebuddy.asm.Advice; import net.bytebuddy.asm.Advice;
import net.bytebuddy.matcher.ElementMatchers; import net.bytebuddy.matcher.ElementMatchers;
@ -36,7 +37,6 @@ import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.EntityBlock; import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.chunk.status.ChunkStatus; import net.minecraft.world.level.chunk.status.ChunkStatus;
import net.minecraft.world.level.chunk.status.WorldGenContext; import net.minecraft.world.level.chunk.status.WorldGenContext;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.dimension.LevelStem; import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.FlatLevelSource; import net.minecraft.world.level.levelgen.FlatLevelSource;
import net.minecraft.world.level.levelgen.flat.FlatLayerInfo; import net.minecraft.world.level.levelgen.flat.FlatLayerInfo;
@ -732,18 +732,13 @@ public class NMSBinding implements INMSBinding {
return ResourceLocation.fromNamespaceAndPath("iris", key.location().getPath()); return ResourceLocation.fromNamespaceAndPath("iris", key.location().getPath());
} }
public LevelStem levelStem(RegistryAccess access, World.Environment env) { public LevelStem levelStem(RegistryAccess access, ChunkGenerator raw) {
if (env == World.Environment.CUSTOM) if (!(raw instanceof PlatformChunkGenerator gen))
env = World.Environment.NORMAL; throw new IllegalStateException("Generator is not platform chunk generator!");
return stems.computeIfAbsent(env, key -> new LevelStem(dimensionType(access, key), chunkGenerator(access)));
}
private Holder.Reference<DimensionType> dimensionType(RegistryAccess access, World.Environment env) { var dimensionKey = ResourceLocation.fromNamespaceAndPath("iris", gen.getTarget().getDimension().getDimensionTypeKey());
return access.lookupOrThrow(Registries.DIMENSION_TYPE).getOrThrow(ResourceKey.create(Registries.DIMENSION_TYPE, ResourceLocation.fromNamespaceAndPath("iris", switch (env) { var dimensionType = access.lookupOrThrow(Registries.DIMENSION_TYPE).getOrThrow(ResourceKey.create(Registries.DIMENSION_TYPE, dimensionKey));
case NORMAL, CUSTOM -> "overworld"; return new LevelStem(dimensionType, chunkGenerator(access));
case NETHER -> "the_nether";
case THE_END -> "the_end";
})));
} }
private net.minecraft.world.level.chunk.ChunkGenerator chunkGenerator(RegistryAccess access) { private net.minecraft.world.level.chunk.ChunkGenerator chunkGenerator(RegistryAccess access) {
@ -754,7 +749,6 @@ public class NMSBinding implements INMSBinding {
} }
private static class ServerLevelAdvice { private static class ServerLevelAdvice {
@SneakyThrows
@Advice.OnMethodEnter @Advice.OnMethodEnter
static void enter( static void enter(
@Advice.Argument(0) MinecraftServer server, @Advice.Argument(0) MinecraftServer server,
@ -766,15 +760,20 @@ public class NMSBinding implements INMSBinding {
if (gen == null || !gen.getClass().getPackageName().startsWith("com.volmit.iris")) if (gen == null || !gen.getClass().getPackageName().startsWith("com.volmit.iris"))
return; return;
try {
Object bindings = Class.forName("com.volmit.iris.core.nms.INMS", true, Bukkit.getPluginManager().getPlugin("Iris") Object bindings = Class.forName("com.volmit.iris.core.nms.INMS", true, Bukkit.getPluginManager().getPlugin("Iris")
.getClass() .getClass()
.getClassLoader()) .getClassLoader())
.getDeclaredMethod("get") .getDeclaredMethod("get")
.invoke(null); .invoke(null);
levelStem = (LevelStem) bindings.getClass() levelStem = (LevelStem) bindings.getClass()
.getDeclaredMethod("levelStem", RegistryAccess.class, World.Environment.class) .getDeclaredMethod("levelStem", RegistryAccess.class, ChunkGenerator.class)
.invoke(bindings, server.registryAccess(), env); .invoke(bindings, server.registryAccess(), gen);
levelData.customDimensions = null; levelData.customDimensions = null;
} catch (Throwable e) {
throw new RuntimeException("Iris failed to replace the levelStem", e instanceof InvocationTargetException ex ? ex.getCause() : e);
}
} }
} }
} }

View File

@ -7,6 +7,7 @@ import com.volmit.iris.core.nms.container.BiomeColor;
import com.volmit.iris.core.nms.datapack.DataVersion; import com.volmit.iris.core.nms.datapack.DataVersion;
import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.engine.data.cache.AtomicCache;
import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.platform.PlatformChunkGenerator;
import com.volmit.iris.util.agent.Agent; import com.volmit.iris.util.agent.Agent;
import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.collection.KMap;
@ -16,13 +17,11 @@ import com.volmit.iris.util.json.JSONObject;
import com.volmit.iris.util.mantle.Mantle; import com.volmit.iris.util.mantle.Mantle;
import com.volmit.iris.util.math.Vector3d; import com.volmit.iris.util.math.Vector3d;
import com.volmit.iris.util.matter.MatterBiomeInject; import com.volmit.iris.util.matter.MatterBiomeInject;
import com.volmit.iris.util.misc.ServerProperties;
import com.volmit.iris.util.nbt.mca.NBTWorld; import com.volmit.iris.util.nbt.mca.NBTWorld;
import com.volmit.iris.util.nbt.mca.palette.*; import com.volmit.iris.util.nbt.mca.palette.*;
import com.volmit.iris.util.nbt.tag.CompoundTag; import com.volmit.iris.util.nbt.tag.CompoundTag;
import com.volmit.iris.util.scheduling.J; import com.volmit.iris.util.scheduling.J;
import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntMap;
import lombok.SneakyThrows;
import net.bytebuddy.ByteBuddy; import net.bytebuddy.ByteBuddy;
import net.bytebuddy.asm.Advice; import net.bytebuddy.asm.Advice;
import net.bytebuddy.matcher.ElementMatchers; import net.bytebuddy.matcher.ElementMatchers;
@ -53,7 +52,6 @@ import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.chunk.status.ChunkStatus; import net.minecraft.world.level.chunk.status.ChunkStatus;
import net.minecraft.world.level.chunk.status.WorldGenContext; import net.minecraft.world.level.chunk.status.WorldGenContext;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.dimension.LevelStem; import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.FlatLevelSource; import net.minecraft.world.level.levelgen.FlatLevelSource;
import net.minecraft.world.level.levelgen.flat.FlatLayerInfo; import net.minecraft.world.level.levelgen.flat.FlatLayerInfo;
@ -81,6 +79,7 @@ import org.jetbrains.annotations.NotNull;
import java.awt.Color; import java.awt.Color;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.List; import java.util.List;
@ -731,18 +730,13 @@ public class NMSBinding implements INMSBinding {
return ResourceLocation.fromNamespaceAndPath("iris", key.location().getPath()); return ResourceLocation.fromNamespaceAndPath("iris", key.location().getPath());
} }
public LevelStem levelStem(RegistryAccess access, World.Environment env) { public LevelStem levelStem(RegistryAccess access, ChunkGenerator raw) {
if (env == World.Environment.CUSTOM) if (!(raw instanceof PlatformChunkGenerator gen))
env = World.Environment.NORMAL; throw new IllegalStateException("Generator is not platform chunk generator!");
return stems.computeIfAbsent(env, key -> new LevelStem(dimensionType(access, key), chunkGenerator(access)));
}
private Holder.Reference<DimensionType> dimensionType(RegistryAccess access, World.Environment env) { var dimensionKey = ResourceLocation.fromNamespaceAndPath("iris", gen.getTarget().getDimension().getDimensionTypeKey());
return access.lookupOrThrow(Registries.DIMENSION_TYPE).getOrThrow(ResourceKey.create(Registries.DIMENSION_TYPE, ResourceLocation.fromNamespaceAndPath("iris", switch (env) { var dimensionType = access.lookupOrThrow(Registries.DIMENSION_TYPE).getOrThrow(ResourceKey.create(Registries.DIMENSION_TYPE, dimensionKey));
case NORMAL, CUSTOM -> "overworld"; return new LevelStem(dimensionType, chunkGenerator(access));
case NETHER -> "the_nether";
case THE_END -> "the_end";
})));
} }
private net.minecraft.world.level.chunk.ChunkGenerator chunkGenerator(RegistryAccess access) { private net.minecraft.world.level.chunk.ChunkGenerator chunkGenerator(RegistryAccess access) {
@ -753,7 +747,6 @@ public class NMSBinding implements INMSBinding {
} }
private static class ServerLevelAdvice { private static class ServerLevelAdvice {
@SneakyThrows
@Advice.OnMethodEnter @Advice.OnMethodEnter
static void enter( static void enter(
@Advice.Argument(0) MinecraftServer server, @Advice.Argument(0) MinecraftServer server,
@ -765,15 +758,20 @@ public class NMSBinding implements INMSBinding {
if (gen == null || !gen.getClass().getPackageName().startsWith("com.volmit.iris")) if (gen == null || !gen.getClass().getPackageName().startsWith("com.volmit.iris"))
return; return;
try {
Object bindings = Class.forName("com.volmit.iris.core.nms.INMS", true, Bukkit.getPluginManager().getPlugin("Iris") Object bindings = Class.forName("com.volmit.iris.core.nms.INMS", true, Bukkit.getPluginManager().getPlugin("Iris")
.getClass() .getClass()
.getClassLoader()) .getClassLoader())
.getDeclaredMethod("get") .getDeclaredMethod("get")
.invoke(null); .invoke(null);
levelStem = (LevelStem) bindings.getClass() levelStem = (LevelStem) bindings.getClass()
.getDeclaredMethod("levelStem", RegistryAccess.class, World.Environment.class) .getDeclaredMethod("levelStem", RegistryAccess.class, ChunkGenerator.class)
.invoke(bindings, server.registryAccess(), env); .invoke(bindings, server.registryAccess(), gen);
levelData.customDimensions = null; levelData.customDimensions = null;
} catch (Throwable e) {
throw new RuntimeException("Iris failed to replace the levelStem", e instanceof InvocationTargetException ex ? ex.getCause() : e);
}
} }
} }
} }