aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-09-08 20:51:26 +0200
committerLinnea Gräf <nea@nea.moe>2024-09-08 20:51:57 +0200
commitc9aaaeed770efcc53992038c08ac188ee27d1671 (patch)
tree22c5ed2bb7c1f3666d0cc9ce590873c3b957a10d /src/main/kotlin
parent26461deda4dc8695dacedefe50d976eb5e3d7714 (diff)
downloadFirmament-c9aaaeed770efcc53992038c08ac188ee27d1671.tar.gz
Firmament-c9aaaeed770efcc53992038c08ac188ee27d1671.tar.bz2
Firmament-c9aaaeed770efcc53992038c08ac188ee27d1671.zip
Fix cit resewn
Diffstat (limited to 'src/main/kotlin')
-rw-r--r--src/main/kotlin/util/ConditionNBTMixin.kt58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/main/kotlin/util/ConditionNBTMixin.kt b/src/main/kotlin/util/ConditionNBTMixin.kt
new file mode 100644
index 0000000..cbc1e66
--- /dev/null
+++ b/src/main/kotlin/util/ConditionNBTMixin.kt
@@ -0,0 +1,58 @@
+package moe.nea.firmament.util
+
+import java.lang.invoke.MethodHandles
+import java.util.function.BiPredicate
+import java.util.function.Function
+import shcm.shsupercm.fabric.citresewn.defaults.cit.conditions.ConditionNBT
+
+object ConditionNBTMixin {
+ class Helper<StringMatcher> {
+
+ val stringMatcherType = ConditionNBT::class.java.getDeclaredField("matchString").type
+
+ val accessMatcher = run {
+ val matchStringF = ConditionNBT::class.java.getDeclaredField("matchString");
+ matchStringF.isAccessible = true
+ val l = MethodHandles.privateLookupIn(ConditionNBT::class.java, MethodHandles.lookup())
+// val mt = MethodType.methodType(stringMatcherType, ConditionNBT::class.java)
+// val callsite = LambdaMetafactory.metafactory(
+// l, "apply",
+// MethodType.methodType(Function::class.java),
+// MethodType.methodType(java.lang.Object::class.java, java.lang.Object::class.java),
+// l.unreflectGetter(matchStringF),
+// mt
+// )
+ val getter = l.unreflectGetter(matchStringF)
+ Function<ConditionNBT, StringMatcher> { getter.invoke(it) as StringMatcher }
+ }
+ val directCaller = run {
+ val matchM = stringMatcherType.getDeclaredMethod("matches", String::class.java);
+ matchM.isAccessible = true
+ val l = MethodHandles.privateLookupIn(ConditionNBT::class.java, MethodHandles.lookup())
+// val mt = MethodType.methodType(java.lang.Boolean.TYPE, stringMatcherType, String::class.java)
+// val callsite = LambdaMetafactory.metafactory(
+// l, "test",
+// MethodType.methodType(BiPredicate::class.java),
+// mt,
+// l.unreflect(matchM),
+// mt
+// )
+ val func = l.unreflect(matchM)
+ BiPredicate<StringMatcher, String> { a, b -> func.invoke(a, b) as Boolean }
+ }
+
+ fun test(condition: ConditionNBT, text: String): Boolean {
+ return directCaller.test(accessMatcher.apply(condition), text) as Boolean
+ }
+ }
+
+ val helper = Helper<Any>()
+
+ @JvmStatic
+ fun invokeDirectConditionNBTStringMatch(
+ nbt: ConditionNBT,
+ text: String,
+ ): Boolean {
+ return helper.test(nbt, text)
+ }
+}