ProtocolLib

3M Downloads

Error Unable to find writeStack(class net.minecraft.world.item.ItemStack) in class net.minecraft.network.FriendlyByteBuf in a Inventory Sync Plugin

LevinGamer8 opened this issue ยท 0 comments

commented

Make sure you're doing the following

  • You're using the latest build for your server version
  • This isn't an issue caused by another plugin
  • You've checked for duplicate issues
  • You didn't use /reload

Describe the question
So i am on Purpur 1.20.6 Java 23 and Protocollib 5.3.0, i have had an working Inventory Syncer and Enderchest Plugin but now i am getting an error when trying to seralize items, so how to fix that?

API method(s) used
i am uisng the StreamSerializer Class with the StreamSerializer#getDefault()#serializeItemStack()

Expected behavior
i expect it to serialize the items correctly so that i can save them and then deserailze them wehn needed

Code
Serialize: public String toBase64(ItemStack[] itemStacks) throws IOException {
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < itemStacks.length; i++) {
if (i > 0) {
stringBuilder.append(";");
}
if ((itemStacks[i] != null) && (itemStacks[i].getType() != Material.AIR)) {
stringBuilder.append(StreamSerializer.getDefault().serializeItemStack(itemStacks[i]));
}
}
return stringBuilder.toString();
}

Deserialize:
public ItemStack[] fromBase64(String data) {
String[] strings = data.split(";");
ItemStack[] itemStacks = new ItemStack[strings.length];
for (int i = 0; i < strings.length; i++) {
if (!strings[i].isEmpty()) {
try {
itemStacks[i] = StreamSerializer.getDefault().deserializeItemStack(strings[i]);
} catch (Exception e) {
MegaEssentials.logger.warning("Error decoding item using ProtocolLib, Error: " + e.getMessage());
}
}
}
return itemStacks;
}

Additional context
Error: Unable to find writeStack(class net.minecraft.world.item.ItemStack) in class net.minecraft.network.FriendlyByteBuf
i had it working on 1.20.4 idk if its just my problem or somebody else does have it