From e45378fd6b61a5871c306ca8439c8ee3d7dec456 Mon Sep 17 00:00:00 2001 From: nea Date: Fri, 29 Jul 2022 23:09:36 +0200 Subject: repo reloading --- .../moe/nea/notenoughupdates/NotEnoughUpdates.kt | 35 ++++++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'src/main/kotlin/moe/nea/notenoughupdates/NotEnoughUpdates.kt') diff --git a/src/main/kotlin/moe/nea/notenoughupdates/NotEnoughUpdates.kt b/src/main/kotlin/moe/nea/notenoughupdates/NotEnoughUpdates.kt index 79b8819..27c51e1 100644 --- a/src/main/kotlin/moe/nea/notenoughupdates/NotEnoughUpdates.kt +++ b/src/main/kotlin/moe/nea/notenoughupdates/NotEnoughUpdates.kt @@ -1,18 +1,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 { +object NotEnoughUpdates : ModInitializer, ClientModInitializer { val DATA_DIR = Path.of(".notenoughupdates") const val MOD_ID = "notenoughupdates" - val neuRepo = NEURepository.of(Path.of("NotEnoughUpdates-REPO")).also { - it.reload() + val neuRepo: NEURepository = NEURepository.of(Path.of("NotEnoughUpdates-REPO")).apply { + registerReloadListener(ItemCache) + reload() + registerReloadListener { + Minecraft.getInstance().connection?.handleUpdateRecipes(ClientboundUpdateRecipesPacket(mutableListOf())) + } + } + + fun registerCommands( + dispatcher: CommandDispatcher, 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() { } } -- cgit