aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/dulkirmod/DulkirMod.kt
blob: 4ae84cca00edb1766c27650170a0e8727f28a034 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package dulkirmod

import dulkirmod.command.*
import dulkirmod.config.DulkirConfig
import dulkirmod.events.ChatEvent
import dulkirmod.features.*
import dulkirmod.features.chat.AbiphoneDND
import dulkirmod.features.dungeons.*
import dulkirmod.features.rift.EffigyWaypoint
import dulkirmod.features.rift.IchorHighlight
import dulkirmod.features.rift.SteakDisplay
import dulkirmod.utils.*
import kotlinx.coroutines.CoroutineScope
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.GuiScreen
import net.minecraft.client.settings.KeyBinding
import net.minecraftforge.client.ClientCommandHandler
import net.minecraftforge.common.MinecraftForge
import net.minecraftforge.fml.client.registry.ClientRegistry
import net.minecraftforge.fml.common.Mod
import net.minecraftforge.fml.common.event.FMLInitializationEvent
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.InputEvent.KeyInputEvent
import net.minecraftforge.fml.common.gameevent.TickEvent
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent
import org.lwjgl.input.Keyboard
import java.io.File
import kotlin.coroutines.EmptyCoroutineContext

@Mod(
    modid = DulkirMod.MOD_ID,
    name = DulkirMod.MOD_NAME,
    version = DulkirMod.MOD_VERSION,
    clientSideOnly = true
)
class DulkirMod {

    var lastLongUpdate: Long = 0
    var lastLongerUpdate: Long = 0

    @Mod.EventHandler
    fun preInit(event: FMLPreInitializationEvent) {
        val directory = File(event.modConfigurationDirectory, "dulkirmod")
        directory.mkdirs()
        val cch = ClientCommandHandler.instance

        // REGISTER COMMANDS HERE        // Help Commands
        cch.registerCommand(HelpCommand())

        // General
        cch.registerCommand(EnchantRuneCommand())
        cch.registerCommand(FairyCommand())
        cch.registerCommand(SettingsCommand())
        cch.registerCommand(JoinDungeonCommand())
        cch.registerCommand(LeapNameCommand())
        cch.registerCommand(HurtCamCommand())
        cch.registerCommand(FarmingControlSchemeCommand())
        cch.registerCommand(DynamicKeyCommand())
    }

    @Mod.EventHandler
    fun onInit(event: FMLInitializationEvent) {
        config.init()
        // REGISTER Classes and such HERE
        val mcBus = MinecraftForge.EVENT_BUS
        mcBus.register(this)
        mcBus.register(MemoryLeakFix)
        mcBus.register(ChatEvent)
        mcBus.register(NametagCleaner)
        mcBus.register(TitleUtils)
        mcBus.register(ArachneTimer)
        mcBus.register(MatchoAlert)
        mcBus.register(Croesus)
        mcBus.register(ContainerNameUtil)
        mcBus.register(DungeonLeap)
        mcBus.register(AbiphoneDND)
        mcBus.register(KeeperWaypoints)
        mcBus.register(ScalableTooltips)
        mcBus.register(GardenVisitorAlert)
        mcBus.register(DragonFeatures)
        mcBus.register(HideHealerFairy)
        mcBus.register(SecretSounds)
        mcBus.register(BlazeSlayerFeatures)
        mcBus.register(WorldRenderUtils)
        mcBus.register(IchorHighlight)
        mcBus.register(SteakDisplay)
        mcBus.register(ArcherHighlight)
        mcBus.register(ReaperDisplay)
        mcBus.register(ImpactDisplay)
        mcBus.register(EffigyWaypoint)

        keyBinds.forEach(ClientRegistry::registerKeyBinding)
    }

    @SubscribeEvent
    fun onTick(event: ClientTickEvent) {
        if (DulkirConfig.noReverse3rdPerson && mc.gameSettings.thirdPersonView == 2)
            mc.gameSettings.thirdPersonView = 0

        if (event.phase == TickEvent.Phase.START && display != null) {
            mc.displayGuiScreen(display)
            display = null
        }

        val currTime = System.currentTimeMillis()
        if (currTime - lastLongUpdate > 1000) { // long update
            alarmClock()
            brokenHypeNotif()
            GardenVisitorAlert.alert()
            MatchoAlert.alert()
            // Now I don't have to fetch the entries for multiple things, this just updates and caches
            // the data structure on 1s cooldown
            TabListUtils.parseTabEntries()
            DragonFeatures.updateDragonDead()
            EffigyWaypoint.checkEffigies()
            lastLongUpdate = currTime
        }

        if (currTime - lastLongerUpdate > 5000) { // longer update
            MemoryLeakFix.clearBlankStands()
            lastLongerUpdate = currTime
        }
    }

    @SubscribeEvent
    fun onKey(event: KeyInputEvent) {
        if (keyBinds[0].isPressed) config.openGui()
        if (keyBinds[1].isPressed) {
            DulkirConfig.noReverse3rdPerson = !DulkirConfig.noReverse3rdPerson
            TextUtils.toggledMessage("No Selfie Camera", DulkirConfig.noReverse3rdPerson)
        }
        if (keyBinds[2].isPressed) {
            FarmingControlSchemeCommand.toggleControls();
        }
        if (keyBinds[3].isPressed) {
            TextUtils.sendMessage("/${DulkirConfig.dynamicCommandString}")
        }
    }

    companion object {
        const val MOD_ID = "dulkirmod"
        const val MOD_NAME = "Dulkir Mod"
        const val MOD_VERSION = "1.2.3"
        const val CHAT_PREFIX = "§f<§3DulkirMod§f>§r"

        val mc: Minecraft = Minecraft.getMinecraft()
        var config = DulkirConfig
        var display: GuiScreen? = null
        val scope = CoroutineScope(EmptyCoroutineContext)

        val keyBinds = arrayOf(
            KeyBinding("Open Settings", Keyboard.KEY_RSHIFT, "Dulkir Mod"),
            KeyBinding("Toggle Selfie Setting", Keyboard.KEY_NONE, "Dulkir Mod"),
            KeyBinding("Toggle Farming Controls", Keyboard.KEY_NONE, "Dulkir Mod"),
            KeyBinding("Dynamic Key", Keyboard.KEY_NONE, "Dulkir Mod")
        )
    }

}