mirror of https://github.com/LOOHP/Limbo.git
Merge e3af7589bb into ba0f98b6c7
This commit is contained in:
commit
569cb2be5e
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.loohp.limbo.network.protocol.packets;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class ClientboundOpenBookPacket extends PacketOut {
|
||||||
|
|
||||||
|
private final int hand; // 0 = main hand, 1 = off hand
|
||||||
|
|
||||||
|
public ClientboundOpenBookPacket(int hand) {
|
||||||
|
this.hand = hand;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHand() {
|
||||||
|
return hand;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] serializePacket() throws IOException {
|
||||||
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||||
|
|
||||||
|
DataOutputStream output = new DataOutputStream(buffer);
|
||||||
|
output.writeByte(Packet.getPlayOut().get(getClass()));
|
||||||
|
output.writeByte(hand);
|
||||||
|
|
||||||
|
return buffer.toByteArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -34,10 +34,12 @@ import com.loohp.limbo.events.player.PlayerTeleportEvent;
|
||||||
import com.loohp.limbo.inventory.Inventory;
|
import com.loohp.limbo.inventory.Inventory;
|
||||||
import com.loohp.limbo.inventory.InventoryHolder;
|
import com.loohp.limbo.inventory.InventoryHolder;
|
||||||
import com.loohp.limbo.inventory.InventoryView;
|
import com.loohp.limbo.inventory.InventoryView;
|
||||||
|
import com.loohp.limbo.inventory.ItemStack;
|
||||||
import com.loohp.limbo.inventory.TitledInventory;
|
import com.loohp.limbo.inventory.TitledInventory;
|
||||||
import com.loohp.limbo.location.Location;
|
import com.loohp.limbo.location.Location;
|
||||||
import com.loohp.limbo.network.ClientConnection;
|
import com.loohp.limbo.network.ClientConnection;
|
||||||
import com.loohp.limbo.network.protocol.packets.ClientboundClearTitlesPacket;
|
import com.loohp.limbo.network.protocol.packets.ClientboundClearTitlesPacket;
|
||||||
|
import com.loohp.limbo.network.protocol.packets.ClientboundOpenBookPacket;
|
||||||
import com.loohp.limbo.network.protocol.packets.ClientboundSetActionBarTextPacket;
|
import com.loohp.limbo.network.protocol.packets.ClientboundSetActionBarTextPacket;
|
||||||
import com.loohp.limbo.network.protocol.packets.ClientboundSetSubtitleTextPacket;
|
import com.loohp.limbo.network.protocol.packets.ClientboundSetSubtitleTextPacket;
|
||||||
import com.loohp.limbo.network.protocol.packets.ClientboundSetTitleTextPacket;
|
import com.loohp.limbo.network.protocol.packets.ClientboundSetTitleTextPacket;
|
||||||
|
|
@ -53,6 +55,7 @@ import com.loohp.limbo.network.protocol.packets.PacketPlayOutPlayerListHeaderFoo
|
||||||
import com.loohp.limbo.network.protocol.packets.PacketPlayOutPositionAndLook;
|
import com.loohp.limbo.network.protocol.packets.PacketPlayOutPositionAndLook;
|
||||||
import com.loohp.limbo.network.protocol.packets.PacketPlayOutResourcePackSend;
|
import com.loohp.limbo.network.protocol.packets.PacketPlayOutResourcePackSend;
|
||||||
import com.loohp.limbo.network.protocol.packets.PacketPlayOutRespawn;
|
import com.loohp.limbo.network.protocol.packets.PacketPlayOutRespawn;
|
||||||
|
import com.loohp.limbo.network.protocol.packets.PacketPlayOutSetSlot;
|
||||||
import com.loohp.limbo.network.protocol.packets.PacketPlayOutStopSound;
|
import com.loohp.limbo.network.protocol.packets.PacketPlayOutStopSound;
|
||||||
import com.loohp.limbo.sounds.SoundEffect;
|
import com.loohp.limbo.sounds.SoundEffect;
|
||||||
import com.loohp.limbo.utils.BungeecordAdventureConversionUtils;
|
import com.loohp.limbo.utils.BungeecordAdventureConversionUtils;
|
||||||
|
|
@ -68,11 +71,15 @@ import net.kyori.adventure.sound.Sound.Emitter;
|
||||||
import net.kyori.adventure.sound.SoundStop;
|
import net.kyori.adventure.sound.SoundStop;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
|
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||||
import net.kyori.adventure.title.Title;
|
import net.kyori.adventure.title.Title;
|
||||||
import net.kyori.adventure.title.Title.Times;
|
import net.kyori.adventure.title.Title.Times;
|
||||||
import net.kyori.adventure.title.TitlePart;
|
import net.kyori.adventure.title.TitlePart;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
|
import net.querz.nbt.tag.CompoundTag;
|
||||||
|
import net.querz.nbt.tag.ListTag;
|
||||||
|
import net.querz.nbt.tag.StringTag;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
|
@ -469,7 +476,34 @@ public class Player extends LivingEntity implements CommandSender, InventoryHold
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void openBook(Book book) {
|
public void openBook(Book book) {
|
||||||
throw new UnsupportedOperationException("This function has not been implemented yet.");
|
ItemStack item = new ItemStack(Key.key("minecraft:written_book"));
|
||||||
|
CompoundTag nbt = new CompoundTag();
|
||||||
|
nbt.putString("title", PlainTextComponentSerializer.plainText().serialize(book.title()));
|
||||||
|
nbt.putString("author", PlainTextComponentSerializer.plainText().serialize(book.author()));
|
||||||
|
ListTag<StringTag> pages = new ListTag<>(StringTag.class);
|
||||||
|
for (Component page : book.pages()) {
|
||||||
|
pages.add(new StringTag(PlainTextComponentSerializer.plainText().serialize(page)));
|
||||||
|
}
|
||||||
|
nbt.put("pages", pages);
|
||||||
|
item.nbt(nbt);
|
||||||
|
PacketPlayOutSetSlot setSlot = new PacketPlayOutSetSlot(0, 0,0, item);
|
||||||
|
try {
|
||||||
|
clientConnection.sendPacket(setSlot);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
ClientboundOpenBookPacket openBook = new ClientboundOpenBookPacket(0);
|
||||||
|
try {
|
||||||
|
clientConnection.sendPacket(openBook);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
PacketPlayOutSetSlot resetSlot = new PacketPlayOutSetSlot(0, 0,0, getInventory().getItemInMainHand());
|
||||||
|
try {
|
||||||
|
clientConnection.sendPacket(resetSlot);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,7 @@
|
||||||
"PacketPlayOutStopSound": "0x5F",
|
"PacketPlayOutStopSound": "0x5F",
|
||||||
"PacketPlayOutWindowItems": "0x10",
|
"PacketPlayOutWindowItems": "0x10",
|
||||||
"PacketPlayOutSetSlot": "0x12",
|
"PacketPlayOutSetSlot": "0x12",
|
||||||
|
"ClientboundOpenBookPacket": "0x2B",
|
||||||
"PacketPlayOutOpenWindow": "0x2C",
|
"PacketPlayOutOpenWindow": "0x2C",
|
||||||
"PacketPlayOutCloseWindow": "0x0F",
|
"PacketPlayOutCloseWindow": "0x0F",
|
||||||
"PacketPlayOutWindowData": "0x11"
|
"PacketPlayOutWindowData": "0x11"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue