aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/util')
-rw-r--r--src/main/kotlin/util/accessors/GetRectangle.kt2
-rw-r--r--src/main/kotlin/util/accessors/castAccessor.kt16
2 files changed, 17 insertions, 1 deletions
diff --git a/src/main/kotlin/util/accessors/GetRectangle.kt b/src/main/kotlin/util/accessors/GetRectangle.kt
index 05ecfa9..109de94 100644
--- a/src/main/kotlin/util/accessors/GetRectangle.kt
+++ b/src/main/kotlin/util/accessors/GetRectangle.kt
@@ -7,7 +7,7 @@ import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen
import moe.nea.firmament.mixins.accessor.AccessorHandledScreen
fun AbstractContainerScreen<*>.getProperRectangle(): Rectangle {
- this as AccessorHandledScreen
+ this.castAccessor()
return Rectangle(
getX_Firmament(),
getY_Firmament(),
diff --git a/src/main/kotlin/util/accessors/castAccessor.kt b/src/main/kotlin/util/accessors/castAccessor.kt
new file mode 100644
index 0000000..0ac85a2
--- /dev/null
+++ b/src/main/kotlin/util/accessors/castAccessor.kt
@@ -0,0 +1,16 @@
+@file:OptIn(ExperimentalContracts::class)
+
+package moe.nea.firmament.util.accessors
+
+import kotlin.contracts.ExperimentalContracts
+import kotlin.contracts.contract
+import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen
+import moe.nea.firmament.mixins.accessor.AccessorHandledScreen
+
+
+inline fun AbstractContainerScreen<*>.castAccessor(): AccessorHandledScreen {
+ contract {
+ returns() implies (this@castAccessor is AccessorHandledScreen)
+ }
+ return this as AccessorHandledScreen
+}