aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/dulkirmod/command/FarmingControlSchemeCommand.kt
blob: 8bbad18d315dca06cad99662dd6a69ab38d9c0ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package dulkirmod.command

import dulkirmod.config.Config
import dulkirmod.utils.TextUtils
import net.minecraft.client.Minecraft
import net.minecraft.client.settings.KeyBinding
import net.minecraft.command.CommandException
import net.minecraft.command.ICommandSender

class FarmingControlSchemeCommand : ClientCommandBase("farmcontrols") {
    private var enabled = false
    @Throws(CommandException::class)
    override fun processCommand(sender: ICommandSender, args: Array<String>) {
        toggleControls()
    }

    companion object {
        private var enabled = false

        /**
         * Method to do the brunt work of the command. This is separate, so I can also let the user set a
         * keybind to do the same thing.
         */
        fun toggleControls() {
            val minecraft = Minecraft.getMinecraft()
            val breakingKey: KeyBinding = minecraft.gameSettings.keyBindAttack
            val jumpKey: KeyBinding = minecraft.gameSettings.keyBindJump
            if (!enabled) {
                KeyBinding.setKeyBindState(breakingKey.keyCode, false)
                breakingKey.keyCode = 57 // 57 = space key code

                KeyBinding.setKeyBindState(jumpKey.keyCode, false)
                jumpKey.keyCode = -100 // -100 = Left click key code
                minecraft.gameSettings.mouseSensitivity = 0.0f
            } else {
                KeyBinding.setKeyBindState(breakingKey.keyCode, false)
                breakingKey.keyCode = -100 // -100 = Left click key code

                KeyBinding.setKeyBindState(jumpKey.keyCode, false)
                jumpKey.keyCode = 57 // 57 = space key code
                minecraft.gameSettings.mouseSensitivity = Config.defaultSens / 2
            }

            // Save the changes to the control settings
            minecraft.gameSettings.saveOptions()
            minecraft.gameSettings.loadOptions()

            enabled = !enabled
            TextUtils.toggledMessage("Farming Controls", enabled)
        }
    }
}