Skip to content

Commit 3709433

Browse files
committed
update to 1.21.10 and fix some bugs
1 parent e2b9ffa commit 3709433

24 files changed

Lines changed: 244 additions & 167 deletions

build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id 'fabric-loom' version '1.7-SNAPSHOT'
2+
id 'fabric-loom' version '1.11-SNAPSHOT'
33
id 'maven-publish'
44
}
55

@@ -32,6 +32,8 @@ loom {
3232
}
3333
}
3434

35+
// log4jConfigs.from(file("log4j.xml"))
36+
3537
}
3638

3739
dependencies {
@@ -51,10 +53,10 @@ dependencies {
5153
modImplementation "net.fabricmc.fabric-api:fabric-key-binding-api-v1:${project.fabric_version}"
5254

5355
// Added Cloth Config and ModMenu
54-
modApi("me.shedaniel.cloth:cloth-config-fabric:17.0.144") {
56+
modApi("me.shedaniel.cloth:cloth-config-fabric:20.0.148") {
5557
exclude(group: "net.fabricmc.fabric-api")
5658
}
57-
modImplementation("com.terraformersmc:modmenu:13.0.2")
59+
modImplementation("com.terraformersmc:modmenu:16.0.0-rc.1")
5860
}
5961

6062
processResources {

gradle.properties

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ org.gradle.parallel=true
44

55
# Fabric Properties
66
# check these on https://fabricmc.net/develop
7-
minecraft_version=1.21.4
8-
yarn_mappings=1.21.4+build.8
9-
loader_version=0.16.10
7+
minecraft_version=1.21.10
8+
yarn_mappings=1.21.10+build.2
9+
loader_version=0.17.3
10+
loom_version=1.11-SNAPSHOT
1011

1112
# Mod Properties
1213
mod_version=0.1.0
1314
maven_group=net.gunivers
1415
archives_base_name=sniffer
1516

1617
# Dependencies
17-
fabric_version=0.118.0+1.21.4
18+
fabric_version=0.136.0+1.21.10

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://maven.fastmirror.net/repositories/gradle-dist/gradle-8.8-bin.zip
3+
distributionUrl=https\://maven.fastmirror.net/repositories/gradle-dist/gradle-8.14-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

src/client/java/net/gunivers/sniffer/DatapackBreakpointClient.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
66
import net.minecraft.client.option.KeyBinding;
77
import net.minecraft.client.util.InputUtil;
8+
import net.minecraft.util.Identifier;
89
import org.lwjgl.glfw.GLFW;
910
import net.gunivers.sniffer.command.BreakPointCommand;;
1011

@@ -22,13 +23,13 @@ public void onInitializeClient() {
2223
"sniffer.step", // The translation key of the keybinding's name
2324
InputUtil.Type.KEYSYM, // The type of the keybinding, KEYSYM for keyboard, MOUSE for mouse.
2425
GLFW.GLFW_KEY_F7, // The keycode of the key
25-
"sniffer.name" // The translation key of the keybinding's category.
26+
KeyBinding.Category.create(Identifier.of("sniffer.name")) // The translation key of the keybinding's category.
2627
));
2728

2829
ClientTickEvents.END_CLIENT_TICK.register(client -> {
2930
while(stepInto.wasPressed()) {
3031
if(BreakPointCommand.debugMode) {
31-
BreakPointCommand.step(1, client.player.getCommandSource(client.getServer().getWorld(client.player.getWorld().getRegistryKey())));
32+
BreakPointCommand.step(1, client.player.getCommandSource(client.getServer().getWorld(client.player.getEntityWorld().getRegistryKey())));
3233
}
3334
}
3435
});

src/main/java/net/gunivers/sniffer/command/BreakPointCommand.java

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
package net.gunivers.sniffer.command;
22

33
import com.google.common.collect.Queues;
4-
import com.mojang.brigadier.arguments.*;
4+
import com.mojang.brigadier.arguments.IntegerArgumentType;
5+
import com.mojang.brigadier.arguments.StringArgumentType;
56
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
7+
import net.gunivers.sniffer.DatapackDebugger;
8+
import net.gunivers.sniffer.dap.DebuggerState;
9+
import net.gunivers.sniffer.dap.ScopeManager;
10+
import net.gunivers.sniffer.util.ReflectUtil;
611
import net.minecraft.command.CommandExecutionContext;
7-
8-
import static net.gunivers.sniffer.Utils.addSnifferPrefix;
9-
import static net.minecraft.server.command.CommandManager.literal;
10-
import static net.minecraft.server.command.CommandManager.argument;
11-
1212
import net.minecraft.nbt.NbtElement;
1313
import net.minecraft.nbt.NbtHelper;
1414
import net.minecraft.server.command.ServerCommandSource;
1515
import net.minecraft.text.MutableText;
1616
import net.minecraft.text.Text;
17+
import net.minecraft.text.TextColor;
1718
import net.minecraft.util.Formatting;
1819
import net.minecraft.util.Pair;
1920
import org.jetbrains.annotations.NotNull;
2021
import org.jetbrains.annotations.Nullable;
21-
import net.gunivers.sniffer.DatapackDebugger;
22-
import net.gunivers.sniffer.dap.DebuggerState;
23-
import net.gunivers.sniffer.dap.ScopeManager;
2422

2523
import java.util.Deque;
2624

25+
import static net.gunivers.sniffer.util.Utils.addSnifferPrefix;
26+
import static net.minecraft.server.command.CommandManager.argument;
27+
import static net.minecraft.server.command.CommandManager.literal;
28+
2729
/**
2830
* Main command handler for the datapack debugging system.
2931
* Provides commands for setting breakpoints, stepping through code, and inspecting variables.
@@ -173,7 +175,7 @@ public static void onInitialize() {
173175
var t = Text.literal(stack.getFunction());
174176
var style = t.getStyle();
175177
if(stacks.indexOf(stack) == 0){
176-
style = style.withBold(true);
178+
style = style.withBold(true).withColor(TextColor.parse("aqua").getOrThrow());
177179
}else {
178180
style = style.withBold(false);
179181
}
@@ -240,40 +242,30 @@ public static void step(int steps, ServerCommandSource source) {
240242
isDebugCommand = true;
241243
moveSteps = steps;
242244
CommandExecutionContext<?> context = null;
243-
try {
244-
while (moveSteps > 0) {
245-
context = storedCommandExecutionContext.peekFirst();
246-
if (context != null) {
247-
var cls = context.getClass();
248-
var method = cls.getDeclaredMethod("onStep");
249-
method.setAccessible(true);
250-
method.invoke(context);
251-
if (moveSteps != 0) {
245+
while (moveSteps > 0) {
246+
context = storedCommandExecutionContext.peekFirst();
247+
if (context != null) {
248+
ReflectUtil.invoke(context, "onStep").onFailure(LOGGER::error);
249+
if (moveSteps != 0) {
250+
storedCommandExecutionContext.pollFirst().close();
251+
}else {
252+
var result = (boolean) ReflectUtil.invoke(context, "ifContainsCommandAction").onFailure(LOGGER::error).getData();
253+
if(!result){
252254
storedCommandExecutionContext.pollFirst().close();
253-
}else {
254-
var method1 = cls.getDeclaredMethod("ifContainsCommandAction");
255-
method1.setAccessible(true);
256-
boolean result = (boolean) method1.invoke(context);
257-
if(!result){
258-
storedCommandExecutionContext.pollFirst().close();
259-
}
260-
break;
261255
}
262-
} else {
263-
source.sendFeedback(() -> addSnifferPrefix(Text.translatable("sniffer.commands.breakpoint.step.over").formatted(Formatting.WHITE)), false);
264-
continueExec(source);
256+
break;
265257
}
258+
} else {
259+
source.sendFeedback(() -> addSnifferPrefix(Text.translatable("sniffer.commands.breakpoint.step.over").formatted(Formatting.WHITE)), false);
260+
continueExec(source);
266261
}
267-
} catch (Exception e) {
268-
LOGGER.error(e.getMessage(), e);
269-
} finally {
270-
isDebugCommand = false;
271-
if (context != null) {
272-
try {
273-
context.close();
274-
} catch (Exception e) {
275-
LOGGER.error(e.getMessage());
276-
}
262+
}
263+
isDebugCommand = false;
264+
if (context != null) {
265+
try {
266+
context.close();
267+
} catch (Exception e) {
268+
LOGGER.error(e.getMessage());
277269
}
278270
}
279271
}
@@ -313,10 +305,10 @@ public static void continueExec(@NotNull ServerCommandSource source) {
313305
return null;
314306
}
315307
try {
316-
var cls = context.getClass();
317-
var method = cls.getDeclaredMethod("getKey", String.class);
318-
method.setAccessible(true);
319-
return (Pair<NbtElement, Boolean>) method.invoke(context, key);
308+
//noinspection unchecked
309+
return (Pair<NbtElement, Boolean>) ReflectUtil.invoke(context, "getKey", key)
310+
.onFailure(LOGGER::error)
311+
.getDataOrElse(null);
320312
}catch (Exception e){
321313
LOGGER.error(e.toString());
322314
source.sendError(Text.translatable("sniffer.commands.breakpoint.get.fail.error", e.toString()));

src/main/java/net/gunivers/sniffer/command/FunctionInAction.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
package net.gunivers.sniffer.command;
22

3-
import net.gunivers.sniffer.EncapsulationBreaker;
3+
import com.mojang.logging.LogUtils;
4+
import net.gunivers.sniffer.dap.ScopeManager;
5+
import net.gunivers.sniffer.util.ReflectUtil;
46
import net.minecraft.command.CommandExecutionContext;
57
import net.minecraft.command.Frame;
68
import net.minecraft.command.SourcedCommandAction;
79
import net.minecraft.nbt.NbtCompound;
810
import net.minecraft.server.command.AbstractServerCommandSource;
911
import net.minecraft.server.function.CommandFunction;
10-
import net.gunivers.sniffer.dap.ScopeManager;
1112
import net.minecraft.server.function.ExpandedMacro;
13+
import net.minecraft.server.function.Macro;
14+
import net.minecraft.server.function.Procedure;
15+
import org.slf4j.Logger;
1216

13-
import static net.gunivers.sniffer.Utils.getId;
1417
import static net.gunivers.sniffer.command.StepType.isStepOut;
18+
import static net.gunivers.sniffer.util.Utils.getId;
1519

1620
/**
1721
* Action handler for when a function is entered during debugging.
@@ -25,6 +29,8 @@
2529
*/
2630
public class FunctionInAction<T extends AbstractServerCommandSource<T>> implements SourcedCommandAction<T> {
2731

32+
private final static Logger LOGGER = LogUtils.getLogger();
33+
2834
/**
2935
* The function being entered.
3036
* This reference stores the Minecraft function that is about to be executed
@@ -52,13 +58,23 @@ public FunctionInAction(CommandFunction<T> function){
5258
public void execute(T source, CommandExecutionContext<T> context, Frame frame){
5359
// Each time we are going into a deeper scope, we want to decrement of one to not skip the mustStop evaluation at the first command
5460
// We must do it here since the decrementation in FixCommandActionMixin is not called when a mcfunction is called
55-
if(BreakPointCommand.moveSteps > 0 && !isStepOut()) BreakPointCommand.moveSteps --;
61+
if(BreakPointCommand.isDebugging && BreakPointCommand.moveSteps > 0 && !isStepOut()){
62+
BreakPointCommand.moveSteps --;
63+
}
5664
var id = function.id();
5765
if(function instanceof ExpandedMacro<T> macro) {
5866
id = getId(macro);
5967
}
68+
if(ReflectUtil.getT(function, "originalMacro", Macro.class).onFailure(LOGGER::error).getDataOrElse(null) != null){
69+
//if originalMacro is not null, we are in a macro call, so we need to get the macro arguments and the original macro.
70+
var function = ReflectUtil.getT(frame, "function", Procedure.class).onFailure(LOGGER::error).getDataOrElse(null);
71+
if(function == null) return;
72+
var macroVariables = ReflectUtil.getT(function, "arguments", NbtCompound.class).onFailure(LOGGER::error).getDataOrElse(null);
73+
ScopeManager.get().newScope(id.toString(), source, macroVariables);
74+
}else{
75+
//otherwise it is a regular function call, so we just create a new scope with the function id without getting the macro arguments.
76+
ScopeManager.get().newScope(id.toString(), source);
77+
}
6078

61-
var macroVariables = EncapsulationBreaker.getAttribute(frame, "function").flatMap(fun -> EncapsulationBreaker.getAttribute(fun, "arguments"));
62-
ScopeManager.get().newScope(id.toString(), source, (NbtCompound) macroVariables.orElse(null));
6379
}
6480
}

src/main/java/net/gunivers/sniffer/command/FunctionOutAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ public FunctionOutAction(CommandFunction<T> function){
4848
public void execute(T source, CommandExecutionContext<T> context, Frame frame) {
4949
ScopeManager.get().unscope();
5050
// BreakPointCommand.stepDepth - 1 because we only want to decrement if we go higher than the stepDepth
51-
if(BreakPointCommand.moveSteps > 0 && isStepOut() && frame.depth() - 1 <= BreakPointCommand.stepDepth - 1) BreakPointCommand.moveSteps --;
51+
if(BreakPointCommand.isDebugging && BreakPointCommand.moveSteps > 0 && isStepOut() && frame.depth() - 1 <= BreakPointCommand.stepDepth - 1) BreakPointCommand.moveSteps --;
5252
}
5353
}

src/main/java/net/gunivers/sniffer/dap/DapServer.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import java.util.*;
1616
import java.util.concurrent.CompletableFuture;
1717

18-
import static net.gunivers.sniffer.Utils.addSnifferPrefix;
18+
import static net.gunivers.sniffer.util.Utils.addSnifferPrefix;
1919
import static net.gunivers.sniffer.command.BreakPointCommand.continueExec;
2020

2121
/**
@@ -70,10 +70,6 @@ public CompletableFuture<Capabilities> initialize(InitializeRequestArguments arg
7070
capabilities.setSupportsConfigurationDoneRequest(true);
7171
// capabilities.setSupportsBreakpointLocationsRequest(true);
7272

73-
// Register event handlers
74-
debuggerState.onStop(this::onStop);
75-
debuggerState.onContinue(this::onContinue);
76-
7773
LOGGER.debug("Sending capabilities response: {}", capabilities);
7874
return CompletableFuture.completedFuture(capabilities).thenApply(capabilities1 -> {
7975
LOGGER.debug("Sending initialized event");

src/main/java/net/gunivers/sniffer/dap/NbtElementVariableVisitor.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public void visitList(NbtList element) {
162162
public void visitCompound(NbtCompound compound) {
163163
var children = new LinkedList<DebuggerVariable>();
164164
var compoundIndex = this.index++;
165-
var compoundVar = new DebuggerVariable(compoundIndex, this.currentName, compound.asString(), children, isRoot);
165+
var compoundVar = new DebuggerVariable(compoundIndex, this.currentName, compound.asString().orElse(null), children, isRoot);
166166
isRoot = false;
167167
variables.put(compoundIndex, compoundVar);
168168
for(var key: compound.getKeys()) {
@@ -187,15 +187,16 @@ public void visitEnd(NbtEnd element) {}
187187
*
188188
* @param list The NBT list or array to convert
189189
*/
190-
private void convertList(AbstractNbtList<?> list) {
190+
private void convertList(AbstractNbtList list) {
191191
var arrayIndex = index++;
192192
var array = new LinkedList<DebuggerVariable>();
193193
var name = currentName;
194-
var result = new DebuggerVariable(arrayIndex, name, list.asString(), array, false);
194+
var result = new DebuggerVariable(arrayIndex, name, list.asString().orElse(null), array, false);
195195
variables.put(arrayIndex, result);
196196
for(int i = 0; i < list.size(); i++) {
197197
currentName = Integer.toString(index);
198-
list.get(i).accept(this);
198+
//method_10534(int i) = get(int i)
199+
list.method_10534(i).accept(this);
199200
array.add(returnVariable);
200201
}
201202
index++;
@@ -210,7 +211,7 @@ private void convertList(AbstractNbtList<?> list) {
210211
*/
211212
private void convertPrimitive(NbtElement element) {
212213
var i = index++;
213-
returnVariable = new DebuggerVariable(i, currentName, element.asString(), List.of(), isRoot);
214+
returnVariable = new DebuggerVariable(i, currentName, element.asString().orElse(null), List.of(), isRoot);
214215
variables.put(i, returnVariable);
215216
}
216217
}

0 commit comments

Comments
 (0)