Add registry-related argument types (#10770)
* Add registry-related argument types * fix tests
This commit is contained in:
parent
a31dc90741
commit
efd91e52a6
6 changed files with 155 additions and 13 deletions
|
@ -9,6 +9,8 @@ public net.minecraft.commands.arguments.DimensionArgument ERROR_INVALID_VALUE
|
|||
public net.minecraft.server.ReloadableServerResources registryLookup
|
||||
public net.minecraft.server.ReloadableServerResources
|
||||
|
||||
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
|
||||
|
||||
diff --git a/src/main/java/com/mojang/brigadier/CommandDispatcher.java b/src/main/java/com/mojang/brigadier/CommandDispatcher.java
|
||||
index 4b4f812eb13d5f03bcf3f8724d8aa8dbbc724e8b..a4d5d7017e0be79844b996de85a63cad5f8488bc 100644
|
||||
--- a/src/main/java/com/mojang/brigadier/CommandDispatcher.java
|
||||
|
@ -1068,10 +1070,10 @@ index 0000000000000000000000000000000000000000..72966584089d3fee9778f572727c9b7f
|
|||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/command/brigadier/argument/VanillaArgumentProviderImpl.java b/src/main/java/io/papermc/paper/command/brigadier/argument/VanillaArgumentProviderImpl.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..5f0b46cb2b3f53a81a949fa64690133baa0a304b
|
||||
index 0000000000000000000000000000000000000000..93edb22c8500e79f86b101ef38955bca45a8d3a9
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/command/brigadier/argument/VanillaArgumentProviderImpl.java
|
||||
@@ -0,0 +1,321 @@
|
||||
@@ -0,0 +1,354 @@
|
||||
+package io.papermc.paper.command.brigadier.argument;
|
||||
+
|
||||
+import com.destroystokyo.paper.profile.CraftPlayerProfile;
|
||||
|
@ -1096,6 +1098,10 @@ index 0000000000000000000000000000000000000000..5f0b46cb2b3f53a81a949fa64690133b
|
|||
+import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||
+import io.papermc.paper.entity.LookAnchor;
|
||||
+import io.papermc.paper.math.Position;
|
||||
+import io.papermc.paper.registry.PaperRegistries;
|
||||
+import io.papermc.paper.registry.RegistryAccess;
|
||||
+import io.papermc.paper.registry.RegistryKey;
|
||||
+import io.papermc.paper.registry.TypedKey;
|
||||
+import java.util.Collection;
|
||||
+import java.util.Collections;
|
||||
+import java.util.List;
|
||||
|
@ -1119,6 +1125,8 @@ index 0000000000000000000000000000000000000000..5f0b46cb2b3f53a81a949fa64690133b
|
|||
+import net.minecraft.commands.arguments.MessageArgument;
|
||||
+import net.minecraft.commands.arguments.ObjectiveCriteriaArgument;
|
||||
+import net.minecraft.commands.arguments.RangeArgument;
|
||||
+import net.minecraft.commands.arguments.ResourceArgument;
|
||||
+import net.minecraft.commands.arguments.ResourceKeyArgument;
|
||||
+import net.minecraft.commands.arguments.ResourceLocationArgument;
|
||||
+import net.minecraft.commands.arguments.ScoreboardSlotArgument;
|
||||
+import net.minecraft.commands.arguments.StyleArgument;
|
||||
|
@ -1139,6 +1147,7 @@ index 0000000000000000000000000000000000000000..5f0b46cb2b3f53a81a949fa64690133b
|
|||
+import net.minecraft.world.level.Level;
|
||||
+import org.bukkit.GameMode;
|
||||
+import org.bukkit.HeightMap;
|
||||
+import org.bukkit.Keyed;
|
||||
+import org.bukkit.NamespacedKey;
|
||||
+import org.bukkit.World;
|
||||
+import org.bukkit.block.BlockState;
|
||||
|
@ -1349,6 +1358,32 @@ index 0000000000000000000000000000000000000000..5f0b46cb2b3f53a81a949fa64690133b
|
|||
+ return this.wrap(TemplateRotationArgument.templateRotation(), mirror -> StructureRotation.valueOf(mirror.name()));
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public <T> ArgumentType<TypedKey<T>> resourceKey(final RegistryKey<T> registryKey) {
|
||||
+ return this.wrap(
|
||||
+ ResourceKeyArgument.key(PaperRegistries.toNms(registryKey)),
|
||||
+ nmsRegistryKey -> TypedKey.create(registryKey, CraftNamespacedKey.fromMinecraft(nmsRegistryKey.location()))
|
||||
+ );
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public <T> ArgumentType<T> resource(final RegistryKey<T> registryKey) {
|
||||
+ return this.resourceRaw(registryKey);
|
||||
+ }
|
||||
+
|
||||
+ @SuppressWarnings({"unchecked", "rawtypes", "UnnecessaryLocalVariable"})
|
||||
+ private <T, K extends Keyed> ArgumentType<T> resourceRaw(final RegistryKey registryKeyRaw) { // TODO remove Keyed
|
||||
+ final RegistryKey<K> registryKey = registryKeyRaw;
|
||||
+ return (ArgumentType<T>) this.wrap(
|
||||
+ ResourceArgument.resource(PaperCommands.INSTANCE.getBuildContext(), PaperRegistries.toNms(registryKey)),
|
||||
+ resource -> requireNonNull(
|
||||
+ RegistryAccess.registryAccess()
|
||||
+ .getRegistry(registryKey)
|
||||
+ .get(CraftNamespacedKey.fromMinecraft(resource.key().location()))
|
||||
+ )
|
||||
+ );
|
||||
+ }
|
||||
+
|
||||
+ private <T> ArgumentType<T> wrap(final ArgumentType<T> base) {
|
||||
+ return this.wrap(base, identity -> identity);
|
||||
+ }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue