isolate iris world height into it's own dimension types (#1171)

This commit is contained in:
Julian Krings 2025-02-20 23:41:19 +01:00 committed by GitHub
parent 8b1636e78a
commit ff2f285784
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 279 additions and 209 deletions

View File

@ -32,6 +32,7 @@ import com.volmit.iris.core.nms.v1X.NMSBinding1X;
import com.volmit.iris.core.pregenerator.LazyPregenerator; import com.volmit.iris.core.pregenerator.LazyPregenerator;
import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.core.service.StudioSVC;
import com.volmit.iris.core.tools.IrisToolbelt; import com.volmit.iris.core.tools.IrisToolbelt;
import com.volmit.iris.core.tools.IrisWorldCreator;
import com.volmit.iris.engine.EnginePanic; import com.volmit.iris.engine.EnginePanic;
import com.volmit.iris.engine.object.IrisCompat; import com.volmit.iris.engine.object.IrisCompat;
import com.volmit.iris.engine.object.IrisDimension; import com.volmit.iris.engine.object.IrisDimension;
@ -517,6 +518,7 @@ public class Iris extends VolmitPlugin implements Listener {
Iris.info(C.LIGHT_PURPLE + "Preparing Spawn for " + s + "' using Iris:" + generator + "..."); Iris.info(C.LIGHT_PURPLE + "Preparing Spawn for " + s + "' using Iris:" + generator + "...");
new WorldCreator(s) new WorldCreator(s)
.type(IrisWorldCreator.IRIS)
.generator(getDefaultWorldGenerator(s, generator)) .generator(getDefaultWorldGenerator(s, generator))
.environment(IrisData.loadAnyDimension(generator).getEnvironment()) .environment(IrisData.loadAnyDimension(generator).getEnvironment())
.createWorld(); .createWorld();

View File

@ -32,6 +32,7 @@ import com.volmit.iris.util.collection.KSet;
import com.volmit.iris.util.format.C; import com.volmit.iris.util.format.C;
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 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;
@ -40,8 +41,12 @@ import org.bukkit.entity.Player;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
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() {
@ -99,57 +104,15 @@ public class ServerConfigurator {
public static void installDataPacks(IDataFixer fixer, boolean fullInstall) { public static void installDataPacks(IDataFixer fixer, boolean fullInstall) {
Iris.info("Checking Data Packs..."); Iris.info("Checking Data Packs...");
File packs = new File("plugins/Iris/packs"); DimensionHeight height = new DimensionHeight(fixer);
double ultimateMaxHeight = 0;
double ultimateMinHeight = 0;
if (packs.exists() && packs.isDirectory()) {
for (File pack : packs.listFiles()) {
IrisData data = IrisData.get(pack);
if (pack.isDirectory()) {
File dimensionsFolder = new File(pack, "dimensions");
if (dimensionsFolder.exists() && dimensionsFolder.isDirectory()) {
for (File file : dimensionsFolder.listFiles()) {
if (file.isFile() && file.getName().endsWith(".json")) {
IrisDimension dim = data.getDimensionLoader().load(file.getName().split("\\Q.\\E")[0]);
if (ultimateMaxHeight < dim.getDimensionHeight().getMax()) {
ultimateMaxHeight = dim.getDimensionHeight().getMax();
}
if (ultimateMinHeight > dim.getDimensionHeight().getMin()) {
ultimateMinHeight = dim.getDimensionHeight().getMin();
}
}
}
}
}
}
}
if (packs.exists()) { allPacks().flatMap(height::merge)
for (File i : packs.listFiles()) { .forEach(dim -> {
if (i.isDirectory()) {
Iris.verbose("Checking Pack: " + i.getPath());
IrisData data = IrisData.get(i);
File dims = new File(i, "dimensions");
if (dims.exists()) {
for (File j : dims.listFiles()) {
if (j.getName().endsWith(".json")) {
IrisDimension dim = data.getDimensionLoader().load(j.getName().split("\\Q.\\E")[0]);
if (dim == null) {
continue;
}
Iris.verbose(" Checking Dimension " + dim.getLoadFile().getPath());
for (File dpack : getDatapacksFolder()) { for (File dpack : getDatapacksFolder()) {
dim.installDataPack(fixer, () -> data, dpack, ultimateMaxHeight, ultimateMinHeight); Iris.verbose(" Checking Dimension " + dim.getLoadFile().getPath());
} dim.installDataPack(fixer, dim::getLoader, dpack, height);
}
}
}
}
}
} }
});
Iris.info("Data Packs Setup!"); Iris.info("Data Packs Setup!");
@ -158,37 +121,21 @@ public class ServerConfigurator {
} }
private static void verifyDataPacksPost(boolean allowRestarting) { private static void verifyDataPacksPost(boolean allowRestarting) {
File packs = new File("plugins/Iris/packs"); boolean bad = allPacks()
.map(data -> {
Iris.verbose("Checking Pack: " + data.getDataFolder().getPath());
var loader = data.getDimensionLoader();
return loader.loadAll(loader.getPossibleKeys())
.stream()
.map(ServerConfigurator::verifyDataPackInstalled)
.toList()
.contains(false);
})
.toList()
.contains(true);
if (!bad) return;
boolean bad = false;
if (packs.exists()) {
for (File i : packs.listFiles()) {
if (i.isDirectory()) {
Iris.verbose("Checking Pack: " + i.getPath());
IrisData data = IrisData.get(i);
File dims = new File(i, "dimensions");
if (dims.exists()) {
for (File j : dims.listFiles()) {
if (j.getName().endsWith(".json")) {
IrisDimension dim = data.getDimensionLoader().load(j.getName().split("\\Q.\\E")[0]);
if (dim == null) {
Iris.error("Failed to load " + j.getPath() + " ");
continue;
}
if (!verifyDataPackInstalled(dim)) {
bad = true;
}
}
}
}
}
}
}
if (bad) {
if (allowRestarting) { if (allowRestarting) {
restart(); restart();
} else if (INMS.get().supportsDataPacks()) { } else if (INMS.get().supportsDataPacks()) {
@ -210,7 +157,6 @@ public class ServerConfigurator {
J.sleep(3000); J.sleep(3000);
} }
} }
}
public static void restart() { public static void restart() {
J.s(() -> { J.s(() -> {
@ -266,4 +212,57 @@ public class ServerConfigurator {
return !warn; return !warn;
} }
public static Stream<IrisData> allPacks() {
return Stream.concat(listFiles(new File("plugins/Iris/packs")),
listFiles(Bukkit.getWorldContainer()).map(w -> new File(w, "iris/pack")))
.filter(File::isDirectory)
.map(IrisData::get);
}
private static Stream<File> listFiles(File parent) {
var files = parent.listFiles();
return files == null ? Stream.empty() : Arrays.stream(files);
}
@Data
public static class DimensionHeight {
private final IDataFixer fixer;
private IrisRange overworld = new IrisRange();
private IrisRange nether = new IrisRange();
private IrisRange end = new IrisRange();
private int logicalOverworld = 0;
private int logicalNether = 0;
private int logicalEnd = 0;
public Stream<IrisDimension> merge(IrisData data) {
Iris.verbose("Checking Pack: " + data.getDataFolder().getPath());
var loader = data.getDimensionLoader();
return loader.loadAll(loader.getPossibleKeys())
.stream()
.peek(this::merge);
}
public void merge(IrisDimension dimension) {
overworld.merge(dimension.getDimensionHeight());
nether.merge(dimension.getDimensionHeight());
end.merge(dimension.getDimensionHeight());
logicalOverworld = Math.max(logicalOverworld, dimension.getLogicalHeight());
logicalNether = Math.max(logicalNether, dimension.getLogicalHeightNether());
logicalEnd = Math.max(logicalEnd, dimension.getLogicalHeightEnd());
}
public String overworldType() {
return fixer.createDimension(OVERRWORLD, overworld, logicalOverworld).toString(4);
}
public String netherType() {
return fixer.createDimension(NETHER, nether, logicalNether).toString(4);
}
public String endType() {
return fixer.createDimension(THE_END, end, logicalEnd).toString(4);
}
}
} }

View File

@ -1,11 +1,68 @@
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 {
JSONObject fixCustomBiome(IrisBiomeCustom biome, JSONObject json); default JSONObject fixCustomBiome(IrisBiomeCustom biome, JSONObject json) {
return json;
}
JSONObject fixDimension(JSONObject json); JSONObject rawDimension(Dimension dimension);
default JSONObject createDimension(Dimension dimension, IrisRange height, int logicalHeight) {
JSONObject obj = rawDimension(dimension);
obj.put("min_y", height.getMin());
obj.put("height", height.getMax() - height.getMin());
obj.put("logical_height", logicalHeight);
return obj;
}
default JSONObject createPreset() {
return new JSONObject("""
{
"dimensions": {
"minecraft:overworld": {
"type": "iris:overworld",
"generator": {
"type": "minecraft:noise",
"biome_source": {
"type": "minecraft:multi_noise",
"preset": "minecraft:overworld"
},
"settings": "minecraft:overworld"
}
},
"minecraft:the_end": {
"type": "iris:the_end",
"generator": {
"type": "minecraft:noise",
"biome_source": {
"type": "minecraft:the_end"
},
"settings": "minecraft:end"
}
},
"minecraft:the_nether": {
"type": "iris:the_nether",
"generator": {
"type": "minecraft:noise",
"biome_source": {
"type": "minecraft:multi_noise",
"preset": "minecraft:nether"
},
"settings": "minecraft:nether"
}
}
}
}""");
}
enum Dimension {
OVERRWORLD,
NETHER,
THE_END
}
} }

View File

@ -1,18 +1,81 @@
package com.volmit.iris.core.nms.datapack.v1192; package com.volmit.iris.core.nms.datapack.v1192;
import com.volmit.iris.core.nms.datapack.IDataFixer; import com.volmit.iris.core.nms.datapack.IDataFixer;
import com.volmit.iris.engine.object.IrisBiomeCustom;
import com.volmit.iris.util.json.JSONObject; import com.volmit.iris.util.json.JSONObject;
import java.util.Map;
public class DataFixerV1192 implements IDataFixer { public class DataFixerV1192 implements IDataFixer {
@Override private static final Map<Dimension, String> DIMENSIONS = Map.of(
public JSONObject fixCustomBiome(IrisBiomeCustom biome, JSONObject json) { Dimension.OVERRWORLD, """
return json; {
"ambient_light": 0.0,
"bed_works": true,
"coordinate_scale": 1.0,
"effects": "minecraft:overworld",
"has_ceiling": false,
"has_raids": true,
"has_skylight": true,
"infiniburn": "#minecraft:infiniburn_overworld",
"monster_spawn_block_light_limit": 0,
"monster_spawn_light_level": {
"type": "minecraft:uniform",
"value": {
"max_inclusive": 7,
"min_inclusive": 0
} }
},
"natural": true,
"piglin_safe": false,
"respawn_anchor_works": false,
"ultrawarm": false
}""",
Dimension.NETHER, """
{
"ambient_light": 0.1,
"bed_works": false,
"coordinate_scale": 8.0,
"effects": "minecraft:the_nether",
"fixed_time": 18000,
"has_ceiling": true,
"has_raids": false,
"has_skylight": false,
"infiniburn": "#minecraft:infiniburn_nether",
"monster_spawn_block_light_limit": 15,
"monster_spawn_light_level": 7,
"natural": false,
"piglin_safe": true,
"respawn_anchor_works": true,
"ultrawarm": true
}""",
Dimension.THE_END, """
{
"ambient_light": 0.0,
"bed_works": false,
"coordinate_scale": 1.0,
"effects": "minecraft:the_end",
"fixed_time": 6000,
"has_ceiling": false,
"has_raids": true,
"has_skylight": false,
"infiniburn": "#minecraft:infiniburn_end",
"monster_spawn_block_light_limit": 0,
"monster_spawn_light_level": {
"type": "minecraft:uniform",
"value": {
"max_inclusive": 7,
"min_inclusive": 0
}
},
"natural": false,
"piglin_safe": false,
"respawn_anchor_works": false,
"ultrawarm": false
}"""
);
@Override @Override
public JSONObject fixDimension(JSONObject json) { public JSONObject rawDimension(Dimension dimension) {
return json; return new JSONObject(DIMENSIONS.get(dimension));
} }
} }

View File

@ -1,6 +1,6 @@
package com.volmit.iris.core.nms.datapack.v1206; package com.volmit.iris.core.nms.datapack.v1206;
import com.volmit.iris.core.nms.datapack.IDataFixer; import com.volmit.iris.core.nms.datapack.v1192.DataFixerV1192;
import com.volmit.iris.engine.object.IrisBiomeCustom; import com.volmit.iris.engine.object.IrisBiomeCustom;
import com.volmit.iris.engine.object.IrisBiomeCustomSpawn; import com.volmit.iris.engine.object.IrisBiomeCustomSpawn;
import com.volmit.iris.engine.object.IrisBiomeCustomSpawnType; import com.volmit.iris.engine.object.IrisBiomeCustomSpawnType;
@ -10,7 +10,7 @@ import com.volmit.iris.util.json.JSONObject;
import java.util.Locale; import java.util.Locale;
public class DataFixerV1206 implements IDataFixer { public class DataFixerV1206 extends DataFixerV1192 {
@Override @Override
public JSONObject fixCustomBiome(IrisBiomeCustom biome, JSONObject json) { public JSONObject fixCustomBiome(IrisBiomeCustom biome, JSONObject json) {
int spawnRarity = biome.getSpawnRarity(); int spawnRarity = biome.getSpawnRarity();
@ -45,7 +45,8 @@ public class DataFixerV1206 implements IDataFixer {
} }
@Override @Override
public JSONObject fixDimension(JSONObject json) { public JSONObject rawDimension(Dimension dimension) {
JSONObject json = super.rawDimension(dimension);
if (!(json.get("monster_spawn_light_level") instanceof JSONObject lightLevel)) if (!(json.get("monster_spawn_light_level") instanceof JSONObject lightLevel))
return json; return json;
var value = (JSONObject) lightLevel.remove("value"); var value = (JSONObject) lightLevel.remove("value");

View File

@ -21,14 +21,19 @@ package com.volmit.iris.core.tools;
import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.core.loader.IrisData;
import com.volmit.iris.engine.object.*; import com.volmit.iris.engine.object.*;
import com.volmit.iris.engine.platform.BukkitChunkGenerator; import com.volmit.iris.engine.platform.BukkitChunkGenerator;
import com.volmit.iris.util.reflect.WrappedField;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.WorldCreator; import org.bukkit.WorldCreator;
import org.bukkit.WorldType;
import org.bukkit.generator.ChunkGenerator; import org.bukkit.generator.ChunkGenerator;
import sun.misc.Unsafe;
import java.io.File; import java.io.File;
public class IrisWorldCreator { public class IrisWorldCreator {
public static final WorldType IRIS;
private String name; private String name;
private boolean studio = false; private boolean studio = false;
private String dimensionName = null; private String dimensionName = null;
@ -80,6 +85,7 @@ public class IrisWorldCreator {
return new WorldCreator(name) return new WorldCreator(name)
.type(IRIS)
.environment(findEnvironment()) .environment(findEnvironment())
.generateStructures(true) .generateStructures(true)
.generator(g).seed(seed); .generator(g).seed(seed);
@ -98,4 +104,17 @@ public class IrisWorldCreator {
this.studio = studio; this.studio = studio;
return this; return this;
} }
static {
try {
var unsafe = new WrappedField<Unsafe, Unsafe>(Unsafe.class, "theUnsafe").get();
var iris = (WorldType) unsafe.allocateInstance(WorldType.class);
unsafe.putIntVolatile(iris, unsafe.objectFieldOffset(Enum.class.getDeclaredField("ordinal")), 0);
unsafe.putObjectVolatile(iris, unsafe.objectFieldOffset(Enum.class.getDeclaredField("name")), "IRIS");
IRIS = iris;
} catch (Throwable e) {
throw new ExceptionInInitializerError(e);
}
}
} }

View File

@ -19,6 +19,7 @@
package com.volmit.iris.engine.object; package com.volmit.iris.engine.object;
import com.volmit.iris.Iris; import com.volmit.iris.Iris;
import com.volmit.iris.core.ServerConfigurator.DimensionHeight;
import com.volmit.iris.core.loader.IrisData; 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;
@ -54,73 +55,6 @@ import java.io.IOException;
public class IrisDimension extends IrisRegistrant { public class IrisDimension extends IrisRegistrant {
public static final BlockData STONE = Material.STONE.createBlockData(); public static final BlockData STONE = Material.STONE.createBlockData();
public static final BlockData WATER = Material.WATER.createBlockData(); public static final BlockData WATER = Material.WATER.createBlockData();
private static final String DP_OVERWORLD_DEFAULT = """
{
"ambient_light": 0.0,
"bed_works": true,
"coordinate_scale": 1.0,
"effects": "minecraft:overworld",
"has_ceiling": false,
"has_raids": true,
"has_skylight": true,
"infiniburn": "#minecraft:infiniburn_overworld",
"monster_spawn_block_light_limit": 0,
"monster_spawn_light_level": {
"type": "minecraft:uniform",
"value": {
"max_inclusive": 7,
"min_inclusive": 0
}
},
"natural": true,
"piglin_safe": false,
"respawn_anchor_works": false,
"ultrawarm": false
}""";
private static final String DP_NETHER_DEFAULT = """
{
"ambient_light": 0.1,
"bed_works": false,
"coordinate_scale": 8.0,
"effects": "minecraft:the_nether",
"fixed_time": 18000,
"has_ceiling": true,
"has_raids": false,
"has_skylight": false,
"infiniburn": "#minecraft:infiniburn_nether",
"monster_spawn_block_light_limit": 15,
"monster_spawn_light_level": 7,
"natural": false,
"piglin_safe": true,
"respawn_anchor_works": true,
"ultrawarm": true
}""";
private static final String DP_END_DEFAULT = """
{
"ambient_light": 0.0,
"bed_works": false,
"coordinate_scale": 1.0,
"effects": "minecraft:the_end",
"fixed_time": 6000,
"has_ceiling": false,
"has_raids": true,
"has_skylight": false,
"infiniburn": "#minecraft:infiniburn_end",
"monster_spawn_block_light_limit": 0,
"monster_spawn_light_level": {
"type": "minecraft:uniform",
"value": {
"max_inclusive": 7,
"min_inclusive": 0
}
},
"natural": false,
"piglin_safe": false,
"respawn_anchor_works": false,
"ultrawarm": false
}""";
private final transient AtomicCache<Position2> parallaxSize = new AtomicCache<>(); private final transient AtomicCache<Position2> parallaxSize = new AtomicCache<>();
private final transient AtomicCache<CNG> rockLayerGenerator = new AtomicCache<>(); private final transient AtomicCache<CNG> rockLayerGenerator = new AtomicCache<>();
private final transient AtomicCache<CNG> fluidLayerGenerator = new AtomicCache<>(); private final transient AtomicCache<CNG> fluidLayerGenerator = new AtomicCache<>();
@ -443,7 +377,7 @@ public class IrisDimension extends IrisRegistrant {
return landBiomeStyle; return landBiomeStyle;
} }
public boolean installDataPack(IDataFixer fixer, DataProvider data, File datapacks, double ultimateMaxHeight, double ultimateMinHeight) { public boolean installDataPack(IDataFixer fixer, DataProvider data, File datapacks, DimensionHeight height) {
boolean write = false; boolean write = false;
boolean changed = false; boolean changed = false;
@ -472,12 +406,11 @@ public class IrisDimension extends IrisRegistrant {
} }
} }
if (!dimensionHeight.equals(new IrisRange(-64, 320)) && this.name.equalsIgnoreCase("overworld")) { Iris.verbose(" Installing Data Pack Dimension Types: \"iris:overworld\", \"iris:the_nether\", \"iris:the_end\"");
Iris.verbose(" Installing Data Pack Dimension Types: \"minecraft:overworld\", \"minecraft:the_nether\", \"minecraft:the_end\""); changed = writeDimensionType(changed, datapacks, height);
dimensionHeight.setMax(ultimateMaxHeight);
dimensionHeight.setMin(ultimateMinHeight); Iris.verbose(" Installing Data Pack World Preset: \"minecraft:iris\"");
changed = writeDimensionType(fixer, changed, datapacks); changed = writeWorldPreset(changed, datapacks, fixer);
}
if (write) { if (write) {
File mcm = new File(datapacks, "iris/pack.mcmeta"); File mcm = new File(datapacks, "iris/pack.mcmeta");
@ -515,37 +448,37 @@ public class IrisDimension extends IrisRegistrant {
} }
public boolean writeDimensionType(IDataFixer fixer, boolean changed, File datapacks) { public boolean writeDimensionType(boolean changed, File datapacks, DimensionHeight height) {
File dimTypeOverworld = new File(datapacks, "iris/data/minecraft/dimension_type/overworld.json"); File dimTypeOverworld = new File(datapacks, "iris/data/iris/dimension_type/overworld.json");
if (!dimTypeOverworld.exists()) if (!dimTypeOverworld.exists())
changed = true; changed = true;
dimTypeOverworld.getParentFile().mkdirs(); dimTypeOverworld.getParentFile().mkdirs();
try { try {
IO.writeAll(dimTypeOverworld, generateDatapackJsonOverworld(fixer)); IO.writeAll(dimTypeOverworld, height.overworldType());
} catch (IOException e) { } catch (IOException e) {
Iris.reportError(e); Iris.reportError(e);
e.printStackTrace(); e.printStackTrace();
} }
File dimTypeNether = new File(datapacks, "iris/data/minecraft/dimension_type/the_nether.json"); File dimTypeNether = new File(datapacks, "iris/data/iris/dimension_type/the_nether.json");
if (!dimTypeNether.exists()) if (!dimTypeNether.exists())
changed = true; changed = true;
dimTypeNether.getParentFile().mkdirs(); dimTypeNether.getParentFile().mkdirs();
try { try {
IO.writeAll(dimTypeNether, generateDatapackJsonNether(fixer)); IO.writeAll(dimTypeNether, height.netherType());
} catch (IOException e) { } catch (IOException e) {
Iris.reportError(e); Iris.reportError(e);
e.printStackTrace(); e.printStackTrace();
} }
File dimTypeEnd = new File(datapacks, "iris/data/minecraft/dimension_type/the_end.json"); File dimTypeEnd = new File(datapacks, "iris/data/iris/dimension_type/the_end.json");
if (!dimTypeEnd.exists()) if (!dimTypeEnd.exists())
changed = true; changed = true;
dimTypeEnd.getParentFile().mkdirs(); dimTypeEnd.getParentFile().mkdirs();
try { try {
IO.writeAll(dimTypeEnd, generateDatapackJsonEnd(fixer)); IO.writeAll(dimTypeEnd, height.endType());
} catch (IOException e) { } catch (IOException e) {
Iris.reportError(e); Iris.reportError(e);
e.printStackTrace(); e.printStackTrace();
@ -554,27 +487,17 @@ public class IrisDimension extends IrisRegistrant {
return changed; return changed;
} }
private String generateDatapackJsonOverworld(IDataFixer fixer) { public boolean writeWorldPreset(boolean changed, File datapacks, IDataFixer fixer) {
JSONObject obj = new JSONObject(DP_OVERWORLD_DEFAULT); File worldPreset = new File(datapacks, "iris/data/minecraft/worldgen/world_preset/iris.json");
obj.put("min_y", dimensionHeight.getMin()); if (!worldPreset.exists())
obj.put("height", dimensionHeight.getMax() - dimensionHeight.getMin()); changed = true;
obj.put("logical_height", logicalHeight); try {
return fixer.fixDimension(obj).toString(4); IO.writeAll(worldPreset, fixer.createPreset());
} catch (IOException e) {
Iris.reportError(e);
e.printStackTrace();
} }
private String generateDatapackJsonNether(IDataFixer fixer) { return changed;
JSONObject obj = new JSONObject(DP_NETHER_DEFAULT);
obj.put("min_y", dimensionHeightNether.getMin());
obj.put("height", dimensionHeightNether.getMax() - dimensionHeightNether.getMin());
obj.put("logical_height", logicalHeightNether);
return fixer.fixDimension(obj).toString(4);
}
private String generateDatapackJsonEnd(IDataFixer fixer) {
JSONObject obj = new JSONObject(DP_END_DEFAULT);
obj.put("min_y", dimensionHeightEnd.getMin());
obj.put("height", dimensionHeightEnd.getMax() - dimensionHeightEnd.getMin());
obj.put("logical_height", logicalHeightEnd);
return fixer.fixDimension(obj).toString(4);
} }
} }

View File

@ -50,4 +50,10 @@ public class IrisRange {
public boolean contains(int v) { public boolean contains(int v) {
return v >= min && v <= max; return v >= min && v <= max;
} }
public IrisRange merge(IrisRange other) {
min = Math.min(min, other.min);
max = Math.max(max, other.max);
return this;
}
} }