mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 10:55:01 -04:00
more functions in PacketSender, more refactoring
This commit is contained in:
parent
9d21f89aad
commit
b3c29f5f52
@ -82,10 +82,6 @@ public class PacketChangeGameState implements ClientboundPacket {
|
||||
|
||||
final byte id;
|
||||
|
||||
Reason(byte id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
Reason(int id) {
|
||||
this.id = (byte) id;
|
||||
}
|
||||
@ -99,7 +95,7 @@ public class PacketChangeGameState implements ClientboundPacket {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
public byte getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class PacketClientStatus implements ServerboundPacket {
|
||||
break;
|
||||
case VERSION_1_8:
|
||||
case VERSION_1_9_4:
|
||||
buffer.writeVarInt((byte) status.getId());
|
||||
buffer.writeVarInt(status.getId());
|
||||
break;
|
||||
}
|
||||
return buffer;
|
||||
@ -52,7 +52,7 @@ public class PacketClientStatus implements ServerboundPacket {
|
||||
public enum ClientStatus {
|
||||
PERFORM_RESPAWN(0),
|
||||
REQUEST_STATISTICS(1),
|
||||
OPEN_INVENTORY_ACHIEVEMENT(2);
|
||||
OPEN_INVENTORY(2);
|
||||
|
||||
final int id;
|
||||
|
||||
|
@ -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 PacketConfirmTeleport implements ServerboundPacket {
|
||||
|
||||
final int teleportId;
|
||||
|
||||
public PacketConfirmTeleport(int teleportId) {
|
||||
this.teleportId = teleportId;
|
||||
log();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public OutPacketBuffer write(ProtocolVersion version) {
|
||||
OutPacketBuffer buffer = new OutPacketBuffer(version, version.getPacketCommand(Packets.Serverbound.PLAY_TELEPORT_CONFIRM));
|
||||
switch (version) {
|
||||
case VERSION_1_9_4:
|
||||
buffer.writeVarInt(teleportId);
|
||||
break;
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log() {
|
||||
Log.protocol(String.format("Confirming teleport (teleportId=%d)", teleportId));
|
||||
}
|
||||
}
|
@ -23,10 +23,10 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
|
||||
public class PacketPlayerDigging implements ServerboundPacket {
|
||||
final DiggingStatus status;
|
||||
final BlockPosition position;
|
||||
final byte face;
|
||||
final DiggingFace face;
|
||||
|
||||
|
||||
public PacketPlayerDigging(DiggingStatus status, BlockPosition position, byte face) {
|
||||
public PacketPlayerDigging(DiggingStatus status, BlockPosition position, DiggingFace face) {
|
||||
this.status = status;
|
||||
this.position = position;
|
||||
this.face = face;
|
||||
@ -47,7 +47,7 @@ public class PacketPlayerDigging implements ServerboundPacket {
|
||||
} else {
|
||||
buffer.writeBlockPositionByte(position);
|
||||
}
|
||||
buffer.writeByte(face);
|
||||
buffer.writeByte(face.getId());
|
||||
break;
|
||||
case VERSION_1_8:
|
||||
buffer.writeByte((byte) status.getId());
|
||||
@ -56,7 +56,7 @@ public class PacketPlayerDigging implements ServerboundPacket {
|
||||
} else {
|
||||
buffer.writePosition(position);
|
||||
}
|
||||
buffer.writeByte(face);
|
||||
buffer.writeByte(face.getId());
|
||||
break;
|
||||
case VERSION_1_9_4:
|
||||
buffer.writeVarInt(status.getId());
|
||||
@ -65,7 +65,7 @@ public class PacketPlayerDigging implements ServerboundPacket {
|
||||
} else {
|
||||
buffer.writePosition(position);
|
||||
}
|
||||
buffer.writeByte(face);
|
||||
buffer.writeByte(face.getId());
|
||||
break;
|
||||
}
|
||||
return buffer;
|
||||
@ -95,4 +95,25 @@ public class PacketPlayerDigging implements ServerboundPacket {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
public enum DiggingFace {
|
||||
BOTTOM(0),
|
||||
TOP(1),
|
||||
NORTH(2),
|
||||
SOUTH(3),
|
||||
WEST(4),
|
||||
EAST(5),
|
||||
SPECIAL(255);
|
||||
|
||||
|
||||
final byte id;
|
||||
|
||||
DiggingFace(int id) {
|
||||
this.id = (byte) id;
|
||||
}
|
||||
|
||||
public byte getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,11 +13,9 @@
|
||||
|
||||
package de.bixilon.minosoft.protocol.protocol;
|
||||
|
||||
import de.bixilon.minosoft.game.datatypes.player.Hand;
|
||||
import de.bixilon.minosoft.protocol.network.Connection;
|
||||
import de.bixilon.minosoft.protocol.packets.serverbound.play.PacketChatMessage;
|
||||
import de.bixilon.minosoft.protocol.packets.serverbound.play.PacketHeldItemChangeSending;
|
||||
import de.bixilon.minosoft.protocol.packets.serverbound.play.PacketPlayerAbilitiesSending;
|
||||
import de.bixilon.minosoft.protocol.packets.serverbound.play.PacketSpectate;
|
||||
import de.bixilon.minosoft.protocol.packets.serverbound.play.*;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@ -43,4 +41,44 @@ public class PacketSender {
|
||||
public void setSlot(int slotId) {
|
||||
connection.sendPacket(new PacketHeldItemChangeSending(slotId));
|
||||
}
|
||||
|
||||
public void swingArm(Hand hand) {
|
||||
connection.sendPacket(new PacketAnimation(hand));
|
||||
}
|
||||
|
||||
public void swingArm() {
|
||||
connection.sendPacket(new PacketAnimation(Hand.RIGHT));
|
||||
}
|
||||
|
||||
public void sendAction(PacketEntityAction.EntityActions action) {
|
||||
connection.sendPacket(new PacketEntityAction(connection.getPlayer().getPlayer().getEntityId(), action));
|
||||
}
|
||||
|
||||
public void jumpWithHorse(int jumpBoost) {
|
||||
connection.sendPacket(new PacketEntityAction(connection.getPlayer().getPlayer().getEntityId(), PacketEntityAction.EntityActions.START_HORSE_JUMP, jumpBoost));
|
||||
}
|
||||
|
||||
public void dropItem() {
|
||||
connection.sendPacket(new PacketPlayerDigging(PacketPlayerDigging.DiggingStatus.DROP_ITEM, null, PacketPlayerDigging.DiggingFace.BOTTOM));
|
||||
}
|
||||
|
||||
public void dropItemStack() {
|
||||
connection.sendPacket(new PacketPlayerDigging(PacketPlayerDigging.DiggingStatus.DROP_ITEM_STACK, null, PacketPlayerDigging.DiggingFace.BOTTOM));
|
||||
}
|
||||
|
||||
public void swapItemInHand() {
|
||||
connection.sendPacket(new PacketPlayerDigging(PacketPlayerDigging.DiggingStatus.SWAP_ITEMS_IN_HAND, null, PacketPlayerDigging.DiggingFace.BOTTOM));
|
||||
}
|
||||
|
||||
public void closeWindow(byte windowId) {
|
||||
connection.sendPacket(new PacketCloseWindowSending(windowId));
|
||||
}
|
||||
|
||||
public void sendClientStatus(PacketClientStatus.ClientStatus status) {
|
||||
connection.sendPacket(new PacketClientStatus(status));
|
||||
}
|
||||
|
||||
public void respawn() {
|
||||
sendClientStatus(PacketClientStatus.ClientStatus.PERFORM_RESPAWN);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user