mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-30 20:39:21 +00:00
add dummy datapack + fix world creation
This commit is contained in:
@@ -2,6 +2,7 @@ package com.volmit.iris.core.nms.v1_19_R1;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
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.framework.Engine;
|
||||
@@ -146,6 +147,7 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
}
|
||||
}
|
||||
}
|
||||
ServerConfigurator.dumpDataPack();
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
package com.volmit.iris.core.nms.v1_19_R1;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
@@ -17,8 +13,12 @@ import java.util.Vector;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
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.IPackRepository;
|
||||
import com.volmit.iris.util.io.IO;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.gson.JsonElement;
|
||||
@@ -101,6 +101,8 @@ import sun.misc.Unsafe;
|
||||
public class NMSBinding implements INMSBinding {
|
||||
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
||||
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<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||
@@ -623,6 +625,7 @@ public class NMSBinding implements INMSBinding {
|
||||
try {
|
||||
var holder = registry.register(key, value, Lifecycle.stable());
|
||||
if (frozen) valueField.set(holder, value);
|
||||
changedRegistries.put(registryKey, true);
|
||||
return true;
|
||||
} finally {
|
||||
field.setBoolean(registry, frozen);
|
||||
@@ -659,6 +662,7 @@ public class NMSBinding implements INMSBinding {
|
||||
toId.put(value, toId.removeInt(oldValue));
|
||||
byValue.put(value, byValue.remove(oldValue));
|
||||
lifecycles.put(value, lifecycles.remove(oldValue));
|
||||
changedRegistries.put(registryKey, true);
|
||||
return true;
|
||||
} catch (Throwable 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
|
||||
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 {
|
||||
@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) {
|
||||
|
||||
@@ -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.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.framework.Engine;
|
||||
@@ -148,6 +149,7 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
}
|
||||
}
|
||||
}
|
||||
ServerConfigurator.dumpDataPack();
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
package com.volmit.iris.core.nms.v1_19_R2;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
@@ -17,8 +13,12 @@ import java.util.Vector;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
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.IPackRepository;
|
||||
import com.volmit.iris.util.io.IO;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.gson.JsonElement;
|
||||
@@ -102,6 +102,8 @@ import sun.misc.Unsafe;
|
||||
public class NMSBinding implements INMSBinding {
|
||||
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
||||
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<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||
@@ -625,6 +627,7 @@ public class NMSBinding implements INMSBinding {
|
||||
try {
|
||||
var holder = registry.register(key, value, Lifecycle.stable());
|
||||
if (frozen) valueField.set(holder, value);
|
||||
changedRegistries.put(registryKey, true);
|
||||
return true;
|
||||
} finally {
|
||||
field.setBoolean(registry, frozen);
|
||||
@@ -661,6 +664,7 @@ public class NMSBinding implements INMSBinding {
|
||||
toId.put(value, toId.removeInt(oldValue));
|
||||
byValue.put(value, byValue.remove(oldValue));
|
||||
lifecycles.put(value, lifecycles.remove(oldValue));
|
||||
changedRegistries.put(registryKey, true);
|
||||
return true;
|
||||
} catch (Throwable 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() {
|
||||
try {
|
||||
Iris.info("Injecting Bukkit");
|
||||
@@ -763,6 +832,11 @@ public class NMSBinding implements INMSBinding {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPackRepository getPackRepository() {
|
||||
return packRepository;
|
||||
}
|
||||
|
||||
private static class ServerLevelAdvice {
|
||||
@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) {
|
||||
|
||||
@@ -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.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.framework.Engine;
|
||||
@@ -151,6 +152,7 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
}
|
||||
}
|
||||
}
|
||||
ServerConfigurator.dumpDataPack();
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
package com.volmit.iris.core.nms.v1_19_R3;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
@@ -17,8 +13,12 @@ import java.util.Vector;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
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.IPackRepository;
|
||||
import com.volmit.iris.util.io.IO;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.gson.JsonElement;
|
||||
@@ -103,6 +103,8 @@ import sun.misc.Unsafe;
|
||||
public class NMSBinding implements INMSBinding {
|
||||
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
||||
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<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||
@@ -629,6 +631,7 @@ public class NMSBinding implements INMSBinding {
|
||||
try {
|
||||
var holder = registry.register(key, value, Lifecycle.stable());
|
||||
if (frozen) valueField.set(holder, value);
|
||||
changedRegistries.put(registryKey, true);
|
||||
return true;
|
||||
} finally {
|
||||
field.setBoolean(registry, frozen);
|
||||
@@ -665,6 +668,7 @@ public class NMSBinding implements INMSBinding {
|
||||
toId.put(value, toId.removeInt(oldValue));
|
||||
byValue.put(value, byValue.remove(oldValue));
|
||||
lifecycles.put(value, lifecycles.remove(oldValue));
|
||||
changedRegistries.put(registryKey, true);
|
||||
return true;
|
||||
} catch (Throwable 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() {
|
||||
try {
|
||||
Iris.info("Injecting Bukkit");
|
||||
@@ -767,6 +836,11 @@ public class NMSBinding implements INMSBinding {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPackRepository getPackRepository() {
|
||||
return packRepository;
|
||||
}
|
||||
|
||||
private static class ServerLevelAdvice {
|
||||
@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) {
|
||||
|
||||
@@ -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.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.framework.Engine;
|
||||
@@ -151,6 +152,7 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
}
|
||||
}
|
||||
}
|
||||
ServerConfigurator.dumpDataPack();
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.volmit.iris.core.nms.v1_20_R1;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
@@ -11,6 +12,7 @@ import com.mojang.serialization.Lifecycle;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.nms.INMSBinding;
|
||||
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.framework.Engine;
|
||||
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.format.C;
|
||||
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.mantle.Mantle;
|
||||
import com.volmit.iris.util.math.Vector3d;
|
||||
@@ -83,11 +86,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import sun.misc.Unsafe;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
@@ -99,12 +98,15 @@ import java.util.Vector;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class NMSBinding implements INMSBinding {
|
||||
|
||||
public static final String NMS_VERSION = "1.20.1";
|
||||
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
||||
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<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||
@@ -614,6 +616,7 @@ public class NMSBinding implements INMSBinding {
|
||||
try {
|
||||
var holder = registry.register(key, value, Lifecycle.stable());
|
||||
if (frozen) valueField.set(holder, value);
|
||||
changedRegistries.put(registryKey, true);
|
||||
return true;
|
||||
} finally {
|
||||
field.setBoolean(registry, frozen);
|
||||
@@ -650,6 +653,7 @@ public class NMSBinding implements INMSBinding {
|
||||
toId.put(value, toId.removeInt(oldValue));
|
||||
byValue.put(value, byValue.remove(oldValue));
|
||||
lifecycles.put(value, lifecycles.remove(oldValue));
|
||||
changedRegistries.put(registryKey, true);
|
||||
return true;
|
||||
} catch (Throwable 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() {
|
||||
try {
|
||||
Iris.info("Injecting Bukkit");
|
||||
@@ -765,6 +834,11 @@ public class NMSBinding implements INMSBinding {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPackRepository getPackRepository() {
|
||||
return packRepository;
|
||||
}
|
||||
|
||||
private static class ServerLevelAdvice {
|
||||
@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) {
|
||||
|
||||
@@ -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.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.framework.Engine;
|
||||
@@ -150,6 +151,7 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
}
|
||||
}
|
||||
}
|
||||
ServerConfigurator.dumpDataPack();
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
package com.volmit.iris.core.nms.v1_20_R2;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
@@ -17,8 +13,13 @@ import java.util.Vector;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
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.IPackRepository;
|
||||
import com.volmit.iris.util.io.IO;
|
||||
import net.minecraft.server.commands.DataPackCommand;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import com.google.common.base.Preconditions;
|
||||
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.entity.CraftDolphin;
|
||||
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.entity.Dolphin;
|
||||
import org.bukkit.entity.Entity;
|
||||
@@ -104,6 +106,8 @@ import sun.misc.Unsafe;
|
||||
public class NMSBinding implements INMSBinding {
|
||||
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
||||
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<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||
@@ -626,6 +630,7 @@ public class NMSBinding implements INMSBinding {
|
||||
try {
|
||||
var holder = registry.register(key, value, Lifecycle.stable());
|
||||
if (frozen) valueField.set(holder, value);
|
||||
changedRegistries.put(registryKey, true);
|
||||
return true;
|
||||
} finally {
|
||||
field.setBoolean(registry, frozen);
|
||||
@@ -662,6 +667,7 @@ public class NMSBinding implements INMSBinding {
|
||||
toId.put(value, toId.removeInt(oldValue));
|
||||
byValue.put(value, byValue.remove(oldValue));
|
||||
lifecycles.put(value, lifecycles.remove(oldValue));
|
||||
changedRegistries.put(registryKey, true);
|
||||
return true;
|
||||
} catch (Throwable 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())));
|
||||
}
|
||||
|
||||
@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() {
|
||||
try {
|
||||
Iris.info("Injecting Bukkit");
|
||||
@@ -769,6 +840,11 @@ public class NMSBinding implements INMSBinding {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPackRepository getPackRepository() {
|
||||
return packRepository;
|
||||
}
|
||||
|
||||
private static class ServerLevelAdvice {
|
||||
@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) {
|
||||
|
||||
@@ -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.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.framework.Engine;
|
||||
@@ -150,6 +151,7 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
}
|
||||
}
|
||||
}
|
||||
ServerConfigurator.dumpDataPack();
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.volmit.iris.core.nms.v1_20_R3;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.ServerConfigurator;
|
||||
import com.volmit.iris.core.nms.BiomeBaseInjector;
|
||||
import com.volmit.iris.core.nms.IHeadless;
|
||||
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);
|
||||
}
|
||||
}
|
||||
ServerConfigurator.dumpDataPack();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
package com.volmit.iris.core.nms.v1_20_R3;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
@@ -13,19 +9,23 @@ import java.util.*;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.JsonOps;
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
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.engine.object.IrisBiomeCustom;
|
||||
import com.volmit.iris.engine.object.IrisDimension;
|
||||
import com.volmit.iris.util.format.C;
|
||||
import com.volmit.iris.util.io.IO;
|
||||
import it.unimi.dsi.fastutil.objects.Reference2IntMap;
|
||||
import net.bytebuddy.ByteBuddy;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
@@ -114,6 +114,8 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
||||
public class NMSBinding implements INMSBinding {
|
||||
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
||||
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<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||
@@ -636,6 +638,7 @@ public class NMSBinding implements INMSBinding {
|
||||
try {
|
||||
var holder = registry.register(key, value, Lifecycle.stable());
|
||||
if (frozen) valueField.set(holder, value);
|
||||
changedRegistries.put(registryKey, true);
|
||||
return true;
|
||||
} finally {
|
||||
field.setBoolean(registry, frozen);
|
||||
@@ -672,6 +675,7 @@ public class NMSBinding implements INMSBinding {
|
||||
toId.put(value, toId.removeInt(oldValue));
|
||||
byValue.put(value, byValue.remove(oldValue));
|
||||
lifecycles.put(value, lifecycles.remove(oldValue));
|
||||
changedRegistries.put(registryKey, true);
|
||||
return true;
|
||||
} catch (Throwable 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())));
|
||||
}
|
||||
|
||||
@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() {
|
||||
try {
|
||||
Iris.info("Injecting Bukkit");
|
||||
@@ -784,6 +853,11 @@ public class NMSBinding implements INMSBinding {
|
||||
return new Headless(this, engine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPackRepository getPackRepository() {
|
||||
return packRepository;
|
||||
}
|
||||
|
||||
private static class ServerLevelAdvice {
|
||||
@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) {
|
||||
|
||||
@@ -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.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.framework.Engine;
|
||||
@@ -150,6 +151,7 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
}
|
||||
}
|
||||
}
|
||||
ServerConfigurator.dumpDataPack();
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
package com.volmit.iris.core.nms.v1_20_R4;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
@@ -17,7 +13,9 @@ import java.util.Vector;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
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.google.common.base.Preconditions;
|
||||
import com.google.gson.JsonElement;
|
||||
@@ -25,10 +23,12 @@ import com.google.gson.JsonObject;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.serialization.Codec;
|
||||
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.engine.object.IrisBiomeCustom;
|
||||
import com.volmit.iris.engine.object.IrisDimension;
|
||||
import com.volmit.iris.util.format.C;
|
||||
import com.volmit.iris.util.io.IO;
|
||||
import it.unimi.dsi.fastutil.objects.Reference2IntMap;
|
||||
import net.bytebuddy.ByteBuddy;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
@@ -107,6 +107,8 @@ import sun.misc.Unsafe;
|
||||
public class NMSBinding implements INMSBinding {
|
||||
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
||||
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<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||
@@ -667,6 +669,7 @@ public class NMSBinding implements INMSBinding {
|
||||
try {
|
||||
var holder = registry.register(key, value, RegistrationInfo.BUILT_IN);
|
||||
if (frozen) valueField.set(holder, value);
|
||||
changedRegistries.put(registryKey, true);
|
||||
return true;
|
||||
} finally {
|
||||
field.setBoolean(registry, frozen);
|
||||
@@ -699,6 +702,7 @@ public class NMSBinding implements INMSBinding {
|
||||
valueField.set(holder, value);
|
||||
toId.put(value, toId.removeInt(oldValue));
|
||||
byValue.put(value, byValue.remove(oldValue));
|
||||
changedRegistries.put(registryKey, true);
|
||||
return true;
|
||||
} catch (Throwable 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() {
|
||||
try {
|
||||
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.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.framework.Engine;
|
||||
import com.volmit.iris.engine.object.IrisBiome;
|
||||
@@ -124,8 +126,16 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
for (IrisBiome i : engine.getAllBiomes()) {
|
||||
if (i.isCustom()) {
|
||||
for (IrisBiomeCustom j : i.getCustomDerivitives()) {
|
||||
ResourceLocation resourceLocation = ResourceLocation.fromNamespaceAndPath(engine.getDimension().getLoadKey(), j.getId());
|
||||
Biome biome = customRegistry.get(resourceLocation);
|
||||
ResourceLocation location = ResourceLocation.fromNamespaceAndPath(engine.getDimension().getLoadKey(), j.getId());
|
||||
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);
|
||||
if (optionalBiomeKey.isEmpty()) {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -9,18 +9,22 @@ import java.util.*;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.JsonOps;
|
||||
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.engine.object.IrisBiomeCustom;
|
||||
import com.volmit.iris.engine.object.IrisDimension;
|
||||
import com.volmit.iris.util.format.C;
|
||||
import com.volmit.iris.util.io.IO;
|
||||
import it.unimi.dsi.fastutil.objects.Reference2IntMap;
|
||||
import net.bytebuddy.ByteBuddy;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
@@ -97,6 +101,8 @@ import sun.misc.Unsafe;
|
||||
public class NMSBinding implements INMSBinding {
|
||||
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
||||
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<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||
@@ -660,6 +666,7 @@ public class NMSBinding implements INMSBinding {
|
||||
try {
|
||||
var holder = registry.register(key, value, RegistrationInfo.BUILT_IN);
|
||||
if (frozen) valueField.set(holder, value);
|
||||
changedRegistries.put(registryKey, true);
|
||||
return true;
|
||||
} finally {
|
||||
field.setBoolean(registry, frozen);
|
||||
@@ -692,6 +699,7 @@ public class NMSBinding implements INMSBinding {
|
||||
valueField.set(holder, value);
|
||||
toId.put(value, toId.removeInt(oldValue));
|
||||
byValue.put(value, byValue.remove(oldValue));
|
||||
changedRegistries.put(registryKey, true);
|
||||
return true;
|
||||
} catch (Throwable 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() {
|
||||
try {
|
||||
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