diff --git a/src/main/java/de/bixilon/minosoft/game/datatypes/InventoryType.java b/src/main/java/de/bixilon/minosoft/game/datatypes/InventoryType.java new file mode 100644 index 000000000..66eeec3c1 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/game/datatypes/InventoryType.java @@ -0,0 +1,38 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.game.datatypes; + +public enum InventoryType { + ; + //ToDo + + final int id; + + InventoryType(int id) { + this.id = id; + } + + public static InventoryType byId(int id) { + for (InventoryType t : values()) { + if (t.getId() == id) { + return t; + } + } + return null; + } + + public int getId() { + return id; + } +} diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketCloseWindow.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketCloseWindow.java new file mode 100644 index 000000000..bfacfd108 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketCloseWindow.java @@ -0,0 +1,49 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.protocol.packets.clientbound.play; + +import de.bixilon.minosoft.logging.Log; +import de.bixilon.minosoft.protocol.packets.ClientboundPacket; +import de.bixilon.minosoft.protocol.protocol.InPacketBuffer; +import de.bixilon.minosoft.protocol.protocol.PacketHandler; +import de.bixilon.minosoft.protocol.protocol.ProtocolVersion; + +public class PacketCloseWindow implements ClientboundPacket { + byte windowId; + + + @Override + public void read(InPacketBuffer buffer, ProtocolVersion v) { + switch (v) { + case VERSION_1_7_10: + this.windowId = buffer.readByte(); + break; + } + } + + @Override + public void log() { + Log.protocol(String.format("Closing inventory (windowId=%d)", windowId)); + } + + @Override + public void handle(PacketHandler h) { + h.handle(this); + } + + + public byte getWindowId() { + return windowId; + } +} diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketConfirmTransactionReceiving.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketConfirmTransactionReceiving.java new file mode 100644 index 000000000..caef21be0 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketConfirmTransactionReceiving.java @@ -0,0 +1,60 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.protocol.packets.clientbound.play; + +import de.bixilon.minosoft.logging.Log; +import de.bixilon.minosoft.protocol.packets.ClientboundPacket; +import de.bixilon.minosoft.protocol.protocol.InPacketBuffer; +import de.bixilon.minosoft.protocol.protocol.PacketHandler; +import de.bixilon.minosoft.protocol.protocol.ProtocolVersion; + +public class PacketConfirmTransactionReceiving implements ClientboundPacket { + byte windowId; + short actionNumber; + boolean accepted; + + + @Override + public void read(InPacketBuffer buffer, ProtocolVersion v) { + switch (v) { + case VERSION_1_7_10: + this.windowId = buffer.readByte(); + this.actionNumber = buffer.readShort(); + this.accepted = buffer.readBoolean(); + break; + } + } + + @Override + public void log() { + Log.protocol(String.format("Closing inventory (windowId=%d)", windowId)); + } + + @Override + public void handle(PacketHandler h) { + h.handle(this); + } + + public byte getWindowId() { + return windowId; + } + + public boolean wasAccepted() { + return accepted; + } + + public short getActionNumber() { + return actionNumber; + } +} diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketOpenWindow.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketOpenWindow.java new file mode 100644 index 000000000..081a90088 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketOpenWindow.java @@ -0,0 +1,77 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.protocol.packets.clientbound.play; + +import de.bixilon.minosoft.game.datatypes.InventoryType; +import de.bixilon.minosoft.logging.Log; +import de.bixilon.minosoft.protocol.packets.ClientboundPacket; +import de.bixilon.minosoft.protocol.protocol.InPacketBuffer; +import de.bixilon.minosoft.protocol.protocol.PacketHandler; +import de.bixilon.minosoft.protocol.protocol.ProtocolVersion; + +public class PacketOpenWindow implements ClientboundPacket { + byte windowId; + InventoryType type; + String title; + byte slots; + int entityId; + + + @Override + public void read(InPacketBuffer buffer, ProtocolVersion v) { + switch (v) { + case VERSION_1_7_10: + this.windowId = buffer.readByte(); + this.type = InventoryType.byId(buffer.readByte()); + this.title = buffer.readString(); + slots = buffer.readByte(); + if (!buffer.readBoolean()) { + // no custom name + title = null; + } + this.entityId = buffer.readInteger(); + break; + } + } + + @Override + public void log() { + Log.protocol(String.format("Received inventory open packet (windowId=%d, type=%s, title=%s, entityId=%d)", windowId, type.name(), ((title == null) ? "null" : title), entityId)); + } + + @Override + public void handle(PacketHandler h) { + h.handle(this); + } + + public byte getSlotCount() { + return slots; + } + + public byte getWindowId() { + return windowId; + } + + public int getEntityId() { + return entityId; + } + + public String getTitle() { + return title; + } + + public InventoryType getType() { + return type; + } +} diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSetSlot.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSetSlot.java new file mode 100644 index 000000000..bf4026962 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSetSlot.java @@ -0,0 +1,61 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.protocol.packets.clientbound.play; + +import de.bixilon.minosoft.game.datatypes.inventory.Slot; +import de.bixilon.minosoft.logging.Log; +import de.bixilon.minosoft.protocol.packets.ClientboundPacket; +import de.bixilon.minosoft.protocol.protocol.InPacketBuffer; +import de.bixilon.minosoft.protocol.protocol.PacketHandler; +import de.bixilon.minosoft.protocol.protocol.ProtocolVersion; + +public class PacketSetSlot implements ClientboundPacket { + byte windowId; + short slotId; + Slot slot; //ToDo use enum Slots + + + @Override + public void read(InPacketBuffer buffer, ProtocolVersion v) { + switch (v) { + case VERSION_1_7_10: + this.windowId = buffer.readByte(); + this.slotId = buffer.readShort(); + this.slot = buffer.readSlot(v); + break; + } + } + + @Override + public void log() { + Log.protocol(String.format("Received slot data (windowId=%d, slotId=%d, item=%s", windowId, slotId, slot.getDisplayName())); + } + + @Override + public void handle(PacketHandler h) { + h.handle(this); + } + + public byte getWindowId() { + return windowId; + } + + public short getSlotId() { + return slotId; + } + + public Slot getSlot() { + return slot; + } +} diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/WindowProperty.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/WindowProperty.java new file mode 100644 index 000000000..76d200a89 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/WindowProperty.java @@ -0,0 +1,60 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.protocol.packets.clientbound.play; + +import de.bixilon.minosoft.logging.Log; +import de.bixilon.minosoft.protocol.packets.ClientboundPacket; +import de.bixilon.minosoft.protocol.protocol.InPacketBuffer; +import de.bixilon.minosoft.protocol.protocol.PacketHandler; +import de.bixilon.minosoft.protocol.protocol.ProtocolVersion; + +public class WindowProperty implements ClientboundPacket { + byte windowId; + short property; + short value; + + + @Override + public void read(InPacketBuffer buffer, ProtocolVersion v) { + switch (v) { + case VERSION_1_7_10: + this.windowId = buffer.readByte(); + this.property = buffer.readShort(); + this.value = buffer.readShort(); + break; + } + } + + @Override + public void log() { + Log.protocol(String.format("Received window property (windowId=%d, property=%d, value=%d)", windowId, property, value)); + } + + @Override + public void handle(PacketHandler h) { + h.handle(this); + } + + public byte getWindowId() { + return windowId; + } + + public short getProperty() { + return property; + } + + public short getValue() { + return value; + } +} diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketCloseWindowSending.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketCloseWindowSending.java new file mode 100644 index 000000000..d53396d8d --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketCloseWindowSending.java @@ -0,0 +1,47 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.protocol.packets.serverbound.play; + +import de.bixilon.minosoft.logging.Log; +import de.bixilon.minosoft.protocol.packets.ServerboundPacket; +import de.bixilon.minosoft.protocol.protocol.OutPacketBuffer; +import de.bixilon.minosoft.protocol.protocol.Packets; +import de.bixilon.minosoft.protocol.protocol.ProtocolVersion; + +public class PacketCloseWindowSending implements ServerboundPacket { + + final byte windowId; + + public PacketCloseWindowSending(byte windowId) { + this.windowId = windowId; + log(); + } + + + @Override + public OutPacketBuffer write(ProtocolVersion v) { + OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_CLOSE_WINDOW)); + switch (v) { + case VERSION_1_7_10: + buffer.writeByte(windowId); + break; + } + return buffer; + } + + @Override + public void log() { + Log.protocol(String.format("Sending Close window packet (windowId=%d)", windowId)); + } +} diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketConfirmTransaction.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketConfirmTransaction.java new file mode 100644 index 000000000..1792169ac --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketConfirmTransaction.java @@ -0,0 +1,53 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.protocol.packets.serverbound.play; + +import de.bixilon.minosoft.logging.Log; +import de.bixilon.minosoft.protocol.packets.ServerboundPacket; +import de.bixilon.minosoft.protocol.protocol.OutPacketBuffer; +import de.bixilon.minosoft.protocol.protocol.Packets; +import de.bixilon.minosoft.protocol.protocol.ProtocolVersion; + +public class PacketConfirmTransaction implements ServerboundPacket { + + final byte windowId; + final short actionNumber; + final boolean accepted; + + public PacketConfirmTransaction(byte windowId, short actionNumber, boolean accepted) { + this.windowId = windowId; + this.actionNumber = actionNumber; + this.accepted = accepted; + log(); + } + + + @Override + public OutPacketBuffer write(ProtocolVersion v) { + OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_WINDOW_CONFIRMATION)); + switch (v) { + case VERSION_1_7_10: + buffer.writeByte(windowId); + buffer.writeShort(actionNumber); + buffer.writeBoolean(accepted); + break; + } + return buffer; + } + + @Override + public void log() { + Log.protocol(String.format("Sending confirm transaction packet (windowId=%d, actionNumber=%d, accepted=%s)", windowId, actionNumber, accepted)); + } +} diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketCreativeInventoryAction.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketCreativeInventoryAction.java new file mode 100644 index 000000000..9f88d564c --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketCreativeInventoryAction.java @@ -0,0 +1,51 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.protocol.packets.serverbound.play; + +import de.bixilon.minosoft.game.datatypes.inventory.Slot; +import de.bixilon.minosoft.logging.Log; +import de.bixilon.minosoft.protocol.packets.ServerboundPacket; +import de.bixilon.minosoft.protocol.protocol.OutPacketBuffer; +import de.bixilon.minosoft.protocol.protocol.Packets; +import de.bixilon.minosoft.protocol.protocol.ProtocolVersion; + +public class PacketCreativeInventoryAction implements ServerboundPacket { + + final short slot; + final Slot clickedItem; + + public PacketCreativeInventoryAction(short slot, Slot clickedItem) { + this.slot = slot; + this.clickedItem = clickedItem; + log(); + } + + + @Override + public OutPacketBuffer write(ProtocolVersion v) { + OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_CREATIVE_INVENTORY_ACTION)); + switch (v) { + case VERSION_1_7_10: + buffer.writeShort(slot); + buffer.writeSlot(v, clickedItem); + break; + } + return buffer; + } + + @Override + public void log() { + Log.protocol(String.format("Sending creative inventory action (slot=%d, item=%s)", slot, clickedItem.getDisplayName())); + } +} diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketEnchantItem.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketEnchantItem.java new file mode 100644 index 000000000..667aeb71d --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketEnchantItem.java @@ -0,0 +1,50 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.protocol.packets.serverbound.play; + +import de.bixilon.minosoft.logging.Log; +import de.bixilon.minosoft.protocol.packets.ServerboundPacket; +import de.bixilon.minosoft.protocol.protocol.OutPacketBuffer; +import de.bixilon.minosoft.protocol.protocol.Packets; +import de.bixilon.minosoft.protocol.protocol.ProtocolVersion; + +public class PacketEnchantItem implements ServerboundPacket { + + final byte windowId; + final byte buttonId; // up, middle, bottom (0, 1, 2); in later versions: lectern page, etc + + public PacketEnchantItem(byte windowId, byte buttonId) { + this.windowId = windowId; + this.buttonId = buttonId; + log(); + } + + + @Override + public OutPacketBuffer write(ProtocolVersion v) { + OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_CLICK_WINDOW_BUTTON)); + switch (v) { + case VERSION_1_7_10: + buffer.writeByte(windowId); + buffer.writeByte(buttonId); + break; + } + return buffer; + } + + @Override + public void log() { + Log.protocol(String.format("Sending Click Window Packet (windowId=%d, buttonId=%d)", windowId, buttonId)); + } +} diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java index 9b0e80b51..b58ee4acd 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java @@ -324,4 +324,24 @@ public class PacketHandler { public void handle(PacketCollectItem pkg) { //ToDo } + + public void handle(PacketOpenWindow pkg) { + //ToDo + } + + public void handle(PacketCloseWindow pkg) { + // ToDo + } + + public void handle(PacketSetSlot pkg) { + //ToDo + } + + public void handle(WindowProperty pkg) { + //ToDo + } + + public void handle(PacketConfirmTransactionReceiving pkg) { + //ToDo + } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/Protocol.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/Protocol.java index 797a042b2..64b24a89b 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/Protocol.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/Protocol.java @@ -88,6 +88,10 @@ public interface Protocol { packetClassMapping.put(Packets.Clientbound.PLAY_BLOCK_ACTION, PacketBlockAction.class); packetClassMapping.put(Packets.Clientbound.PLAY_EXPLOSION, PacketExplosion.class); packetClassMapping.put(Packets.Clientbound.PLAY_COLLECT_ITEM, PacketCollectItem.class); + packetClassMapping.put(Packets.Clientbound.PLAY_OPEN_WINDOW, PacketOpenWindow.class); + packetClassMapping.put(Packets.Clientbound.PLAY_CLOSE_WINDOW, PacketCloseWindow.class); + packetClassMapping.put(Packets.Clientbound.PLAY_SET_SLOT, PacketSetSlot.class); + packetClassMapping.put(Packets.Clientbound.PLAY_WINDOW_CONFIRMATION, PacketConfirmTransactionReceiving.class); } int getProtocolVersion();