Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 35 additions & 21 deletions src/main/java/io/github/misode/packtest/commands/DummyCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.misode.packtest.commands;

import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.BoolArgumentType;
import com.mojang.brigadier.arguments.IntegerArgumentType;
Expand All @@ -19,6 +20,7 @@
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
import net.minecraft.commands.arguments.coordinates.Vec3Argument;
import net.minecraft.commands.arguments.selector.EntitySelector;
import net.minecraft.commands.execution.ExecutionContext;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
Expand Down Expand Up @@ -91,60 +93,72 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
.then(argument("dummy", EntityArgument.entity())
.suggests(SUGGEST_DUMMY_NAME)
.then(literal("spawn")
.executes(DummyCommand::spawn))
.executes(asPacket(DummyCommand::spawn)))
.then(literal("leave")
.executes(DummyCommand::leave))
.executes(asPacket(DummyCommand::leave)))
.then(literal("respawn")
.executes(DummyCommand::respawn))
.executes(asPacket(DummyCommand::respawn)))
.then(literal("jump")
.executes(DummyCommand::jump))
.executes(asPacket(DummyCommand::jump)))
.then(literal("sneak")
.then(argument("active", BoolArgumentType.bool())
.executes(DummyCommand::sneak)))
.executes(asPacket(DummyCommand::sneak))))
.then(literal("sprint")
.then(argument("active", BoolArgumentType.bool())
.executes(DummyCommand::sprint)))
.executes(asPacket(DummyCommand::sprint))))
.then(literal("drop")
.executes(ctx -> dropMainhand(ctx, false))
.executes(asPacket(ctx -> dropMainhand(ctx, false)))
.then(literal("all")
.executes(ctx -> dropMainhand(ctx, true)))
.executes(asPacket(ctx -> dropMainhand(ctx, true))))
.then(literal("from")
.then(argument("slot", SlotArgument.slot())
.executes(ctx -> dropFromSlot(ctx, false))
.executes(asPacket(ctx -> dropFromSlot(ctx, false)))
.then(literal("all")
.executes(ctx -> dropFromSlot(ctx, true))))))
.executes(asPacket(ctx -> dropFromSlot(ctx, true)))))))
.then(literal("swap")
.executes(DummyCommand::swap))
.executes(asPacket(DummyCommand::swap)))
.then(literal("selectslot")
.then(argument("slot", IntegerArgumentType.integer(1, 9))
.executes(ctx -> selectSlot(ctx, 1))))
.executes(asPacket(ctx -> selectSlot(ctx, 1)))))
.then(literal("mainhand")
.then(argument("slot", IntegerArgumentType.integer(0, 8))
.executes(ctx -> selectSlot(ctx, 0))))
.executes(asPacket(ctx -> selectSlot(ctx, 0)))))
.then(literal("use")
.executes(DummyCommand::useItem)
.executes(asPacket(DummyCommand::useItem))
.then(literal("item")
.executes(DummyCommand::useItem))
.executes(asPacket(DummyCommand::useItem)))
.then(literal("block")
.then(argument("pos", Vec3Argument.vec3(false))
.executes(ctx -> useBlock(ctx, Direction.UP))
.executes(asPacket(ctx -> useBlock(ctx, Direction.UP)))
.then(argument("direction", StringArgumentType.word())
.suggests(SUGGEST_DIRECTION)
.executes(ctx -> useBlock(ctx, Direction.byName(StringArgumentType.getString(ctx, "direction")))))))
.executes(asPacket(ctx -> useBlock(ctx, Direction.byName(StringArgumentType.getString(ctx, "direction"))))))))
.then(literal("entity")
.then(argument("entity", EntityArgument.entity())
.executes(ctx -> useEntity(ctx, null))
.executes(asPacket(ctx -> useEntity(ctx, null)))
.then(argument("pos", Vec3Argument.vec3(false))
.executes(ctx -> useEntity(ctx, Vec3Argument.getVec3(ctx, "pos")))))))
.executes(asPacket(ctx -> useEntity(ctx, Vec3Argument.getVec3(ctx, "pos"))))))))
.then(literal("attack")
.then(argument("entity", EntityArgument.entity())
.executes(DummyCommand::attackEntity)))
.executes(asPacket(DummyCommand::attackEntity))))
.then(literal("mine")
.then(argument("pos", BlockPosArgument.blockPos())
.executes(DummyCommand::mineBlock)))
.executes(asPacket(DummyCommand::mineBlock))))
));
}

private static Command<CommandSourceStack> asPacket(Command<CommandSourceStack> action) {
return ctx -> {
ExecutionContext<CommandSourceStack> running = Commands.CURRENT_EXECUTION_CONTEXT.get();
Commands.CURRENT_EXECUTION_CONTEXT.remove();
try {
return action.run(ctx);
} finally {
Commands.CURRENT_EXECUTION_CONTEXT.set(running);
}
};
}

private static Dummy getDummy(CommandContext<CommandSourceStack> ctx) throws CommandSyntaxException {
EntitySelector selector = ctx.getArgument("dummy", EntitySelector.class);
ServerPlayer player;
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/packtest.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ accessible class net/minecraft/commands/arguments/NbtPathArgument$MatchObjectNod
accessible field net/minecraft/commands/arguments/NbtPathArgument$MatchObjectNode name Ljava/lang/String;
accessible field net/minecraft/commands/arguments/NbtPathArgument$NbtPath nodes [Lnet/minecraft/commands/arguments/NbtPathArgument$Node;
accessible field net/minecraft/commands/arguments/NbtPathArgument$NbtPath nodeToOriginalPosition Lit/unimi/dsi/fastutil/objects/Object2IntMap;
accessible field net/minecraft/commands/Commands CURRENT_EXECUTION_CONTEXT Ljava/lang/ThreadLocal;
accessible field net/minecraft/commands/arguments/selector/EntitySelector playerName Ljava/lang/String;
accessible field net/minecraft/gametest/framework/GameTestHelper testInfo Lnet/minecraft/gametest/framework/GameTestInfo;
accessible method net/minecraft/server/commands/ExecuteCommand checkCustomPredicate (Lnet/minecraft/commands/CommandSourceStack;Lnet/minecraft/core/Holder;)Z
Expand Down
Loading