Skip to content

Commit

Permalink
fix serverside packet handling on fabric
Browse files Browse the repository at this point in the history
  • Loading branch information
fayer3 committed May 5, 2024
1 parent 3bd2a51 commit c9ceba5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 31 deletions.
19 changes: 18 additions & 1 deletion fabric/src/main/java/org/vivecraft/fabric/VivecraftMod.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package org.vivecraft.fabric;

import io.netty.buffer.Unpooled;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.network.FriendlyByteBuf;
import org.vivecraft.client.network.ClientNetworking;
import org.vivecraft.common.network.packets.VivecraftDataPacket;
import org.vivecraft.server.ServerNetworking;
import org.vivecraft.server.ServerUtil;
Expand All @@ -21,11 +25,24 @@ public void onInitialize() {
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) ->
ServerUtil.registerCommands(dispatcher));

// register packets
PayloadTypeRegistry.playS2C().register(VivecraftDataPacket.TYPE, VivecraftDataPacket.STREAM_CODEC);
PayloadTypeRegistry.playC2S().register(VivecraftDataPacket.TYPE, VivecraftDataPacket.STREAM_CODEC);

if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
// register client packet receiver
ClientPlayNetworking.registerGlobalReceiver(VivecraftDataPacket.TYPE,
(payload, context) -> context.client().execute(() -> {
FriendlyByteBuf buffer = new FriendlyByteBuf(Unpooled.buffer()).writeBytes(payload.buffer());
ClientNetworking.handlePacket(payload.packetid(), buffer);
buffer.release();
}));
}

// register server packet receiver
ServerPlayNetworking.registerGlobalReceiver(VivecraftDataPacket.TYPE, (payload, context) -> {
FriendlyByteBuf buffer = new FriendlyByteBuf(Unpooled.buffer()).writeBytes(payload.buffer());
ServerNetworking.handlePacket(payload.packetid(), buffer, context.player(), p -> context.responseSender().sendPacket(p.payload()));
ServerNetworking.handlePacket(payload.packetid(), buffer, context.player(), p -> context.responseSender().sendPacket(p));
buffer.release();
});
}
Expand Down

This file was deleted.

3 changes: 0 additions & 3 deletions fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
"main": [
"org.vivecraft.fabric.VivecraftMod"
],
"client": [
"org.vivecraft.fabric.VivecraftModClientOnly"
],
"modmenu": [
"org.vivecraft.client.fabric.VivecraftModMenuApiImpl"
]
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ minecraft_version=1.20.5
enabled_platforms=fabric,neoforge

archives_base_name=vivecraft
mod_version=1.1.9-a2
mod_version=1.1.9-a3
maven_group=org.vivecraft

architectury_version=12.0.26

fabric_loader_version=0.15.7
fabric_api_version=0.97.7+1.20.5
fabric_api_version=0.97.8+1.20.5

forge_version=1.20.4-49.0.30
neoforge_version=20.5.5-beta
Expand Down

0 comments on commit c9ceba5

Please sign in to comment.