diff --git a/Fabric/src/main/java/at/petrak/hexcasting/FabricHexClientInitializer.kt b/Fabric/src/main/java/at/petrak/hexcasting/FabricHexClientInitializer.kt new file mode 100644 index 00000000..657fb018 --- /dev/null +++ b/Fabric/src/main/java/at/petrak/hexcasting/FabricHexClientInitializer.kt @@ -0,0 +1,8 @@ +import at.petrak.hexcasting.fabric.network.FabricPacketHandler +import net.fabricmc.api.ClientModInitializer + +object FabricHexClientInitializer : ClientModInitializer { + override fun onInitializeClient() { + FabricPacketHandler.initClient() + } +} \ No newline at end of file diff --git a/Fabric/src/main/java/at/petrak/hexcasting/HexMod.kt b/Fabric/src/main/java/at/petrak/hexcasting/FabricHexInitializer.kt similarity index 64% rename from Fabric/src/main/java/at/petrak/hexcasting/HexMod.kt rename to Fabric/src/main/java/at/petrak/hexcasting/FabricHexInitializer.kt index 7a562d78..3a380074 100644 --- a/Fabric/src/main/java/at/petrak/hexcasting/HexMod.kt +++ b/Fabric/src/main/java/at/petrak/hexcasting/FabricHexInitializer.kt @@ -1,11 +1,12 @@ import at.petrak.hexcasting.fabric.FabricHexConfig +import at.petrak.hexcasting.fabric.network.FabricPacketHandler import at.petrak.hexcasting.xplat.IXplatAbstractions import net.fabricmc.api.ModInitializer -object HexMod : ModInitializer { +object FabricHexInitializer : ModInitializer { override fun onInitialize() { IXplatAbstractions.INSTANCE.init() - + FabricPacketHandler.init() FabricHexConfig.setup() } } \ No newline at end of file diff --git a/Fabric/src/main/java/at/petrak/hexcasting/fabric/network/FabricPacketHandler.java b/Fabric/src/main/java/at/petrak/hexcasting/fabric/network/FabricPacketHandler.java index bdd67151..c30978be 100644 --- a/Fabric/src/main/java/at/petrak/hexcasting/fabric/network/FabricPacketHandler.java +++ b/Fabric/src/main/java/at/petrak/hexcasting/fabric/network/FabricPacketHandler.java @@ -1,4 +1,52 @@ package at.petrak.hexcasting.fabric.network; +import at.petrak.hexcasting.common.network.*; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerPlayer; +import org.apache.logging.log4j.util.TriConsumer; + +import java.util.function.Consumer; +import java.util.function.Function; + public class FabricPacketHandler { + public static void init() { + ServerPlayNetworking.registerGlobalReceiver(MsgNewSpellPatternSyn.ID, + makeServerBoundHandler(MsgNewSpellPatternSyn::deserialize, MsgNewSpellPatternSyn::handle)); + ServerPlayNetworking.registerGlobalReceiver( + MsgShiftScrollSyn.ID, makeServerBoundHandler(MsgShiftScrollSyn::deserialize, MsgShiftScrollSyn::handle)); + } + + private static ServerPlayNetworking.PlayChannelHandler makeServerBoundHandler( + Function decoder, TriConsumer handle) { + return (server, player, _handler, buf, _responseSender) -> handle.accept(decoder.apply(buf), server, player); + } + + public static void initClient() { + ClientPlayNetworking.registerGlobalReceiver(MsgNewSpellPatternAck.ID, + makeClientBoundHandler(MsgNewSpellPatternAck::deserialize, MsgNewSpellPatternAck::handle)); + ClientPlayNetworking.registerGlobalReceiver( + MsgBlinkAck.ID, makeClientBoundHandler(MsgBlinkAck::deserialize, MsgBlinkAck::handle)); + ClientPlayNetworking.registerGlobalReceiver(MsgSentinelStatusUpdateAck.ID, + makeClientBoundHandler(MsgSentinelStatusUpdateAck::deserialize, MsgSentinelStatusUpdateAck::handle)); + ClientPlayNetworking.registerGlobalReceiver(MsgColorizerUpdateAck.ID, + makeClientBoundHandler(MsgColorizerUpdateAck::deserialize, MsgColorizerUpdateAck::handle)); + ClientPlayNetworking.registerGlobalReceiver(MsgCastParticleAck.ID, + makeClientBoundHandler(MsgCastParticleAck::deserialize, MsgCastParticleAck::handle)); + ClientPlayNetworking.registerGlobalReceiver(MsgOpenSpellGuiAck.ID, + makeClientBoundHandler(MsgOpenSpellGuiAck::deserialize, MsgOpenSpellGuiAck::handle)); + ClientPlayNetworking.registerGlobalReceiver(MsgBeepAck.ID, + makeClientBoundHandler(MsgBeepAck::deserialize, MsgBeepAck::handle)); + ClientPlayNetworking.registerGlobalReceiver(MsgBrainsweepAck.ID, + makeClientBoundHandler(MsgBrainsweepAck::deserialize, MsgBrainsweepAck::handle)); + ClientPlayNetworking.registerGlobalReceiver(MsgUpdateComparatorVisualsAck.ID, + makeClientBoundHandler(MsgUpdateComparatorVisualsAck::deserialize, MsgUpdateComparatorVisualsAck::handle)); + } + + private static ClientPlayNetworking.PlayChannelHandler makeClientBoundHandler( + Function decoder, Consumer handler) { + return (_client, _handler, buf, _responseSender) -> handler.accept(decoder.apply(buf)); + } } diff --git a/Fabric/src/main/resources/fabric.mod.json b/Fabric/src/main/resources/fabric.mod.json index 461a0df0..520b9833 100644 --- a/Fabric/src/main/resources/fabric.mod.json +++ b/Fabric/src/main/resources/fabric.mod.json @@ -14,12 +14,15 @@ }, "license": "MIT", - "icon": "assets/logo.png", + "icon": "logo.png", "environment": "*", "entrypoints": { "main": [ - {"adapter": "kotlin", "value": "at.petrak.hexcasting.HexMod"} + {"adapter": "kotlin", "value": "at.petrak.hexcasting.FabricHexInitializer"} + ], + "client": [ + {"adapter": "kotlin", "value": "at.petrak.hexcasting.FabricHexInitializer"} ] }, "mixins": [ @@ -28,8 +31,8 @@ "depends": { "fabricloader": ">=0.13", - "fabric": "*", - "minecraft": "1.18.x", + "fabric": ">=0.50", + "minecraft": ">=1.18.2", "java": ">=17", "fabric-language-kotlin": ">=1.7.4+kotlin.1.6.21", "patchouli": ">=1.18.2-66", diff --git a/Forge/src/main/java/at/petrak/hexcasting/HexMod.kt b/Forge/src/main/java/at/petrak/hexcasting/ForgeHexInitializer.kt similarity index 96% rename from Forge/src/main/java/at/petrak/hexcasting/HexMod.kt rename to Forge/src/main/java/at/petrak/hexcasting/ForgeHexInitializer.kt index 7972f633..0c3850ff 100644 --- a/Forge/src/main/java/at/petrak/hexcasting/HexMod.kt +++ b/Forge/src/main/java/at/petrak/hexcasting/ForgeHexInitializer.kt @@ -17,12 +17,8 @@ import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent import org.apache.logging.log4j.Logger -@Mod(HexMod.MOD_ID) -object HexMod { - - // mumblemumble thanks shy mumble mumble - const val MOD_ID = "hexcasting" - +@Mod(HexAPI.MOD_ID) +object ForgeHexInitializer { init { IXplatAbstractions.INSTANCE.init() @@ -42,7 +38,7 @@ object HexMod { ForgeListenersSetup.init() ForgePacketHandler.init() - + /* // mod lifecycle diff --git a/Forge/src/main/java/at/petrak/hexcasting/forge/network/ForgePacketHandler.java b/Forge/src/main/java/at/petrak/hexcasting/forge/network/ForgePacketHandler.java index 0ee5cb4b..7bc5d377 100644 --- a/Forge/src/main/java/at/petrak/hexcasting/forge/network/ForgePacketHandler.java +++ b/Forge/src/main/java/at/petrak/hexcasting/forge/network/ForgePacketHandler.java @@ -1,6 +1,6 @@ package at.petrak.hexcasting.forge.network; -import at.petrak.hexcasting.HexMod; +import at.petrak.hexcasting.ForgeHexInitializer; import at.petrak.hexcasting.common.network.*; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; @@ -17,7 +17,7 @@ import java.util.function.Supplier; public class ForgePacketHandler { private static final String PROTOCOL_VERSION = "1"; private static final SimpleChannel NETWORK = NetworkRegistry.newSimpleChannel( - new ResourceLocation(HexMod.MOD_ID, "main"), + new ResourceLocation(ForgeHexInitializer.MOD_ID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals