mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-01 23:47:21 +00:00
add datapack upgrade command
This commit is contained in:
parent
8345a58f2b
commit
52ec80d384
@ -21,6 +21,8 @@ package com.volmit.iris.core;
|
|||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.core.loader.IrisData;
|
import com.volmit.iris.core.loader.IrisData;
|
||||||
import com.volmit.iris.core.nms.INMS;
|
import com.volmit.iris.core.nms.INMS;
|
||||||
|
import com.volmit.iris.core.nms.datapack.DataVersion;
|
||||||
|
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;
|
||||||
@ -91,8 +93,11 @@ public class ServerConfigurator {
|
|||||||
return worlds;
|
return worlds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void installDataPacks(boolean fullInstall) {
|
public static void installDataPacks(boolean fullInstall) {
|
||||||
|
installDataPacks(DataVersion.getDefault(), 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");
|
File packs = new File("plugins/Iris/packs");
|
||||||
double ultimateMaxHeight = 0;
|
double ultimateMaxHeight = 0;
|
||||||
@ -137,7 +142,7 @@ public class ServerConfigurator {
|
|||||||
|
|
||||||
Iris.verbose(" Checking Dimension " + dim.getLoadFile().getPath());
|
Iris.verbose(" Checking Dimension " + dim.getLoadFile().getPath());
|
||||||
for (File dpack : getDatapacksFolder()) {
|
for (File dpack : getDatapacksFolder()) {
|
||||||
dim.installDataPack(() -> data, dpack, ultimateMaxHeight, ultimateMinHeight);
|
dim.installDataPack(fixer, () -> data, dpack, ultimateMaxHeight, ultimateMinHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,9 @@ package com.volmit.iris.core.commands;
|
|||||||
|
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.core.IrisSettings;
|
import com.volmit.iris.core.IrisSettings;
|
||||||
|
import com.volmit.iris.core.ServerConfigurator;
|
||||||
import com.volmit.iris.core.loader.IrisData;
|
import com.volmit.iris.core.loader.IrisData;
|
||||||
|
import com.volmit.iris.core.nms.datapack.DataVersion;
|
||||||
import com.volmit.iris.core.pregenerator.ChunkUpdater;
|
import com.volmit.iris.core.pregenerator.ChunkUpdater;
|
||||||
import com.volmit.iris.core.service.StudioSVC;
|
import com.volmit.iris.core.service.StudioSVC;
|
||||||
import com.volmit.iris.core.tools.IrisBenchmarking;
|
import com.volmit.iris.core.tools.IrisBenchmarking;
|
||||||
@ -427,6 +429,15 @@ public class CommandIris implements DecreeExecutor {
|
|||||||
sender().sendMessage(C.GREEN + "Hotloaded settings");
|
sender().sendMessage(C.GREEN + "Hotloaded settings");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Decree(description = "Upgrade to another Minecraft version")
|
||||||
|
public void upgrade(
|
||||||
|
@Param(description = "The version to upgrade to", defaultValue = "latest")
|
||||||
|
DataVersion version) {
|
||||||
|
sender().sendMessage(C.GREEN + "Upgrading to " + version.getVersion() + "...");
|
||||||
|
ServerConfigurator.installDataPacks(version.get(), false);
|
||||||
|
sender().sendMessage(C.GREEN + "Done upgrading! You can now update your server version to " + version.getVersion());
|
||||||
|
}
|
||||||
|
|
||||||
@Decree(description = "Update the pack of a world (UNSAFE!)", name = "^world", aliases = "update-world")
|
@Decree(description = "Update the pack of a world (UNSAFE!)", name = "^world", aliases = "update-world")
|
||||||
public void updateWorld(
|
public void updateWorld(
|
||||||
@Param(description = "The world to update", contextual = true)
|
@Param(description = "The world to update", contextual = true)
|
||||||
|
@ -18,11 +18,10 @@
|
|||||||
|
|
||||||
package com.volmit.iris.core.nms;
|
package com.volmit.iris.core.nms;
|
||||||
|
|
||||||
|
import com.volmit.iris.core.nms.datapack.DataVersion;
|
||||||
import com.volmit.iris.engine.framework.Engine;
|
import com.volmit.iris.engine.framework.Engine;
|
||||||
import com.volmit.iris.engine.object.IrisBiomeCustom;
|
|
||||||
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.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.nbt.mca.palette.MCABiomeContainer;
|
import com.volmit.iris.util.nbt.mca.palette.MCABiomeContainer;
|
||||||
@ -113,11 +112,7 @@ public interface INMSBinding {
|
|||||||
|
|
||||||
Entity spawnEntity(Location location, EntityType type, CreatureSpawnEvent.SpawnReason reason);
|
Entity spawnEntity(Location location, EntityType type, CreatureSpawnEvent.SpawnReason reason);
|
||||||
|
|
||||||
default JSONObject fixCustomBiome(IrisBiomeCustom biome, JSONObject json) {
|
default DataVersion getDataVersion() {
|
||||||
return json;
|
return DataVersion.V1192;
|
||||||
}
|
|
||||||
|
|
||||||
default JSONObject fixDimension(JSONObject json) {
|
|
||||||
return json;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,40 @@
|
|||||||
|
package com.volmit.iris.core.nms.datapack;
|
||||||
|
|
||||||
|
import com.volmit.iris.core.nms.INMS;
|
||||||
|
import com.volmit.iris.core.nms.datapack.v1192.DataFixerV1192;
|
||||||
|
import com.volmit.iris.core.nms.datapack.v1206.DataFixerV1206;
|
||||||
|
import com.volmit.iris.util.collection.KMap;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
//https://minecraft.wiki/w/Pack_format
|
||||||
|
@Getter
|
||||||
|
public enum DataVersion {
|
||||||
|
V1192("1.19.2", 10, DataFixerV1192::new),
|
||||||
|
V1205("1.20.6", 41, DataFixerV1206::new);
|
||||||
|
private static final KMap<DataVersion, IDataFixer> cache = new KMap<>();
|
||||||
|
@Getter(AccessLevel.NONE)
|
||||||
|
private final Supplier<IDataFixer> constructor;
|
||||||
|
private final String version;
|
||||||
|
private final int packFormat;
|
||||||
|
|
||||||
|
DataVersion(String version, int packFormat, Supplier<IDataFixer> constructor) {
|
||||||
|
this.constructor = constructor;
|
||||||
|
this.packFormat = packFormat;
|
||||||
|
this.version = version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IDataFixer get() {
|
||||||
|
return cache.computeIfAbsent(this, k -> constructor.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IDataFixer getDefault() {
|
||||||
|
return INMS.get().getDataVersion().get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DataVersion getLatest() {
|
||||||
|
return values()[values().length - 1];
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.volmit.iris.core.nms.datapack;
|
||||||
|
|
||||||
|
import com.volmit.iris.engine.object.IrisBiomeCustom;
|
||||||
|
import com.volmit.iris.util.json.JSONObject;
|
||||||
|
|
||||||
|
public interface IDataFixer {
|
||||||
|
|
||||||
|
JSONObject fixCustomBiome(IrisBiomeCustom biome, JSONObject json);
|
||||||
|
|
||||||
|
JSONObject fixDimension(JSONObject json);
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.volmit.iris.core.nms.datapack.v1192;
|
||||||
|
|
||||||
|
import com.volmit.iris.core.nms.datapack.IDataFixer;
|
||||||
|
import com.volmit.iris.engine.object.IrisBiomeCustom;
|
||||||
|
import com.volmit.iris.util.json.JSONObject;
|
||||||
|
|
||||||
|
public class DataFixerV1192 implements IDataFixer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject fixCustomBiome(IrisBiomeCustom biome, JSONObject json) {
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject fixDimension(JSONObject json) {
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
package com.volmit.iris.core.nms.datapack.v1206;
|
||||||
|
|
||||||
|
import com.volmit.iris.core.nms.datapack.IDataFixer;
|
||||||
|
import com.volmit.iris.engine.object.IrisBiomeCustom;
|
||||||
|
import com.volmit.iris.engine.object.IrisBiomeCustomSpawn;
|
||||||
|
import com.volmit.iris.engine.object.IrisBiomeCustomSpawnType;
|
||||||
|
import com.volmit.iris.util.collection.KMap;
|
||||||
|
import com.volmit.iris.util.json.JSONArray;
|
||||||
|
import com.volmit.iris.util.json.JSONObject;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public class DataFixerV1206 implements IDataFixer {
|
||||||
|
@Override
|
||||||
|
public JSONObject fixCustomBiome(IrisBiomeCustom biome, JSONObject json) {
|
||||||
|
int spawnRarity = biome.getSpawnRarity();
|
||||||
|
if (spawnRarity > 0) {
|
||||||
|
json.put("creature_spawn_probability", Math.min(spawnRarity/20d, 0.9999999));
|
||||||
|
}
|
||||||
|
|
||||||
|
var spawns = biome.getSpawns();
|
||||||
|
if (spawns != null && spawns.isNotEmpty()) {
|
||||||
|
JSONObject spawners = new JSONObject();
|
||||||
|
KMap<IrisBiomeCustomSpawnType, JSONArray> groups = new KMap<>();
|
||||||
|
|
||||||
|
for (IrisBiomeCustomSpawn i : spawns) {
|
||||||
|
JSONArray g = groups.computeIfAbsent(i.getGroup(), (k) -> new JSONArray());
|
||||||
|
JSONObject o = new JSONObject();
|
||||||
|
o.put("type", "minecraft:" + i.getType().name().toLowerCase());
|
||||||
|
o.put("weight", i.getWeight());
|
||||||
|
o.put("minCount", Math.min(i.getMinCount()/20d, 0));
|
||||||
|
o.put("maxCount", Math.min(i.getMaxCount()/20d, 0.9999999));
|
||||||
|
g.put(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (IrisBiomeCustomSpawnType i : groups.k()) {
|
||||||
|
spawners.put(i.name().toLowerCase(Locale.ROOT), groups.get(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
json.put("spawners", spawners);
|
||||||
|
}
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject fixDimension(JSONObject json) {
|
||||||
|
if (!(json.get("monster_spawn_light_level") instanceof JSONObject lightLevel))
|
||||||
|
return json;
|
||||||
|
var value = (JSONObject) lightLevel.remove("value");
|
||||||
|
lightLevel.put("max_inclusive", value.get("max_inclusive"));
|
||||||
|
lightLevel.put("min_inclusive", value.get("min_inclusive"));
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
}
|
@ -37,7 +37,7 @@ public class UtilsSFG {
|
|||||||
}
|
}
|
||||||
if (ServerBootSFG.unsuportedversion) {
|
if (ServerBootSFG.unsuportedversion) {
|
||||||
Iris.safeguard(C.RED + "Server Version");
|
Iris.safeguard(C.RED + "Server Version");
|
||||||
Iris.safeguard(C.RED + "- Iris only supports 1.19.2 > 1.20.4");
|
Iris.safeguard(C.RED + "- Iris only supports 1.19.2 > 1.20.6");
|
||||||
}
|
}
|
||||||
if (!ServerBootSFG.passedserversoftware) {
|
if (!ServerBootSFG.passedserversoftware) {
|
||||||
Iris.safeguard(C.YELLOW + "Unsupported Server Software");
|
Iris.safeguard(C.YELLOW + "Unsupported Server Software");
|
||||||
|
@ -19,7 +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.nms.INMS;
|
import com.volmit.iris.core.nms.datapack.IDataFixer;
|
||||||
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.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
@ -92,7 +92,7 @@ public class IrisBiomeCustom {
|
|||||||
@Desc("The color of foliage (hex format). Leave blank / don't define to not change")
|
@Desc("The color of foliage (hex format). Leave blank / don't define to not change")
|
||||||
private String foliageColor = "";
|
private String foliageColor = "";
|
||||||
|
|
||||||
public String generateJson() {
|
public String generateJson(IDataFixer fixer) {
|
||||||
JSONObject effects = new JSONObject();
|
JSONObject effects = new JSONObject();
|
||||||
effects.put("sky_color", parseColor(getSkyColor()));
|
effects.put("sky_color", parseColor(getSkyColor()));
|
||||||
effects.put("fog_color", parseColor(getFogColor()));
|
effects.put("fog_color", parseColor(getFogColor()));
|
||||||
@ -158,7 +158,7 @@ public class IrisBiomeCustom {
|
|||||||
j.put("spawners", spawners);
|
j.put("spawners", spawners);
|
||||||
}
|
}
|
||||||
|
|
||||||
return INMS.get().fixCustomBiome(this, j).toString(4);
|
return fixer.fixCustomBiome(this, j).toString(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int parseColor(String c) {
|
private int parseColor(String c) {
|
||||||
|
@ -19,16 +19,13 @@
|
|||||||
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.IrisSettings;
|
|
||||||
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.datapack.IDataFixer;
|
||||||
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.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.data.DataProvider;
|
import com.volmit.iris.util.data.DataProvider;
|
||||||
import com.volmit.iris.util.data.Dimension;
|
|
||||||
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;
|
||||||
@ -44,7 +41,6 @@ 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.DataInput;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@ -448,7 +444,7 @@ public class IrisDimension extends IrisRegistrant {
|
|||||||
return landBiomeStyle;
|
return landBiomeStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean installDataPack(DataProvider data, File datapacks, double ultimateMaxHeight, double ultimateMinHeight) {
|
public boolean installDataPack(IDataFixer fixer, DataProvider data, File datapacks, double ultimateMaxHeight, double ultimateMinHeight) {
|
||||||
boolean write = false;
|
boolean write = false;
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
|
|
||||||
@ -468,7 +464,7 @@ public class IrisDimension extends IrisRegistrant {
|
|||||||
Iris.verbose(" Installing Data Pack Biome: " + output.getPath());
|
Iris.verbose(" Installing Data Pack Biome: " + output.getPath());
|
||||||
output.getParentFile().mkdirs();
|
output.getParentFile().mkdirs();
|
||||||
try {
|
try {
|
||||||
IO.writeAll(output, j.generateJson());
|
IO.writeAll(output, j.generateJson(fixer));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Iris.reportError(e);
|
Iris.reportError(e);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -481,7 +477,7 @@ public class IrisDimension extends IrisRegistrant {
|
|||||||
Iris.verbose(" Installing Data Pack Dimension Types: \"minecraft:overworld\", \"minecraft:the_nether\", \"minecraft:the_end\"");
|
Iris.verbose(" Installing Data Pack Dimension Types: \"minecraft:overworld\", \"minecraft:the_nether\", \"minecraft:the_end\"");
|
||||||
dimensionHeight.setMax(ultimateMaxHeight);
|
dimensionHeight.setMax(ultimateMaxHeight);
|
||||||
dimensionHeight.setMin(ultimateMinHeight);
|
dimensionHeight.setMin(ultimateMinHeight);
|
||||||
changed = writeDimensionType(changed, datapacks);
|
changed = writeDimensionType(fixer, changed, datapacks);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (write) {
|
if (write) {
|
||||||
@ -520,13 +516,13 @@ public class IrisDimension extends IrisRegistrant {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean writeDimensionType(boolean changed, File datapacks) {
|
public boolean writeDimensionType(IDataFixer fixer, boolean changed, File datapacks) {
|
||||||
File dimTypeOverworld = new File(datapacks, "iris/data/minecraft/dimension_type/overworld.json");
|
File dimTypeOverworld = new File(datapacks, "iris/data/minecraft/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());
|
IO.writeAll(dimTypeOverworld, generateDatapackJsonOverworld(fixer));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Iris.reportError(e);
|
Iris.reportError(e);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -538,7 +534,7 @@ public class IrisDimension extends IrisRegistrant {
|
|||||||
changed = true;
|
changed = true;
|
||||||
dimTypeNether.getParentFile().mkdirs();
|
dimTypeNether.getParentFile().mkdirs();
|
||||||
try {
|
try {
|
||||||
IO.writeAll(dimTypeNether, generateDatapackJsonNether());
|
IO.writeAll(dimTypeNether, generateDatapackJsonNether(fixer));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Iris.reportError(e);
|
Iris.reportError(e);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -550,7 +546,7 @@ public class IrisDimension extends IrisRegistrant {
|
|||||||
changed = true;
|
changed = true;
|
||||||
dimTypeEnd.getParentFile().mkdirs();
|
dimTypeEnd.getParentFile().mkdirs();
|
||||||
try {
|
try {
|
||||||
IO.writeAll(dimTypeEnd, generateDatapackJsonEnd());
|
IO.writeAll(dimTypeEnd, generateDatapackJsonEnd(fixer));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Iris.reportError(e);
|
Iris.reportError(e);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -559,27 +555,27 @@ public class IrisDimension extends IrisRegistrant {
|
|||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String generateDatapackJsonOverworld() {
|
private String generateDatapackJsonOverworld(IDataFixer fixer) {
|
||||||
JSONObject obj = new JSONObject(DP_OVERWORLD_DEFAULT);
|
JSONObject obj = new JSONObject(DP_OVERWORLD_DEFAULT);
|
||||||
obj.put("min_y", dimensionHeight.getMin());
|
obj.put("min_y", dimensionHeight.getMin());
|
||||||
obj.put("height", dimensionHeight.getMax() - dimensionHeight.getMin());
|
obj.put("height", dimensionHeight.getMax() - dimensionHeight.getMin());
|
||||||
obj.put("logical_height", logicalHeight);
|
obj.put("logical_height", logicalHeight);
|
||||||
return INMS.get().fixDimension(obj).toString(4);
|
return fixer.fixDimension(obj).toString(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String generateDatapackJsonNether() {
|
private String generateDatapackJsonNether(IDataFixer fixer) {
|
||||||
JSONObject obj = new JSONObject(DP_NETHER_DEFAULT);
|
JSONObject obj = new JSONObject(DP_NETHER_DEFAULT);
|
||||||
obj.put("min_y", dimensionHeightNether.getMin());
|
obj.put("min_y", dimensionHeightNether.getMin());
|
||||||
obj.put("height", dimensionHeightNether.getMax() - dimensionHeightNether.getMin());
|
obj.put("height", dimensionHeightNether.getMax() - dimensionHeightNether.getMin());
|
||||||
obj.put("logical_height", logicalHeightNether);
|
obj.put("logical_height", logicalHeightNether);
|
||||||
return INMS.get().fixDimension(obj).toString(4);
|
return fixer.fixDimension(obj).toString(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String generateDatapackJsonEnd() {
|
private String generateDatapackJsonEnd(IDataFixer fixer) {
|
||||||
JSONObject obj = new JSONObject(DP_END_DEFAULT);
|
JSONObject obj = new JSONObject(DP_END_DEFAULT);
|
||||||
obj.put("min_y", dimensionHeightEnd.getMin());
|
obj.put("min_y", dimensionHeightEnd.getMin());
|
||||||
obj.put("height", dimensionHeightEnd.getMax() - dimensionHeightEnd.getMin());
|
obj.put("height", dimensionHeightEnd.getMax() - dimensionHeightEnd.getMin());
|
||||||
obj.put("logical_height", logicalHeightEnd);
|
obj.put("logical_height", logicalHeightEnd);
|
||||||
return INMS.get().fixDimension(obj).toString(4);
|
return fixer.fixDimension(obj).toString(4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
package com.volmit.iris.util.decree.handlers;
|
||||||
|
|
||||||
|
import com.volmit.iris.core.nms.datapack.DataVersion;
|
||||||
|
import com.volmit.iris.util.collection.KList;
|
||||||
|
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
||||||
|
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||||
|
|
||||||
|
public class DataVersionHandler implements DecreeParameterHandler<DataVersion> {
|
||||||
|
@Override
|
||||||
|
public KList<DataVersion> getPossibilities() {
|
||||||
|
return new KList<>(DataVersion.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(DataVersion version) {
|
||||||
|
return version.getVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DataVersion parse(String in, boolean force) throws DecreeParsingException {
|
||||||
|
if (in.equalsIgnoreCase("latest")) {
|
||||||
|
return DataVersion.getLatest();
|
||||||
|
}
|
||||||
|
for (DataVersion v : DataVersion.values()) {
|
||||||
|
if (v.getVersion().equalsIgnoreCase(in)) {
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new DecreeParsingException("Unable to parse data version \"" + in + "\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supports(Class<?> type) {
|
||||||
|
return DataVersion.class.equals(type);
|
||||||
|
}
|
||||||
|
}
|
@ -9,14 +9,10 @@ import java.lang.reflect.Method;
|
|||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import com.volmit.iris.engine.object.IrisBiomeCustom;
|
import com.volmit.iris.core.nms.datapack.DataVersion;
|
||||||
import com.volmit.iris.engine.object.IrisBiomeCustomSpawn;
|
|
||||||
import com.volmit.iris.engine.object.IrisBiomeCustomSpawnType;
|
|
||||||
import com.volmit.iris.util.json.JSONArray;
|
|
||||||
import net.minecraft.core.component.DataComponents;
|
import net.minecraft.core.component.DataComponents;
|
||||||
import net.minecraft.world.item.component.CustomData;
|
import net.minecraft.world.item.component.CustomData;
|
||||||
import net.minecraft.world.level.chunk.status.ChunkStatus;
|
import net.minecraft.world.level.chunk.status.ChunkStatus;
|
||||||
@ -528,47 +524,6 @@ public class NMSBinding implements INMSBinding {
|
|||||||
return ((CraftWorld) location.getWorld()).spawn(location, type.getEntityClass(), null, reason);
|
return ((CraftWorld) location.getWorld()).spawn(location, type.getEntityClass(), null, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public JSONObject fixCustomBiome(IrisBiomeCustom biome, JSONObject json) {
|
|
||||||
int spawnRarity = biome.getSpawnRarity();
|
|
||||||
if (spawnRarity > 0) {
|
|
||||||
json.put("creature_spawn_probability", Math.min(spawnRarity/20d, 0.9999999));
|
|
||||||
}
|
|
||||||
|
|
||||||
var spawns = biome.getSpawns();
|
|
||||||
if (spawns != null && spawns.isNotEmpty()) {
|
|
||||||
JSONObject spawners = new JSONObject();
|
|
||||||
KMap<IrisBiomeCustomSpawnType, JSONArray> groups = new KMap<>();
|
|
||||||
|
|
||||||
for (IrisBiomeCustomSpawn i : spawns) {
|
|
||||||
JSONArray g = groups.computeIfAbsent(i.getGroup(), (k) -> new JSONArray());
|
|
||||||
JSONObject o = new JSONObject();
|
|
||||||
o.put("type", "minecraft:" + i.getType().name().toLowerCase());
|
|
||||||
o.put("weight", i.getWeight());
|
|
||||||
o.put("minCount", Math.min(i.getMinCount()/20d, 0));
|
|
||||||
o.put("maxCount", Math.min(i.getMaxCount()/20d, 0.9999999));
|
|
||||||
g.put(o);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (IrisBiomeCustomSpawnType i : groups.k()) {
|
|
||||||
spawners.put(i.name().toLowerCase(Locale.ROOT), groups.get(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
json.put("spawners", spawners);
|
|
||||||
}
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JSONObject fixDimension(JSONObject json) {
|
|
||||||
if (!(json.get("monster_spawn_light_level") instanceof JSONObject lightLevel))
|
|
||||||
return json;
|
|
||||||
var value = (JSONObject) lightLevel.remove("value");
|
|
||||||
lightLevel.put("max_inclusive", value.get("max_inclusive"));
|
|
||||||
lightLevel.put("min_inclusive", value.get("min_inclusive"));
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Field getField(Class<?> clazz, Class<?> fieldType) throws NoSuchFieldException {
|
private static Field getField(Class<?> clazz, Class<?> fieldType) throws NoSuchFieldException {
|
||||||
try {
|
try {
|
||||||
for (Field f : clazz.getDeclaredFields()) {
|
for (Field f : clazz.getDeclaredFields()) {
|
||||||
@ -589,4 +544,9 @@ public class NMSBinding implements INMSBinding {
|
|||||||
public static Holder<net.minecraft.world.level.biome.Biome> biomeToBiomeBase(Registry<net.minecraft.world.level.biome.Biome> registry, Biome biome) {
|
public static Holder<net.minecraft.world.level.biome.Biome> biomeToBiomeBase(Registry<net.minecraft.world.level.biome.Biome> registry, Biome biome) {
|
||||||
return registry.getHolderOrThrow(ResourceKey.create(Registries.BIOME, CraftNamespacedKey.toMinecraft(biome.getKey())));
|
return registry.getHolderOrThrow(ResourceKey.create(Registries.BIOME, CraftNamespacedKey.toMinecraft(biome.getKey())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DataVersion getDataVersion() {
|
||||||
|
return DataVersion.V1205;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user