Fix ClientEditBookPacket

This commit is contained in:
TheMode 2021-07-14 16:51:22 +02:00
parent a565ee77aa
commit 2e4975eb9a

View File

@ -1,7 +1,5 @@
package net.minestom.server.network.packet.client.play;
import net.minestom.server.entity.Player;
import net.minestom.server.item.ItemStack;
import net.minestom.server.network.packet.client.ClientPlayPacket;
import net.minestom.server.utils.binary.BinaryReader;
import net.minestom.server.utils.binary.BinaryWriter;
@ -9,21 +7,35 @@ import org.jetbrains.annotations.NotNull;
public class ClientEditBookPacket extends ClientPlayPacket {
public ItemStack book = ItemStack.AIR;
public boolean isSigning;
public Player.Hand hand = Player.Hand.MAIN;
public int slot;
public String[] pages;
public String title;
public ClientEditBookPacket(int slot, String[] pages, String title) {
this.slot = slot;
this.pages = pages;
this.title = title;
}
public ClientEditBookPacket() {
this(0, null, "");
}
@Override
public void read(@NotNull BinaryReader reader) {
this.book = reader.readItemStack();
this.isSigning = reader.readBoolean();
this.hand = Player.Hand.values()[reader.readVarInt()];
this.slot = reader.readVarInt();
final int pageLength = reader.readVarInt();
this.pages = new String[pageLength];
for (int i = 0; i < pageLength; i++) {
pages[i] = reader.readSizedString(8192);
}
this.title = reader.readBoolean() ? reader.readSizedString(128) : null;
}
@Override
public void write(@NotNull BinaryWriter writer) {
writer.writeItemStack(book);
writer.writeBoolean(isSigning);
writer.writeVarInt(hand.ordinal());
writer.writeVarInt(slot);
writer.writeStringArray(pages);
writer.writeSizedString(title);
}
}