Skip to content

Commit

Permalink
Fixed packet registration closes #44
Browse files Browse the repository at this point in the history
  • Loading branch information
Buuz135 committed Sep 22, 2024
1 parent 62d8b0b commit b73519f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
24 changes: 21 additions & 3 deletions common/src/main/java/com/buuz135/findme/FindMeMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -82,4 +88,16 @@ private static void createConfig(File file) {
}
}

private static <T extends CustomPacketPayload> void registerS2C(CustomPacketPayload.Type<T> packetType, StreamCodec<? super RegistryFriendlyByteBuf, T> codec, NetworkManager.NetworkReceiver<T> 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 <T extends CustomPacketPayload> void registerC2S(CustomPacketPayload.Type<T> packetType, StreamCodec<? super RegistryFriendlyByteBuf, T> codec, NetworkManager.NetworkReceiver<T> receiver) {
NetworkAggregator.registerReceiver(NetworkManager.c2s(), packetType, codec, Collections.emptyList(), receiver);
}

}
2 changes: 1 addition & 1 deletion common/src/main/resources/findme-common.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"MixinSlotRenderer",
"ParticleEngineAccessor"
],
"minVersion": "0.8"
"minVersion": "0.8.4"
}
2 changes: 1 addition & 1 deletion forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -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
neoforge_version=21.0.110-beta

0 comments on commit b73519f

Please sign in to comment.