#Crash after adding packets/payloads

1 messages · Page 1 of 1 (latest)

torpid steeple
#

I am adding a sort of dash feature to a mod and i am encountering a crash everytime i try and use it.
This happened right after i added some new payloads for the particles and sounds. Here is the log:

Plz help

#

Crash after adding packets/payloads

olive flicker
#

Caused by: net.minecraft.util.InvalidIdentifierException: Non [a-z0-9/._-] character in path of location: minecraft:mrmrmrpizza_mod:add_draft_particles

#

AddDraftParticlesPayload.java
Line 16

torpid steeple
#

There is nothing wrong in that class though, or that method. I can share the code, gimme a sec

#
    public static final CustomPayload.Id<AddDraftParticlesPayload> ID = CustomPayload.id(Mrmrmrpizza_Mod.mod_id("add_draft_particles").toString());
    public static final PacketCodec<PacketByteBuf, AddDraftParticlesPayload> CODEC = PacketCodec.tuple(PacketCodecs.VAR_INT, AddDraftParticlesPayload::entityId, AddDraftParticlesPayload::new);

    @Override
    public CustomPayload.Id<? extends CustomPayload> getId() {
        return ID;
    }

    public static void send(ServerPlayerEntity player, int id) {
        ServerPlayNetworking.send(player, new AddDraftParticlesPayload(id));
    }

    public static class Receiver implements ClientPlayNetworking.PlayPayloadHandler<AddDraftParticlesPayload> {
        @Override
        public void receive(AddDraftParticlesPayload payload, ClientPlayNetworking.Context context) {
            Entity entity = context.player().getWorld().getEntityById(payload.entityId());
            if (entity != null) {
                DraftEnchantmentUtil.addDraftParticles(entity);
            }
        }
    }
}
olive flicker
#
public record AddDraftParticlesPayload(int entityId) implements CustomPayload {
    public static final CustomPayload.Id<AddDraftParticlesPayload> ID = CustomPayload.id(Mrmrmrpizza_Mod.mod_id("add_draft_particles").toString());
    public static final PacketCodec<PacketByteBuf, AddDraftParticlesPayload> CODEC = PacketCodec.tuple(PacketCodecs.VAR_INT, AddDraftParticlesPayload::entityId, AddDraftParticlesPayload::new);

    @Override
    public CustomPayload.Id<? extends CustomPayload> getId() {
        return ID;
    }

    public static void send(ServerPlayerEntity player, int id) {
        ServerPlayNetworking.send(player, new AddDraftParticlesPayload(id));
    }

    public static class Receiver implements ClientPlayNetworking.PlayPayloadHandler<AddDraftParticlesPayload> {
        @Override
        public void receive(AddDraftParticlesPayload payload, ClientPlayNetworking.Context context) {
            Entity entity = context.player().getWorld().getEntityById(payload.entityId());
            if (entity != null) {
                DraftEnchantmentUtil.addDraftParticles(entity);
            }
        }
    }

#

Now it readable

torpid steeple
#

How did u do that?

olive flicker
#

```java
code
```

torpid steeple
#
public record AddDraftParticlesPayload(int entityId) implements CustomPayload {
    public static final CustomPayload.Id<AddDraftParticlesPayload> ID = CustomPayload.id(Mrmrmrpizza_Mod.mod_id("add_draft_particles").toString());
    public static final PacketCodec<PacketByteBuf, AddDraftParticlesPayload> CODEC = PacketCodec.tuple(PacketCodecs.VAR_INT, AddDraftParticlesPayload::entityId, AddDraftParticlesPayload::new);

    @Override
    public CustomPayload.Id<? extends CustomPayload> getId() {
        return ID;
    }

    public static void send(ServerPlayerEntity player, int id) {
        ServerPlayNetworking.send(player, new AddDraftParticlesPayload(id));
    }

    public static class Receiver implements ClientPlayNetworking.PlayPayloadHandler<AddDraftParticlesPayload> {
        @Override
        public void receive(AddDraftParticlesPayload payload, ClientPlayNetworking.Context context) {
            Entity entity = context.player().getWorld().getEntityById(payload.entityId());
            if (entity != null) {
                DraftEnchantmentUtil.addDraftParticles(entity);
            }
        }
    }
#

Ooooh

olive flicker
#

What the hell is that Mrmrmrpizza_Mod.mod_id("add_draft_particles").toString()

torpid steeple
#

Its an id for this line of code: Line 20:

    public CustomPayload.Id<? extends CustomPayload> getId() {
        return ID;
    }
olive flicker
torpid steeple
#

Wym?

#

Ill give u the variables involved

#
    public static final String MOD_ID = "mrmrmrpizza_mod";
    public static Identifier mod_id(String path) {
        return Identifier.of(MOD_ID, path);
    }
#

The class must return an id for it to be valid

#

Hence the mention of the id

#

Oh yeah, and here is the initialization:

        PayloadTypeRegistry.playS2C().register(AddDraftParticlesPayload.ID, AddDraftParticlesPayload.CODEC);
        PayloadTypeRegistry.playC2S().register(DraftPayload.ID, DraftPayload.CODEC);
        ServerPlayNetworking.registerGlobalReceiver(DraftPayload.ID, new DraftPayload.Receiver());
olive flicker
#
  1. Method in java are snakeCase, not lower_case
  2. Why return is as toString()
  3. Use
public static final CustomPayload.Id<AddDraftParticlesPayload> ID = CustomPayload.Id(Mrmrmrpizza_Mod.mod_id("add_draft_particles"));
torpid steeple
#

Ok good

torpid steeple
olive flicker
#

Not text

torpid steeple
torpid steeple
olive flicker
#

Just do screenshot of code

#

Like this one random

torpid steeple
#

Alr

olive flicker
#

Ah

#

The problem now is in DraftPayload

#

Not in AddDraftParticlesPayload

torpid steeple
#

Ok,

olive flicker
#

I'm sure with same mistake

torpid steeple
#

Lemme check

#

Yep, the exact same

#

Ill try that

#

These lines of code are yelling now because they expect Id<T>, but insead got Id<AddDraftParticles

        PayloadTypeRegistry.playC2S().register(DraftPayload.ID, DraftPayload.CODEC);
        ServerPlayNetworking.registerGlobalReceiver(DraftPayload.ID, new DraftPayload.Receiver());
olive flicker
torpid steeple
#

Lol

olive flicker
#

Let me open my project

torpid steeple
#

Alr alr

olive flicker
#

6 IDEAs same timepepega

torpid steeple
#

It do be like that sometimes tho

olive flicker
#

I'm implementing logic on same level as registration instead of in packetpepeHmmm

#

For java my looks like this

ServerPlayNetworking.registerGlobalReceiver(Packet.ID, (payload, context) -> {
            
})
olive flicker
#

And for extract IDEA suggest just void method. But I mostly keep Mojang like ways (so I don't extract)

        ServerPlayNetworking.registerGlobalReceiver(Packet.ID, BoxRenderer::receive);
        
    }

    private static void receive(DeaconPacket payload, ServerPlayNetworking.Context context) {

    }
torpid steeple
#

Soo, i put that into something?

olive flicker
torpid steeple
#

Ahh, gotcha

olive flicker
#

I can't totally say about your Reciver implementation. Never used it. But found sometimes weeks ago made my java example


public record S2CPingPacket(String userName) implements CustomPayload {

    public static final CustomPayload.Id<S2CPingPacket> PACKET_ID = new CustomPayload.Id<>(Identifier.of("mod_id", "ping"));

    public static final PacketCodec<RegistryByteBuf, S2CPingPacket> PACKET_CODEC = PacketCodec.of((value, buf) -> {
        buf.writeString(value.userName);
    }, buf -> {
        return new S2CPingPacket(buf.readString());
    });

    @Override
    public Id<? extends CustomPayload> getId() {
        return PACKET_ID;
    }
}

public class Java implements ModInitializer {
    @Override
    public void onInitialize() {
        PayloadTypeRegistry.playS2C().register(S2CPingPacket.PACKET_ID, S2CPingPacket.PACKET_CODEC);

        ClientPlayNetworking.registerGlobalReceiver(S2CPingPacket.PACKET_ID, (payload, context) -> {
            System.out.println("CLIENT RECEIVE: " + payload.userName());
        });

        PlayerBlockBreakEvents.AFTER.register((world, player, pos, state, blockEntity) -> {
            ServerPlayNetworking.send((ServerPlayerEntity) player, new S2CPingPacket(player.getName().getString()));
        });
    }
}
#

It should be compatible with almost all cases (That is Server to Client but I'm sure you understand how it should looks on Client to Server. For you main case is PACKET_CODEC)

torpid steeple
#

Ok, so that seems to be fine, ill run the client just to make sure

#

Ok, the probel now is that its complaining that i didnt send the packet right in my previoud code. So how would i send this packet?

#
                DraftPayload.send();
#

that no longer works

olive flicker
#

In my example that one send packet

ServerPlayNetworking.send((ServerPlayerEntity) player, new S2CPingPacket(player.getName().getString()));
#

Use that table to select correct method

#

My code almost all based on MC sourse + support from mod-dev-1 channel on first day when 1.21 was release

torpid steeple
#

Ok, so i am trying to run this packet from the client, not the server, and its throwing the "Inconvertible types;" error

torpid steeple
olive flicker
#

Where/when you call it?

torpid steeple
#

Where/When/How i call "AddDraftParticles"

olive flicker
torpid steeple
#

Yeah,

olive flicker
#

Where you previosly call it?

torpid steeple
#
    public static class Receiver implements ServerPlayNetworking.PlayPayloadHandler<DraftPayload> {
        @Override
        public void receive(DraftPayload payload, ServerPlayNetworking.Context context) {
                PlayerLookup.tracking(context.player()).forEach(foundPlayer -> AddDraftParticlesPayload.send(foundPlayer, context.player().getId()));
            }
        }
    }```
olive flicker
#

So

#

Replacy with you correct lines. I don't have time for it xD

ServerPlayNetworking.registerGlobalReceiver(DraftPayload.ID, (payload, context) -> {
    PlayerLookup.tracking(context.player()).forEach(foundPlayer -> AddDraftParticlesPayload.send(foundPlayer, context.player().getId()))
};
#

I only now saw that you call one network from other. Never did that before. But that should works

torpid steeple
#

Is that for the new system you suggested, or the old one I had?

olive flicker
#

For my example
It replacy your old ServerPlayNetworking.registerGlobalReceiver(DraftPayload.ID, new DraftPayload.Receiver())

torpid steeple
#

Ok, then do I put it in a method? Because the old method doesn't exist anymore in your example

olive flicker
torpid steeple
#

Sorry if I am being a bit demanding, this is just my first time doing packets and I am very confused

olive flicker
#

Something like that. I'm bad online teacherPepoG

#

So replace that with my

torpid steeple
#

So re-import my old method, but replace what is in there with your code?

olive flicker
#

If I understand question correctly - yes
If I missunderstode, then you can just share Github and I will make Pull request

edgy gazelle
#

I code a packet as same as Mrpizza
but I confuse which one is c2s / s2c

edgy gazelle
#

my bad I mean his code

#

🙏

olive flicker
#

Ah. We there now maybe have confused chat. Because my example is for S2C and he make C2S

But techincally its 1:1. Just replace class by table above

#

I should later make better exampleoh
But I don't have time right now

edgy gazelle
#

which one did you want to send? Mrpizza?

torpid steeple
#

I am just trying to get this to work, and its so confusing

#

I appriciate the help that Syorito gave, but i dont understand how it works, or how to use it

olive flicker
olive flicker
olive flicker
#

@torpid steeple My example send packet when player break block

torpid steeple
#

Ahh

#

Ok, ill try breaking something

edgy gazelle
#
AddDraftParticlesPayload.send(entity.getId); //server side
torpid steeple
#

My original issue is that the particles and sounds that were playing wouldnt play for the other players nearby

#

So i looked it up, saw i needed to use packets, and tried to go off of the little i knew

edgy gazelle
#

that still need to send form server to make client side excute

torpid steeple
#

I am trying to execute code on the server side, but from the client side

olive flicker
#

Ye. My another example is for tuples. But I prefer to send example that is easy to customizesteve_lambda

edgy gazelle
torpid steeple
#

Wym?

#

Ill give my classes

edgy gazelle
#

like this

torpid steeple
#

Ahh,

edgy gazelle
#
ClientPlayNetworking.send()
torpid steeple
#
public record AddDraftParticlesPayload(int entityId) implements CustomPayload {
    public static final CustomPayload.Id<AddDraftParticlesPayload> ID = new Id(Mrmrmrpizza_Mod.mod_id("add_draft_particles"));
    public static final PacketCodec<PacketByteBuf, AddDraftParticlesPayload> CODEC = PacketCodec.tuple(PacketCodecs.VAR_INT, AddDraftParticlesPayload::entityId, AddDraftParticlesPayload::new);

    @Override
    public CustomPayload.Id<? extends CustomPayload> getId() {
        return ID;
    }

    public static void send(ServerPlayerEntity player, int id) {
        ServerPlayNetworking.send(player, new AddDraftParticlesPayload(id));
    }

    public static class Receiver implements ClientPlayNetworking.PlayPayloadHandler<AddDraftParticlesPayload> {
        @Override
        public void receive(AddDraftParticlesPayload payload, ClientPlayNetworking.Context context) {
            Entity entity = context.player().getWorld().getEntityById(payload.entityId());
            if (entity != null) {
                DraftEnchantmentUtil.addDraftParticles(entity);
            }
        }
    }
}
edgy gazelle
torpid steeple
#

Ahh

edgy gazelle
torpid steeple
#

With that it wont even launch the game. It just crashes, i dont have a single chance to hear the sound anyways

edgy gazelle
#

where is PayloadTypeRegistry of AddDraftParticlesPayload?

torpid steeple
#
        PayloadTypeRegistry.playS2C().register(AddDraftParticlesPayload.ID, AddDraftParticlesPayload.CODEC);```
edgy gazelle
#

but it playS2C

#

not C2S

torpid steeple
#

I dont know the difference, should i change it?

olive flicker
# edgy gazelle

He execute client
Client go to server
Server execute another to client

That how I understand

edgy gazelle
#

yes

torpid steeple
#

Yes, the client goes to the server with the request, the server authorizes it and sends the displayed sound and particle effect packets to everyone nearby

edgy gazelle
#

you swap the payload

#

the s2c should be c2s

torpid steeple
#

I just tried that, and it still crashes

edgy gazelle
#

did you update playS2C to C2S yet?

torpid steeple
#
PayloadTypeRegistry.playC2S().register(AddDraftParticlesPayload.ID, AddDraftParticlesPayload.CODEC);
torpid steeple
edgy gazelle
#

and change to ClientNetwork in AddDraftParticlesPayload?

valid sparrow
#

e

torpid steeple
#
    public static class Receiver implements ClientPlayNetworking.PlayPayloadHandler<AddDraftParticlesPayload> {
        @Override
        public void receive(AddDraftParticlesPayload payload, ClientPlayNetworking.Context context) {
            Entity entity = context.player().getWorld().getEntityById(payload.entityId());
            if (entity != null) {
                DraftEnchantmentUtil.addDraftParticles(entity);
            }
        }
    }
}
#

in there?

edgy gazelle
#
public static void send(int id) {
        ClientPlayNetworking.send(new AddDraftParticlesPayload(id));
    }

    public static class Receiver implements ServerPlayNetworking.PlayPayloadHandler<AddDraftParticlesPayload> {
        @Override
        public void receive(AddDraftParticlesPayload payload, ServerPlayNetworking.Context context) {
            Entity entity = context.player().getWorld().getEntityById(payload.entityId());
            if (entity != null) {
                DraftEnchantmentUtil.addDraftParticles(entity);
            }
        }
    }

this in your AddDraftParticlesPayload

torpid steeple
#
                PlayerLookup.tracking(context.player()).forEach(foundPlayer -> AddDraftParticlesPayload.send(foundPlayer, context.player().getId()));
#

this is then complaining about that it has the serverplayerentity instead of an int, do i just add the peramiter to ur code?

#

Do i do this?

    public static void send(ServerPlayerEntity foundPlayer, int id) {
        ClientPlayNetworking.send(new AddDraftParticlesPayload(id));
    }```
edgy gazelle
#

can you give me a client payload and server payload pls

#

like the whole class

torpid steeple
#

Sure, i dont know which ones are which, so ill just give you all the classes involved

edgy gazelle
#

did you have repo?

torpid steeple
#

Nope

edgy gazelle
#

I'm confuse on your code which one is server which one is client

torpid steeple
#

"DraftPayload.java"

public record DraftPayload() implements CustomPayload {
    public static final CustomPayload.Id<DraftPayload> ID = CustomPayload.id(Mrmrmrpizza_Mod.mod_id("draft").toString());
    public static final PacketCodec<PacketByteBuf, DraftPayload> CODEC = PacketCodec.unit(new DraftPayload());

    @Override
    public CustomPayload.Id<? extends CustomPayload> getId() {
        return ID;
    }

    public static void send(int id) {
        ClientPlayNetworking.send(new AddDraftParticlesPayload(id));
    }

    public static class Receiver implements ServerPlayNetworking.PlayPayloadHandler<AddDraftParticlesPayload> {
        @Override
        public void receive(AddDraftParticlesPayload payload, ServerPlayNetworking.Context context) {
            Entity entity = context.player().getWorld().getEntityById(payload.entityId());
            if (entity != null) {
                DraftEnchantmentUtil.addDraftParticles(entity);
            }
        }
    }
}```
#

Me too, i didnt know there was a difference

edgy gazelle
#

then you just send this one

torpid steeple
#

"AddDraftParticlesPayload.java"

public record AddDraftParticlesPayload(int entityId) implements CustomPayload {
    public static final CustomPayload.Id<AddDraftParticlesPayload> ID = new Id(Mrmrmrpizza_Mod.mod_id("add_draft_particles"));
    public static final PacketCodec<PacketByteBuf, AddDraftParticlesPayload> CODEC = PacketCodec.tuple(PacketCodecs.VAR_INT, AddDraftParticlesPayload::entityId, AddDraftParticlesPayload::new);

    @Override
    public CustomPayload.Id<? extends CustomPayload> getId() {
        return ID;
    }

    public static void send(int id) {
        ClientPlayNetworking.send(new AddDraftParticlesPayload(id));
    }

    public static class Receiver implements ServerPlayNetworking.PlayPayloadHandler<AddDraftParticlesPayload> {
        @Override
        public void receive(AddDraftParticlesPayload payload, ServerPlayNetworking.Context context) {
            Entity entity = context.player().getWorld().getEntityById(payload.entityId());
            if (entity != null) {
                DraftEnchantmentUtil.addDraftParticles(entity);
            }
        }
    }
}
olive flicker
edgy gazelle
# torpid steeple "AddDraftParticlesPayload.java" ```java public record AddDraftParticlesPayload(i...

ok my bad
that is your serverside

public record AddDraftParticlesPayload(int entityId) implements CustomPayload {
    public static final CustomPayload.Id<AddDraftParticlesPayload> ID = new Id(Mrmrmrpizza_Mod.mod_id("add_draft_particles"));
    public static final PacketCodec<PacketByteBuf, AddDraftParticlesPayload> CODEC = PacketCodec.tuple(PacketCodecs.VAR_INT, AddDraftParticlesPayload::entityId, AddDraftParticlesPayload::new);

    @Override
    public CustomPayload.Id<? extends CustomPayload> getId() {
        return ID;
    }

    public static void send(ServerPlayerEntity player, int id) {
        ServerPlayNetworking.send(player, new AddDraftParticlesPayload(id));
    }

    public static class Receiver implements ClientPlayNetworking.PlayPayloadHandler<AddDraftParticlesPayload> {
        @Override
        public void receive(AddDraftParticlesPayload payload, ClientPlayNetworking.Context context) {
            Entity entity = context.player().getWorld().getEntityById(payload.entityId());
            if (entity != null) {
                DraftEnchantmentUtil.addDraftParticles(entity);
            }
        }
    }
}
torpid steeple
#

"DraftEnchantmentUtil.java"

public abstract class DraftEnchantmentUtil extends PlayerEntity {
    public DraftEnchantmentUtil(World world, BlockPos pos, float yaw, GameProfile gameProfile) {
        super(world, pos, yaw, gameProfile);
    }


    public static void addDraftParticles(Entity entity) {
        if (MinecraftClient.getInstance().gameRenderer.getCamera().isThirdPerson() || entity != MinecraftClient.getInstance().cameraEntity) {
            for (int i = 0; i < 8; i++) {
                entity.getWorld().addParticle(ParticleTypes.CLOUD, entity.getParticleX(1), entity.getY(), entity.getParticleZ(1), 0, 0, 0);
            }
        }
    }





    public static boolean hasCustomEnchantment(PlayerEntity player) {
        ItemStack boots = player.getInventory().armor.get(0);
        if (!boots.isEmpty()) {
            DynamicRegistryManager registryManager = player.getWorld().getRegistryManager();
            Identifier draftIdentifier = Identifier.of("mrmrmrpizza_mod", "draft");
            Optional<RegistryEntry.Reference<Enchantment>> draftEnchantmentEntry = registryManager.get(RegistryKeys.ENCHANTMENT)
                    .getEntry(draftIdentifier);
            if (draftEnchantmentEntry.isPresent()) {
                return EnchantmentHelper.getLevel(draftEnchantmentEntry.get(), boots) > 0;
            }
        }
        return false;
    }
edgy gazelle
#

ok now playload registry

torpid steeple
#

Ok,

torpid steeple
#

"Mrmrmrpizza_Mod.java"

public class Mrmrmrpizza_Mod implements ModInitializer {
    public static final String MOD_ID = "mrmrmrpizza_mod";
    public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
    public static Identifier mod_id(String path) {
        return Identifier.of(MOD_ID, path);
    }


    @Override
    public void onInitialize() {
        ModBlocks.initialize();
        ModItems.initialize();
        ModEffects.initialize();
        ModArmor.initialize();
        ModDataTracker.initialize();
        PayloadTypeRegistry.playC2S().register(AddDraftParticlesPayload.ID, AddDraftParticlesPayload.CODEC);
        PayloadTypeRegistry.playC2S().register(DraftPayload.ID, DraftPayload.CODEC);
        ServerPlayNetworking.registerGlobalReceiver(DraftPayload.ID, new DraftPayload.Receiver());
    }
}


torpid steeple
edgy gazelle
#

ok now clientside one

olive flicker
torpid steeple
edgy gazelle
#

you missing client..

#

I think you miss client one

#

ClientPlayNetworking.registerGlobalReceiver() thing

#

on your AddDraftParticlesPayload

edgy gazelle
#

but you missing client receiver

torpid steeple
#

Ok,

#

So how i do that?

edgy gazelle
#

same as ServerPlayNetworking.registerGlobalReceiver(DraftPayload.ID, new DraftPayload.Receiver());

but change to client and put client playload instead

torpid steeple
#

Ok, ill try that

edgy gazelle
#

in ClientModInitializer

#

not ModInitializer

torpid steeple
#

Yeahh, so i didnt split client and server when creating this mod Lmao

edgy gazelle
torpid steeple
#

I SPACED IT

torpid steeple
#

I MADE THE TEMPLATE

#

AND I COMPLETELY SPACED IT

#

I didnt want to recreate it and have to put everything in the riht places again, so i just didnt

#

So how do i do this then?

#

How do i just do the system

#

I am done with trying to modify this, just tell me how to remake it, please.

olive flicker
#

You should have github repo with our origin unwork version and re create thread

#

With Repository is much easier to help

torpid steeple
#

I can try to throw this on a github real quick

#

It doesnt let me upload my project, the file is apperantly too big

olive flicker
#

You shouldn't upload allconcern

torpid steeple
#

What should i upload then? Just the files involved?

valid sparrow
olive flicker
#

Only that
Screenshot of CoFH repo

torpid steeple
#

It still doesnt let me upload it

olive flicker
#

Github/Git tutorials on YT will help you prayge or ChatGPT

torpid steeple
#

Ok, i did it, its in a repo

torpid steeple
#

Or let you see it?

olive flicker
#

If you made it public. Just link

#

Else - make it publicpepega

torpid steeple
#

Ahh, ok

edgy gazelle
#

🧑‍🍳

valid sparrow
#

im lurking

#

im waiting

#

for the repo

#

and then its mine

#

rtahahhahahahha

#

RHAHAHAHHAHAHAHHAHAHAH

torpid steeple
#

?

valid sparrow
olive flicker
#

And because I'm right now ending today job I'm go sleep. So 🍵 and 🐱 maybe help youpepecomfy

torpid steeple
#

Ok, goodnight

olive flicker
#

Resolved?

torpid steeple
#

Nope

#

If you would like, I can share the github repo that I made for it so you could get a better scope of the problems

olive flicker
#

Didn't you should share it yesterday?

olive flicker
torpid steeple
#

Yeah Lol

torpid steeple