mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-04-22 16:09:16 +00:00
add dummy datapack + fix world creation
This commit is contained in:
@@ -469,6 +469,7 @@ public class Iris extends VolmitPlugin implements Listener {
|
|||||||
IrisSafeguard.instance.IrisSafeguardSystem();
|
IrisSafeguard.instance.IrisSafeguardSystem();
|
||||||
getSender().setTag(getTag());
|
getSender().setTag(getTag());
|
||||||
INMS.get().injectBukkit();
|
INMS.get().injectBukkit();
|
||||||
|
ServerConfigurator.disableDataPack();
|
||||||
if (IrisSafeguard.instance.unstablemode && !IrisSafeguard.instance.acceptUnstable) IrisSafeguard.instance.earlySplash();
|
if (IrisSafeguard.instance.unstablemode && !IrisSafeguard.instance.acceptUnstable) IrisSafeguard.instance.earlySplash();
|
||||||
compat = IrisCompat.configured(getDataFile("compat.json"));
|
compat = IrisCompat.configured(getDataFile("compat.json"));
|
||||||
linkMultiverseCore = new MultiverseCoreLink();
|
linkMultiverseCore = new MultiverseCoreLink();
|
||||||
|
|||||||
@@ -19,13 +19,18 @@
|
|||||||
package com.volmit.iris.core;
|
package com.volmit.iris.core;
|
||||||
|
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
|
import com.volmit.iris.core.nms.INMS;
|
||||||
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.scheduling.J;
|
import com.volmit.iris.util.scheduling.J;
|
||||||
|
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;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Properties;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class ServerConfigurator {
|
public class ServerConfigurator {
|
||||||
@@ -67,4 +72,42 @@ public class ServerConfigurator {
|
|||||||
f.save(spigotConfig);
|
f.save(spigotConfig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static KList<File> getDataPacksFolder() {
|
||||||
|
if (!IrisSettings.get().getGeneral().forceMainWorld.isEmpty()) {
|
||||||
|
return new KList<File>().qadd(new File(Bukkit.getWorldContainer(), IrisSettings.get().getGeneral().forceMainWorld + "/datapacks"));
|
||||||
|
}
|
||||||
|
KList<File> worlds = new KList<>();
|
||||||
|
Bukkit.getServer().getWorlds().forEach(w -> worlds.add(new File(w.getWorldFolder(), "datapacks")));
|
||||||
|
if (worlds.isEmpty()) {
|
||||||
|
worlds.add(new File(getMainWorldFolder(), "datapacks"));
|
||||||
|
}
|
||||||
|
return worlds;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static File getMainWorldFolder() {
|
||||||
|
try {
|
||||||
|
Properties prop = new Properties();
|
||||||
|
prop.load(new FileInputStream("server.properties"));
|
||||||
|
String world = prop.getProperty("level-name", "world");
|
||||||
|
return new File(Bukkit.getWorldContainer(), world);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void dumpDataPack() {
|
||||||
|
if (!INMS.get().dumpRegistry(getDataPacksFolder().toArray(File[]::new)))
|
||||||
|
return;
|
||||||
|
disableDataPack();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void disableDataPack() {
|
||||||
|
var packs = INMS.get().getPackRepository();
|
||||||
|
packs.reload();
|
||||||
|
if (!packs.removePack("file/iris"))
|
||||||
|
return;
|
||||||
|
packs.reloadWorldData();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
package com.volmit.iris.core.nms;
|
package com.volmit.iris.core.nms;
|
||||||
|
|
||||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||||
|
import com.volmit.iris.core.nms.container.IPackRepository;
|
||||||
import com.volmit.iris.core.nms.datapack.DataVersion;
|
import com.volmit.iris.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.engine.object.IrisBiomeCustom;
|
||||||
@@ -43,6 +44,7 @@ import org.bukkit.generator.ChunkGenerator;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
public interface INMSBinding {
|
public interface INMSBinding {
|
||||||
boolean hasTile(Location l);
|
boolean hasTile(Location l);
|
||||||
@@ -127,9 +129,17 @@ public interface INMSBinding {
|
|||||||
|
|
||||||
boolean registerBiome(String dimensionId, IrisBiomeCustom biome, boolean replace);
|
boolean registerBiome(String dimensionId, IrisBiomeCustom biome, boolean replace);
|
||||||
|
|
||||||
|
boolean dumpRegistry(File... folders);
|
||||||
|
|
||||||
void injectBukkit();
|
void injectBukkit();
|
||||||
|
|
||||||
default IHeadless createHeadless(Engine engine) {
|
default IHeadless createHeadless(Engine engine) {
|
||||||
throw new IllegalStateException("Headless mode not supported");
|
throw new IllegalStateException("Headless mode not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default int getSpawnChunkCount(World world) {
|
||||||
|
return 441;
|
||||||
|
}
|
||||||
|
|
||||||
|
IPackRepository getPackRepository();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.volmit.iris.core.nms.container;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public interface IPackRepository {
|
||||||
|
void reload();
|
||||||
|
void reloadWorldData();
|
||||||
|
void setSelected(Collection<String> packs);
|
||||||
|
boolean addPack(String packId);
|
||||||
|
boolean removePack(String packId);
|
||||||
|
Collection<String> getAvailableIds();
|
||||||
|
Collection<String> getSelectedIds();
|
||||||
|
boolean isAvailable(String packId);
|
||||||
|
}
|
||||||
@@ -23,6 +23,7 @@ import com.volmit.iris.Iris;
|
|||||||
import com.volmit.iris.core.nms.INMSBinding;
|
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.core.nms.container.BlockPos;
|
import com.volmit.iris.core.nms.container.BlockPos;
|
||||||
|
import com.volmit.iris.core.nms.container.IPackRepository;
|
||||||
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.engine.object.IrisBiomeCustom;
|
||||||
import com.volmit.iris.engine.object.IrisDimension;
|
import com.volmit.iris.engine.object.IrisDimension;
|
||||||
@@ -121,6 +122,11 @@ public class NMSBinding1X implements INMSBinding {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean dumpRegistry(File... folders) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Color getBiomeColor(Location location, BiomeColor type) {
|
public Color getBiomeColor(Location location, BiomeColor type) {
|
||||||
return Color.GREEN;
|
return Color.GREEN;
|
||||||
@@ -272,6 +278,11 @@ public class NMSBinding1X implements INMSBinding {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPackRepository getPackRepository() {
|
||||||
|
return new PackRepository1X();
|
||||||
|
}
|
||||||
|
|
||||||
private static class WorldCreatorAdvice {
|
private static class WorldCreatorAdvice {
|
||||||
@Advice.OnMethodEnter
|
@Advice.OnMethodEnter
|
||||||
static void enter(@Advice.Argument(0) String name) {
|
static void enter(@Advice.Argument(0) String name) {
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package com.volmit.iris.core.nms.v1X;
|
||||||
|
|
||||||
|
import com.volmit.iris.core.nms.container.IPackRepository;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
class PackRepository1X implements IPackRepository {
|
||||||
|
@Override
|
||||||
|
public void reload() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reloadWorldData() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSelected(Collection<String> packs) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addPack(String packId) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removePack(String packId) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getAvailableIds() {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getSelectedIds() {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable(String packId) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,6 +21,7 @@ package com.volmit.iris.core.tools;
|
|||||||
import com.google.common.util.concurrent.AtomicDouble;
|
import com.google.common.util.concurrent.AtomicDouble;
|
||||||
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.nms.INMS;
|
||||||
import com.volmit.iris.core.pregenerator.PregenTask;
|
import com.volmit.iris.core.pregenerator.PregenTask;
|
||||||
import com.volmit.iris.core.service.StudioSVC;
|
import com.volmit.iris.core.service.StudioSVC;
|
||||||
import com.volmit.iris.engine.object.IrisDimension;
|
import com.volmit.iris.engine.object.IrisDimension;
|
||||||
@@ -147,7 +148,6 @@ public class IrisCreator {
|
|||||||
|
|
||||||
J.a(() ->
|
J.a(() ->
|
||||||
{
|
{
|
||||||
int req = 441;
|
|
||||||
Supplier<Integer> g = () -> {
|
Supplier<Integer> g = () -> {
|
||||||
if (finalAccess1 == null || finalAccess1.getEngine() == null) {
|
if (finalAccess1 == null || finalAccess1.getEngine() == null) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -155,6 +155,9 @@ public class IrisCreator {
|
|||||||
return finalAccess1.getEngine().getGenerated();
|
return finalAccess1.getEngine().getGenerated();
|
||||||
};
|
};
|
||||||
if(!benchmark) {
|
if(!benchmark) {
|
||||||
|
if (finalAccess1 == null) return;
|
||||||
|
int req = finalAccess1.getSpawnChunks().join();
|
||||||
|
|
||||||
while (g.get() < req) {
|
while (g.get() < req) {
|
||||||
double v = (double) g.get() / (double) req;
|
double v = (double) g.get() / (double) req;
|
||||||
if (sender.isPlayer()) {
|
if (sender.isPlayer()) {
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ import java.io.IOException;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.Semaphore;
|
import java.util.concurrent.Semaphore;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
@@ -86,6 +87,7 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
|||||||
private final AtomicBoolean setup;
|
private final AtomicBoolean setup;
|
||||||
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 boolean smartVanillaHeight;
|
private final boolean smartVanillaHeight;
|
||||||
private Engine engine;
|
private Engine engine;
|
||||||
private Looper hotloader;
|
private Looper hotloader;
|
||||||
@@ -150,6 +152,7 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
|||||||
} else {
|
} else {
|
||||||
INMS.get().inject(event.getWorld().getSeed(), engine, event.getWorld());
|
INMS.get().inject(event.getWorld().getSeed(), engine, event.getWorld());
|
||||||
Iris.info("Injected Iris Biome Source into " + event.getWorld().getName());
|
Iris.info("Injected Iris Biome Source into " + event.getWorld().getName());
|
||||||
|
spawnChunks.complete(INMS.get().getSpawnChunkCount(event.getWorld()));
|
||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ 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 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 {
|
||||||
@@ -46,4 +47,6 @@ public interface PlatformChunkGenerator extends Hotloadable, DataProvider {
|
|||||||
boolean isStudio();
|
boolean isStudio();
|
||||||
|
|
||||||
void touch(World world);
|
void touch(World world);
|
||||||
|
|
||||||
|
CompletableFuture<Integer> getSpawnChunks();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.volmit.iris.core.nms.v1_19_R1;
|
|||||||
|
|
||||||
import com.mojang.serialization.Codec;
|
import com.mojang.serialization.Codec;
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
|
import com.volmit.iris.core.ServerConfigurator;
|
||||||
import com.volmit.iris.core.nms.INMS;
|
import com.volmit.iris.core.nms.INMS;
|
||||||
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;
|
||||||
@@ -146,6 +147,7 @@ public class CustomBiomeSource extends BiomeSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ServerConfigurator.dumpDataPack();
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
package com.volmit.iris.core.nms.v1_19_R1;
|
package com.volmit.iris.core.nms.v1_19_R1;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.*;
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
@@ -17,8 +13,12 @@ import java.util.Vector;
|
|||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import com.google.gson.JsonNull;
|
||||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||||
|
import com.volmit.iris.core.nms.container.IPackRepository;
|
||||||
|
import com.volmit.iris.util.io.IO;
|
||||||
import net.minecraft.world.level.LevelReader;
|
import net.minecraft.world.level.LevelReader;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
@@ -101,6 +101,8 @@ import sun.misc.Unsafe;
|
|||||||
public class NMSBinding implements INMSBinding {
|
public class NMSBinding implements INMSBinding {
|
||||||
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
||||||
private final BlockData AIR = Material.AIR.createBlockData();
|
private final BlockData AIR = Material.AIR.createBlockData();
|
||||||
|
private final WPackRepository packRepository = new WPackRepository();
|
||||||
|
private final KMap<ResourceKey<?>, Boolean> changedRegistries = new KMap<>();
|
||||||
private final AtomicCache<MCAIdMap<net.minecraft.world.level.biome.Biome>> biomeMapCache = new AtomicCache<>();
|
private final AtomicCache<MCAIdMap<net.minecraft.world.level.biome.Biome>> biomeMapCache = new AtomicCache<>();
|
||||||
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||||
@@ -623,6 +625,7 @@ public class NMSBinding implements INMSBinding {
|
|||||||
try {
|
try {
|
||||||
var holder = registry.register(key, value, Lifecycle.stable());
|
var holder = registry.register(key, value, Lifecycle.stable());
|
||||||
if (frozen) valueField.set(holder, value);
|
if (frozen) valueField.set(holder, value);
|
||||||
|
changedRegistries.put(registryKey, true);
|
||||||
return true;
|
return true;
|
||||||
} finally {
|
} finally {
|
||||||
field.setBoolean(registry, frozen);
|
field.setBoolean(registry, frozen);
|
||||||
@@ -659,6 +662,7 @@ public class NMSBinding implements INMSBinding {
|
|||||||
toId.put(value, toId.removeInt(oldValue));
|
toId.put(value, toId.removeInt(oldValue));
|
||||||
byValue.put(value, byValue.remove(oldValue));
|
byValue.put(value, byValue.remove(oldValue));
|
||||||
lifecycles.put(value, lifecycles.remove(oldValue));
|
lifecycles.put(value, lifecycles.remove(oldValue));
|
||||||
|
changedRegistries.put(registryKey, true);
|
||||||
return true;
|
return true;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
@@ -696,6 +700,70 @@ public class NMSBinding implements INMSBinding {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean dumpRegistry(File... folders) {
|
||||||
|
var biomes = collect(Registry.BIOME_REGISTRY, net.minecraft.world.level.biome.Biome.DIRECT_CODEC);
|
||||||
|
var dimensions = collect(Registry.DIMENSION_TYPE_REGISTRY, DimensionType.DIRECT_CODEC);
|
||||||
|
|
||||||
|
if (biomes.isEmpty() && dimensions.isEmpty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (File folder : folders) {
|
||||||
|
if (folder.getName().equals("datapacks"))
|
||||||
|
folder = new File(folder, "iris");
|
||||||
|
File data = new File(folder, "data");
|
||||||
|
|
||||||
|
for (var entry : biomes.entrySet()) {
|
||||||
|
File file = new File(data, entry.getKey().getNamespace() + "/worldgen/biome/" + entry.getKey().getPath() + ".json");
|
||||||
|
if (!file.getParentFile().exists() && !file.getParentFile().mkdirs())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
IO.writeAll(file, entry.getValue().toString());
|
||||||
|
} catch (IOException e) {
|
||||||
|
Iris.error("Failed to write biome " + entry.getKey().toString() + " to " + file.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var entry : dimensions.entrySet()) {
|
||||||
|
File file = new File(data, entry.getKey().getNamespace() + "/dimension_type/" + entry.getKey().getPath() + ".json");
|
||||||
|
if (!file.getParentFile().exists() && !file.getParentFile().mkdirs())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
IO.writeAll(file, entry.getValue().toString());
|
||||||
|
} catch (IOException e) {
|
||||||
|
Iris.error("Failed to write dimension " + entry.getKey().toString() + " to " + file.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
File meta = new File(folder, "pack.mcmeta");
|
||||||
|
if (!meta.getParentFile().exists() && !meta.getParentFile().mkdirs())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
IO.writeAll(meta, "{\"pack\": {\"pack_format\": "+getDataVersion().getPackFormat()+", \"description\": \"Iris Data Pack. This pack contains all installed Iris Packs' resources.\"}}");
|
||||||
|
} catch (IOException e) {
|
||||||
|
Iris.error("Failed to write pack.mcmeta to " + meta.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> Map<ResourceLocation, JsonElement> collect(ResourceKey<Registry<T>> registryKey, Codec<T> codec) {
|
||||||
|
var registry = registry().registry(registryKey).orElse(null);
|
||||||
|
if (registry == null || !changedRegistries.getOrDefault(registryKey, false))
|
||||||
|
return Map.of();
|
||||||
|
try {
|
||||||
|
return registry
|
||||||
|
.registryKeySet()
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.toMap(ResourceKey::location, id -> encode(codec, registry.get(id)).orElse(JsonNull.INSTANCE)));
|
||||||
|
} finally {
|
||||||
|
changedRegistries.put(registryKey, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Color getBiomeColor(Location location, BiomeColor type) {
|
public Color getBiomeColor(Location location, BiomeColor type) {
|
||||||
@@ -762,6 +830,11 @@ public class NMSBinding implements INMSBinding {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPackRepository getPackRepository() {
|
||||||
|
return packRepository;
|
||||||
|
}
|
||||||
|
|
||||||
private static class ServerLevelAdvice {
|
private static class ServerLevelAdvice {
|
||||||
@Advice.OnMethodEnter
|
@Advice.OnMethodEnter
|
||||||
static void enter(@Advice.Argument(0) MinecraftServer server, @Advice.Argument(2) LevelStorageSource.LevelStorageAccess access, @Advice.Argument(4) ResourceKey<Level> key, @Advice.Argument(value = 5, readOnly = false) LevelStem levelStem) {
|
static void enter(@Advice.Argument(0) MinecraftServer server, @Advice.Argument(2) LevelStorageSource.LevelStorageAccess access, @Advice.Argument(4) ResourceKey<Level> key, @Advice.Argument(value = 5, readOnly = false) LevelStem levelStem) {
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package com.volmit.iris.core.nms.v1_19_R1;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.volmit.iris.core.nms.container.IPackRepository;
|
||||||
|
import net.minecraft.server.packs.repository.PackRepository;
|
||||||
|
import net.minecraft.world.level.DataPackConfig;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_19_R1.CraftServer;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
public class WPackRepository implements IPackRepository {
|
||||||
|
private PackRepository repository;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reload() {
|
||||||
|
getRepository().reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reloadWorldData() {
|
||||||
|
((CraftServer) Bukkit.getServer()).getServer().getWorldData()
|
||||||
|
.setDataPackConfig(getSelectedPacks());
|
||||||
|
}
|
||||||
|
|
||||||
|
private DataPackConfig getSelectedPacks() {
|
||||||
|
Collection<String> selectedIds = getSelectedIds();
|
||||||
|
List<String> enabled = ImmutableList.copyOf(selectedIds);
|
||||||
|
List<String> disabled = getAvailableIds().stream()
|
||||||
|
.filter((s) -> !selectedIds.contains(s))
|
||||||
|
.toList();
|
||||||
|
return new DataPackConfig(enabled, disabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSelected(Collection<String> packs) {
|
||||||
|
getRepository().setSelected(packs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addPack(String packId) {
|
||||||
|
var repo = getRepository();
|
||||||
|
var packs = new ArrayList<>(repo.getSelectedIds());
|
||||||
|
if (repo.isAvailable(packId) && !packs.contains(packId)) {
|
||||||
|
packs.add(packId);
|
||||||
|
repo.setSelected(packs);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removePack(String packId) {
|
||||||
|
var repo = getRepository();
|
||||||
|
var packs = new ArrayList<>(repo.getSelectedIds());
|
||||||
|
if (repo.isAvailable(packId) && packs.contains(packId)) {
|
||||||
|
packs.remove(packId);
|
||||||
|
repo.setSelected(packs);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getAvailableIds() {
|
||||||
|
return getRepository().getAvailableIds();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getSelectedIds() {
|
||||||
|
return getRepository().getSelectedIds();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable(String packId) {
|
||||||
|
return getRepository().isAvailable(packId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PackRepository getRepository() {
|
||||||
|
if (repository == null)
|
||||||
|
repository = ((CraftServer) Bukkit.getServer()).getHandle().getServer().getPackRepository();
|
||||||
|
|
||||||
|
return repository;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package com.volmit.iris.core.nms.v1_19_R2;
|
|||||||
|
|
||||||
import com.mojang.serialization.Codec;
|
import com.mojang.serialization.Codec;
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
|
import com.volmit.iris.core.ServerConfigurator;
|
||||||
import com.volmit.iris.core.nms.INMS;
|
import com.volmit.iris.core.nms.INMS;
|
||||||
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;
|
||||||
@@ -148,6 +149,7 @@ public class CustomBiomeSource extends BiomeSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ServerConfigurator.dumpDataPack();
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
package com.volmit.iris.core.nms.v1_19_R2;
|
package com.volmit.iris.core.nms.v1_19_R2;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.*;
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
@@ -17,8 +13,12 @@ import java.util.Vector;
|
|||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import com.google.gson.JsonNull;
|
||||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||||
|
import com.volmit.iris.core.nms.container.IPackRepository;
|
||||||
|
import com.volmit.iris.util.io.IO;
|
||||||
import net.minecraft.world.level.LevelReader;
|
import net.minecraft.world.level.LevelReader;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
@@ -102,6 +102,8 @@ import sun.misc.Unsafe;
|
|||||||
public class NMSBinding implements INMSBinding {
|
public class NMSBinding implements INMSBinding {
|
||||||
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
||||||
private final BlockData AIR = Material.AIR.createBlockData();
|
private final BlockData AIR = Material.AIR.createBlockData();
|
||||||
|
private final WPackRepository packRepository = new WPackRepository();
|
||||||
|
private final KMap<ResourceKey<?>, Boolean> changedRegistries = new KMap<>();
|
||||||
private final AtomicCache<MCAIdMap<net.minecraft.world.level.biome.Biome>> biomeMapCache = new AtomicCache<>();
|
private final AtomicCache<MCAIdMap<net.minecraft.world.level.biome.Biome>> biomeMapCache = new AtomicCache<>();
|
||||||
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||||
@@ -625,6 +627,7 @@ public class NMSBinding implements INMSBinding {
|
|||||||
try {
|
try {
|
||||||
var holder = registry.register(key, value, Lifecycle.stable());
|
var holder = registry.register(key, value, Lifecycle.stable());
|
||||||
if (frozen) valueField.set(holder, value);
|
if (frozen) valueField.set(holder, value);
|
||||||
|
changedRegistries.put(registryKey, true);
|
||||||
return true;
|
return true;
|
||||||
} finally {
|
} finally {
|
||||||
field.setBoolean(registry, frozen);
|
field.setBoolean(registry, frozen);
|
||||||
@@ -661,6 +664,7 @@ public class NMSBinding implements INMSBinding {
|
|||||||
toId.put(value, toId.removeInt(oldValue));
|
toId.put(value, toId.removeInt(oldValue));
|
||||||
byValue.put(value, byValue.remove(oldValue));
|
byValue.put(value, byValue.remove(oldValue));
|
||||||
lifecycles.put(value, lifecycles.remove(oldValue));
|
lifecycles.put(value, lifecycles.remove(oldValue));
|
||||||
|
changedRegistries.put(registryKey, true);
|
||||||
return true;
|
return true;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
@@ -739,6 +743,71 @@ public class NMSBinding implements INMSBinding {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean dumpRegistry(File... folders) {
|
||||||
|
var biomes = collect(Registries.BIOME, net.minecraft.world.level.biome.Biome.DIRECT_CODEC);
|
||||||
|
var dimensions = collect(Registries.DIMENSION_TYPE, DimensionType.DIRECT_CODEC);
|
||||||
|
|
||||||
|
if (biomes.isEmpty() && dimensions.isEmpty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (File folder : folders) {
|
||||||
|
if (folder.getName().equals("datapacks"))
|
||||||
|
folder = new File(folder, "iris");
|
||||||
|
File data = new File(folder, "data");
|
||||||
|
|
||||||
|
for (var entry : biomes.entrySet()) {
|
||||||
|
File file = new File(data, entry.getKey().getNamespace() + "/worldgen/biome/" + entry.getKey().getPath() + ".json");
|
||||||
|
if (!file.getParentFile().exists() && !file.getParentFile().mkdirs())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
IO.writeAll(file, entry.getValue().toString());
|
||||||
|
} catch (IOException e) {
|
||||||
|
Iris.error("Failed to write biome " + entry.getKey().toString() + " to " + file.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var entry : dimensions.entrySet()) {
|
||||||
|
File file = new File(data, entry.getKey().getNamespace() + "/dimension_type/" + entry.getKey().getPath() + ".json");
|
||||||
|
if (!file.getParentFile().exists() && !file.getParentFile().mkdirs())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
IO.writeAll(file, entry.getValue().toString());
|
||||||
|
} catch (IOException e) {
|
||||||
|
Iris.error("Failed to write dimension " + entry.getKey().toString() + " to " + file.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
File meta = new File(folder, "pack.mcmeta");
|
||||||
|
if (!meta.getParentFile().exists() && !meta.getParentFile().mkdirs())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
IO.writeAll(meta, "{\"pack\": {\"pack_format\": "+getDataVersion().getPackFormat()+", \"description\": \"Iris Data Pack. This pack contains all installed Iris Packs' resources.\"}}");
|
||||||
|
} catch (IOException e) {
|
||||||
|
Iris.error("Failed to write pack.mcmeta to " + meta.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> Map<ResourceLocation, JsonElement> collect(ResourceKey<Registry<T>> registryKey, Codec<T> codec) {
|
||||||
|
var registry = registry().registry(registryKey).orElse(null);
|
||||||
|
if (registry == null || !changedRegistries.getOrDefault(registryKey, false))
|
||||||
|
return Map.of();
|
||||||
|
try {
|
||||||
|
return registry
|
||||||
|
.registryKeySet()
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.toMap(ResourceKey::location, id -> encode(codec, registry.get(id)).orElse(JsonNull.INSTANCE)));
|
||||||
|
} finally {
|
||||||
|
changedRegistries.put(registryKey, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void injectBukkit() {
|
public void injectBukkit() {
|
||||||
try {
|
try {
|
||||||
Iris.info("Injecting Bukkit");
|
Iris.info("Injecting Bukkit");
|
||||||
@@ -763,6 +832,11 @@ public class NMSBinding implements INMSBinding {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPackRepository getPackRepository() {
|
||||||
|
return packRepository;
|
||||||
|
}
|
||||||
|
|
||||||
private static class ServerLevelAdvice {
|
private static class ServerLevelAdvice {
|
||||||
@Advice.OnMethodEnter
|
@Advice.OnMethodEnter
|
||||||
static void enter(@Advice.Argument(0) MinecraftServer server, @Advice.Argument(2) LevelStorageSource.LevelStorageAccess access, @Advice.Argument(4) ResourceKey<Level> key, @Advice.Argument(value = 5, readOnly = false) LevelStem levelStem) {
|
static void enter(@Advice.Argument(0) MinecraftServer server, @Advice.Argument(2) LevelStorageSource.LevelStorageAccess access, @Advice.Argument(4) ResourceKey<Level> key, @Advice.Argument(value = 5, readOnly = false) LevelStem levelStem) {
|
||||||
|
|||||||
@@ -0,0 +1,93 @@
|
|||||||
|
package com.volmit.iris.core.nms.v1_19_R2;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.volmit.iris.core.nms.container.IPackRepository;
|
||||||
|
import net.minecraft.server.packs.repository.PackRepository;
|
||||||
|
import net.minecraft.world.level.DataPackConfig;
|
||||||
|
import net.minecraft.world.level.WorldDataConfiguration;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_19_R2.CraftServer;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
public class WPackRepository implements IPackRepository {
|
||||||
|
private PackRepository repository;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reload() {
|
||||||
|
getRepository().reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reloadWorldData() {
|
||||||
|
var worldData = ((CraftServer) Bukkit.getServer()).getServer().getWorldData();
|
||||||
|
var config = new WorldDataConfiguration(getSelectedPacks(), worldData.enabledFeatures());
|
||||||
|
worldData.setDataConfiguration(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
private DataPackConfig getSelectedPacks() {
|
||||||
|
Collection<String> selectedIds = getSelectedIds();
|
||||||
|
List<String> enabled = ImmutableList.copyOf(selectedIds);
|
||||||
|
List<String> disabled = getAvailableIds().stream()
|
||||||
|
.filter((s) -> !selectedIds.contains(s))
|
||||||
|
.toList();
|
||||||
|
return new DataPackConfig(enabled, disabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSelected(Collection<String> packs) {
|
||||||
|
getRepository().setSelected(packs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addPack(String packId) {
|
||||||
|
var repo = getRepository();
|
||||||
|
var packs = new ArrayList<>(repo.getSelectedIds());
|
||||||
|
if (repo.isAvailable(packId) && !packs.contains(packId)) {
|
||||||
|
packs.add(packId);
|
||||||
|
repo.setSelected(packs);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removePack(String packId) {
|
||||||
|
var repo = getRepository();
|
||||||
|
var packs = new ArrayList<>(repo.getSelectedIds());
|
||||||
|
if (repo.isAvailable(packId) && packs.contains(packId)) {
|
||||||
|
packs.remove(packId);
|
||||||
|
repo.setSelected(packs);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getAvailableIds() {
|
||||||
|
return getRepository().getAvailableIds();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getSelectedIds() {
|
||||||
|
return getRepository().getSelectedIds();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable(String packId) {
|
||||||
|
return getRepository().isAvailable(packId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PackRepository getRepository() {
|
||||||
|
if (repository == null)
|
||||||
|
repository = ((CraftServer) Bukkit.getServer()).getHandle().getServer().getPackRepository();
|
||||||
|
return repository;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package com.volmit.iris.core.nms.v1_19_R3;
|
|||||||
|
|
||||||
import com.mojang.serialization.Codec;
|
import com.mojang.serialization.Codec;
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
|
import com.volmit.iris.core.ServerConfigurator;
|
||||||
import com.volmit.iris.core.nms.INMS;
|
import com.volmit.iris.core.nms.INMS;
|
||||||
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;
|
||||||
@@ -151,6 +152,7 @@ public class CustomBiomeSource extends BiomeSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ServerConfigurator.dumpDataPack();
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
package com.volmit.iris.core.nms.v1_19_R3;
|
package com.volmit.iris.core.nms.v1_19_R3;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.*;
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
@@ -17,8 +13,12 @@ import java.util.Vector;
|
|||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import com.google.gson.JsonNull;
|
||||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||||
|
import com.volmit.iris.core.nms.container.IPackRepository;
|
||||||
|
import com.volmit.iris.util.io.IO;
|
||||||
import net.minecraft.world.level.LevelReader;
|
import net.minecraft.world.level.LevelReader;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
@@ -103,6 +103,8 @@ import sun.misc.Unsafe;
|
|||||||
public class NMSBinding implements INMSBinding {
|
public class NMSBinding implements INMSBinding {
|
||||||
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
||||||
private final BlockData AIR = Material.AIR.createBlockData();
|
private final BlockData AIR = Material.AIR.createBlockData();
|
||||||
|
private final WPackRepository packRepository = new WPackRepository();
|
||||||
|
private final KMap<ResourceKey<?>, Boolean> changedRegistries = new KMap<>();
|
||||||
private final AtomicCache<MCAIdMap<net.minecraft.world.level.biome.Biome>> biomeMapCache = new AtomicCache<>();
|
private final AtomicCache<MCAIdMap<net.minecraft.world.level.biome.Biome>> biomeMapCache = new AtomicCache<>();
|
||||||
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||||
@@ -629,6 +631,7 @@ public class NMSBinding implements INMSBinding {
|
|||||||
try {
|
try {
|
||||||
var holder = registry.register(key, value, Lifecycle.stable());
|
var holder = registry.register(key, value, Lifecycle.stable());
|
||||||
if (frozen) valueField.set(holder, value);
|
if (frozen) valueField.set(holder, value);
|
||||||
|
changedRegistries.put(registryKey, true);
|
||||||
return true;
|
return true;
|
||||||
} finally {
|
} finally {
|
||||||
field.setBoolean(registry, frozen);
|
field.setBoolean(registry, frozen);
|
||||||
@@ -665,6 +668,7 @@ public class NMSBinding implements INMSBinding {
|
|||||||
toId.put(value, toId.removeInt(oldValue));
|
toId.put(value, toId.removeInt(oldValue));
|
||||||
byValue.put(value, byValue.remove(oldValue));
|
byValue.put(value, byValue.remove(oldValue));
|
||||||
lifecycles.put(value, lifecycles.remove(oldValue));
|
lifecycles.put(value, lifecycles.remove(oldValue));
|
||||||
|
changedRegistries.put(registryKey, true);
|
||||||
return true;
|
return true;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
@@ -743,6 +747,71 @@ public class NMSBinding implements INMSBinding {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean dumpRegistry(File... folders) {
|
||||||
|
var biomes = collect(Registries.BIOME, net.minecraft.world.level.biome.Biome.DIRECT_CODEC);
|
||||||
|
var dimensions = collect(Registries.DIMENSION_TYPE, DimensionType.DIRECT_CODEC);
|
||||||
|
|
||||||
|
if (biomes.isEmpty() && dimensions.isEmpty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (File folder : folders) {
|
||||||
|
if (folder.getName().equals("datapacks"))
|
||||||
|
folder = new File(folder, "iris");
|
||||||
|
File data = new File(folder, "data");
|
||||||
|
|
||||||
|
for (var entry : biomes.entrySet()) {
|
||||||
|
File file = new File(data, entry.getKey().getNamespace() + "/worldgen/biome/" + entry.getKey().getPath() + ".json");
|
||||||
|
if (!file.getParentFile().exists() && !file.getParentFile().mkdirs())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
IO.writeAll(file, entry.getValue().toString());
|
||||||
|
} catch (IOException e) {
|
||||||
|
Iris.error("Failed to write biome " + entry.getKey().toString() + " to " + file.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var entry : dimensions.entrySet()) {
|
||||||
|
File file = new File(data, entry.getKey().getNamespace() + "/dimension_type/" + entry.getKey().getPath() + ".json");
|
||||||
|
if (!file.getParentFile().exists() && !file.getParentFile().mkdirs())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
IO.writeAll(file, entry.getValue().toString());
|
||||||
|
} catch (IOException e) {
|
||||||
|
Iris.error("Failed to write dimension " + entry.getKey().toString() + " to " + file.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
File meta = new File(folder, "pack.mcmeta");
|
||||||
|
if (!meta.getParentFile().exists() && !meta.getParentFile().mkdirs())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
IO.writeAll(meta, "{\"pack\": {\"pack_format\": "+getDataVersion().getPackFormat()+", \"description\": \"Iris Data Pack. This pack contains all installed Iris Packs' resources.\"}}");
|
||||||
|
} catch (IOException e) {
|
||||||
|
Iris.error("Failed to write pack.mcmeta to " + meta.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> Map<ResourceLocation, JsonElement> collect(ResourceKey<Registry<T>> registryKey, Codec<T> codec) {
|
||||||
|
var registry = registry().registry(registryKey).orElse(null);
|
||||||
|
if (registry == null || !changedRegistries.getOrDefault(registryKey, false))
|
||||||
|
return Map.of();
|
||||||
|
try {
|
||||||
|
return registry
|
||||||
|
.registryKeySet()
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.toMap(ResourceKey::location, id -> encode(codec, registry.get(id)).orElse(JsonNull.INSTANCE)));
|
||||||
|
} finally {
|
||||||
|
changedRegistries.put(registryKey, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void injectBukkit() {
|
public void injectBukkit() {
|
||||||
try {
|
try {
|
||||||
Iris.info("Injecting Bukkit");
|
Iris.info("Injecting Bukkit");
|
||||||
@@ -767,6 +836,11 @@ public class NMSBinding implements INMSBinding {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPackRepository getPackRepository() {
|
||||||
|
return packRepository;
|
||||||
|
}
|
||||||
|
|
||||||
private static class ServerLevelAdvice {
|
private static class ServerLevelAdvice {
|
||||||
@Advice.OnMethodEnter
|
@Advice.OnMethodEnter
|
||||||
static void enter(@Advice.Argument(0) MinecraftServer server, @Advice.Argument(2) LevelStorageSource.LevelStorageAccess access, @Advice.Argument(4) ResourceKey<Level> key, @Advice.Argument(value = 5, readOnly = false) LevelStem levelStem) {
|
static void enter(@Advice.Argument(0) MinecraftServer server, @Advice.Argument(2) LevelStorageSource.LevelStorageAccess access, @Advice.Argument(4) ResourceKey<Level> key, @Advice.Argument(value = 5, readOnly = false) LevelStem levelStem) {
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package com.volmit.iris.core.nms.v1_19_R3;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.volmit.iris.core.nms.container.IPackRepository;
|
||||||
|
import net.minecraft.server.packs.repository.PackRepository;
|
||||||
|
import net.minecraft.world.level.DataPackConfig;
|
||||||
|
import net.minecraft.world.level.WorldDataConfiguration;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_19_R3.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_19_R3.packs.CraftDataPackManager;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
public class WPackRepository implements IPackRepository {
|
||||||
|
private PackRepository repository;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reload() {
|
||||||
|
getRepository().reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reloadWorldData() {
|
||||||
|
var worldData = ((CraftServer) Bukkit.getServer()).getServer().getWorldData();
|
||||||
|
var config = new WorldDataConfiguration(getSelectedPacks(), worldData.enabledFeatures());
|
||||||
|
worldData.setDataConfiguration(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
private DataPackConfig getSelectedPacks() {
|
||||||
|
Collection<String> selectedIds = getSelectedIds();
|
||||||
|
List<String> enabled = ImmutableList.copyOf(selectedIds);
|
||||||
|
List<String> disabled = getAvailableIds().stream()
|
||||||
|
.filter((s) -> !selectedIds.contains(s))
|
||||||
|
.toList();
|
||||||
|
return new DataPackConfig(enabled, disabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSelected(Collection<String> packs) {
|
||||||
|
getRepository().setSelected(packs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addPack(String packId) {
|
||||||
|
return getRepository().addPack(packId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removePack(String packId) {
|
||||||
|
return getRepository().removePack(packId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getAvailableIds() {
|
||||||
|
return getRepository().getAvailableIds();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getSelectedIds() {
|
||||||
|
return getRepository().getSelectedIds();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable(String packId) {
|
||||||
|
return getRepository().isAvailable(packId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PackRepository getRepository() {
|
||||||
|
if (repository == null)
|
||||||
|
repository = ((CraftDataPackManager) Bukkit.getDataPackManager()).getHandle();
|
||||||
|
return repository;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package com.volmit.iris.core.nms.v1_20_R1;
|
|||||||
|
|
||||||
import com.mojang.serialization.Codec;
|
import com.mojang.serialization.Codec;
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
|
import com.volmit.iris.core.ServerConfigurator;
|
||||||
import com.volmit.iris.core.nms.INMS;
|
import com.volmit.iris.core.nms.INMS;
|
||||||
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;
|
||||||
@@ -151,6 +152,7 @@ public class CustomBiomeSource extends BiomeSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ServerConfigurator.dumpDataPack();
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.volmit.iris.core.nms.v1_20_R1;
|
|||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonNull;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
import com.mojang.datafixers.util.Pair;
|
import com.mojang.datafixers.util.Pair;
|
||||||
@@ -11,6 +12,7 @@ import com.mojang.serialization.Lifecycle;
|
|||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.core.nms.INMSBinding;
|
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.core.nms.container.IPackRepository;
|
||||||
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.object.IrisBiomeCustom;
|
import com.volmit.iris.engine.object.IrisBiomeCustom;
|
||||||
@@ -19,6 +21,7 @@ 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.format.C;
|
import com.volmit.iris.util.format.C;
|
||||||
import com.volmit.iris.util.hunk.Hunk;
|
import com.volmit.iris.util.hunk.Hunk;
|
||||||
|
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.mantle.Mantle;
|
import com.volmit.iris.util.mantle.Mantle;
|
||||||
import com.volmit.iris.util.math.Vector3d;
|
import com.volmit.iris.util.math.Vector3d;
|
||||||
@@ -83,11 +86,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import sun.misc.Unsafe;
|
import sun.misc.Unsafe;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.*;
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
@@ -99,12 +98,15 @@ import java.util.Vector;
|
|||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class NMSBinding implements INMSBinding {
|
public class NMSBinding implements INMSBinding {
|
||||||
|
|
||||||
public static final String NMS_VERSION = "1.20.1";
|
public static final String NMS_VERSION = "1.20.1";
|
||||||
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
||||||
private final BlockData AIR = Material.AIR.createBlockData();
|
private final BlockData AIR = Material.AIR.createBlockData();
|
||||||
|
private final WPackRepository packRepository = new WPackRepository();
|
||||||
|
private final KMap<ResourceKey<?>, Boolean> changedRegistries = new KMap<>();
|
||||||
private final AtomicCache<MCAIdMap<net.minecraft.world.level.biome.Biome>> biomeMapCache = new AtomicCache<>();
|
private final AtomicCache<MCAIdMap<net.minecraft.world.level.biome.Biome>> biomeMapCache = new AtomicCache<>();
|
||||||
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||||
@@ -614,6 +616,7 @@ public class NMSBinding implements INMSBinding {
|
|||||||
try {
|
try {
|
||||||
var holder = registry.register(key, value, Lifecycle.stable());
|
var holder = registry.register(key, value, Lifecycle.stable());
|
||||||
if (frozen) valueField.set(holder, value);
|
if (frozen) valueField.set(holder, value);
|
||||||
|
changedRegistries.put(registryKey, true);
|
||||||
return true;
|
return true;
|
||||||
} finally {
|
} finally {
|
||||||
field.setBoolean(registry, frozen);
|
field.setBoolean(registry, frozen);
|
||||||
@@ -650,6 +653,7 @@ public class NMSBinding implements INMSBinding {
|
|||||||
toId.put(value, toId.removeInt(oldValue));
|
toId.put(value, toId.removeInt(oldValue));
|
||||||
byValue.put(value, byValue.remove(oldValue));
|
byValue.put(value, byValue.remove(oldValue));
|
||||||
lifecycles.put(value, lifecycles.remove(oldValue));
|
lifecycles.put(value, lifecycles.remove(oldValue));
|
||||||
|
changedRegistries.put(registryKey, true);
|
||||||
return true;
|
return true;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
@@ -741,6 +745,71 @@ public class NMSBinding implements INMSBinding {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean dumpRegistry(File... folders) {
|
||||||
|
var biomes = collect(Registries.BIOME, net.minecraft.world.level.biome.Biome.DIRECT_CODEC);
|
||||||
|
var dimensions = collect(Registries.DIMENSION_TYPE, DimensionType.DIRECT_CODEC);
|
||||||
|
|
||||||
|
if (biomes.isEmpty() && dimensions.isEmpty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (File folder : folders) {
|
||||||
|
if (folder.getName().equals("datapacks"))
|
||||||
|
folder = new File(folder, "iris");
|
||||||
|
File data = new File(folder, "data");
|
||||||
|
|
||||||
|
for (var entry : biomes.entrySet()) {
|
||||||
|
File file = new File(data, entry.getKey().getNamespace() + "/worldgen/biome/" + entry.getKey().getPath() + ".json");
|
||||||
|
if (!file.getParentFile().exists() && !file.getParentFile().mkdirs())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
IO.writeAll(file, entry.getValue().toString());
|
||||||
|
} catch (IOException e) {
|
||||||
|
Iris.error("Failed to write biome " + entry.getKey().toString() + " to " + file.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var entry : dimensions.entrySet()) {
|
||||||
|
File file = new File(data, entry.getKey().getNamespace() + "/dimension_type/" + entry.getKey().getPath() + ".json");
|
||||||
|
if (!file.getParentFile().exists() && !file.getParentFile().mkdirs())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
IO.writeAll(file, entry.getValue().toString());
|
||||||
|
} catch (IOException e) {
|
||||||
|
Iris.error("Failed to write dimension " + entry.getKey().toString() + " to " + file.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
File meta = new File(folder, "pack.mcmeta");
|
||||||
|
if (!meta.getParentFile().exists() && !meta.getParentFile().mkdirs())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
IO.writeAll(meta, "{\"pack\": {\"pack_format\": "+getDataVersion().getPackFormat()+", \"description\": \"Iris Data Pack. This pack contains all installed Iris Packs' resources.\"}}");
|
||||||
|
} catch (IOException e) {
|
||||||
|
Iris.error("Failed to write pack.mcmeta to " + meta.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> Map<ResourceLocation, JsonElement> collect(ResourceKey<Registry<T>> registryKey, Codec<T> codec) {
|
||||||
|
var registry = registry().registry(registryKey).orElse(null);
|
||||||
|
if (registry == null || !changedRegistries.getOrDefault(registryKey, false))
|
||||||
|
return Map.of();
|
||||||
|
try {
|
||||||
|
return registry
|
||||||
|
.registryKeySet()
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.toMap(ResourceKey::location, id -> encode(codec, registry.get(id)).orElse(JsonNull.INSTANCE)));
|
||||||
|
} finally {
|
||||||
|
changedRegistries.put(registryKey, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void injectBukkit() {
|
public void injectBukkit() {
|
||||||
try {
|
try {
|
||||||
Iris.info("Injecting Bukkit");
|
Iris.info("Injecting Bukkit");
|
||||||
@@ -765,6 +834,11 @@ public class NMSBinding implements INMSBinding {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPackRepository getPackRepository() {
|
||||||
|
return packRepository;
|
||||||
|
}
|
||||||
|
|
||||||
private static class ServerLevelAdvice {
|
private static class ServerLevelAdvice {
|
||||||
@Advice.OnMethodEnter
|
@Advice.OnMethodEnter
|
||||||
static void enter(@Advice.Argument(0) MinecraftServer server, @Advice.Argument(2) LevelStorageSource.LevelStorageAccess access, @Advice.Argument(4) ResourceKey<Level> key, @Advice.Argument(value = 5, readOnly = false) LevelStem levelStem) {
|
static void enter(@Advice.Argument(0) MinecraftServer server, @Advice.Argument(2) LevelStorageSource.LevelStorageAccess access, @Advice.Argument(4) ResourceKey<Level> key, @Advice.Argument(value = 5, readOnly = false) LevelStem levelStem) {
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package com.volmit.iris.core.nms.v1_20_R1;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.volmit.iris.core.nms.container.IPackRepository;
|
||||||
|
import net.minecraft.server.packs.repository.PackRepository;
|
||||||
|
import net.minecraft.world.level.DataPackConfig;
|
||||||
|
import net.minecraft.world.level.WorldDataConfiguration;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_20_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_20_R1.packs.CraftDataPackManager;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
public class WPackRepository implements IPackRepository {
|
||||||
|
private PackRepository repository;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reload() {
|
||||||
|
getRepository().reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reloadWorldData() {
|
||||||
|
var worldData = ((CraftServer) Bukkit.getServer()).getServer().getWorldData();
|
||||||
|
var config = new WorldDataConfiguration(getSelectedPacks(), worldData.enabledFeatures());
|
||||||
|
worldData.setDataConfiguration(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
private DataPackConfig getSelectedPacks() {
|
||||||
|
Collection<String> selectedIds = getSelectedIds();
|
||||||
|
List<String> enabled = ImmutableList.copyOf(selectedIds);
|
||||||
|
List<String> disabled = getAvailableIds().stream()
|
||||||
|
.filter((s) -> !selectedIds.contains(s))
|
||||||
|
.toList();
|
||||||
|
return new DataPackConfig(enabled, disabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSelected(Collection<String> packs) {
|
||||||
|
getRepository().setSelected(packs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addPack(String packId) {
|
||||||
|
return getRepository().addPack(packId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removePack(String packId) {
|
||||||
|
return getRepository().removePack(packId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getAvailableIds() {
|
||||||
|
return getRepository().getAvailableIds();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getSelectedIds() {
|
||||||
|
return getRepository().getSelectedIds();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable(String packId) {
|
||||||
|
return getRepository().isAvailable(packId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PackRepository getRepository() {
|
||||||
|
if (repository == null)
|
||||||
|
repository = ((CraftDataPackManager) Bukkit.getDataPackManager()).getHandle();
|
||||||
|
return repository;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package com.volmit.iris.core.nms.v1_20_R2;
|
|||||||
|
|
||||||
import com.mojang.serialization.Codec;
|
import com.mojang.serialization.Codec;
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
|
import com.volmit.iris.core.ServerConfigurator;
|
||||||
import com.volmit.iris.core.nms.INMS;
|
import com.volmit.iris.core.nms.INMS;
|
||||||
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;
|
||||||
@@ -150,6 +151,7 @@ public class CustomBiomeSource extends BiomeSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ServerConfigurator.dumpDataPack();
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
package com.volmit.iris.core.nms.v1_20_R2;
|
package com.volmit.iris.core.nms.v1_20_R2;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.*;
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
@@ -17,8 +13,13 @@ import java.util.Vector;
|
|||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import com.google.gson.JsonNull;
|
||||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||||
|
import com.volmit.iris.core.nms.container.IPackRepository;
|
||||||
|
import com.volmit.iris.util.io.IO;
|
||||||
|
import net.minecraft.server.commands.DataPackCommand;
|
||||||
import net.minecraft.world.level.LevelReader;
|
import net.minecraft.world.level.LevelReader;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
@@ -54,6 +55,7 @@ import org.bukkit.craftbukkit.v1_20_R2.CraftWorld;
|
|||||||
import org.bukkit.craftbukkit.v1_20_R2.block.data.CraftBlockData;
|
import org.bukkit.craftbukkit.v1_20_R2.block.data.CraftBlockData;
|
||||||
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftDolphin;
|
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftDolphin;
|
||||||
import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack;
|
import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack;
|
||||||
|
import org.bukkit.craftbukkit.v1_20_R2.packs.CraftDataPackManager;
|
||||||
import org.bukkit.craftbukkit.v1_20_R2.util.CraftNamespacedKey;
|
import org.bukkit.craftbukkit.v1_20_R2.util.CraftNamespacedKey;
|
||||||
import org.bukkit.entity.Dolphin;
|
import org.bukkit.entity.Dolphin;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
@@ -104,6 +106,8 @@ import sun.misc.Unsafe;
|
|||||||
public class NMSBinding implements INMSBinding {
|
public class NMSBinding implements INMSBinding {
|
||||||
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
||||||
private final BlockData AIR = Material.AIR.createBlockData();
|
private final BlockData AIR = Material.AIR.createBlockData();
|
||||||
|
private final WPackRepository packRepository = new WPackRepository();
|
||||||
|
private final KMap<ResourceKey<?>, Boolean> changedRegistries = new KMap<>();
|
||||||
private final AtomicCache<MCAIdMap<net.minecraft.world.level.biome.Biome>> biomeMapCache = new AtomicCache<>();
|
private final AtomicCache<MCAIdMap<net.minecraft.world.level.biome.Biome>> biomeMapCache = new AtomicCache<>();
|
||||||
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||||
@@ -626,6 +630,7 @@ public class NMSBinding implements INMSBinding {
|
|||||||
try {
|
try {
|
||||||
var holder = registry.register(key, value, Lifecycle.stable());
|
var holder = registry.register(key, value, Lifecycle.stable());
|
||||||
if (frozen) valueField.set(holder, value);
|
if (frozen) valueField.set(holder, value);
|
||||||
|
changedRegistries.put(registryKey, true);
|
||||||
return true;
|
return true;
|
||||||
} finally {
|
} finally {
|
||||||
field.setBoolean(registry, frozen);
|
field.setBoolean(registry, frozen);
|
||||||
@@ -662,6 +667,7 @@ public class NMSBinding implements INMSBinding {
|
|||||||
toId.put(value, toId.removeInt(oldValue));
|
toId.put(value, toId.removeInt(oldValue));
|
||||||
byValue.put(value, byValue.remove(oldValue));
|
byValue.put(value, byValue.remove(oldValue));
|
||||||
lifecycles.put(value, lifecycles.remove(oldValue));
|
lifecycles.put(value, lifecycles.remove(oldValue));
|
||||||
|
changedRegistries.put(registryKey, true);
|
||||||
return true;
|
return true;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
@@ -745,6 +751,71 @@ public class NMSBinding implements INMSBinding {
|
|||||||
return registry.getHolderOrThrow(ResourceKey.create(Registries.BIOME, CraftNamespacedKey.toMinecraft(biome.getKey())));
|
return registry.getHolderOrThrow(ResourceKey.create(Registries.BIOME, CraftNamespacedKey.toMinecraft(biome.getKey())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean dumpRegistry(File... folders) {
|
||||||
|
var biomes = collect(Registries.BIOME, net.minecraft.world.level.biome.Biome.DIRECT_CODEC);
|
||||||
|
var dimensions = collect(Registries.DIMENSION_TYPE, DimensionType.DIRECT_CODEC);
|
||||||
|
|
||||||
|
if (biomes.isEmpty() && dimensions.isEmpty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (File folder : folders) {
|
||||||
|
if (folder.getName().equals("datapacks"))
|
||||||
|
folder = new File(folder, "iris");
|
||||||
|
File data = new File(folder, "data");
|
||||||
|
|
||||||
|
for (var entry : biomes.entrySet()) {
|
||||||
|
File file = new File(data, entry.getKey().getNamespace() + "/worldgen/biome/" + entry.getKey().getPath() + ".json");
|
||||||
|
if (!file.getParentFile().exists() && !file.getParentFile().mkdirs())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
IO.writeAll(file, entry.getValue().toString());
|
||||||
|
} catch (IOException e) {
|
||||||
|
Iris.error("Failed to write biome " + entry.getKey().toString() + " to " + file.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var entry : dimensions.entrySet()) {
|
||||||
|
File file = new File(data, entry.getKey().getNamespace() + "/dimension_type/" + entry.getKey().getPath() + ".json");
|
||||||
|
if (!file.getParentFile().exists() && !file.getParentFile().mkdirs())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
IO.writeAll(file, entry.getValue().toString());
|
||||||
|
} catch (IOException e) {
|
||||||
|
Iris.error("Failed to write dimension " + entry.getKey().toString() + " to " + file.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
File meta = new File(folder, "pack.mcmeta");
|
||||||
|
if (!meta.getParentFile().exists() && !meta.getParentFile().mkdirs())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
IO.writeAll(meta, "{\"pack\": {\"pack_format\": "+getDataVersion().getPackFormat()+", \"description\": \"Iris Data Pack. This pack contains all installed Iris Packs' resources.\"}}");
|
||||||
|
} catch (IOException e) {
|
||||||
|
Iris.error("Failed to write pack.mcmeta to " + meta.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> Map<ResourceLocation, JsonElement> collect(ResourceKey<Registry<T>> registryKey, Codec<T> codec) {
|
||||||
|
var registry = registry().registry(registryKey).orElse(null);
|
||||||
|
if (registry == null || !changedRegistries.getOrDefault(registryKey, false))
|
||||||
|
return Map.of();
|
||||||
|
try {
|
||||||
|
return registry
|
||||||
|
.registryKeySet()
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.toMap(ResourceKey::location, id -> encode(codec, registry.get(id)).orElse(JsonNull.INSTANCE)));
|
||||||
|
} finally {
|
||||||
|
changedRegistries.put(registryKey, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void injectBukkit() {
|
public void injectBukkit() {
|
||||||
try {
|
try {
|
||||||
Iris.info("Injecting Bukkit");
|
Iris.info("Injecting Bukkit");
|
||||||
@@ -769,6 +840,11 @@ public class NMSBinding implements INMSBinding {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPackRepository getPackRepository() {
|
||||||
|
return packRepository;
|
||||||
|
}
|
||||||
|
|
||||||
private static class ServerLevelAdvice {
|
private static class ServerLevelAdvice {
|
||||||
@Advice.OnMethodEnter
|
@Advice.OnMethodEnter
|
||||||
static void enter(@Advice.Argument(0) MinecraftServer server, @Advice.Argument(2) LevelStorageSource.LevelStorageAccess access, @Advice.Argument(4) ResourceKey<Level> key, @Advice.Argument(value = 5, readOnly = false) LevelStem levelStem) {
|
static void enter(@Advice.Argument(0) MinecraftServer server, @Advice.Argument(2) LevelStorageSource.LevelStorageAccess access, @Advice.Argument(4) ResourceKey<Level> key, @Advice.Argument(value = 5, readOnly = false) LevelStem levelStem) {
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package com.volmit.iris.core.nms.v1_20_R2;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.volmit.iris.core.nms.container.IPackRepository;
|
||||||
|
import net.minecraft.server.packs.repository.PackRepository;
|
||||||
|
import net.minecraft.world.level.DataPackConfig;
|
||||||
|
import net.minecraft.world.level.WorldDataConfiguration;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_20_R2.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_20_R2.packs.CraftDataPackManager;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
public class WPackRepository implements IPackRepository {
|
||||||
|
private PackRepository repository;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reload() {
|
||||||
|
getRepository().reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reloadWorldData() {
|
||||||
|
var worldData = ((CraftServer) Bukkit.getServer()).getServer().getWorldData();
|
||||||
|
var config = new WorldDataConfiguration(getSelectedPacks(), worldData.enabledFeatures());
|
||||||
|
worldData.setDataConfiguration(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
private DataPackConfig getSelectedPacks() {
|
||||||
|
Collection<String> selectedIds = getSelectedIds();
|
||||||
|
List<String> enabled = ImmutableList.copyOf(selectedIds);
|
||||||
|
List<String> disabled = getAvailableIds().stream()
|
||||||
|
.filter((s) -> !selectedIds.contains(s))
|
||||||
|
.toList();
|
||||||
|
return new DataPackConfig(enabled, disabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSelected(Collection<String> packs) {
|
||||||
|
getRepository().setSelected(packs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addPack(String packId) {
|
||||||
|
return getRepository().addPack(packId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removePack(String packId) {
|
||||||
|
return getRepository().removePack(packId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getAvailableIds() {
|
||||||
|
return getRepository().getAvailableIds();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getSelectedIds() {
|
||||||
|
return getRepository().getSelectedIds();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable(String packId) {
|
||||||
|
return getRepository().isAvailable(packId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PackRepository getRepository() {
|
||||||
|
if (repository == null)
|
||||||
|
repository = ((CraftDataPackManager) Bukkit.getDataPackManager()).getHandle();
|
||||||
|
return repository;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package com.volmit.iris.core.nms.v1_20_R3;
|
|||||||
|
|
||||||
import com.mojang.serialization.Codec;
|
import com.mojang.serialization.Codec;
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
|
import com.volmit.iris.core.ServerConfigurator;
|
||||||
import com.volmit.iris.core.nms.INMS;
|
import com.volmit.iris.core.nms.INMS;
|
||||||
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;
|
||||||
@@ -150,6 +151,7 @@ public class CustomBiomeSource extends BiomeSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ServerConfigurator.dumpDataPack();
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.volmit.iris.core.nms.v1_20_R3;
|
package com.volmit.iris.core.nms.v1_20_R3;
|
||||||
|
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
|
import com.volmit.iris.core.ServerConfigurator;
|
||||||
import com.volmit.iris.core.nms.BiomeBaseInjector;
|
import com.volmit.iris.core.nms.BiomeBaseInjector;
|
||||||
import com.volmit.iris.core.nms.IHeadless;
|
import com.volmit.iris.core.nms.IHeadless;
|
||||||
import com.volmit.iris.core.nms.v1_20_R3.mca.MCATerrainChunk;
|
import com.volmit.iris.core.nms.v1_20_R3.mca.MCATerrainChunk;
|
||||||
@@ -74,6 +75,7 @@ public class Headless implements IHeadless, LevelHeightAccessor {
|
|||||||
binding.registerBiome(dimKey, custom, false);
|
binding.registerBiome(dimKey, custom, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ServerConfigurator.dumpDataPack();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
package com.volmit.iris.core.nms.v1_20_R3;
|
package com.volmit.iris.core.nms.v1_20_R3;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.*;
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
@@ -13,19 +9,23 @@ import java.util.*;
|
|||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonNull;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.mojang.datafixers.util.Pair;
|
import com.mojang.datafixers.util.Pair;
|
||||||
import com.mojang.serialization.Codec;
|
import com.mojang.serialization.Codec;
|
||||||
import com.mojang.serialization.JsonOps;
|
import com.mojang.serialization.JsonOps;
|
||||||
import com.mojang.serialization.Lifecycle;
|
import com.mojang.serialization.Lifecycle;
|
||||||
import com.volmit.iris.core.nms.IHeadless;
|
import com.volmit.iris.core.nms.IHeadless;
|
||||||
|
import com.volmit.iris.core.nms.container.IPackRepository;
|
||||||
import com.volmit.iris.core.nms.v1_20_R3.mca.ChunkSerializer;
|
import com.volmit.iris.core.nms.v1_20_R3.mca.ChunkSerializer;
|
||||||
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.util.format.C;
|
import com.volmit.iris.util.format.C;
|
||||||
|
import com.volmit.iris.util.io.IO;
|
||||||
import it.unimi.dsi.fastutil.objects.Reference2IntMap;
|
import it.unimi.dsi.fastutil.objects.Reference2IntMap;
|
||||||
import net.bytebuddy.ByteBuddy;
|
import net.bytebuddy.ByteBuddy;
|
||||||
import net.bytebuddy.asm.Advice;
|
import net.bytebuddy.asm.Advice;
|
||||||
@@ -114,6 +114,8 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
|||||||
public class NMSBinding implements INMSBinding {
|
public class NMSBinding implements INMSBinding {
|
||||||
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
||||||
private final BlockData AIR = Material.AIR.createBlockData();
|
private final BlockData AIR = Material.AIR.createBlockData();
|
||||||
|
private final WPackRepository packRepository = new WPackRepository();
|
||||||
|
private final KMap<ResourceKey<?>, Boolean> changedRegistries = new KMap<>();
|
||||||
private final AtomicCache<MCAIdMap<net.minecraft.world.level.biome.Biome>> biomeMapCache = new AtomicCache<>();
|
private final AtomicCache<MCAIdMap<net.minecraft.world.level.biome.Biome>> biomeMapCache = new AtomicCache<>();
|
||||||
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||||
@@ -636,6 +638,7 @@ public class NMSBinding implements INMSBinding {
|
|||||||
try {
|
try {
|
||||||
var holder = registry.register(key, value, Lifecycle.stable());
|
var holder = registry.register(key, value, Lifecycle.stable());
|
||||||
if (frozen) valueField.set(holder, value);
|
if (frozen) valueField.set(holder, value);
|
||||||
|
changedRegistries.put(registryKey, true);
|
||||||
return true;
|
return true;
|
||||||
} finally {
|
} finally {
|
||||||
field.setBoolean(registry, frozen);
|
field.setBoolean(registry, frozen);
|
||||||
@@ -672,6 +675,7 @@ public class NMSBinding implements INMSBinding {
|
|||||||
toId.put(value, toId.removeInt(oldValue));
|
toId.put(value, toId.removeInt(oldValue));
|
||||||
byValue.put(value, byValue.remove(oldValue));
|
byValue.put(value, byValue.remove(oldValue));
|
||||||
lifecycles.put(value, lifecycles.remove(oldValue));
|
lifecycles.put(value, lifecycles.remove(oldValue));
|
||||||
|
changedRegistries.put(registryKey, true);
|
||||||
return true;
|
return true;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
@@ -754,6 +758,71 @@ public class NMSBinding implements INMSBinding {
|
|||||||
return registry.getHolderOrThrow(ResourceKey.create(Registries.BIOME, CraftNamespacedKey.toMinecraft(biome.getKey())));
|
return registry.getHolderOrThrow(ResourceKey.create(Registries.BIOME, CraftNamespacedKey.toMinecraft(biome.getKey())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean dumpRegistry(File... folders) {
|
||||||
|
var biomes = collect(Registries.BIOME, net.minecraft.world.level.biome.Biome.DIRECT_CODEC);
|
||||||
|
var dimensions = collect(Registries.DIMENSION_TYPE, DimensionType.DIRECT_CODEC);
|
||||||
|
|
||||||
|
if (biomes.isEmpty() && dimensions.isEmpty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (File folder : folders) {
|
||||||
|
if (folder.getName().equals("datapacks"))
|
||||||
|
folder = new File(folder, "iris");
|
||||||
|
File data = new File(folder, "data");
|
||||||
|
|
||||||
|
for (var entry : biomes.entrySet()) {
|
||||||
|
File file = new File(data, entry.getKey().getNamespace() + "/worldgen/biome/" + entry.getKey().getPath() + ".json");
|
||||||
|
if (!file.getParentFile().exists() && !file.getParentFile().mkdirs())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
IO.writeAll(file, entry.getValue().toString());
|
||||||
|
} catch (IOException e) {
|
||||||
|
Iris.error("Failed to write biome " + entry.getKey().toString() + " to " + file.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var entry : dimensions.entrySet()) {
|
||||||
|
File file = new File(data, entry.getKey().getNamespace() + "/dimension_type/" + entry.getKey().getPath() + ".json");
|
||||||
|
if (!file.getParentFile().exists() && !file.getParentFile().mkdirs())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
IO.writeAll(file, entry.getValue().toString());
|
||||||
|
} catch (IOException e) {
|
||||||
|
Iris.error("Failed to write dimension " + entry.getKey().toString() + " to " + file.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
File meta = new File(folder, "pack.mcmeta");
|
||||||
|
if (!meta.getParentFile().exists() && !meta.getParentFile().mkdirs())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
IO.writeAll(meta, "{\"pack\": {\"pack_format\": "+getDataVersion().getPackFormat()+", \"description\": \"Iris Data Pack. This pack contains all installed Iris Packs' resources.\"}}");
|
||||||
|
} catch (IOException e) {
|
||||||
|
Iris.error("Failed to write pack.mcmeta to " + meta.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> Map<ResourceLocation, JsonElement> collect(ResourceKey<Registry<T>> registryKey, Codec<T> codec) {
|
||||||
|
var registry = registry().registry(registryKey).orElse(null);
|
||||||
|
if (registry == null || !changedRegistries.getOrDefault(registryKey, false))
|
||||||
|
return Map.of();
|
||||||
|
try {
|
||||||
|
return registry
|
||||||
|
.registryKeySet()
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.toMap(ResourceKey::location, id -> encode(codec, registry.get(id)).orElse(JsonNull.INSTANCE)));
|
||||||
|
} finally {
|
||||||
|
changedRegistries.put(registryKey, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void injectBukkit() {
|
public void injectBukkit() {
|
||||||
try {
|
try {
|
||||||
Iris.info("Injecting Bukkit");
|
Iris.info("Injecting Bukkit");
|
||||||
@@ -784,6 +853,11 @@ public class NMSBinding implements INMSBinding {
|
|||||||
return new Headless(this, engine);
|
return new Headless(this, engine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPackRepository getPackRepository() {
|
||||||
|
return packRepository;
|
||||||
|
}
|
||||||
|
|
||||||
private static class ServerLevelAdvice {
|
private static class ServerLevelAdvice {
|
||||||
@Advice.OnMethodEnter
|
@Advice.OnMethodEnter
|
||||||
static void enter(@Advice.Argument(0) MinecraftServer server, @Advice.Argument(2) LevelStorageSource.LevelStorageAccess access, @Advice.Argument(4) ResourceKey<Level> key, @Advice.Argument(value = 5, readOnly = false) LevelStem levelStem) {
|
static void enter(@Advice.Argument(0) MinecraftServer server, @Advice.Argument(2) LevelStorageSource.LevelStorageAccess access, @Advice.Argument(4) ResourceKey<Level> key, @Advice.Argument(value = 5, readOnly = false) LevelStem levelStem) {
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package com.volmit.iris.core.nms.v1_20_R3;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.volmit.iris.core.nms.container.IPackRepository;
|
||||||
|
import net.minecraft.server.packs.repository.PackRepository;
|
||||||
|
import net.minecraft.world.level.DataPackConfig;
|
||||||
|
import net.minecraft.world.level.WorldDataConfiguration;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_20_R3.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_20_R3.packs.CraftDataPackManager;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
public class WPackRepository implements IPackRepository {
|
||||||
|
private PackRepository repository;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reload() {
|
||||||
|
getRepository().reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reloadWorldData() {
|
||||||
|
var worldData = ((CraftServer) Bukkit.getServer()).getServer().getWorldData();
|
||||||
|
var config = new WorldDataConfiguration(getSelectedPacks(), worldData.enabledFeatures());
|
||||||
|
worldData.setDataConfiguration(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
private DataPackConfig getSelectedPacks() {
|
||||||
|
Collection<String> selectedIds = getSelectedIds();
|
||||||
|
List<String> enabled = ImmutableList.copyOf(selectedIds);
|
||||||
|
List<String> disabled = getAvailableIds().stream()
|
||||||
|
.filter((s) -> !selectedIds.contains(s))
|
||||||
|
.toList();
|
||||||
|
return new DataPackConfig(enabled, disabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSelected(Collection<String> packs) {
|
||||||
|
getRepository().setSelected(packs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addPack(String packId) {
|
||||||
|
return getRepository().addPack(packId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removePack(String packId) {
|
||||||
|
return getRepository().removePack(packId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getAvailableIds() {
|
||||||
|
return getRepository().getAvailableIds();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getSelectedIds() {
|
||||||
|
return getRepository().getSelectedIds();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable(String packId) {
|
||||||
|
return getRepository().isAvailable(packId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PackRepository getRepository() {
|
||||||
|
if (repository == null)
|
||||||
|
repository = ((CraftDataPackManager) Bukkit.getDataPackManager()).getHandle();
|
||||||
|
return repository;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package com.volmit.iris.core.nms.v1_20_R4;
|
|||||||
|
|
||||||
import com.mojang.serialization.MapCodec;
|
import com.mojang.serialization.MapCodec;
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
|
import com.volmit.iris.core.ServerConfigurator;
|
||||||
import com.volmit.iris.core.nms.INMS;
|
import com.volmit.iris.core.nms.INMS;
|
||||||
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;
|
||||||
@@ -150,6 +151,7 @@ public class CustomBiomeSource extends BiomeSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ServerConfigurator.dumpDataPack();
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
package com.volmit.iris.core.nms.v1_20_R4;
|
package com.volmit.iris.core.nms.v1_20_R4;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.*;
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
@@ -17,7 +13,9 @@ import java.util.Vector;
|
|||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import com.google.gson.JsonNull;
|
||||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
@@ -25,10 +23,12 @@ import com.google.gson.JsonObject;
|
|||||||
import com.mojang.datafixers.util.Pair;
|
import com.mojang.datafixers.util.Pair;
|
||||||
import com.mojang.serialization.Codec;
|
import com.mojang.serialization.Codec;
|
||||||
import com.mojang.serialization.JsonOps;
|
import com.mojang.serialization.JsonOps;
|
||||||
|
import com.volmit.iris.core.nms.container.IPackRepository;
|
||||||
import com.volmit.iris.core.nms.datapack.DataVersion;
|
import com.volmit.iris.core.nms.datapack.DataVersion;
|
||||||
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.util.format.C;
|
import com.volmit.iris.util.format.C;
|
||||||
|
import com.volmit.iris.util.io.IO;
|
||||||
import it.unimi.dsi.fastutil.objects.Reference2IntMap;
|
import it.unimi.dsi.fastutil.objects.Reference2IntMap;
|
||||||
import net.bytebuddy.ByteBuddy;
|
import net.bytebuddy.ByteBuddy;
|
||||||
import net.bytebuddy.asm.Advice;
|
import net.bytebuddy.asm.Advice;
|
||||||
@@ -107,6 +107,8 @@ import sun.misc.Unsafe;
|
|||||||
public class NMSBinding implements INMSBinding {
|
public class NMSBinding implements INMSBinding {
|
||||||
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
||||||
private final BlockData AIR = Material.AIR.createBlockData();
|
private final BlockData AIR = Material.AIR.createBlockData();
|
||||||
|
private final WPackRepository packRepository = new WPackRepository();
|
||||||
|
private final KMap<ResourceKey<?>, Boolean> changedRegistries = new KMap<>();
|
||||||
private final AtomicCache<MCAIdMap<net.minecraft.world.level.biome.Biome>> biomeMapCache = new AtomicCache<>();
|
private final AtomicCache<MCAIdMap<net.minecraft.world.level.biome.Biome>> biomeMapCache = new AtomicCache<>();
|
||||||
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||||
@@ -667,6 +669,7 @@ public class NMSBinding implements INMSBinding {
|
|||||||
try {
|
try {
|
||||||
var holder = registry.register(key, value, RegistrationInfo.BUILT_IN);
|
var holder = registry.register(key, value, RegistrationInfo.BUILT_IN);
|
||||||
if (frozen) valueField.set(holder, value);
|
if (frozen) valueField.set(holder, value);
|
||||||
|
changedRegistries.put(registryKey, true);
|
||||||
return true;
|
return true;
|
||||||
} finally {
|
} finally {
|
||||||
field.setBoolean(registry, frozen);
|
field.setBoolean(registry, frozen);
|
||||||
@@ -699,6 +702,7 @@ public class NMSBinding implements INMSBinding {
|
|||||||
valueField.set(holder, value);
|
valueField.set(holder, value);
|
||||||
toId.put(value, toId.removeInt(oldValue));
|
toId.put(value, toId.removeInt(oldValue));
|
||||||
byValue.put(value, byValue.remove(oldValue));
|
byValue.put(value, byValue.remove(oldValue));
|
||||||
|
changedRegistries.put(registryKey, true);
|
||||||
return true;
|
return true;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
@@ -736,6 +740,84 @@ public class NMSBinding implements INMSBinding {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean dumpRegistry(File... folders) {
|
||||||
|
var biomes = collect(Registries.BIOME, net.minecraft.world.level.biome.Biome.DIRECT_CODEC);
|
||||||
|
var dimensions = collect(Registries.DIMENSION_TYPE, DimensionType.DIRECT_CODEC);
|
||||||
|
|
||||||
|
if (biomes.isEmpty() && dimensions.isEmpty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (File folder : folders) {
|
||||||
|
if (folder.getName().equals("datapacks"))
|
||||||
|
folder = new File(folder, "iris");
|
||||||
|
File data = new File(folder, "data");
|
||||||
|
|
||||||
|
for (var entry : biomes.entrySet()) {
|
||||||
|
File file = new File(data, entry.getKey().getNamespace() + "/worldgen/biome/" + entry.getKey().getPath() + ".json");
|
||||||
|
if (!file.getParentFile().exists() && !file.getParentFile().mkdirs())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
IO.writeAll(file, entry.getValue().toString());
|
||||||
|
} catch (IOException e) {
|
||||||
|
Iris.error("Failed to write biome " + entry.getKey().toString() + " to " + file.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var entry : dimensions.entrySet()) {
|
||||||
|
File file = new File(data, entry.getKey().getNamespace() + "/dimension_type/" + entry.getKey().getPath() + ".json");
|
||||||
|
if (!file.getParentFile().exists() && !file.getParentFile().mkdirs())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
IO.writeAll(file, entry.getValue().toString());
|
||||||
|
} catch (IOException e) {
|
||||||
|
Iris.error("Failed to write dimension " + entry.getKey().toString() + " to " + file.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
File meta = new File(folder, "pack.mcmeta");
|
||||||
|
if (!meta.getParentFile().exists() && !meta.getParentFile().mkdirs())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
IO.writeAll(meta, "{\"pack\": {\"pack_format\": "+getDataVersion().getPackFormat()+", \"description\": \"Iris Data Pack. This pack contains all installed Iris Packs' resources.\"}}");
|
||||||
|
} catch (IOException e) {
|
||||||
|
Iris.error("Failed to write pack.mcmeta to " + meta.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> Map<ResourceLocation, JsonElement> collect(ResourceKey<Registry<T>> registryKey, Codec<T> codec) {
|
||||||
|
var registry = registry().registry(registryKey).orElse(null);
|
||||||
|
if (registry == null || !changedRegistries.getOrDefault(registryKey, false))
|
||||||
|
return Map.of();
|
||||||
|
try {
|
||||||
|
return registry
|
||||||
|
.registryKeySet()
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.toMap(ResourceKey::location, id -> encode(codec, registry.get(id)).orElse(JsonNull.INSTANCE)));
|
||||||
|
} finally {
|
||||||
|
changedRegistries.put(registryKey, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSpawnChunkCount(World world) {
|
||||||
|
var radius = Optional.ofNullable(world.getGameRuleValue(GameRule.SPAWN_CHUNK_RADIUS))
|
||||||
|
.orElseGet(() -> world.getGameRuleDefault(GameRule.SPAWN_CHUNK_RADIUS));
|
||||||
|
if (radius == null) throw new IllegalStateException("GameRule.SPAWN_CHUNK_RADIUS is null!");
|
||||||
|
return (int) Math.pow(2 * radius + 1, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPackRepository getPackRepository() {
|
||||||
|
return packRepository;
|
||||||
|
}
|
||||||
|
|
||||||
public void injectBukkit() {
|
public void injectBukkit() {
|
||||||
try {
|
try {
|
||||||
Iris.info("Injecting Bukkit");
|
Iris.info("Injecting Bukkit");
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package com.volmit.iris.core.nms.v1_20_R4;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.volmit.iris.core.nms.container.IPackRepository;
|
||||||
|
import net.minecraft.server.packs.repository.PackRepository;
|
||||||
|
import net.minecraft.world.level.DataPackConfig;
|
||||||
|
import net.minecraft.world.level.WorldDataConfiguration;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_20_R4.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_20_R4.packs.CraftDataPackManager;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
public class WPackRepository implements IPackRepository {
|
||||||
|
private PackRepository repository;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reload() {
|
||||||
|
getRepository().reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reloadWorldData() {
|
||||||
|
var worldData = ((CraftServer) Bukkit.getServer()).getServer().getWorldData();
|
||||||
|
var config = new WorldDataConfiguration(getSelectedPacks(), worldData.enabledFeatures());
|
||||||
|
worldData.setDataConfiguration(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
private DataPackConfig getSelectedPacks() {
|
||||||
|
Collection<String> selectedIds = getSelectedIds();
|
||||||
|
List<String> enabled = ImmutableList.copyOf(selectedIds);
|
||||||
|
List<String> disabled = getAvailableIds().stream()
|
||||||
|
.filter((s) -> !selectedIds.contains(s))
|
||||||
|
.toList();
|
||||||
|
return new DataPackConfig(enabled, disabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSelected(Collection<String> packs) {
|
||||||
|
getRepository().setSelected(packs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addPack(String packId) {
|
||||||
|
return getRepository().addPack(packId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removePack(String packId) {
|
||||||
|
return getRepository().removePack(packId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getAvailableIds() {
|
||||||
|
return getRepository().getAvailableIds();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getSelectedIds() {
|
||||||
|
return getRepository().getSelectedIds();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable(String packId) {
|
||||||
|
return getRepository().isAvailable(packId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PackRepository getRepository() {
|
||||||
|
if (repository == null)
|
||||||
|
repository = ((CraftDataPackManager) Bukkit.getDataPackManager()).getHandle();
|
||||||
|
return repository;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,8 @@ package com.volmit.iris.core.nms.v1_21_R1;
|
|||||||
|
|
||||||
import com.mojang.serialization.MapCodec;
|
import com.mojang.serialization.MapCodec;
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
|
import com.volmit.iris.core.ServerConfigurator;
|
||||||
|
import com.volmit.iris.core.nms.INMS;
|
||||||
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.object.IrisBiome;
|
import com.volmit.iris.engine.object.IrisBiome;
|
||||||
@@ -124,8 +126,16 @@ public class CustomBiomeSource extends BiomeSource {
|
|||||||
for (IrisBiome i : engine.getAllBiomes()) {
|
for (IrisBiome i : engine.getAllBiomes()) {
|
||||||
if (i.isCustom()) {
|
if (i.isCustom()) {
|
||||||
for (IrisBiomeCustom j : i.getCustomDerivitives()) {
|
for (IrisBiomeCustom j : i.getCustomDerivitives()) {
|
||||||
ResourceLocation resourceLocation = ResourceLocation.fromNamespaceAndPath(engine.getDimension().getLoadKey(), j.getId());
|
ResourceLocation location = ResourceLocation.fromNamespaceAndPath(engine.getDimension().getLoadKey(), j.getId());
|
||||||
Biome biome = customRegistry.get(resourceLocation);
|
Biome biome = customRegistry.get(location);
|
||||||
|
if (biome == null) {
|
||||||
|
INMS.get().registerBiome(location.getNamespace(), j, false);
|
||||||
|
biome = customRegistry.get(location);
|
||||||
|
if (biome == null) {
|
||||||
|
Iris.error("Cannot find biome for IrisBiomeCustom " + j.getId() + " from engine " + engine.getName());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
Optional<ResourceKey<Biome>> optionalBiomeKey = customRegistry.getResourceKey(biome);
|
Optional<ResourceKey<Biome>> optionalBiomeKey = customRegistry.getResourceKey(biome);
|
||||||
if (optionalBiomeKey.isEmpty()) {
|
if (optionalBiomeKey.isEmpty()) {
|
||||||
Iris.error("Cannot find biome for IrisBiomeCustom " + j.getId() + " from engine " + engine.getName());
|
Iris.error("Cannot find biome for IrisBiomeCustom " + j.getId() + " from engine " + engine.getName());
|
||||||
@@ -141,6 +151,7 @@ public class CustomBiomeSource extends BiomeSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ServerConfigurator.dumpDataPack();
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,18 +9,22 @@ import java.util.*;
|
|||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonNull;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.mojang.datafixers.util.Pair;
|
import com.mojang.datafixers.util.Pair;
|
||||||
import com.mojang.serialization.Codec;
|
import com.mojang.serialization.Codec;
|
||||||
import com.mojang.serialization.JsonOps;
|
import com.mojang.serialization.JsonOps;
|
||||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||||
|
import com.volmit.iris.core.nms.container.IPackRepository;
|
||||||
import com.volmit.iris.core.nms.datapack.DataVersion;
|
import com.volmit.iris.core.nms.datapack.DataVersion;
|
||||||
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.util.format.C;
|
import com.volmit.iris.util.format.C;
|
||||||
|
import com.volmit.iris.util.io.IO;
|
||||||
import it.unimi.dsi.fastutil.objects.Reference2IntMap;
|
import it.unimi.dsi.fastutil.objects.Reference2IntMap;
|
||||||
import net.bytebuddy.ByteBuddy;
|
import net.bytebuddy.ByteBuddy;
|
||||||
import net.bytebuddy.asm.Advice;
|
import net.bytebuddy.asm.Advice;
|
||||||
@@ -97,6 +101,8 @@ import sun.misc.Unsafe;
|
|||||||
public class NMSBinding implements INMSBinding {
|
public class NMSBinding implements INMSBinding {
|
||||||
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
||||||
private final BlockData AIR = Material.AIR.createBlockData();
|
private final BlockData AIR = Material.AIR.createBlockData();
|
||||||
|
private final WPackRepository packRepository = new WPackRepository();
|
||||||
|
private final KMap<ResourceKey<?>, Boolean> changedRegistries = new KMap<>();
|
||||||
private final AtomicCache<MCAIdMap<net.minecraft.world.level.biome.Biome>> biomeMapCache = new AtomicCache<>();
|
private final AtomicCache<MCAIdMap<net.minecraft.world.level.biome.Biome>> biomeMapCache = new AtomicCache<>();
|
||||||
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||||
@@ -660,6 +666,7 @@ public class NMSBinding implements INMSBinding {
|
|||||||
try {
|
try {
|
||||||
var holder = registry.register(key, value, RegistrationInfo.BUILT_IN);
|
var holder = registry.register(key, value, RegistrationInfo.BUILT_IN);
|
||||||
if (frozen) valueField.set(holder, value);
|
if (frozen) valueField.set(holder, value);
|
||||||
|
changedRegistries.put(registryKey, true);
|
||||||
return true;
|
return true;
|
||||||
} finally {
|
} finally {
|
||||||
field.setBoolean(registry, frozen);
|
field.setBoolean(registry, frozen);
|
||||||
@@ -692,6 +699,7 @@ public class NMSBinding implements INMSBinding {
|
|||||||
valueField.set(holder, value);
|
valueField.set(holder, value);
|
||||||
toId.put(value, toId.removeInt(oldValue));
|
toId.put(value, toId.removeInt(oldValue));
|
||||||
byValue.put(value, byValue.remove(oldValue));
|
byValue.put(value, byValue.remove(oldValue));
|
||||||
|
changedRegistries.put(registryKey, true);
|
||||||
return true;
|
return true;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
@@ -729,6 +737,85 @@ public class NMSBinding implements INMSBinding {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean dumpRegistry(File... folders) {
|
||||||
|
var biomes = collect(Registries.BIOME, net.minecraft.world.level.biome.Biome.DIRECT_CODEC);
|
||||||
|
var dimensions = collect(Registries.DIMENSION_TYPE, DimensionType.DIRECT_CODEC);
|
||||||
|
|
||||||
|
if (biomes.isEmpty() && dimensions.isEmpty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (File folder : folders) {
|
||||||
|
if (folder.getName().equals("datapacks"))
|
||||||
|
folder = new File(folder, "iris");
|
||||||
|
File data = new File(folder, "data");
|
||||||
|
|
||||||
|
for (var entry : biomes.entrySet()) {
|
||||||
|
File file = new File(data, entry.getKey().getNamespace() + "/worldgen/biome/" + entry.getKey().getPath() + ".json");
|
||||||
|
if (!file.getParentFile().exists() && !file.getParentFile().mkdirs())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
IO.writeAll(file, entry.getValue().toString());
|
||||||
|
} catch (IOException e) {
|
||||||
|
Iris.error("Failed to write biome " + entry.getKey().toString() + " to " + file.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var entry : dimensions.entrySet()) {
|
||||||
|
File file = new File(data, entry.getKey().getNamespace() + "/dimension_type/" + entry.getKey().getPath() + ".json");
|
||||||
|
if (!file.getParentFile().exists() && !file.getParentFile().mkdirs())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
IO.writeAll(file, entry.getValue().toString());
|
||||||
|
} catch (IOException e) {
|
||||||
|
Iris.error("Failed to write dimension " + entry.getKey().toString() + " to " + file.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
File meta = new File(folder, "pack.mcmeta");
|
||||||
|
if (!meta.getParentFile().exists() && !meta.getParentFile().mkdirs())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
IO.writeAll(meta, "{\"pack\": {\"pack_format\": "+getDataVersion().getPackFormat()+", \"description\": \"Iris Data Pack. This pack contains all installed Iris Packs' resources.\"}}");
|
||||||
|
} catch (IOException e) {
|
||||||
|
Iris.error("Failed to write pack.mcmeta to " + meta.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> Map<ResourceLocation, JsonElement> collect(ResourceKey<Registry<T>> registryKey, Codec<T> codec) {
|
||||||
|
var registry = registry().registry(registryKey).orElse(null);
|
||||||
|
if (registry == null || !changedRegistries.getOrDefault(registryKey, false))
|
||||||
|
return Map.of();
|
||||||
|
try {
|
||||||
|
return registry
|
||||||
|
.registryKeySet()
|
||||||
|
.stream()
|
||||||
|
.filter(id -> !id.location().getNamespace().equals("minecraft"))
|
||||||
|
.collect(Collectors.toMap(ResourceKey::location, id -> encode(codec, registry.get(id)).orElse(JsonNull.INSTANCE)));
|
||||||
|
} finally {
|
||||||
|
changedRegistries.put(registryKey, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSpawnChunkCount(World world) {
|
||||||
|
var radius = Optional.ofNullable(world.getGameRuleValue(GameRule.SPAWN_CHUNK_RADIUS))
|
||||||
|
.orElseGet(() -> world.getGameRuleDefault(GameRule.SPAWN_CHUNK_RADIUS));
|
||||||
|
if (radius == null) throw new IllegalStateException("GameRule.SPAWN_CHUNK_RADIUS is null!");
|
||||||
|
return (int) Math.pow(2 * radius + 1, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPackRepository getPackRepository() {
|
||||||
|
return packRepository;
|
||||||
|
}
|
||||||
|
|
||||||
public void injectBukkit() {
|
public void injectBukkit() {
|
||||||
try {
|
try {
|
||||||
Iris.info("Injecting Bukkit");
|
Iris.info("Injecting Bukkit");
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package com.volmit.iris.core.nms.v1_21_R1;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.volmit.iris.core.nms.container.IPackRepository;
|
||||||
|
import net.minecraft.server.packs.repository.PackRepository;
|
||||||
|
import net.minecraft.world.level.DataPackConfig;
|
||||||
|
import net.minecraft.world.level.WorldDataConfiguration;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_21_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_21_R1.packs.CraftDataPackManager;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
public class WPackRepository implements IPackRepository {
|
||||||
|
private PackRepository repository;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reload() {
|
||||||
|
getRepository().reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reloadWorldData() {
|
||||||
|
var worldData = ((CraftServer) Bukkit.getServer()).getServer().getWorldData();
|
||||||
|
var config = new WorldDataConfiguration(getSelectedPacks(), worldData.enabledFeatures());
|
||||||
|
worldData.setDataConfiguration(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
private DataPackConfig getSelectedPacks() {
|
||||||
|
Collection<String> selectedIds = getSelectedIds();
|
||||||
|
List<String> enabled = ImmutableList.copyOf(selectedIds);
|
||||||
|
List<String> disabled = getAvailableIds().stream()
|
||||||
|
.filter((s) -> !selectedIds.contains(s))
|
||||||
|
.toList();
|
||||||
|
return new DataPackConfig(enabled, disabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSelected(Collection<String> packs) {
|
||||||
|
getRepository().setSelected(packs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addPack(String packId) {
|
||||||
|
return getRepository().addPack(packId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removePack(String packId) {
|
||||||
|
return getRepository().removePack(packId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getAvailableIds() {
|
||||||
|
return getRepository().getAvailableIds();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getSelectedIds() {
|
||||||
|
return getRepository().getSelectedIds();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable(String packId) {
|
||||||
|
return getRepository().isAvailable(packId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PackRepository getRepository() {
|
||||||
|
if (repository == null)
|
||||||
|
repository = ((CraftDataPackManager) Bukkit.getDataPackManager()).getHandle();
|
||||||
|
return repository;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user