diff --git a/src/main/kotlin/settingdust/item_converter/Config.kt b/src/main/kotlin/settingdust/item_converter/Config.kt index 02d79ca..bcc4f2f 100644 --- a/src/main/kotlin/settingdust/item_converter/Config.kt +++ b/src/main/kotlin/settingdust/item_converter/Config.kt @@ -5,6 +5,8 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.json.Json import kotlinx.serialization.json.decodeFromStream import kotlinx.serialization.json.encodeToStream +import net.minecraftforge.api.distmarker.Dist +import net.minecraftforge.api.distmarker.OnlyIn import net.minecraftforge.fml.loading.FMLPaths import kotlin.io.path.createFile import kotlin.io.path.div @@ -17,6 +19,7 @@ internal val json = Json { prettyPrint = true } +@OnlyIn(Dist.CLIENT) @Serializable data class ClientConfig(val pressTicks: Int = 20) { companion object { diff --git a/src/main/kotlin/settingdust/item_converter/Entrypoint.kt b/src/main/kotlin/settingdust/item_converter/Entrypoint.kt index 79f4a75..e3a292e 100644 --- a/src/main/kotlin/settingdust/item_converter/Entrypoint.kt +++ b/src/main/kotlin/settingdust/item_converter/Entrypoint.kt @@ -12,7 +12,6 @@ import net.minecraft.network.chat.Component import net.minecraft.resources.ResourceKey import net.minecraft.resources.ResourceLocation import net.minecraftforge.api.distmarker.Dist -import net.minecraftforge.client.event.ClientPlayerNetworkEvent import net.minecraftforge.event.RegisterCommandsEvent import net.minecraftforge.event.server.ServerStartingEvent import net.minecraftforge.event.server.ServerStoppingEvent @@ -23,7 +22,7 @@ import net.minecraftforge.fml.loading.FMLPaths import org.apache.commons.lang3.math.Fraction import org.apache.logging.log4j.LogManager import org.jgrapht.graph.SimpleDirectedWeightedGraph -import settingdust.item_converter.client.SlotInteractManager +import settingdust.item_converter.client.ItemConverterClient import settingdust.item_converter.networking.Networking import thedarkcolour.kotlinforforge.forge.FORGE_BUS import thedarkcolour.kotlinforforge.forge.MOD_BUS @@ -46,12 +45,7 @@ object ItemConverter { MOD_BUS.register(ModEventHandler) FORGE_BUS.register(this) Networking - if (FMLEnvironment.dist == Dist.CLIENT) clientInit() - } - - fun clientInit() { - SlotInteractManager - ClientConfig.reload() + if (FMLEnvironment.dist == Dist.CLIENT) ItemConverterClient } fun id(path: String) = ResourceLocation(ID, path) @@ -107,14 +101,7 @@ object ItemConverter { serverCoroutineScope = null } - - @SubscribeEvent - fun onClientPlayerNetwork(event: ClientPlayerNetworkEvent.LoggingIn) { - refreshGraph(event.player.level.registryAccess()) - } - - - private fun refreshGraph(registryAccess: RegistryAccess) { + fun refreshGraph(registryAccess: RegistryAccess) { ConvertRules.graph = SimpleDirectedWeightedGraph(null) { FractionUnweightedEdge(Fraction.ZERO) } diff --git a/src/main/kotlin/settingdust/item_converter/client/ClientEntrypoint.kt b/src/main/kotlin/settingdust/item_converter/client/ClientEntrypoint.kt new file mode 100644 index 0000000..cc8be4d --- /dev/null +++ b/src/main/kotlin/settingdust/item_converter/client/ClientEntrypoint.kt @@ -0,0 +1,20 @@ +package settingdust.item_converter.client + +import net.minecraftforge.client.event.ClientPlayerNetworkEvent +import net.minecraftforge.eventbus.api.SubscribeEvent +import settingdust.item_converter.ClientConfig +import settingdust.item_converter.ItemConverter.refreshGraph +import thedarkcolour.kotlinforforge.forge.FORGE_BUS + +object ItemConverterClient { + init { + SlotInteractManager + ClientConfig.Companion.reload() + FORGE_BUS.register(this) + } + + @SubscribeEvent + fun onClientPlayerNetwork(event: ClientPlayerNetworkEvent.LoggingIn) { + refreshGraph(event.player.level.registryAccess()) + } +} \ No newline at end of file diff --git a/src/main/kotlin/settingdust/item_converter/client/ItemConvertScreen.kt b/src/main/kotlin/settingdust/item_converter/client/ItemConvertScreen.kt index 24839d4..b32402c 100644 --- a/src/main/kotlin/settingdust/item_converter/client/ItemConvertScreen.kt +++ b/src/main/kotlin/settingdust/item_converter/client/ItemConvertScreen.kt @@ -13,6 +13,8 @@ import net.minecraft.sounds.SoundSource import net.minecraft.world.inventory.Slot import net.minecraft.world.item.BlockItem import net.minecraft.world.item.ItemStack +import net.minecraftforge.api.distmarker.Dist +import net.minecraftforge.api.distmarker.OnlyIn import net.minecraftforge.client.ForgeHooksClient import net.minecraftforge.client.event.ScreenEvent import net.minecraftforge.common.MinecraftForge @@ -27,6 +29,7 @@ import settingdust.item_converter.networking.C2SConvertItemPacket import settingdust.item_converter.networking.C2SConvertItemPacket.Mode import settingdust.item_converter.networking.Networking +@OnlyIn(Dist.CLIENT) data class ItemConvertScreen( val parent: Screen?, val slot: Slot ) : Screen(Component.translatable("gui.${ItemConverter.ID}.item_convert")) { diff --git a/src/main/kotlin/settingdust/item_converter/client/SlotInteractManager.kt b/src/main/kotlin/settingdust/item_converter/client/SlotInteractManager.kt index 76196c1..a9256ae 100644 --- a/src/main/kotlin/settingdust/item_converter/client/SlotInteractManager.kt +++ b/src/main/kotlin/settingdust/item_converter/client/SlotInteractManager.kt @@ -8,6 +8,8 @@ import net.minecraft.client.gui.GuiComponent import net.minecraft.client.gui.components.Widget import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen import net.minecraft.resources.ResourceLocation +import net.minecraftforge.api.distmarker.Dist +import net.minecraftforge.api.distmarker.OnlyIn import net.minecraftforge.client.event.InputEvent import net.minecraftforge.client.event.RegisterGuiOverlaysEvent import net.minecraftforge.client.event.RegisterKeyMappingsEvent @@ -23,6 +25,7 @@ import settingdust.item_converter.networking.Networking import thedarkcolour.kotlinforforge.forge.FORGE_BUS import thedarkcolour.kotlinforforge.forge.MOD_BUS +@OnlyIn(Dist.CLIENT) object SlotInteractManager { var pressedTicks = 0 var converting = false