From a51f78aeb15ea337ab32eec1f1ee38a78e0fb774 Mon Sep 17 00:00:00 2001 From: bixilon Date: Tue, 16 Jun 2020 16:32:45 +0200 Subject: [PATCH] entity use packet (interaction, attack) --- .../serverbound/play/PacketUseEntity.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUseEntity.java diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUseEntity.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUseEntity.java new file mode 100644 index 000000000..d176b961e --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUseEntity.java @@ -0,0 +1,71 @@ +/* + * 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.entities.Entity; +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 PacketUseEntity implements ServerboundPacket { + final int entityId; + final Click click; + + public PacketUseEntity(Entity entity, Click click) { + this.entityId = entity.getId(); + this.click = click; + log(); + } + + public PacketUseEntity(int entityId, Click click) { + this.entityId = entityId; + this.click = click; + log(); + } + + + @Override + public OutPacketBuffer write(ProtocolVersion v) { + OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_INTERACT_ENTITY)); + switch (v) { + case VERSION_1_7_10: + buffer.writeInteger(entityId); + buffer.writeByte((byte) click.getId()); + break; + } + return buffer; + } + + @Override + public void log() { + Log.protocol(String.format("Interacting with entity (entityId=%d, click=%s)", entityId, click.name())); + } + + public enum Click { + RIGHT(0), + LEFT(1); + + final int id; + + Click(int id) { + this.id = id; + } + + public int getId() { + return id; + } + } +}