From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Wed, 6 Jan 2021 00:34:04 -0800 Subject: [PATCH] Implement Keyed on World diff --git a/src/main/java/net/minecraft/core/IRegistry.java b/src/main/java/net/minecraft/core/IRegistry.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/core/IRegistry.java +++ b/src/main/java/net/minecraft/core/IRegistry.java @@ -0,0 +0,0 @@ public abstract class IRegistry implements Codec, Keyable, Registry { public static final ResourceKey> I = a("loot_function_type"); public static final ResourceKey> J = a("loot_condition_type"); public static final ResourceKey> K = a("dimension_type"); - public static final ResourceKey> L = a("dimension"); + public static final ResourceKey> L = a("dimension"); public static final ResourceKey> getWorldRegistry() { return L; } // Paper - OBFHELPER public static final ResourceKey> M = a("dimension"); public static final IRegistry SOUND_EVENT = a(IRegistry.g, () -> { return SoundEffects.ENTITY_ITEM_PICKUP; @@ -0,0 +0,0 @@ public abstract class IRegistry implements Codec, Keyable, Registry { MinecraftKey minecraftkey = resourcekey.a(); IRegistry.a.put(minecraftkey, supplier); - IRegistryWritable iregistrywritable = IRegistry.e; + IRegistryWritable iregistrywritable = IRegistry.e; // Paper - decompile fix - return (IRegistryWritable) iregistrywritable.a(resourcekey, (Object) r0, lifecycle); + return (R) iregistrywritable.a(resourcekey, (Object) r0, lifecycle); // Paper - decompile fix } protected IRegistry(ResourceKey> resourcekey, Lifecycle lifecycle) { @@ -0,0 +0,0 @@ public abstract class IRegistry implements Codec, Keyable, Registry { } public static T a(IRegistry iregistry, MinecraftKey minecraftkey, T t0) { - return ((IRegistryWritable) iregistry).a(ResourceKey.a(iregistry.b, minecraftkey), t0, Lifecycle.stable()); + return ((IRegistryWritable) iregistry).a(ResourceKey.a(iregistry.b, minecraftkey), t0, Lifecycle.stable()); // Paper - decompile fix } public static T a(IRegistry iregistry, int i, String s, T t0) { - return ((IRegistryWritable) iregistry).a(i, ResourceKey.a(iregistry.b, new MinecraftKey(s)), t0, Lifecycle.stable()); + return ((IRegistryWritable) iregistry).a(i, ResourceKey.a(iregistry.b, new MinecraftKey(s)), t0, Lifecycle.stable()); // Paper - decompile fix } static { diff --git a/src/main/java/net/minecraft/resources/ResourceKey.java b/src/main/java/net/minecraft/resources/ResourceKey.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/resources/ResourceKey.java +++ b/src/main/java/net/minecraft/resources/ResourceKey.java @@ -0,0 +0,0 @@ public class ResourceKey { private final MinecraftKey b; private final MinecraftKey c; + public static ResourceKey newResourceKey(ResourceKey> registryKey, MinecraftKey minecraftKey) { return a(registryKey, minecraftKey); } // Paper - OBFHELPER public static ResourceKey a(ResourceKey> resourcekey, MinecraftKey minecraftkey) { return a(resourcekey.c, minecraftkey); } @@ -0,0 +0,0 @@ public class ResourceKey { return this.b.equals(resourcekey.a()); } + public MinecraftKey getLocation() { return a(); } // Paper - OBFHELPER public MinecraftKey a() { return this.c; } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -0,0 +0,0 @@ public final class CraftServer implements Server { chunkgenerator = worlddimension.c(); } - ResourceKey worldKey = ResourceKey.a(IRegistry.L, new MinecraftKey(name.toLowerCase(java.util.Locale.ENGLISH))); + ResourceKey worldKey = ResourceKey.newResourceKey(IRegistry.getWorldRegistry(), new MinecraftKey(creator.key().getNamespace().toLowerCase(java.util.Locale.ENGLISH), creator.key().getKey().toLowerCase(java.util.Locale.ENGLISH))); // Paper WorldServer internal = (WorldServer) new WorldServer(console, console.executorService, worldSession, worlddata, worldKey, dimensionmanager, getServer().worldLoadListenerFactory.create(11), chunkgenerator, worlddata.getGeneratorSettings().isDebugWorld(), j, creator.environment() == Environment.NORMAL ? list : ImmutableList.of(), true, creator.environment(), generator); @@ -0,0 +0,0 @@ public final class CraftServer implements Server { return null; } + // Paper start + @Override + public World getWorld(NamespacedKey worldKey) { + WorldServer worldServer = console.getWorldServer(ResourceKey.newResourceKey(IRegistry.getWorldRegistry(), CraftNamespacedKey.toMinecraft(worldKey))); + if (worldServer == null) return null; + return worldServer.getWorld(); + } + // Paper end + public void addWorld(World world) { // Check if a World already exists with the UID. if (getWorld(world.getUID()) != null) { diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -0,0 +0,0 @@ public class CraftWorld implements World { return CompletableFuture.completedFuture(chunk == null ? null : chunk.getBukkitChunk()); }, net.minecraft.server.MinecraftServer.getServer()); } + + @Override + public org.bukkit.NamespacedKey getKey() { + return org.bukkit.craftbukkit.util.CraftNamespacedKey.fromMinecraft(world.getDimensionKey().getLocation()); + } // Paper end // Spigot start