Skip to content

Commit

Permalink
一回だけKeyのactionが実行される
Browse files Browse the repository at this point in the history
  • Loading branch information
yuuki1293 committed Sep 15, 2022
1 parent ca2b170 commit 979ac73
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package staticallytyped.kagawaassist

import com.mojang.blaze3d.platform.InputConstants
import net.minecraft.client.KeyMapping
import net.minecraftforge.client.settings.{IKeyConflictContext, KeyModifier}

class KagawaAssistKeyMapping(name: String, key: Int, val f: Unit => _)(implicit category: String)
extends KeyMapping(name, key, category){
class KagawaAssistKeyMapping(description: String, keyConflictContext: IKeyConflictContext, keyModifier: KeyModifier, keyCode: InputConstants.Key, val f: Unit => _)(implicit category: String)
extends KeyMapping(description, keyConflictContext, keyModifier, keyCode, category){
}
9 changes: 6 additions & 3 deletions src/main/scala/staticallytyped/kagawaassist/KeyBind.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package staticallytyped.kagawaassist

import com.mojang.blaze3d.platform.InputConstants
import com.mojang.blaze3d.platform.InputConstants._
import net.minecraftforge.client.event.{InputEvent, RegisterKeyMappingsEvent}
import net.minecraftforge.client.settings.{KeyConflictContext, KeyModifier}
import net.minecraftforge.eventbus.api.SubscribeEvent
import net.minecraftforge.fml.common.Mod
import staticallytyped.kagawaassist.coordinate.{CopyCoordinate, SendCoordinate}
Expand All @@ -16,14 +18,15 @@ object KeyBind {
)

def newKeyMap(name: String, key: Int, f: Unit => _)(implicit category: String): KagawaAssistKeyMapping = {
new KagawaAssistKeyMapping(name, key, f)(category)
new KagawaAssistKeyMapping(name, KeyConflictContext.IN_GAME, KeyModifier.NONE, InputConstants.Type.KEYSYM.getOrCreate(key), f)(category)
}

@SubscribeEvent
def onKeyInput(event: InputEvent.Key): Unit = {
keyMappings.foreach(keyMapping => {
if (event.getKey == keyMapping.getKey.getValue)
keyMapping.f()
if (keyMapping.consumeClick()) {
keyMapping.f(())
}
})
}

Expand Down

0 comments on commit 979ac73

Please sign in to comment.