Skip to content

Commit 5d87e23

Browse files
committed
Adds NMS support for 1.21
1 parent d9ae27b commit 5d87e23

File tree

2 files changed

+16
-10
lines changed
  • commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21

2 files changed

+16
-10
lines changed

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<properties>
3131
<minecraft.mappings>1.21-R0.1-SNAPSHOT</minecraft.mappings>
3232
<spigot.version>1.21-R0.1-SNAPSHOT</spigot.version>
33-
<paper.version>1.21-R0.1-SNAPSHOT</paper.version>
33+
<paper.version>1.20.6-R0.1-SNAPSHOT</paper.version>
3434
</properties>
3535

3636
<repositories>

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R1.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import java.util.function.Predicate;
4040
import java.util.function.ToIntFunction;
4141

42-
import dev.jorel.commandapi.*;
4342
import org.bukkit.Bukkit;
4443
import org.bukkit.Color;
4544
import org.bukkit.Location;
@@ -90,6 +89,12 @@
9089
import com.mojang.serialization.Codec;
9190
import com.mojang.serialization.DataResult;
9291

92+
import dev.jorel.commandapi.CommandAPI;
93+
import dev.jorel.commandapi.CommandAPIHandler;
94+
import dev.jorel.commandapi.CommandRegistrationStrategy;
95+
import dev.jorel.commandapi.PaperCommandRegistration;
96+
import dev.jorel.commandapi.SafeVarHandle;
97+
import dev.jorel.commandapi.SpigotCommandRegistration;
9398
import dev.jorel.commandapi.arguments.ArgumentSubType;
9499
import dev.jorel.commandapi.arguments.SuggestionProviders;
95100
import dev.jorel.commandapi.commandsenders.AbstractCommandSender;
@@ -146,8 +151,6 @@
146151
import net.minecraft.commands.functions.InstantiatedFunction;
147152
import net.minecraft.commands.synchronization.ArgumentUtils;
148153
import net.minecraft.core.BlockPos;
149-
import net.minecraft.core.component.DataComponentMap;
150-
import net.minecraft.core.component.PatchedDataComponentMap;
151154
import net.minecraft.core.particles.BlockParticleOption;
152155
import net.minecraft.core.particles.ColorParticleOption;
153156
import net.minecraft.core.particles.DustColorTransitionOptions;
@@ -304,9 +307,9 @@ public String[] compatibleVersions() {
304307
return new String[] { "1.21" };
305308
};
306309

310+
@Differs(from = "1.20.6", by = "ItemInput constructor uses a data components patch, instead of a data components map")
307311
private static String serializeNMSItemStack(ItemStack is) {
308-
final DataComponentMap patchedMap = PatchedDataComponentMap.fromPatch(PatchedDataComponentMap.EMPTY, is.getComponentsPatch());
309-
return new ItemInput(is.getItemHolder(), patchedMap).serialize(COMMAND_BUILD_CONTEXT);
312+
return new ItemInput(is.getItemHolder(), is.getComponentsPatch()).serialize(COMMAND_BUILD_CONTEXT);
310313
}
311314

312315
@Override
@@ -474,8 +477,9 @@ public final World getDimension(CommandContext<CommandSourceStack> cmdCtx, Strin
474477
@Override
475478
public final Enchantment getEnchantment(CommandContext<CommandSourceStack> cmdCtx, String key)
476479
throws CommandSyntaxException {
477-
return Registry.ENCHANTMENT.get(fromResourceLocation(
478-
BuiltInRegistries.ENCHANTMENT.getKey(ResourceArgument.getEnchantment(cmdCtx, key).value())));
480+
final net.minecraft.world.item.enchantment.Enchantment enchantment = ResourceArgument.getEnchantment(cmdCtx, key).value();
481+
final ResourceLocation resource = this.<MinecraftServer>getMinecraftServer().registryAccess().registryOrThrow(Registries.ENCHANTMENT).getKey(enchantment);
482+
return Registry.ENCHANTMENT.get(fromResourceLocation(resource));
479483
}
480484

481485
@Override
@@ -570,9 +574,10 @@ public final FunctionWrapper[] getFunction(CommandContext<CommandSourceStack> cm
570574
return result.toArray(new FunctionWrapper[0]);
571575
}
572576

577+
@Differs(from = "1.20.6", by = "ResourceLocation constructor change to static ResourceLocation#fromNamespaceAndPath")
573578
@Override
574579
public SimpleFunctionWrapper getFunction(NamespacedKey key) {
575-
final ResourceLocation resourceLocation = new ResourceLocation(key.getNamespace(), key.getKey());
580+
final ResourceLocation resourceLocation = ResourceLocation.fromNamespaceAndPath(key.getNamespace(), key.getKey());
576581
Optional<CommandFunction<CommandSourceStack>> commandFunctionOptional = this
577582
.<MinecraftServer>getMinecraftServer().getFunctions().get(resourceLocation);
578583
if (commandFunctionOptional.isPresent()) {
@@ -862,9 +867,10 @@ public SuggestionProvider<CommandSourceStack> getSuggestionProvider(SuggestionPr
862867
};
863868
}
864869

870+
@Differs(from = "1.20.6", by = "ResourceLocation constructor change to static ResourceLocation#fromNamespaceAndPath")
865871
@Override
866872
public final SimpleFunctionWrapper[] getTag(NamespacedKey key) {
867-
Collection<CommandFunction<CommandSourceStack>> customFunctions = this.<MinecraftServer>getMinecraftServer().getFunctions().getTag(new ResourceLocation(key.getNamespace(), key.getKey()));
873+
Collection<CommandFunction<CommandSourceStack>> customFunctions = this.<MinecraftServer>getMinecraftServer().getFunctions().getTag(ResourceLocation.fromNamespaceAndPath(key.getNamespace(), key.getKey()));
868874
SimpleFunctionWrapper[] convertedCustomFunctions = new SimpleFunctionWrapper[customFunctions.size()];
869875
int index = 0;
870876
for (CommandFunction<CommandSourceStack> customFunction : customFunctions) {

0 commit comments

Comments
 (0)