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:
#Packet Encoding Error
17 messages · Page 1 of 1 (latest)
you need to send way more code than that
you trying to encode a component as a list somewhere
why are you not using a PacketCodec to begin with?
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
I am using a packet codec, but it didn't appear that any of them could apply to my case. However, I could be entirely wrong
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
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())
)));