From b73519f2d9918e3dfb9b2655178230270dcdd7e0 Mon Sep 17 00:00:00 2001 From: Buuz135 Date: Sun, 22 Sep 2024 13:08:38 +0200 Subject: [PATCH] Fixed packet registration closes #44 --- .../java/com/buuz135/findme/FindMeMod.java | 24 ++++++++++++++++--- .../main/resources/findme-common.mixins.json | 2 +- forge/build.gradle | 2 +- gradle.properties | 10 ++++---- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/common/src/main/java/com/buuz135/findme/FindMeMod.java b/common/src/main/java/com/buuz135/findme/FindMeMod.java index f19d366..ec102c0 100644 --- a/common/src/main/java/com/buuz135/findme/FindMeMod.java +++ b/common/src/main/java/com/buuz135/findme/FindMeMod.java @@ -6,12 +6,17 @@ import com.buuz135.findme.particle.CustomParticleType; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import dev.architectury.impl.NetworkAggregator; import dev.architectury.networking.NetworkManager; import dev.architectury.platform.Platform; import dev.architectury.registry.registries.DeferredRegister; import dev.architectury.registry.registries.RegistrySupplier; +import dev.architectury.utils.Env; import net.minecraft.core.particles.ParticleType; import net.minecraft.core.registries.Registries; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.world.Container; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.entity.BlockEntity; @@ -21,6 +26,7 @@ import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.function.BiPredicate; @@ -41,9 +47,9 @@ public class FindMeMod { public static void init() { PARTICLES.register(); - NetworkManager.registerReceiver(NetworkManager.Side.C2S, PositionRequestMessage.TYPE, PositionRequestMessage.CODEC, PositionRequestMessage::handle); - NetworkManager.registerReceiver(NetworkManager.Side.S2C, PositionResponseMessage.TYPE, PositionResponseMessage.CODEC, PositionResponseMessage::handle); - NetworkManager.registerReceiver(NetworkManager.Side.C2S, PullItemRequestMessage.TYPE, PullItemRequestMessage.CODEC, PullItemRequestMessage::handle); + registerC2S(PositionRequestMessage.TYPE, PositionRequestMessage.CODEC, PositionRequestMessage::handle); + registerS2C(PositionResponseMessage.TYPE, PositionResponseMessage.CODEC, PositionResponseMessage::handle); + registerC2S(PullItemRequestMessage.TYPE, PullItemRequestMessage.CODEC, PullItemRequestMessage::handle); BLOCK_CHECKERS.add((blockEntity, itemStack) -> { if (blockEntity instanceof Container inventory) { if (inventory.isEmpty()) return false; @@ -82,4 +88,16 @@ private static void createConfig(File file) { } } + private static void registerS2C(CustomPacketPayload.Type packetType, StreamCodec codec, NetworkManager.NetworkReceiver receiver) { + if (Platform.getEnvironment().equals(Env.SERVER)) { + NetworkAggregator.registerS2CType(packetType, codec, List.of()); + } else { + NetworkAggregator.registerReceiver(NetworkManager.s2c(), packetType, codec, Collections.emptyList(), receiver); + } + } + + private static void registerC2S(CustomPacketPayload.Type packetType, StreamCodec codec, NetworkManager.NetworkReceiver receiver) { + NetworkAggregator.registerReceiver(NetworkManager.c2s(), packetType, codec, Collections.emptyList(), receiver); + } + } diff --git a/common/src/main/resources/findme-common.mixins.json b/common/src/main/resources/findme-common.mixins.json index 3e96f76..c0b89e9 100644 --- a/common/src/main/resources/findme-common.mixins.json +++ b/common/src/main/resources/findme-common.mixins.json @@ -6,5 +6,5 @@ "MixinSlotRenderer", "ParticleEngineAccessor" ], - "minVersion": "0.8" + "minVersion": "0.8.4" } \ No newline at end of file diff --git a/forge/build.gradle b/forge/build.gradle index c10cacc..05e9085 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -28,7 +28,7 @@ dependencies { //forge "net.minecraftforge:forge:${rootProject.minecraft_version}-${rootProject.forge_version}" // Remove the next line if you don't want to depend on the API modApi "dev.architectury:architectury-neoforge:${rootProject.architectury_version}" - implementation "curse.maven:functional-storage-556861:5545676" + //implementation "curse.maven:functional-storage-556861:5545676" implementation(project(path: ":common", configuration: "dev")) { transitive = false diff --git a/gradle.properties b/gradle.properties index 76889af..443b073 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,10 +1,10 @@ org.gradle.jvmargs=-Xmx4G minecraft_version=1.21 archives_base_name=findme -mod_version=3.3.1 +mod_version=3.3.2 maven_group=com.buuz135.findme -architectury_version=13.0.3 -fabric_loader_version=0.14.21 -fabric_api_version=0.100.4+1.21 +architectury_version=13.0.6 +fabric_loader_version=0.16.5 +fabric_api_version=0.104.0+1.21.1 enabled_platforms=fabric,neoforge -neoforge_version=21.0.65-beta \ No newline at end of file +neoforge_version=21.0.110-beta \ No newline at end of file