Skip to content

Commit 80e0cfa

Browse files
committed
Add element keyword to incorrect types in ops
1 parent 6b77b40 commit 80e0cfa

3 files changed

Lines changed: 102 additions & 8 deletions

File tree

src/main/java/net/errorcraft/codecium/mixin/minecraft/nbt/NbtOpsExtender.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class NbtOpsExtender {
2020
remap = false
2121
)
2222
private Supplier<String> notANumberUseBetterErrorMessage(Supplier<String> message, @Local(argsOnly = true) final NbtElement input) {
23-
return () -> "Not a number: " + input;
23+
return () -> "Element is not a number: " + input;
2424
}
2525

2626
@ModifyArg(
@@ -32,7 +32,19 @@ private Supplier<String> notANumberUseBetterErrorMessage(Supplier<String> messag
3232
remap = false
3333
)
3434
private Supplier<String> notAStringUseBetterErrorMessage(Supplier<String> message, @Local(argsOnly = true) final NbtElement input) {
35-
return () -> "Not a string: " + input;
35+
return () -> "Element is not a string: " + input;
36+
}
37+
38+
@ModifyArg(
39+
method = { "getMapValues(Lnet/minecraft/nbt/NbtElement;)Lcom/mojang/serialization/DataResult;", "getMapEntries(Lnet/minecraft/nbt/NbtElement;)Lcom/mojang/serialization/DataResult;", "getMap(Lnet/minecraft/nbt/NbtElement;)Lcom/mojang/serialization/DataResult;" },
40+
at = @At(
41+
value = "INVOKE",
42+
target = "Lcom/mojang/serialization/DataResult;error(Ljava/util/function/Supplier;)Lcom/mojang/serialization/DataResult;"
43+
),
44+
remap = false
45+
)
46+
private Supplier<String> notAMapUseBetterErrorMessage(Supplier<String> message, @Local(argsOnly = true) final NbtElement input) {
47+
return () -> "Element is not a map: " + input;
3648
}
3749

3850
@ModifyArg(
@@ -44,6 +56,6 @@ private Supplier<String> notAStringUseBetterErrorMessage(Supplier<String> messag
4456
remap = false
4557
)
4658
private Supplier<String> notAListUseBetterErrorMessage(Supplier<String> message, @Local(argsOnly = true) final NbtElement input) {
47-
return () -> "Not a list: " + input;
59+
return () -> "Element is not a list: " + input;
4860
}
4961
}

src/main/java/net/errorcraft/codecium/mixin/mojang/serialization/JavaOpsExtender.java

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,61 @@
1111
@Mixin(value = JavaOps.class, remap = false)
1212
public class JavaOpsExtender {
1313
@ModifyArg(
14-
method = { "getStream", "getList", "getByteBuffer", "getIntStream", "getLongStream" },
14+
method = "getNumberValue",
15+
at = @At(
16+
value = "INVOKE",
17+
target = "Lcom/mojang/serialization/DataResult;error(Ljava/util/function/Supplier;)Lcom/mojang/serialization/DataResult;"
18+
),
19+
remap = false
20+
)
21+
private Supplier<String> notANumberUseBetterErrorMessage(Supplier<String> message, @Local(argsOnly = true) final Object input) {
22+
return () -> "Element is not a number: " + input;
23+
}
24+
25+
@ModifyArg(
26+
method = "getBooleanValue",
27+
at = @At(
28+
value = "INVOKE",
29+
target = "Lcom/mojang/serialization/DataResult;error(Ljava/util/function/Supplier;)Lcom/mojang/serialization/DataResult;"
30+
),
31+
remap = false
32+
)
33+
private Supplier<String> notABooleanUseBetterErrorMessage(Supplier<String> message, @Local(argsOnly = true) final Object input) {
34+
return () -> "Element is not a boolean: " + input;
35+
}
36+
37+
@ModifyArg(
38+
method = "getStringValue",
39+
at = @At(
40+
value = "INVOKE",
41+
target = "Lcom/mojang/serialization/DataResult;error(Ljava/util/function/Supplier;)Lcom/mojang/serialization/DataResult;"
42+
),
43+
remap = false
44+
)
45+
private Supplier<String> notAStringUseBetterErrorMessage(Supplier<String> message, @Local(argsOnly = true) final Object input) {
46+
return () -> "Element is not a string: " + input;
47+
}
48+
49+
@ModifyArg(
50+
method = { "mergeToMap(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Lcom/mojang/serialization/DataResult;", "mergeToMap(Ljava/lang/Object;Ljava/util/Map;)Lcom/mojang/serialization/DataResult;", "mergeToMap(Ljava/lang/Object;Lcom/mojang/serialization/MapLike;)Lcom/mojang/serialization/DataResult;", "getMapValues", "getMapEntries(Ljava/lang/Object;)Lcom/mojang/serialization/DataResult;", "getMap" },
51+
at = @At(
52+
value = "INVOKE",
53+
target = "Lcom/mojang/serialization/DataResult;error(Ljava/util/function/Supplier;)Lcom/mojang/serialization/DataResult;"
54+
),
55+
remap = false
56+
)
57+
private Supplier<String> notAMapUseBetterErrorMessage(Supplier<String> message, @Local(argsOnly = true, ordinal = 0) final Object input) {
58+
return () -> "Element is not a map: " + input;
59+
}
60+
61+
@ModifyArg(
62+
method = { "mergeToList(Ljava/lang/Object;Ljava/lang/Object;)Lcom/mojang/serialization/DataResult;", "mergeToList(Ljava/lang/Object;Ljava/util/List;)Lcom/mojang/serialization/DataResult;", "getStream", "getList", "getByteBuffer", "getIntStream", "getLongStream" },
1563
at = @At(
1664
value = "INVOKE",
1765
target = "Lcom/mojang/serialization/DataResult;error(Ljava/util/function/Supplier;)Lcom/mojang/serialization/DataResult;"
1866
)
1967
)
20-
private Supplier<String> notAListUseBetterErrorMessage(Supplier<String> message, @Local(argsOnly = true) final Object input) {
21-
return () -> "Not a list: " + input;
68+
private Supplier<String> notAListUseBetterErrorMessage(Supplier<String> message, @Local(argsOnly = true, ordinal = 0) final Object input) {
69+
return () -> "Element is not a list: " + input;
2270
}
2371
}

src/main/java/net/errorcraft/codecium/mixin/mojang/serialization/JsonOpsExtender.java

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,40 @@ private Supplier<String> notANumberWithExceptionUseBetterErrorMessage(Supplier<S
2424
return () -> ExceptionUtil.errorMessage(e, input);
2525
}
2626

27+
@ModifyArg(
28+
method = "getNumberValue(Lcom/google/gson/JsonElement;)Lcom/mojang/serialization/DataResult;",
29+
at = @At(
30+
value = "INVOKE",
31+
target = "Lcom/mojang/serialization/DataResult;error(Ljava/util/function/Supplier;)Lcom/mojang/serialization/DataResult;",
32+
ordinal = 1
33+
)
34+
)
35+
private Supplier<String> notANumberUseBetterErrorMessage(Supplier<String> message, @Local(argsOnly = true) final JsonElement input) {
36+
return () -> "Element is not a number: " + input;
37+
}
38+
39+
@ModifyArg(
40+
method = "getBooleanValue(Lcom/google/gson/JsonElement;)Lcom/mojang/serialization/DataResult;",
41+
at = @At(
42+
value = "INVOKE",
43+
target = "Lcom/mojang/serialization/DataResult;error(Ljava/util/function/Supplier;)Lcom/mojang/serialization/DataResult;"
44+
)
45+
)
46+
private Supplier<String> notABooleanUseBetterErrorMessage(Supplier<String> message, @Local(argsOnly = true) final JsonElement input) {
47+
return () -> "Element is not a boolean: " + input;
48+
}
49+
50+
@ModifyArg(
51+
method = "getStringValue(Lcom/google/gson/JsonElement;)Lcom/mojang/serialization/DataResult;",
52+
at = @At(
53+
value = "INVOKE",
54+
target = "Lcom/mojang/serialization/DataResult;error(Ljava/util/function/Supplier;)Lcom/mojang/serialization/DataResult;"
55+
)
56+
)
57+
private Supplier<String> notAStringUseBetterErrorMessage(Supplier<String> message, @Local(argsOnly = true) final JsonElement input) {
58+
return () -> "Element is not a string: " + input;
59+
}
60+
2761
@ModifyArg(
2862
method = { "getMapValues(Lcom/google/gson/JsonElement;)Lcom/mojang/serialization/DataResult;", "getMapEntries(Lcom/google/gson/JsonElement;)Lcom/mojang/serialization/DataResult;", "getMap(Lcom/google/gson/JsonElement;)Lcom/mojang/serialization/DataResult;" },
2963
at = @At(
@@ -32,7 +66,7 @@ private Supplier<String> notANumberWithExceptionUseBetterErrorMessage(Supplier<S
3266
)
3367
)
3468
private Supplier<String> notAMapUseBetterErrorMessage(Supplier<String> message, @Local(argsOnly = true) final JsonElement input) {
35-
return () -> "Not a map: " + input;
69+
return () -> "Element is not a map: " + input;
3670
}
3771

3872
@ModifyArg(
@@ -43,6 +77,6 @@ private Supplier<String> notAMapUseBetterErrorMessage(Supplier<String> message,
4377
)
4478
)
4579
private Supplier<String> notAListUseBetterErrorMessage(Supplier<String> message, @Local(argsOnly = true) final JsonElement input) {
46-
return () -> "Not a list: " + input;
80+
return () -> "Element is not a list: " + input;
4781
}
4882
}

0 commit comments

Comments
 (0)