mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-25 20:16:19 +01:00
111 lines
6.8 KiB
Diff
111 lines
6.8 KiB
Diff
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
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/core/Registry.java b/src/main/java/net/minecraft/core/Registry.java
|
|
index 5a98bc1522c2035487ce0a048c236903dbfa816e..4924d8cd3004a6e1ce76cd5cf7520556c23fe20a 100644
|
|
--- a/src/main/java/net/minecraft/core/Registry.java
|
|
+++ b/src/main/java/net/minecraft/core/Registry.java
|
|
@@ -130,7 +130,7 @@ public abstract class Registry<T> implements Codec<T>, Keyable, IdMap<T> {
|
|
public static final ResourceKey<Registry<LootItemFunctionType>> LOOT_FUNCTION_REGISTRY = createRegistryKey("loot_function_type");
|
|
public static final ResourceKey<Registry<LootItemConditionType>> LOOT_ITEM_REGISTRY = createRegistryKey("loot_condition_type");
|
|
public static final ResourceKey<Registry<DimensionType>> DIMENSION_TYPE_REGISTRY = createRegistryKey("dimension_type");
|
|
- public static final ResourceKey<Registry<Level>> DIMENSION_REGISTRY = createRegistryKey("dimension");
|
|
+ public static final ResourceKey<Registry<Level>> DIMENSION_REGISTRY = createRegistryKey("dimension"); public static final ResourceKey<Registry<Level>> getWorldRegistry() { return DIMENSION_REGISTRY; } // Paper - OBFHELPER
|
|
public static final ResourceKey<Registry<LevelStem>> LEVEL_STEM_REGISTRY = createRegistryKey("dimension");
|
|
public static final Registry<SoundEvent> SOUND_EVENT = registerSimple(Registry.SOUND_EVENT_REGISTRY, () -> {
|
|
return SoundEvents.ITEM_PICKUP;
|
|
@@ -339,9 +339,9 @@ public abstract class Registry<T> implements Codec<T>, Keyable, IdMap<T> {
|
|
ResourceLocation minecraftkey = resourcekey.location();
|
|
|
|
Registry.LOADERS.put(minecraftkey, defaultEntry);
|
|
- WritableRegistry<R> iregistrywritable = Registry.WRITABLE_REGISTRY;
|
|
+ WritableRegistry iregistrywritable = Registry.WRITABLE_REGISTRY; // Paper - decompile fix
|
|
|
|
- return (WritableRegistry) iregistrywritable.register(resourcekey, (Object) registry, lifecycle);
|
|
+ return (R) iregistrywritable.register(resourcekey, (Object) registry, lifecycle); // Paper - decompile fix
|
|
}
|
|
|
|
protected Registry(ResourceKey<? extends Registry<T>> key, Lifecycle lifecycle) {
|
|
@@ -428,11 +428,11 @@ public abstract class Registry<T> implements Codec<T>, Keyable, IdMap<T> {
|
|
}
|
|
|
|
public static <V, T extends V> T register(Registry<V> registry, ResourceLocation id, T entry) {
|
|
- return ((WritableRegistry) registry).register(ResourceKey.create(registry.key, id), entry, Lifecycle.stable());
|
|
+ return ((WritableRegistry<V>) registry).register(ResourceKey.create(registry.key, id), entry, Lifecycle.stable()); // Paper - decompile fix
|
|
}
|
|
|
|
public static <V, T extends V> T registerMapping(Registry<V> registry, int rawId, String id, T entry) {
|
|
- return ((WritableRegistry) registry).registerMapping(rawId, ResourceKey.create(registry.key, new ResourceLocation(id)), entry, Lifecycle.stable());
|
|
+ return ((WritableRegistry<V>) registry).registerMapping(rawId, ResourceKey.create(registry.key, new ResourceLocation(id)), entry, 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 2f39438ee9b23706efb2fd877fe223777b6968c7..3085ec1f20f4c945242697b809188a8c828cfb75 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> {
|
|
private final ResourceLocation registryName;
|
|
private final ResourceLocation location;
|
|
|
|
+ public static <T> ResourceKey<T> newResourceKey(ResourceKey<? extends Registry<T>> registryKey, ResourceLocation minecraftKey) { return create(registryKey, minecraftKey); } // Paper - OBFHELPER
|
|
public static <T> ResourceKey<T> create(ResourceKey<? extends Registry<T>> registry, ResourceLocation value) {
|
|
return create(registry.location, value);
|
|
}
|
|
@@ -41,6 +42,7 @@ public class ResourceKey<T> {
|
|
return this.registryName.equals(registry.location());
|
|
}
|
|
|
|
+ public ResourceLocation getLocation() { return location(); } // Paper - OBFHELPER
|
|
public ResourceLocation location() {
|
|
return this.location;
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
index 794b894ed24636aec60de9a28ba7613d7a917324..6905256147d9bd79e5f52bf86bdb21c89b8411a7 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
@@ -1156,7 +1156,7 @@ public final class CraftServer implements Server {
|
|
} else if (name.equals(levelName + "_the_end")) {
|
|
worldKey = net.minecraft.world.level.Level.END;
|
|
} else {
|
|
- worldKey = ResourceKey.create(Registry.DIMENSION_REGISTRY, new ResourceLocation(name.toLowerCase(java.util.Locale.ENGLISH)));
|
|
+ worldKey = ResourceKey.newResourceKey(Registry.getWorldRegistry(), new net.minecraft.resources.ResourceLocation(creator.key().getNamespace().toLowerCase(java.util.Locale.ENGLISH), creator.key().getKey().toLowerCase(java.util.Locale.ENGLISH))); // Paper
|
|
}
|
|
|
|
ServerLevel internal = (ServerLevel) new ServerLevel(console, console.executor, worldSession, worlddata, worldKey, dimensionmanager, getServer().progressListenerFactory.create(11),
|
|
@@ -1246,6 +1246,15 @@ public final class CraftServer implements Server {
|
|
return null;
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public World getWorld(NamespacedKey worldKey) {
|
|
+ ServerLevel worldServer = console.getLevel(ResourceKey.newResourceKey(Registry.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 f497b9e11a075a84ff0a2117eb79d0532e4a326f..b0212b2043ee5fd77c8876ef0b51ef91488712f0 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
@@ -2566,6 +2566,11 @@ 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.dimension().getLocation());
|
|
+ }
|
|
// Paper end
|
|
|
|
// Spigot start
|