-
Bug
-
Resolution: Invalid
-
None
-
1.21.1
-
None
-
windows 10 64bit 19045
-
Plausible
-
Commands
Looking into DataCommand i see that /data modify ... is registered in a loop in a loop.
This problem existed at least since 2023-06
In both: register and addModifyArgument. but only the loop from addModifyArgument is usefull
for (DataCommand.ObjectType objectType : TARGET_OBJECT_TYPES)
Code snippet from net.minecraft.server.command.DataCommand.java
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) { LiteralArgumentBuilder<ServerCommandSource> literalArgumentBuilder = CommandManager.literal("data").requires(source -> source.hasPermissionLevel(2)); for (DataCommand.ObjectType objectType : TARGET_OBJECT_TYPES) { literalArgumentBuilder.then( objectType.addArgumentsToBuilder( CommandManager.literal("merge"), builder -> builder.then( CommandManager.argument("nbt", NbtCompoundArgumentType.nbtCompound()) .executes(context -> executeMerge(context.getSource(), objectType.getObject(context), NbtCompoundArgumentType.getNbtCompound(context, "nbt"))) ) ) ) .then( addModifyArgument( //this section is not using objectType (builder, modifier) -> builder.then( CommandManager.literal("insert") .then( CommandManager.argument("index", IntegerArgumentType.integer()) .then(modifier.create((context, sourceNbt, path, elements) -> path.insert(IntegerArgumentType.getInteger(context, "index"), sourceNbt, elements))) ) ) .then(CommandManager.literal("prepend").then(modifier.create((context, sourceNbt, path, elements) -> path.insert(0, sourceNbt, elements)))) .then(CommandManager.literal("append").then(modifier.create((context, sourceNbt, path, elements) -> path.insert(-1, sourceNbt, elements)))) .then(CommandManager.literal("set").then(modifier.create((context, sourceNbt, path, elements) -> path.put(sourceNbt, Iterables.getLast(elements))))) .then(CommandManager.literal("merge").then(modifier.create((context, element, path, elements) -> { NbtCompound nbtCompound = new NbtCompound(); for (NbtElement nbtElement : elements) { if (NbtPathArgumentType.NbtPath.isTooDeep(nbtElement, 0)) { throw NbtPathArgumentType.TOO_DEEP_EXCEPTION.create(); } if (!(nbtElement instanceof NbtCompound nbtCompound2)) { throw MODIFY_EXPECTED_OBJECT_EXCEPTION.create(nbtElement); } nbtCompound.copyFrom(nbtCompound2); } Collection<NbtElement> collection = path.getOrInit(element, NbtCompound::new); int i = 0; for (NbtElement nbtElement2 : collection) { if (!(nbtElement2 instanceof NbtCompound nbtCompound3)) { throw MODIFY_EXPECTED_OBJECT_EXCEPTION.create(nbtElement2); } NbtCompound nbtCompound4 = nbtCompound3.copy(); nbtCompound3.copyFrom(nbtCompound); i += nbtCompound4.equals(nbtCompound3) ? 0 : 1; } return i; }))) ) ); } dispatcher.register(literalArgumentBuilder); } private static ArgumentBuilder<ServerCommandSource, ?> addModifyArgument( BiConsumer<ArgumentBuilder<ServerCommandSource, ?>, DataCommand.ModifyArgumentCreator> subArgumentAdder ) { LiteralArgumentBuilder<ServerCommandSource> literalArgumentBuilder = CommandManager.literal("modify"); for (DataCommand.ObjectType objectType : TARGET_OBJECT_TYPES) { objectType.addArgumentsToBuilder( //instead creates its own objectType