#Networking between fabric and spigot

20 messages · Page 1 of 1 (latest)

pliant coral
#

I'm trying to send packet from my spigot plugin to recieve it on my fabric mod (client, 1.21.3)

#

I've found that on the web but it's not working (the second parameter of the function is not (player, handler, buf, responseSender) but (payload, context) ):

ClientPlayNetworking.registerGlobalReceiver(new Identifier(EshMain.MOD_ID,
                "player.region.data.sync//update"), (player, handler, buf, responseSender) ->{

            String title = buf.readString();
            String description = buf.readString();
            int color = buf.readInt();

            _regionData.setRegionName(title);
            _regionData.setRegionDescription(description);
            _regionData.setRegionDescriptionColor(color);
        });

so i've tryed like that: ```java
ClientPlayNetworking.registerGlobalReceiver(new CustomPayload.Id<>(Identifier.of("mymod:channel")), (payload, context) -> {
context.client().execute(() -> {
System.out.println("TEST");
MinecraftClient mc = context.client();
if (mc.player == null) return;

            System.out.println(mc.player);
        });
    });
But i'm getting an error, the message recieve is 39 bytes to long.

I've sent it like that on server side:
```java
ByteArrayOutputStream baos = new ByteArrayOutputStream();
            DataOutputStream out = new DataOutputStream(baos);

            out.writeUTF("minecraft:entity.experience_orb.pickup");
            out.writeFloat(1.5f);

            player.sendPluginMessage(INSTANCE, "mymod:channel", baos.toByteArray());
spiral pulsar
#

Lets start from main thing. Create own class of custom payload that will be 1:1 on both side and extend CustomPayload

#

So it will have PACKET_ID and CODEC

pliant coral
#

Yea but i'm using spigot on server side

#

i've already tried with a custom payload too:

public record PlaySoundPayload(String soundId, float offset) implements CustomPayload {

    public static final Id<PlaySoundPayload> ID = new Id<>(Identifier.of("mymod", "channel"));

    private static final PacketCodec<PacketByteBuf, PlaySoundPayload> CODEC = new PacketCodec<>() {

        @Override
        public PlaySoundPayload decode(PacketByteBuf buf) {
            String soundId = buf.readString();
            float offset = buf.readFloat();
            return new PlaySoundPayload(soundId, offset);
        }

        @Override
        public void encode(PacketByteBuf buf, PlaySoundPayload payload) {
            buf.writeString(payload.soundId());
            buf.writeFloat(payload.offset());
        }
    };

    public static void register() {
        PayloadTypeRegistry.playS2C().register(ID, CODEC);
    }

    public Id<? extends CustomPayload> getId() {
        return ID;
    }
}
#

i get that when trying to send the packet from server to client:

spiral pulsar
#

What if try Paper isntead Spigot, I'm not familiar with server cores, but I didnt hear about Spigot almost 8 yearsconcern

pliant coral
#

i'm using a paper server with a spigot bukkit plugin

spiral pulsar
#

Hmm... Then my ideas out

pliant coral
#

wich idea ?

spiral pulsar
#

That use CustomPayload extended class instead of raw implement

pliant coral
#

yea, but on paper there is no CustomPayload either?

spiral pulsar
#

Maybe Henkel repo can help somehow

#

He mod work over all networks and cores

pliant coral
#

yea

#

i'll try

formal bay
#

you'll have to find out what they use (you aren't the first one asking, can just search here) and then make a SPIGOT_STRING codec based on that