Skip to content

Commit 444ba21

Browse files
committed
get all args in macro
1 parent 650fa07 commit 444ba21

File tree

4 files changed

+50
-3
lines changed

4 files changed

+50
-3
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ yarn_mappings=1.21+build.9
99
loader_version=0.15.11
1010

1111
# Mod Properties
12-
mod_version=1.1.0
12+
mod_version=1.1.1
1313
maven_group=top.mcfpp.mod.debugger
1414
archives_base_name=datapack-debugger
1515

src/main/java/top/mcfpp/mod/debugger/command/BreakPointCommand.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ public static void onInitialize() {
7575
return 1;
7676
})
7777
)
78+
.executes(context -> {
79+
final var args = getAllNBT(context.getSource());
80+
if(args == null){
81+
context.getSource().sendError(Text.translatable("commands.breakpoint.get.fail.not_macro"));
82+
}else {
83+
context.getSource().sendFeedback(() -> (NbtHelper.toPrettyPrintedText(args)), false);
84+
}
85+
return 1;
86+
})
7887
)
7988
.then(literal("stack")
8089
.executes(context -> {
@@ -192,7 +201,24 @@ private static void moveOn(@NotNull ServerCommandSource source) {
192201
return (Pair<NbtElement, Boolean>) method.invoke(context, key);
193202
}catch (Exception e){
194203
LOGGER.error(e.toString());
195-
source.sendError(Text.translatable("commands.breakpoint.get.fail.error", key, e.toString()));
204+
source.sendError(Text.translatable("commands.breakpoint.get.fail.error", e.toString()));
205+
return null;
206+
}
207+
}
208+
209+
private static @Nullable NbtElement getAllNBT(ServerCommandSource source){
210+
var context = storedCommandExecutionContext.peekFirst();
211+
if(context == null){
212+
return null;
213+
}
214+
try {
215+
var cls = context.getClass();
216+
var method = cls.getDeclaredMethod("getAllNBT");
217+
method.setAccessible(true);
218+
return (NbtElement) method.invoke(context);
219+
}catch (Exception e){
220+
LOGGER.error(e.toString());
221+
source.sendError(Text.translatable("commands.breakpoint.get.fail.error", e.toString()));
196222
return null;
197223
}
198224
}

src/main/java/top/mcfpp/mod/debugger/mixin/CommandExecutionContextMixin.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,27 @@ private Pair<NbtElement, Boolean> getKey(String key){
137137
}
138138
}
139139

140+
@Unique
141+
private NbtElement getAllNBT(){
142+
CommandQueueEntry<T> commandQueueEntry = this.commandQueue.peekFirst();
143+
144+
if (commandQueueEntry == null) {
145+
return null;
146+
}
147+
148+
var frame = commandQueueEntry.frame();
149+
try {
150+
Field field = frame.getClass().getDeclaredField("function");
151+
field.setAccessible(true);
152+
var function = (ExpandedMacro<T>) field.get(frame);
153+
Field field1 = function.getClass().getDeclaredField("arguments");
154+
field1.setAccessible(true);
155+
return (NbtCompound)field1.get(function);
156+
} catch (NoSuchFieldException | IllegalAccessException e) {
157+
throw new RuntimeException(e);
158+
}
159+
}
160+
140161
@Unique
141162
private List<String> getKeys(){
142163
CommandQueueEntry<T> commandQueueEntry = this.commandQueue.peekFirst();

src/main/resources/assets/datapack-debugger/lang/en_us.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"commands.breakpoint.set": "Breakpoint has triggered",
33
"commands.breakpoint.get": "Argument %s has the following value: %s",
44
"commands.breakpoint.get.fail": "Failed to get the value of argument %s",
5-
"commands.breakpoint.get.fail.error": "Unexpected error while getting the value of argument %s: %s",
5+
"commands.breakpoint.get.fail.error": "Unexpected error while getting the value of argument: %s",
66
"commands.breakpoint.get.fail.not_macro": "Current function is not a macro",
77
"commands.breakpoint.move": "The game is now moving on",
88
"commands.breakpoint.move.not_debugging": "Can only use `move` command in breakpoint mode",

0 commit comments

Comments
 (0)