#Packet Encoding Error

17 messages · Page 1 of 1 (latest)

unborn glacier
#

Client seems to be having a difficult time encoding this item component. I did notice the stack trace saying it is being casted, but I am unsure as to how that is even happening. Here is the log: https://mclo.gs/nPLM2QM and here is my encoder:

prisma palm
#

you need to send way more code than that

#

you trying to encode a component as a list somewhere

jolly nest
#

why are you not using a PacketCodec to begin with?

unborn glacier
#
public static final DataComponentType<List<Integer>> LEAPER_SPECIFICATIONS = register("specifications", builder -> builder.codec(Codec.list(Codec.INT)).packetCodec(PacketCodec.of(
            ModItemComponents::specificationsEncode,
            ModItemComponents::specificationsDecode
    )));

    private static void specificationsEncode(List<Integer> value, RegistryByteBuf buf) {
        buf.writeInt(value.size());
        value.forEach(buf::writeInt);
    }

    private static List<Integer> specificationsDecode(RegistryByteBuf buf) {
        Leapers.LOGGER.info("decoding!");
        int size = buf.readInt();
        System.out.println("size: "+size);
        List<Integer> list = new ArrayList<>();
        for(int i = 0; i < size; i++) list.add(buf.readInt());
        return list;
    }

Here is the remainder

unborn glacier
jolly nest
#

how so?

#

you compoent is a list of ints

#

wich may not exactly be a good choice for a component class

#

for starters, it's not immutable

unborn glacier
#

I may be able to just use two integers. Would this be a suitable setup for a pair?

public static final DataComponentType<Pair<Integer, Integer>> LEAPER_SPECIFICATIONS = register("specifications", builder -> builder.codec(Codec.pair(Codec.INT, Codec.INT)).packetCodec(PacketCodec.of(
            (value, buf) -> {
                buf.writeInt(value.getFirst());
                buf.writeInt(value.getSecond());
            },
            buf -> new Pair<>(buf.readInt(), buf.readInt())
    )));
jolly nest
#

start by making your own immutable class for that data

#

2 ints, a list, whatever

#

use a record for it

#

then, build the codecs for that class

#

then, use those codecs for the component type

#

and don't use the buffer for the packet codec