aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/notenoughupdates/NotEnoughUpdates.kt
blob: 27c51e1fc7cd6ea0adc9a6a0a7ec5d87c9eb0ad3 (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
package moe.nea.notenoughupdates

import com.mojang.brigadier.CommandDispatcher
import io.github.moulberry.repo.NEURepository
import moe.nea.notenoughupdates.repo.ItemCache
import net.fabricmc.api.ClientModInitializer
import net.fabricmc.api.ModInitializer
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
import net.minecraft.client.Minecraft
import net.minecraft.commands.CommandBuildContext
import net.minecraft.network.chat.Component
import net.minecraft.network.protocol.game.ClientboundUpdateRecipesPacket
import java.nio.file.Path

object NotEnoughUpdates : ModInitializer, ClientModInitializer {
    val DATA_DIR = Path.of(".notenoughupdates")

    const val MOD_ID = "notenoughupdates"

    val neuRepo: NEURepository = NEURepository.of(Path.of("NotEnoughUpdates-REPO")).apply {
        registerReloadListener(ItemCache)
        reload()
        registerReloadListener {
            Minecraft.getInstance().connection?.handleUpdateRecipes(ClientboundUpdateRecipesPacket(mutableListOf()))
        }
    }

    fun registerCommands(
        dispatcher: CommandDispatcher<FabricClientCommandSource>, registryAccess: CommandBuildContext
    ) {
        dispatcher.register(ClientCommandManager.literal("neureload").executes {
            it.source.sendFeedback(Component.literal("Reloading repository from disk. This may lag a bit."))
            neuRepo.reload()
            0
        })

    }

    override fun onInitialize() {
        ClientCommandRegistrationCallback.EVENT.register(this::registerCommands)
    }

    override fun onInitializeClient() {
    }
}