2021-01-06 09:35:50 +01:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Wed, 6 Jan 2021 00:34:04 -0800
Subject: [PATCH] Implement Keyed on World
2021-03-16 08:19:45 +01:00
diff --git a/src/main/java/net/minecraft/core/IRegistry.java b/src/main/java/net/minecraft/core/IRegistry.java
index 3e9ebeffdf66f8a959630b344149d17137c6901c..4f04d8081912e0fe771f0db9e086c789328f246f 100644
--- a/src/main/java/net/minecraft/core/IRegistry.java
+++ b/src/main/java/net/minecraft/core/IRegistry.java
@@ -130,7 +130,7 @@ public abstract class IRegistry<T> implements Codec<T>, Keyable, Registry<T> {
2021-01-06 09:35:50 +01:00
public static final ResourceKey<IRegistry<LootItemFunctionType>> I = a("loot_function_type");
public static final ResourceKey<IRegistry<LootItemConditionType>> J = a("loot_condition_type");
public static final ResourceKey<IRegistry<DimensionManager>> K = a("dimension_type");
- public static final ResourceKey<IRegistry<World>> L = a("dimension");
+ public static final ResourceKey<IRegistry<World>> L = a("dimension"); public static final ResourceKey<IRegistry<World>> getWorldRegistry() { return L; } // Paper - OBFHELPER
public static final ResourceKey<IRegistry<WorldDimension>> M = a("dimension");
public static final IRegistry<SoundEffect> SOUND_EVENT = a(IRegistry.g, () -> {
return SoundEffects.ENTITY_ITEM_PICKUP;
2021-03-16 08:19:45 +01:00
@@ -339,9 +339,9 @@ public abstract class IRegistry<T> implements Codec<T>, Keyable, Registry<T> {
2021-01-06 09:35:50 +01:00
MinecraftKey minecraftkey = resourcekey.a();
IRegistry.a.put(minecraftkey, supplier);
- IRegistryWritable<R> 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<? extends IRegistry<T>> resourcekey, Lifecycle lifecycle) {
2021-03-16 08:19:45 +01:00
@@ -428,11 +428,11 @@ public abstract class IRegistry<T> implements Codec<T>, Keyable, Registry<T> {
2021-01-06 09:35:50 +01:00
}
public static <V, T extends V> T a(IRegistry<V> iregistry, MinecraftKey minecraftkey, T t0) {
- return ((IRegistryWritable) iregistry).a(ResourceKey.a(iregistry.b, minecraftkey), t0, Lifecycle.stable());
+ return ((IRegistryWritable<V>) iregistry).a(ResourceKey.a(iregistry.b, minecraftkey), t0, Lifecycle.stable()); // Paper - decompile fix
}
public static <V, T extends V> T a(IRegistry<V> iregistry, int i, String s, T t0) {
- return ((IRegistryWritable) iregistry).a(i, ResourceKey.a(iregistry.b, new MinecraftKey(s)), t0, Lifecycle.stable());
+ return ((IRegistryWritable<V>) iregistry).a(i, ResourceKey.a(iregistry.b, new MinecraftKey(s)), t0, Lifecycle.stable()); // Paper - decompile fix
}
static {
2021-03-16 08:19:45 +01:00
diff --git a/src/main/java/net/minecraft/resources/ResourceKey.java b/src/main/java/net/minecraft/resources/ResourceKey.java
index 760579921927b4c8b0f20b2611b95fd626e4b27f..3075700dfa992da81b10246fcf7c7ad1115c4ba3 100644
--- a/src/main/java/net/minecraft/resources/ResourceKey.java
+++ b/src/main/java/net/minecraft/resources/ResourceKey.java
@@ -12,6 +12,7 @@ public class ResourceKey<T> {
2021-01-06 09:35:50 +01:00
private final MinecraftKey b;
private final MinecraftKey c;
+ public static <T> ResourceKey<T> newResourceKey(ResourceKey<? extends IRegistry<T>> registryKey, MinecraftKey minecraftKey) { return a(registryKey, minecraftKey); } // Paper - OBFHELPER
public static <T> ResourceKey<T> a(ResourceKey<? extends IRegistry<T>> resourcekey, MinecraftKey minecraftkey) {
return a(resourcekey.c, minecraftkey);
}
2021-03-16 08:19:45 +01:00
@@ -41,6 +42,7 @@ public class ResourceKey<T> {
2021-01-06 09:35:50 +01:00
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
2021-05-18 06:54:25 +02:00
index ab4ddd62d6361ca99a7ec24c5b83f74314d1494a..16ed4a59fa70b94a80c94c99af74fdce9b44768d 100644
2021-01-06 09:35:50 +01:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
2021-05-18 06:54:25 +02:00
@@ -1158,7 +1158,7 @@ public final class CraftServer implements Server {
2021-05-12 10:07:08 +02:00
} else if (name.equals(levelName + "_the_end")) {
worldKey = net.minecraft.world.level.World.THE_END;
} else {
- worldKey = ResourceKey.a(IRegistry.L, new MinecraftKey(name.toLowerCase(java.util.Locale.ENGLISH)));
+ worldKey = ResourceKey.newResourceKey(IRegistry.getWorldRegistry(), new net.minecraft.resources.MinecraftKey(creator.key().getNamespace().toLowerCase(java.util.Locale.ENGLISH), creator.key().getKey().toLowerCase(java.util.Locale.ENGLISH))); // Paper
2021-01-06 09:35:50 +01:00
}
WorldServer internal = (WorldServer) new WorldServer(console, console.executorService, worldSession, worlddata, worldKey, dimensionmanager, getServer().worldLoadListenerFactory.create(11),
2021-05-18 06:54:25 +02:00
@@ -1248,6 +1248,15 @@ public final class CraftServer implements Server {
2021-01-06 09:35:50 +01:00
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
2021-05-02 21:37:24 +02:00
index 05a7f5f61330bd52705640345524cdedbf105285..a152d5bec8bf0dd87239b0a3432fb589cea61bd8 100644
2021-01-06 09:35:50 +01:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
2021-04-18 09:52:36 +02:00
@@ -2584,6 +2584,11 @@ public class CraftWorld implements World {
2021-01-06 09:35:50 +01:00
return CompletableFuture.completedFuture(chunk == null ? null : chunk.getBukkitChunk());
2021-03-16 08:19:45 +01:00
}, net.minecraft.server.MinecraftServer.getServer());
2021-01-06 09:35:50 +01:00
}
+
+ @Override
+ public org.bukkit.NamespacedKey getKey() {
+ return org.bukkit.craftbukkit.util.CraftNamespacedKey.fromMinecraft(world.getDimensionKey().getLocation());
+ }
// Paper end
// Spigot start