wip inventory (2)

This commit is contained in:
Bixilon 2020-06-18 20:55:55 +02:00
parent e5e237ed36
commit 4da2fac01f
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
12 changed files with 570 additions and 0 deletions

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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;
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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;
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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;
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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;
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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;
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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;
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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));
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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));
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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()));
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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));
}
}

View File

@ -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
}
}

View File

@ -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();