Skip to content

Commit 22acfbe

Browse files
committed
Implement hexical interop for telepathy and notebook in splicing table
1 parent 764c5ee commit 22acfbe

File tree

16 files changed

+168
-5
lines changed

16 files changed

+168
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
99
### Added
1010

1111
- Added a new resource-pack-based data-driven system for addon devs to customize how their iotas are rendered in the Splicing Table.
12+
- Added Hexical interop to make the telepathy and notebook keys work in the Splicing/Mindsplice Table GUI.
1213

1314
### Changed
1415

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package gay.object.hexdebug.mixin;
2+
3+
import gay.object.hexdebug.gui.IMixinScreen;
4+
import net.minecraft.client.Minecraft;
5+
import net.minecraft.client.gui.screens.Screen;
6+
import org.jetbrains.annotations.Nullable;
7+
import org.spongepowered.asm.mixin.Mixin;
8+
import org.spongepowered.asm.mixin.Unique;
9+
import org.spongepowered.asm.mixin.injection.At;
10+
import org.spongepowered.asm.mixin.injection.Inject;
11+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
12+
13+
@Mixin(Screen.class)
14+
public abstract class MixinScreen implements IMixinScreen {
15+
@Unique
16+
@Nullable
17+
private Screen hexdebug$previousScreen = null;
18+
19+
@Override
20+
public void hexdebug$setPreviousScreen(@Nullable Screen screen) {
21+
hexdebug$previousScreen = screen;
22+
}
23+
24+
@Inject(method = "onClose", at = @At("HEAD"), cancellable = true)
25+
private void hexdebug$returnToPreviousScreen(CallbackInfo ci) {
26+
if (hexdebug$previousScreen != null) {
27+
Minecraft.getInstance().setScreen(hexdebug$previousScreen);
28+
hexdebug$previousScreen = null;
29+
ci.cancel();
30+
}
31+
}
32+
}

Common/src/main/kotlin/gay/object/hexdebug/HexDebugClientAbstractions.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@
44
package gay.`object`.hexdebug
55

66
import dev.architectury.injectables.annotations.ExpectPlatform
7+
import net.minecraft.client.Minecraft
78
import net.minecraft.resources.ResourceLocation
89
import net.minecraft.server.packs.resources.PreparableReloadListener
910

1011
@ExpectPlatform
1112
fun registerClientResourceReloadListener(id: ResourceLocation, listener: PreparableReloadListener) {
1213
throw AssertionError()
1314
}
15+
16+
@ExpectPlatform
17+
fun sendHexicalKeyEvent(client: Minecraft, keyCode: Int, scanCode: Int, isPressed: Boolean) {
18+
throw AssertionError()
19+
}

Common/src/main/kotlin/gay/object/hexdebug/config/HexDebugClientConfig.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ object HexDebugClientConfig {
108108
@Tooltip
109109
val overrideVanillaArrowKeys = true
110110

111+
@Tooltip
112+
val sendHexicalTelepathy = true
113+
111114
val viewLeft = ConfigModifierKey(InputConstants.KEY_UP)
112115
val viewLeftPage = ConfigModifierKey(InputConstants.KEY_PAGEUP)
113116
val viewLeftFull = ConfigModifierKey(InputConstants.KEY_HOME)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package gay.`object`.hexdebug.gui
2+
3+
import net.minecraft.client.gui.screens.Screen
4+
5+
@Suppress("FunctionName")
6+
interface IMixinScreen {
7+
fun `hexdebug$setPreviousScreen`(screen: Screen?)
8+
}
9+
10+
@Suppress("CAST_NEVER_SUCCEEDS")
11+
val Screen.mixin get() = this as IMixinScreen

Common/src/main/kotlin/gay/object/hexdebug/gui/splicing/SplicingTableScreen.kt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import gay.`object`.hexdebug.config.ConfigModifierKey
1010
import gay.`object`.hexdebug.config.HexDebugClientConfig
1111
import gay.`object`.hexdebug.config.HexDebugServerConfig
1212
import gay.`object`.hexdebug.gui.splicing.widgets.*
13+
import gay.`object`.hexdebug.sendHexicalKeyEvent
1314
import gay.`object`.hexdebug.splicing.IOTA_BUTTONS
1415
import gay.`object`.hexdebug.splicing.Selection
1516
import gay.`object`.hexdebug.splicing.SplicingTableAction
@@ -542,11 +543,17 @@ class SplicingTableScreen(
542543
}
543544

544545
override fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
545-
if (HexDebugClientConfig.config.splicingTableKeybinds.enabled) {
546+
val keybinds = HexDebugClientConfig.config.splicingTableKeybinds
547+
548+
if (keybinds.enabled) {
549+
if (keybinds.sendHexicalTelepathy) {
550+
sendHexicalKeyEvent(minecraft!!, keyCode, scanCode, isPressed = true)
551+
}
552+
546553
// AbstractContainerScreen.keyPressed always returns true, so check our keys first
547554
if (keyPressedInner(keyCode, scanCode)) return true
548555

549-
if (HexDebugClientConfig.config.splicingTableKeybinds.overrideVanillaArrowKeys) {
556+
if (keybinds.overrideVanillaArrowKeys) {
550557
when (keyCode) {
551558
GLFW.GLFW_KEY_UP,
552559
GLFW.GLFW_KEY_DOWN,
@@ -588,6 +595,14 @@ class SplicingTableScreen(
588595
minecraft!!.soundManager.play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1f))
589596
}
590597

598+
override fun keyReleased(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
599+
val keybinds = HexDebugClientConfig.config.splicingTableKeybinds
600+
if (keybinds.enabled && keybinds.sendHexicalTelepathy) {
601+
sendHexicalKeyEvent(minecraft!!, keyCode, scanCode, isPressed = false)
602+
}
603+
return super.keyReleased(keyCode, scanCode, modifiers)
604+
}
605+
591606
// TODO: limit scroll to certain regions? (let's see if anyone complains first)
592607
override fun mouseScrolled(mouseX: Double, mouseY: Double, delta: Double): Boolean {
593608
if (super.mouseScrolled(mouseX, mouseY, delta)) return true

Common/src/main/resources/assets/hexdebug/lang/en_us.flatten.json5

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@
109109
"": "Override Vanilla Arrow Key Navigation",
110110
"@Tooltip": "In the Splicing Table GUI, override the vanilla feature that allows the arrow keys to be used to focus on UI elements. This setting improves usability with the default keybinds, but you may want to disable it if you rely on this feature for accessibility purposes.",
111111
},
112+
sendHexicalTelepathy: {
113+
"": "Enable Hexical Telepathy",
114+
"@Tooltip": "Fabric-only. If Hexical is installed, enable all telepathy keys in the Splicing Table GUI. Note: If Hexical adds its own support for using telepathy in GUIs, disabling this feature will not disable that.",
115+
},
112116
enlightened: {
113117
"": "Mindsplice Table",
114118
"@Tooltip": "Keybinds for actions in the Mindsplice Table GUI.",

Common/src/main/resources/hexdebug-common.mixins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"minVersion": "0.8",
66
"client": [
77
"MixinGuiSpellcasting",
8+
"MixinScreen",
89
"MixinShiftScrollListener"
910
],
1011
"mixins": [

Fabric/build.gradle.kts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ dependencies {
6767
exclude(module = "phosphor")
6868
}
6969
modLocalRuntime(libs.paucal.fabric)
70-
modLocalRuntime(libs.patchouli.fabric)
70+
modImplementation(libs.patchouli.fabric)
7171
modLocalRuntime(libs.cardinalComponents)
7272
modLocalRuntime(libs.serializationHooks)
7373
modLocalRuntime(libs.trinkets)
@@ -99,6 +99,10 @@ dependencies {
9999
modApi(libs.ioticblocks.fabric)
100100

101101
modImplementation(libs.emi.fabric)
102+
103+
modImplementation(libs.hexical)
104+
modLocalRuntime(libs.hexpose) { isTransitive = false }
105+
modLocalRuntime(libs.playerAnimator.fabric)
102106
}
103107

104108
publishMods {

Fabric/src/main/kotlin/gay/object/hexdebug/fabric/HexDebugClientAbstractionsImpl.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
package gay.`object`.hexdebug.fabric
44

5+
import gay.`object`.hexdebug.fabric.interop.FabricHexDebugHexicalInterop
56
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener
67
import net.fabricmc.fabric.api.resource.ResourceManagerHelper
8+
import net.fabricmc.loader.api.FabricLoader
9+
import net.minecraft.client.Minecraft
710
import net.minecraft.resources.ResourceLocation
811
import net.minecraft.server.packs.PackType
912
import net.minecraft.server.packs.resources.PreparableReloadListener
@@ -30,3 +33,9 @@ fun registerClientResourceReloadListener(id: ResourceLocation, listener: Prepara
3033
}
3134
)
3235
}
36+
37+
fun sendHexicalKeyEvent(client: Minecraft, keyCode: Int, scanCode: Int, isPressed: Boolean) {
38+
if (FabricLoader.getInstance().isModLoaded("hexical")) {
39+
FabricHexDebugHexicalInterop.sendKeyEvent(client, keyCode, scanCode, isPressed)
40+
}
41+
}

0 commit comments

Comments
 (0)