mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-04 00:46:08 +00:00
f
This commit is contained in:
parent
1634454700
commit
efe800c606
@ -1,13 +0,0 @@
|
|||||||
package IrisBukkit.extensions.org.bukkit.Chunk;
|
|
||||||
|
|
||||||
import com.volmit.iris.platform.bukkit.wrapper.BukkitChunk;
|
|
||||||
import manifold.ext.rt.api.Extension;
|
|
||||||
import manifold.ext.rt.api.This;
|
|
||||||
import org.bukkit.Chunk;
|
|
||||||
|
|
||||||
@Extension
|
|
||||||
public class XChunk {
|
|
||||||
public static BukkitChunk bukkitChunk(@This Chunk self) {
|
|
||||||
return BukkitChunk.of(self);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
package IrisBukkit.extensions.org.bukkit.NamespacedKey;
|
|
||||||
|
|
||||||
import com.volmit.iris.platform.bukkit.wrapper.BukkitKey;
|
|
||||||
import manifold.ext.rt.api.Extension;
|
|
||||||
import manifold.ext.rt.api.This;
|
|
||||||
import org.bukkit.NamespacedKey;
|
|
||||||
|
|
||||||
@Extension
|
|
||||||
public class XNamespacedKey {
|
|
||||||
public static BukkitKey bukkitKey(@This NamespacedKey self) {
|
|
||||||
return BukkitKey.of(self);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
package IrisBukkit.extensions.org.bukkit.World;
|
|
||||||
|
|
||||||
import com.volmit.iris.platform.bukkit.wrapper.BukkitWorld;
|
|
||||||
import manifold.ext.rt.api.Extension;
|
|
||||||
import manifold.ext.rt.api.This;
|
|
||||||
import org.bukkit.World;
|
|
||||||
|
|
||||||
@Extension
|
|
||||||
public class XWorld {
|
|
||||||
public static BukkitWorld bukkitWorld(@This World self) {
|
|
||||||
return BukkitWorld.of(self);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
package IrisBukkit.extensions.org.bukkit.block.Biome;
|
|
||||||
|
|
||||||
import com.volmit.iris.platform.bukkit.wrapper.BukkitBiome;
|
|
||||||
import com.volmit.iris.platform.bukkit.wrapper.BukkitKey;
|
|
||||||
import manifold.ext.rt.api.Extension;
|
|
||||||
import manifold.ext.rt.api.This;
|
|
||||||
import org.bukkit.block.Biome;
|
|
||||||
|
|
||||||
@Extension
|
|
||||||
public class XBiome {
|
|
||||||
public static BukkitKey bukkitKey(@This Biome self) {
|
|
||||||
return self.getKey().bukkitKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BukkitBiome bukkitBiome(@This Biome self) {
|
|
||||||
return BukkitBiome.of(self);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
package IrisBukkit.extensions.org.bukkit.block.data.BlockData;
|
|
||||||
|
|
||||||
import com.volmit.iris.platform.bukkit.wrapper.BukkitBlock;
|
|
||||||
import com.volmit.iris.platform.bukkit.wrapper.BukkitKey;
|
|
||||||
import manifold.ext.rt.api.Extension;
|
|
||||||
import manifold.ext.rt.api.This;
|
|
||||||
import org.bukkit.block.data.BlockData;
|
|
||||||
|
|
||||||
@Extension
|
|
||||||
public class XBlockData {
|
|
||||||
public static BukkitKey bukkitKey(@This BlockData self) {
|
|
||||||
return self.getMaterial().getKey().bukkitKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BukkitBlock bukkitBlock(@This BlockData self) {
|
|
||||||
return BukkitBlock.of(self);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
package IrisBukkit.extensions.org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.volmit.iris.platform.bukkit.wrapper.BukkitPlayer;
|
|
||||||
import manifold.ext.rt.api.Extension;
|
|
||||||
import manifold.ext.rt.api.This;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
@Extension
|
|
||||||
public class XPlayer {
|
|
||||||
public static BukkitPlayer bukkitPlayer(@This Player self) {
|
|
||||||
return BukkitPlayer.of(self);
|
|
||||||
}
|
|
||||||
}
|
|
@ -7,7 +7,10 @@ import com.volmit.iris.platform.PlatformBiome;
|
|||||||
import com.volmit.iris.platform.PlatformBlock;
|
import com.volmit.iris.platform.PlatformBlock;
|
||||||
import com.volmit.iris.platform.PlatformNamespaceKey;
|
import com.volmit.iris.platform.PlatformNamespaceKey;
|
||||||
import com.volmit.iris.platform.PlatformWorld;
|
import com.volmit.iris.platform.PlatformWorld;
|
||||||
|
import com.volmit.iris.platform.bukkit.wrapper.BukkitBiome;
|
||||||
|
import com.volmit.iris.platform.bukkit.wrapper.BukkitBlock;
|
||||||
import com.volmit.iris.platform.bukkit.wrapper.BukkitKey;
|
import com.volmit.iris.platform.bukkit.wrapper.BukkitKey;
|
||||||
|
import com.volmit.iris.platform.bukkit.wrapper.BukkitWorld;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -69,7 +72,7 @@ public class IrisBukkit extends JavaPlugin implements IrisPlatform {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
i.bukkitWorld().unloadChunks(false, true);
|
BukkitWorld.of(i).unloadChunks(false, true);
|
||||||
File folder = i.getWorldFolder();
|
File folder = i.getWorldFolder();
|
||||||
Bukkit.unloadWorld(i, false);
|
Bukkit.unloadWorld(i, false);
|
||||||
IO.delete(folder);
|
IO.delete(folder);
|
||||||
@ -93,14 +96,14 @@ public class IrisBukkit extends JavaPlugin implements IrisPlatform {
|
|||||||
return Arrays.stream(Material.values())
|
return Arrays.stream(Material.values())
|
||||||
.filter(i -> !i.isLegacy())
|
.filter(i -> !i.isLegacy())
|
||||||
.filter(Material::isBlock)
|
.filter(Material::isBlock)
|
||||||
.map(Material::createBlockData).map(i -> i.bukkitBlock());
|
.map(Material::createBlockData).map(i -> BukkitBlock.of(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Stream<PlatformBiome> getBiomes() {
|
public Stream<PlatformBiome> getBiomes() {
|
||||||
//This is because it's a method extension
|
//This is because it's a method extension
|
||||||
//noinspection Convert2MethodRef
|
//noinspection Convert2MethodRef
|
||||||
return Arrays.stream(Biome.values()).parallel().filter((i) -> i != Biome.CUSTOM).map(i -> i.bukkitBiome());
|
return Arrays.stream(Biome.values()).parallel().filter((i) -> i != Biome.CUSTOM).map(i -> BukkitBiome.of(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -117,12 +120,12 @@ public class IrisBukkit extends JavaPlugin implements IrisPlatform {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return w.bukkitWorld();
|
return BukkitWorld.of(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlatformBlock parseBlock(String raw) {
|
public PlatformBlock parseBlock(String raw) {
|
||||||
return Bukkit.createBlockData(raw).bukkitBlock();
|
return BukkitBlock.of(Bukkit.createBlockData(raw));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -130,6 +133,13 @@ public class IrisBukkit extends JavaPlugin implements IrisPlatform {
|
|||||||
return BukkitKey.of(namespace, key);
|
return BukkitKey.of(namespace, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File getStudioFolder(String dimension) {
|
||||||
|
File f = new File(getDataFolder(), "packs/" + dimension);
|
||||||
|
f.mkdirs();
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
|
public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
|
||||||
return new IrisBukkitChunkGenerator(this, EngineConfiguration.builder()
|
return new IrisBukkitChunkGenerator(this, EngineConfiguration.builder()
|
||||||
|
@ -10,6 +10,7 @@ import com.volmit.iris.engine.feature.IrisFeatureTarget;
|
|||||||
import com.volmit.iris.engine.pipeline.PipedHunkStack;
|
import com.volmit.iris.engine.pipeline.PipedHunkStack;
|
||||||
import com.volmit.iris.platform.IrisPlatform;
|
import com.volmit.iris.platform.IrisPlatform;
|
||||||
import com.volmit.iris.platform.PlatformBlock;
|
import com.volmit.iris.platform.PlatformBlock;
|
||||||
|
import com.volmit.iris.platform.bukkit.wrapper.BukkitWorld;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.generator.ChunkGenerator;
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
@ -77,7 +78,11 @@ public class IrisBukkitChunkGenerator extends ChunkGenerator implements Closeabl
|
|||||||
|
|
||||||
if(engine.get() == null)
|
if(engine.get() == null)
|
||||||
{
|
{
|
||||||
engine.set(new Engine(platform, world.bukkitWorld(), configuration));
|
try {
|
||||||
|
engine.set(new Engine(platform, BukkitWorld.of(world), configuration));
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
engineLock.unlock();
|
engineLock.unlock();
|
||||||
|
@ -48,6 +48,6 @@ public class ChunkDataHunkView implements Hunk<PlatformBlock> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlatformBlock getRaw(int x, int y, int z) {
|
public PlatformBlock getRaw(int x, int y, int z) {
|
||||||
return chunk.getBlockData(x, y + chunk.getMinHeight(), z).bukkitBlock();
|
return BukkitBlock.of(chunk.getBlockData(x, y + chunk.getMinHeight(), z));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,7 +15,7 @@ public class BukkitBiome implements PlatformBiome {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlatformNamespaceKey getKey() {
|
public PlatformNamespaceKey getKey() {
|
||||||
return delegate.getKey().bukkitKey();
|
return BukkitKey.of(delegate.getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BukkitBiome of(Biome biome) {
|
public static BukkitBiome of(Biome biome) {
|
||||||
|
@ -52,7 +52,7 @@ public class BukkitBlock implements PlatformBlock {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlatformNamespaceKey getKey() {
|
public PlatformNamespaceKey getKey() {
|
||||||
return delegate.getMaterial().getKey().bukkitKey();
|
return BukkitKey.of(delegate.getMaterial().getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BukkitBlock of(BlockData blockData) {
|
public static BukkitBlock of(BlockData blockData) {
|
||||||
|
@ -31,7 +31,7 @@ public class BukkitPlayer implements PlatformPlayer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlatformWorld getWorld() {
|
public PlatformWorld getWorld() {
|
||||||
return delegate.getWorld().bukkitWorld();
|
return BukkitWorld.of(delegate.getWorld());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -10,6 +10,7 @@ import lombok.Data;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@ -40,28 +41,28 @@ public class BukkitWorld implements PlatformWorld {
|
|||||||
@Override
|
@Override
|
||||||
public Iterable<PlatformPlayer> getPlayers() {
|
public Iterable<PlatformPlayer> getPlayers() {
|
||||||
//noinspection Convert2MethodRef
|
//noinspection Convert2MethodRef
|
||||||
return delegate.getPlayers().stream().map(i -> i.bukkitPlayer()).collect(Collectors.toList());
|
return delegate.getPlayers().stream().map(i -> BukkitPlayer.of(i)).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<PlatformChunk> getLoadedChunks() {
|
public Iterable<PlatformChunk> getLoadedChunks() {
|
||||||
//noinspection Convert2MethodRef
|
//noinspection Convert2MethodRef
|
||||||
return delegate.getLoadedChunks().stream().map(i -> i.bukkitChunk()).collect(Collectors.toList());
|
return Arrays.stream(delegate.getLoadedChunks()).map(i -> BukkitChunk.of(i)).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlatformChunk getOrLoadChunk(int x, int z) {
|
public PlatformChunk getOrLoadChunk(int x, int z) {
|
||||||
return delegate.getChunkAt(x, z).bukkitChunk();
|
return BukkitChunk.of(delegate.getChunkAt(x, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlatformBlock getBlock(int x, int y, int z) {
|
public PlatformBlock getBlock(int x, int y, int z) {
|
||||||
return delegate.getBlockAt(x, y, z).getBlockData().bukkitBlock();
|
return BukkitBlock.of(delegate.getBlockAt(x, y, z).getBlockData());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlatformBiome getBiome(int x, int y, int z) {
|
public PlatformBiome getBiome(int x, int y, int z) {
|
||||||
return delegate.getBiome(x, y, z).bukkitBiome();
|
return BukkitBiome.of(delegate.getBiome(x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -33,7 +33,7 @@ public class Engine implements Closeable {
|
|||||||
private final EngineSeedManager seedManager;
|
private final EngineSeedManager seedManager;
|
||||||
private final EngineData data;
|
private final EngineData data;
|
||||||
|
|
||||||
public Engine(IrisPlatform platform, PlatformWorld world, EngineConfiguration configuration) {
|
public Engine(IrisPlatform platform, PlatformWorld world, EngineConfiguration configuration) throws IOException {
|
||||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
this.platform = platform;
|
this.platform = platform;
|
||||||
@ -56,6 +56,9 @@ public class Engine implements Closeable {
|
|||||||
.build())
|
.build())
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
|
data.loadData(getConfiguration().isMutable()
|
||||||
|
? getPlatform().getStudioFolder(getConfiguration().getDimension())
|
||||||
|
: getWorld().getIrisDataFolder());
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlatformBlock block(String block)
|
public PlatformBlock block(String block)
|
||||||
|
@ -22,4 +22,7 @@ public class EngineConfiguration {
|
|||||||
|
|
||||||
@Builder.Default
|
@Builder.Default
|
||||||
private int threadPriority = 3;
|
private int threadPriority = 3;
|
||||||
|
|
||||||
|
@Builder.Default
|
||||||
|
private String dimension = "overworld";
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
package com.volmit.iris.engine;
|
package com.volmit.iris.engine;
|
||||||
|
|
||||||
import art.arcane.amulet.concurrent.J;
|
import art.arcane.amulet.concurrent.J;
|
||||||
|
import art.arcane.amulet.io.IO;
|
||||||
import art.arcane.amulet.io.JarLoader;
|
import art.arcane.amulet.io.JarLoader;
|
||||||
|
import art.arcane.cram.PakFile;
|
||||||
|
import art.arcane.cram.PakKey;
|
||||||
|
import art.arcane.cram.PakResource;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.TypeAdapterFactory;
|
import com.google.gson.TypeAdapterFactory;
|
||||||
@ -9,6 +13,7 @@ import com.volmit.iris.engine.resolver.*;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -19,10 +24,9 @@ public class EngineData {
|
|||||||
private final Engine engine;
|
private final Engine engine;
|
||||||
private final Gson gson;
|
private final Gson gson;
|
||||||
private List<Resolvable> resolvableTypes;
|
private List<Resolvable> resolvableTypes;
|
||||||
private final Map<Class<? extends Resolvable>, Resolver<? extends Resolvable>> resolvers;
|
private final Map<Class<?>, Resolver<?>> resolvers;
|
||||||
|
|
||||||
public EngineData(Engine engine)
|
public EngineData(Engine engine) throws IOException {
|
||||||
{
|
|
||||||
this.engine = engine;
|
this.engine = engine;
|
||||||
this.resolvers = new HashMap<>();
|
this.resolvers = new HashMap<>();
|
||||||
this.resolvableTypes = J.attempt(() -> new JarLoader(getClass()).all().parallel()
|
this.resolvableTypes = J.attempt(() -> new JarLoader(getClass()).all().parallel()
|
||||||
@ -37,44 +41,77 @@ public class EngineData {
|
|||||||
i("Registered " + resolvableTypes.size() + " Mutators with " + resolvableTypes.stream().filter(i -> i instanceof TypeAdapterFactory).count() + " Type Adapter Factories");
|
i("Registered " + resolvableTypes.size() + " Mutators with " + resolvableTypes.stream().filter(i -> i instanceof TypeAdapterFactory).count() + " Type Adapter Factories");
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends Resolvable> void registerResolver(Class<T> type, Resolver<T> resolver, String... namespaces)
|
public void registerResolver(Class<?> type, Resolver<?> resolver, String namespace)
|
||||||
{
|
{
|
||||||
if(resolvers.containsKey(type)) {
|
if(resolvers.containsKey(type)) {
|
||||||
Resolver<T> existing = (Resolver<T>) resolvers.get(type);
|
Resolver r = resolvers.get(type);
|
||||||
|
resolvers.put(type, r.and(namespace, r));
|
||||||
if(existing instanceof CompositeResolver<T> c) {
|
|
||||||
Map<String, Resolver<T>> oresolvers = c.getResolvers();
|
|
||||||
|
|
||||||
if(namespaces.length > 1) {
|
|
||||||
CompositeResolver<T> n = (CompositeResolver<T>) resolver;
|
|
||||||
|
|
||||||
for(String i : n.getResolvers().keySet()) {
|
|
||||||
if(oresolvers.containsKey(i)) {
|
|
||||||
oresolvers.put(i, new MergedResolver<>(oresolvers.get(i), n.getResolvers().get(i)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
oresolvers.put(i, n.getResolvers().get(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
resolvers.put(type, resolver);
|
resolvers.put(type, resolver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadData(File folder)
|
public void loadData(File folder) throws IOException {
|
||||||
{
|
i("Loading Data in " + folder.getPath());
|
||||||
|
for(File i : folder.listFiles()) {
|
||||||
|
if(i.isDirectory()) {
|
||||||
|
loadDataNamespaced(i, i.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadDataNamespaced(File folder, String namespace) throws IOException {
|
||||||
|
i("Loading Namespace " + namespace + " in " + folder.getPath());
|
||||||
|
for(Resolvable i : resolvableTypes)
|
||||||
|
{
|
||||||
|
new File(folder, i.entity().getId()).mkdirs();
|
||||||
|
IO.writeAll(
|
||||||
|
new File(new File(folder, i.entity().getId()), "example.json"), gson.toJson(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
for(File i : folder.listFiles())
|
||||||
|
{
|
||||||
|
if(i.isDirectory()) {
|
||||||
|
loadDataFolder(i, namespace);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(i.getName().endsWith(".dat")) {
|
||||||
|
loadPakFile(folder, i.getName().split("\\Q.\\E")[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadDataFolder(File folder, String namespace) {
|
||||||
|
for(Resolvable i : resolvableTypes)
|
||||||
|
{
|
||||||
|
if(!folder.getName().equals(i.entity().getId())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
registerResolver(i.getClass(), Resolver.hotDirectoryJson(namespace, i.getClass(), folder, gson), namespace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadPakFile(File folder, String name) throws IOException {
|
||||||
|
PakFile pakFile = new PakFile(folder, name);
|
||||||
|
Map<PakKey, PakResource> resources = pakFile.getAllResources();
|
||||||
|
|
||||||
|
for(Resolvable i : resolvableTypes)
|
||||||
|
{
|
||||||
|
Class<? extends Resolvable> resolvableClass = i.getClass();
|
||||||
|
CompositeResolver<?> composite = Resolver.frozen(resources, (p) -> p.getClass().equals(resolvableClass));
|
||||||
|
|
||||||
|
for(String j : composite.getResolvers().keySet())
|
||||||
|
{
|
||||||
|
Resolver<? extends Resolvable> resolver = composite.getResolvers().get(i);
|
||||||
|
this.registerResolver(i.getClass(), resolver, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void printResolvers() {
|
||||||
|
resolvers.forEach((k, i) -> i.print(k.simpleName(), this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package com.volmit.iris.engine.resolver;
|
package com.volmit.iris.engine.resolver;
|
||||||
|
|
||||||
|
import art.arcane.amulet.format.Form;
|
||||||
import com.volmit.iris.platform.PlatformNamespaceKey;
|
import com.volmit.iris.platform.PlatformNamespaceKey;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@ -36,4 +38,28 @@ public class CompositeResolver<T extends Resolvable> implements Resolver<T> {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Resolver<T> and(String namespace, Resolver<T> resolver) {
|
||||||
|
Map<String, Resolver<T>> resolvers = this.resolvers.copy();
|
||||||
|
|
||||||
|
if(hasNamespace(namespace)) {
|
||||||
|
resolvers.put(namespace, resolvers.get(namespace).and(namespace, resolver));
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
resolvers.put(namespace, resolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new CompositeResolver<>(resolvers);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print(String type, Object printer, int indent) {
|
||||||
|
printer.i(Form.repeat(" ", indent) + "Composite[" + Arrays.toString(getNamespaces()) + "] " + type);
|
||||||
|
|
||||||
|
for(Resolver<T> i : getResolvers().values()) {
|
||||||
|
i.print(type, printer, indent + 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.volmit.iris.engine.resolver;
|
package com.volmit.iris.engine.resolver;
|
||||||
|
|
||||||
|
import art.arcane.amulet.format.Form;
|
||||||
import com.volmit.iris.platform.PlatformNamespaceKey;
|
import com.volmit.iris.platform.PlatformNamespaceKey;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@ -30,4 +31,18 @@ public class FrozenResolver<T extends Resolvable> implements Resolver<T> {
|
|||||||
public T resolve(String key) {
|
public T resolve(String key) {
|
||||||
return registry.get(key);
|
return registry.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print(String type, Object printer, int indent) {
|
||||||
|
printer.i(Form.repeat(" ", indent) + "Frozen[" + namespace + "] " + type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Resolver<T> and(String namespace, Resolver<T> resolver) {
|
||||||
|
if(!namespace.equals(getNamespace())) {
|
||||||
|
return new CompositeResolver<>(Map.of(namespace, resolver, getNamespace(), this));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new MergedNamespaceResolver<>(namespace, this, resolver);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.volmit.iris.engine.resolver;
|
package com.volmit.iris.engine.resolver;
|
||||||
|
|
||||||
|
import art.arcane.amulet.format.Form;
|
||||||
import com.github.benmanes.caffeine.cache.CacheLoader;
|
import com.github.benmanes.caffeine.cache.CacheLoader;
|
||||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||||
@ -55,4 +56,18 @@ public class HotResolver<T extends Resolvable> implements Resolver<T>, CacheLoad
|
|||||||
public @Nullable T load(String key) {
|
public @Nullable T load(String key) {
|
||||||
return loader.apply(key);
|
return loader.apply(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Resolver<T> and(String namespace, Resolver<T> resolver) {
|
||||||
|
if(!namespace.equals(getNamespace())) {
|
||||||
|
return new CompositeResolver<>(Map.of(namespace, resolver, getNamespace(), this));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new MergedNamespaceResolver<>(namespace, this, resolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print(String type, Object printer, int indent) {
|
||||||
|
printer.i(Form.repeat(" ", indent) + "Hot[" + namespace + "] " + type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,80 @@
|
|||||||
|
package com.volmit.iris.engine.resolver;
|
||||||
|
|
||||||
|
import art.arcane.amulet.format.Form;
|
||||||
|
import com.volmit.iris.platform.PlatformNamespaceKey;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class MergedNamespaceResolver<T extends Resolvable> implements Resolver<T> {
|
||||||
|
private final String namespace;
|
||||||
|
private final List<Resolver<T>> resolvers;
|
||||||
|
|
||||||
|
public MergedNamespaceResolver(String namespace, Resolver<T>... resolvers)
|
||||||
|
{
|
||||||
|
this(namespace, Arrays.stream(resolvers).toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public MergedNamespaceResolver(String namespace, List<Resolver<T>> resolvers)
|
||||||
|
{
|
||||||
|
this.namespace = namespace;
|
||||||
|
this.resolvers = resolvers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasNamespace(String namespace) {
|
||||||
|
return this.namespace.equals(namespace);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T resolve(PlatformNamespaceKey key) {
|
||||||
|
for(Resolver<T> i : resolvers) {
|
||||||
|
T t = i.resolve(key);
|
||||||
|
|
||||||
|
if(t != null)
|
||||||
|
{
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T resolve(String key) {
|
||||||
|
for(Resolver<T> i : resolvers) {
|
||||||
|
T t = i.resolve(key);
|
||||||
|
|
||||||
|
if(t != null)
|
||||||
|
{
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print(String type, Object printer, int indent) {
|
||||||
|
printer.i(Form.repeat(" ", indent) + "Merged[" + namespace + "] " + type);
|
||||||
|
|
||||||
|
for(Resolver<T> i : getResolvers()) {
|
||||||
|
i.print(type, printer, indent + 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Resolver<T> and(String namespace, Resolver<T> resolver) {
|
||||||
|
if(namespace.equals(getNamespace()))
|
||||||
|
{
|
||||||
|
List<Resolver<T>> r = resolvers.copy();
|
||||||
|
r.add(resolver);
|
||||||
|
return new MergedNamespaceResolver<>(namespace, r);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new CompositeResolver<>(Map.of(getNamespace(), this, namespace, resolver));
|
||||||
|
}
|
||||||
|
}
|
@ -1,60 +0,0 @@
|
|||||||
package com.volmit.iris.engine.resolver;
|
|
||||||
|
|
||||||
import com.volmit.iris.platform.PlatformNamespaceKey;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class MergedResolver<T extends Resolvable> implements Resolver<T> {
|
|
||||||
private final List<Resolver<T>> resolvers;
|
|
||||||
|
|
||||||
public MergedResolver(Resolver<T>... resolvers)
|
|
||||||
{
|
|
||||||
this(Arrays.stream(resolvers).toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
public MergedResolver(List<Resolver<T>> resolvers)
|
|
||||||
{
|
|
||||||
this.resolvers = resolvers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasNamespace(String namespace) {
|
|
||||||
for(Resolver<T> i : resolvers) {
|
|
||||||
if(i.hasNamespace(namespace)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public T resolve(PlatformNamespaceKey key) {
|
|
||||||
for(Resolver<T> i : resolvers) {
|
|
||||||
T t = i.resolve(key);
|
|
||||||
|
|
||||||
if(t != null)
|
|
||||||
{
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public T resolve(String key) {
|
|
||||||
for(Resolver<T> i : resolvers) {
|
|
||||||
T t = i.resolve(key);
|
|
||||||
|
|
||||||
if(t != null)
|
|
||||||
{
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -24,6 +24,10 @@ public interface Resolvable extends PlatformNamespaced, PlatformNamespacedMutabl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default Entity.ResolverEntityData entity() {
|
||||||
|
return new Entity.ResolverEntityData(getClass().getDeclaredAnnotation(Resolvable.Entity.class));
|
||||||
|
}
|
||||||
|
|
||||||
default <T> void writeSafeJson(TypeAdapter<T> delegate, JsonWriter out, T value) {
|
default <T> void writeSafeJson(TypeAdapter<T> delegate, JsonWriter out, T value) {
|
||||||
try {
|
try {
|
||||||
delegate.write(out, value);
|
delegate.write(out, value);
|
||||||
|
@ -17,7 +17,7 @@ import java.util.function.Predicate;
|
|||||||
|
|
||||||
public interface Resolver<T extends Resolvable> {
|
public interface Resolver<T extends Resolvable> {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
static <F extends Resolvable> Resolver<F> frozen(Map<PakKey, PakResource> resources, Predicate<PakResource> isTypePredicate) {
|
static <F extends Resolvable> CompositeResolver<F> frozen(Map<PakKey, PakResource> resources, Predicate<PakResource> isTypePredicate) {
|
||||||
Map<String, Map<String, F>> resolvables = new HashMap<>();
|
Map<String, Map<String, F>> resolvables = new HashMap<>();
|
||||||
Map<String, Resolver<F>> resolvers = new HashMap<>();
|
Map<String, Resolver<F>> resolvers = new HashMap<>();
|
||||||
|
|
||||||
@ -85,7 +85,12 @@ public interface Resolver<T extends Resolvable> {
|
|||||||
return hasNamespace(key.getNamespace()) && resolve(key) != null;
|
return hasNamespace(key.getNamespace()) && resolve(key) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
default Resolver<T> addResolver(Resolver<T> resolver, String namespace) {
|
Resolver<T> and(String namespace, Resolver<T> resolver);
|
||||||
return new MergedResolver<>(resolver, this);
|
|
||||||
|
default void print(String type, Object printer)
|
||||||
|
{
|
||||||
|
print(type, printer, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print(String type, Object printer, int index);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.volmit.iris.platform;
|
package com.volmit.iris.platform;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public interface IrisPlatform {
|
public interface IrisPlatform {
|
||||||
@ -21,4 +22,6 @@ public interface IrisPlatform {
|
|||||||
{
|
{
|
||||||
return key("minecraft", nsk);
|
return key("minecraft", nsk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File getStudioFolder(String dimension);
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,9 @@ public interface PlatformWorld {
|
|||||||
}
|
}
|
||||||
|
|
||||||
default File getIrisDataFolder() {
|
default File getIrisDataFolder() {
|
||||||
return new File(getWorldFolder("iris"), "data");
|
File f = new File(getWorldFolder("iris"), "data");
|
||||||
|
f.mkdirs();
|
||||||
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
default boolean isRegionLoaded(int x, int z) {
|
default boolean isRegionLoaded(int x, int z) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user