wip many more outgoing and incoming packets

This commit is contained in:
Bixilon 2020-06-22 18:41:04 +02:00
parent 9ad656712e
commit 0bdc2d0bb3
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
23 changed files with 150 additions and 11 deletions

View File

@ -32,6 +32,10 @@ public class PacketEncryptionKeyRequest implements ClientboundPacket {
publicKey = buffer.readBytes(buffer.readShort()); // read length, then the bytes publicKey = buffer.readBytes(buffer.readShort()); // read length, then the bytes
verifyToken = buffer.readBytes(buffer.readShort()); // read length, then the bytes verifyToken = buffer.readBytes(buffer.readShort()); // read length, then the bytes
break; break;
case VERSION_1_8:
serverId = buffer.readString();
publicKey = buffer.readBytes(buffer.readVarInt()); // read length, then the bytes
verifyToken = buffer.readBytes(buffer.readVarInt()); // read length, then the bytes
} }
} }

View File

@ -51,6 +51,13 @@ public class PacketEncryptionResponse implements ServerboundPacket {
buffer.writeBytes(secret); buffer.writeBytes(secret);
buffer.writeShort((short) token.length); buffer.writeShort((short) token.length);
buffer.writeBytes(token); buffer.writeBytes(token);
break;
case VERSION_1_8:
buffer.writeVarInt(secret.length);
buffer.writeBytes(secret);
buffer.writeVarInt(token.length);
buffer.writeBytes(token);
break;
} }
//buffer.writeString(username); //buffer.writeString(username);
return buffer; return buffer;

View File

@ -34,6 +34,7 @@ public class PacketChatMessage implements ServerboundPacket {
OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_CHAT_MESSAGE)); OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_CHAT_MESSAGE));
switch (v) { switch (v) {
case VERSION_1_7_10: case VERSION_1_7_10:
case VERSION_1_8:
buffer.writeString(message); buffer.writeString(message);
break; break;
} }

View File

@ -44,6 +44,7 @@ public class PacketClickWindow implements ServerboundPacket {
OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_CLICK_WINDOW)); OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_CLICK_WINDOW));
switch (v) { switch (v) {
case VERSION_1_7_10: case VERSION_1_7_10:
case VERSION_1_8:
buffer.writeByte(windowId); buffer.writeByte(windowId);
buffer.writeShort(slot); buffer.writeShort(slot);
buffer.writeByte(action.getButton()); buffer.writeByte(action.getButton());

View File

@ -38,11 +38,15 @@ public class PacketClientSettings implements ServerboundPacket {
OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_CLIENT_SETTINGS)); OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_CLIENT_SETTINGS));
switch (v) { switch (v) {
case VERSION_1_7_10: case VERSION_1_7_10:
case VERSION_1_8:
buffer.writeString(locale.getName()); // locale buffer.writeString(locale.getName()); // locale
buffer.writeByte(renderDistance); // render Distance buffer.writeByte(renderDistance); // render Distance
buffer.writeByte((byte) 0x00); // chat settings (nobody uses them) buffer.writeByte((byte) 0x00); // chat settings (nobody uses them)
buffer.writeBoolean(true); // chat colors buffer.writeBoolean(true); // chat colors
buffer.writeByte((byte) Difficulty.NORMAL.getId()); // difficulty //skip this if not 1.7.10
if (v == ProtocolVersion.VERSION_1_7_10) {
buffer.writeByte((byte) Difficulty.NORMAL.getId()); // difficulty
}
buffer.writeBoolean(true); // cape buffer.writeBoolean(true); // cape
break; break;
} }

View File

@ -36,6 +36,9 @@ public class PacketClientStatus implements ServerboundPacket {
case VERSION_1_7_10: case VERSION_1_7_10:
buffer.writeByte((byte) status.getId()); buffer.writeByte((byte) status.getId());
break; break;
case VERSION_1_8:
buffer.writeVarInt((byte) status.getId());
break;
} }
return buffer; return buffer;
} }

View File

@ -34,6 +34,7 @@ public class PacketCloseWindowSending implements ServerboundPacket {
OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_CLOSE_WINDOW)); OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_CLOSE_WINDOW));
switch (v) { switch (v) {
case VERSION_1_7_10: case VERSION_1_7_10:
case VERSION_1_8:
buffer.writeByte(windowId); buffer.writeByte(windowId);
break; break;
} }

View File

@ -38,6 +38,7 @@ public class PacketConfirmTransaction implements ServerboundPacket {
OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_WINDOW_CONFIRMATION)); OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_WINDOW_CONFIRMATION));
switch (v) { switch (v) {
case VERSION_1_7_10: case VERSION_1_7_10:
case VERSION_1_8:
buffer.writeByte(windowId); buffer.writeByte(windowId);
buffer.writeShort(actionNumber); buffer.writeShort(actionNumber);
buffer.writeBoolean(accepted); buffer.writeBoolean(accepted);

View File

@ -37,6 +37,7 @@ public class PacketCreativeInventoryAction implements ServerboundPacket {
OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_CREATIVE_INVENTORY_ACTION)); OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_CREATIVE_INVENTORY_ACTION));
switch (v) { switch (v) {
case VERSION_1_7_10: case VERSION_1_7_10:
case VERSION_1_8:
buffer.writeShort(slot); buffer.writeShort(slot);
buffer.writeSlot(v, clickedItem); buffer.writeSlot(v, clickedItem);
break; break;

View File

@ -36,6 +36,7 @@ public class PacketEnchantItem implements ServerboundPacket {
OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_CLICK_WINDOW_BUTTON)); OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_CLICK_WINDOW_BUTTON));
switch (v) { switch (v) {
case VERSION_1_7_10: case VERSION_1_7_10:
case VERSION_1_8:
buffer.writeByte(windowId); buffer.writeByte(windowId);
buffer.writeByte(buttonId); buffer.writeByte(buttonId);
break; break;

View File

@ -21,9 +21,9 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
public class PacketHeldItemChangeSending implements ServerboundPacket { public class PacketHeldItemChangeSending implements ServerboundPacket {
private final byte slot; private final short slot;
public PacketHeldItemChangeSending(byte slot) { public PacketHeldItemChangeSending(short slot) {
this.slot = slot; this.slot = slot;
log(); log();
} }
@ -39,7 +39,8 @@ public class PacketHeldItemChangeSending implements ServerboundPacket {
OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_HELD_ITEM_CHANGE)); OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_HELD_ITEM_CHANGE));
switch (v) { switch (v) {
case VERSION_1_7_10: case VERSION_1_7_10:
buffer.writeByte(slot); case VERSION_1_8:
buffer.writeShort(slot);
break; break;
} }
return buffer; return buffer;

View File

@ -36,6 +36,9 @@ public class PacketKeepAliveResponse implements ServerboundPacket {
case VERSION_1_7_10: case VERSION_1_7_10:
buffer.writeInteger(id); buffer.writeInteger(id);
break; break;
case VERSION_1_8:
buffer.writeVarInt(id);
break;
} }
return buffer; return buffer;
} }

View File

@ -53,6 +53,7 @@ public class PacketPlayerAbilitiesSending implements ServerboundPacket {
OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_CLIENT_SETTINGS)); OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_CLIENT_SETTINGS));
switch (v) { switch (v) {
case VERSION_1_7_10: case VERSION_1_7_10:
case VERSION_1_8:
byte flags = 0; byte flags = 0;
if (creative) { if (creative) {
flags |= 0b1; flags |= 0b1;

View File

@ -50,6 +50,15 @@ public class PacketPlayerBlockPlacement implements ServerboundPacket {
buffer.writeByte(direction); buffer.writeByte(direction);
buffer.writeSlot(v, item); buffer.writeSlot(v, item);
buffer.writeByte(cursorX);
buffer.writeByte(cursorY);
buffer.writeByte(cursorZ);
break;
case VERSION_1_8:
buffer.writePosition(position);
buffer.writeByte(direction);
buffer.writeSlot(v, item);
buffer.writeByte(cursorX); buffer.writeByte(cursorX);
buffer.writeByte(cursorY); buffer.writeByte(cursorY);
buffer.writeByte(cursorZ); buffer.writeByte(cursorZ);

View File

@ -48,7 +48,15 @@ public class PacketPlayerDigging implements ServerboundPacket {
buffer.writeBlockPositionByte(position); buffer.writeBlockPositionByte(position);
} }
buffer.writeByte(face); buffer.writeByte(face);
break;
case VERSION_1_8:
buffer.writeByte((byte) status.getId());
if (position == null) {
buffer.writeLong(0L);
} else {
buffer.writePosition(position);
}
buffer.writeByte(face);
break; break;
} }
return buffer; return buffer;

View File

@ -39,6 +39,17 @@ public class PacketPlayerPositionAndRotationSending implements ServerboundPacket
log(); log();
} }
public PacketPlayerPositionAndRotationSending(double x, double feetY, double z, float yaw, float pitch, boolean onGround) {
this.x = x;
this.feetY = feetY;
this.headY = feetY - 1.62F;
this.z = z;
this.yaw = yaw;
this.pitch = pitch;
this.onGround = onGround;
log();
}
@Override @Override
public OutPacketBuffer write(ProtocolVersion v) { public OutPacketBuffer write(ProtocolVersion v) {
@ -53,6 +64,14 @@ public class PacketPlayerPositionAndRotationSending implements ServerboundPacket
buffer.writeFloat(pitch); buffer.writeFloat(pitch);
buffer.writeBoolean(onGround); buffer.writeBoolean(onGround);
break; break;
case VERSION_1_8:
buffer.writeDouble(x);
buffer.writeDouble(feetY);
buffer.writeDouble(z);
buffer.writeFloat(yaw);
buffer.writeFloat(pitch);
buffer.writeBoolean(onGround);
break;
} }
return buffer; return buffer;
} }

View File

@ -35,6 +35,15 @@ public class PacketPlayerPositionSending implements ServerboundPacket {
log(); log();
} }
public PacketPlayerPositionSending(double x, double feetY, double z, boolean onGround) {
this.x = x;
this.feetY = feetY;
this.headY = feetY - 1.62F;
this.z = z;
this.onGround = onGround;
log();
}
@Override @Override
public OutPacketBuffer write(ProtocolVersion v) { public OutPacketBuffer write(ProtocolVersion v) {
@ -47,6 +56,12 @@ public class PacketPlayerPositionSending implements ServerboundPacket {
buffer.writeDouble(z); buffer.writeDouble(z);
buffer.writeBoolean(onGround); buffer.writeBoolean(onGround);
break; break;
case VERSION_1_8:
buffer.writeDouble(x);
buffer.writeDouble(feetY);
buffer.writeDouble(z);
buffer.writeBoolean(onGround);
break;
} }
return buffer; return buffer;
} }

View File

@ -37,6 +37,7 @@ public class PacketPlayerRotationSending implements ServerboundPacket {
OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_PLAYER_ROTATION)); OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_PLAYER_ROTATION));
switch (v) { switch (v) {
case VERSION_1_7_10: case VERSION_1_7_10:
case VERSION_1_8:
buffer.writeFloat(yaw); buffer.writeFloat(yaw);
buffer.writeFloat(pitch); buffer.writeFloat(pitch);
buffer.writeBoolean(onGround); buffer.writeBoolean(onGround);

View File

@ -45,6 +45,18 @@ public class PacketSteerVehicle implements ServerboundPacket {
buffer.writeBoolean(jump); buffer.writeBoolean(jump);
buffer.writeBoolean(unmount); buffer.writeBoolean(unmount);
break; break;
case VERSION_1_8:
buffer.writeFloat(sideways);
buffer.writeFloat(forward);
byte flags = 0;
if (jump) {
flags |= 0x1;
}
if (unmount) {
flags |= 0x2;
}
buffer.writeByte(flags);
break;
} }
return buffer; return buffer;
} }

View File

@ -13,6 +13,7 @@
package de.bixilon.minosoft.protocol.packets.serverbound.play; package de.bixilon.minosoft.protocol.packets.serverbound.play;
import de.bixilon.minosoft.game.datatypes.world.BlockPosition;
import de.bixilon.minosoft.logging.Log; import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.protocol.packets.ServerboundPacket; import de.bixilon.minosoft.protocol.packets.ServerboundPacket;
import de.bixilon.minosoft.protocol.protocol.OutPacketBuffer; import de.bixilon.minosoft.protocol.protocol.OutPacketBuffer;
@ -21,9 +22,17 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
public class PacketTabCompleteSending implements ServerboundPacket { public class PacketTabCompleteSending implements ServerboundPacket {
final String text; final String text;
final BlockPosition position;
public PacketTabCompleteSending(String text) { public PacketTabCompleteSending(String text) {
this.text = text; this.text = text;
position = null;
log();
}
public PacketTabCompleteSending(String text, BlockPosition position) {
this.text = text;
this.position = position;
log(); log();
} }
@ -34,6 +43,15 @@ public class PacketTabCompleteSending implements ServerboundPacket {
case VERSION_1_7_10: case VERSION_1_7_10:
buffer.writeString(text); buffer.writeString(text);
break; break;
case VERSION_1_8:
buffer.writeString(text);
if (position == null) {
buffer.writeBoolean(false);
} else {
buffer.writeBoolean(true);
buffer.writePosition(position);
}
break;
} }
return buffer; return buffer;
} }

View File

@ -13,6 +13,7 @@
package de.bixilon.minosoft.protocol.packets.serverbound.play; package de.bixilon.minosoft.protocol.packets.serverbound.play;
import de.bixilon.minosoft.game.datatypes.TextComponent;
import de.bixilon.minosoft.game.datatypes.world.BlockPosition; import de.bixilon.minosoft.game.datatypes.world.BlockPosition;
import de.bixilon.minosoft.logging.Log; import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.protocol.packets.ServerboundPacket; import de.bixilon.minosoft.protocol.packets.ServerboundPacket;
@ -22,9 +23,9 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
public class PacketUpdateSignSending implements ServerboundPacket { public class PacketUpdateSignSending implements ServerboundPacket {
final BlockPosition position; final BlockPosition position;
final String[] lines; final TextComponent[] lines;
public PacketUpdateSignSending(BlockPosition position, String[] lines) { public PacketUpdateSignSending(BlockPosition position, TextComponent[] lines) {
this.position = position; this.position = position;
this.lines = lines; this.lines = lines;
log(); log();
@ -38,7 +39,13 @@ public class PacketUpdateSignSending implements ServerboundPacket {
case VERSION_1_7_10: case VERSION_1_7_10:
buffer.writeBlockPositionByte(position); buffer.writeBlockPositionByte(position);
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
buffer.writeString(lines[i]); buffer.writeString(lines[i].getRawMessage());
}
break;
case VERSION_1_8:
buffer.writeBlockPositionByte(position);
for (int i = 0; i < 4; i++) {
buffer.writeChatComponent(lines[i]);
} }
break; break;
} }

View File

@ -14,6 +14,7 @@
package de.bixilon.minosoft.protocol.packets.serverbound.play; package de.bixilon.minosoft.protocol.packets.serverbound.play;
import de.bixilon.minosoft.game.datatypes.entities.Entity; import de.bixilon.minosoft.game.datatypes.entities.Entity;
import de.bixilon.minosoft.game.datatypes.entities.Location;
import de.bixilon.minosoft.logging.Log; import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.protocol.packets.ServerboundPacket; import de.bixilon.minosoft.protocol.packets.ServerboundPacket;
import de.bixilon.minosoft.protocol.protocol.OutPacketBuffer; import de.bixilon.minosoft.protocol.protocol.OutPacketBuffer;
@ -23,16 +24,26 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
public class PacketUseEntity implements ServerboundPacket { public class PacketUseEntity implements ServerboundPacket {
final int entityId; final int entityId;
final Click click; final Click click;
final Location location;
public PacketUseEntity(Entity entity, Click click) { public PacketUseEntity(Entity entity, Click click) {
this.entityId = entity.getId(); this.entityId = entity.getId();
this.click = click; this.click = click;
location = null;
log(); log();
} }
public PacketUseEntity(int entityId, Click click) { public PacketUseEntity(int entityId, Click click) {
this.entityId = entityId; this.entityId = entityId;
this.click = click; this.click = click;
location = null;
log();
}
public PacketUseEntity(int entityId, Click click, Location location) {
this.entityId = entityId;
this.click = click;
this.location = location;
log(); log();
} }
@ -45,6 +56,16 @@ public class PacketUseEntity implements ServerboundPacket {
buffer.writeInteger(entityId); buffer.writeInteger(entityId);
buffer.writeByte((byte) click.getId()); buffer.writeByte((byte) click.getId());
break; break;
case VERSION_1_8:
buffer.writeInteger(entityId);
buffer.writeByte((byte) click.getId());
if (click == Click.INTERACT_AT) {
// position
buffer.writeFloat((float) location.getX());
buffer.writeFloat((float) location.getY());
buffer.writeFloat((float) location.getZ());
}
break;
} }
return buffer; return buffer;
} }
@ -56,7 +77,8 @@ public class PacketUseEntity implements ServerboundPacket {
public enum Click { public enum Click {
RIGHT(0), RIGHT(0),
LEFT(1); LEFT(1),
INTERACT_AT(2);
final int id; final int id;

View File

@ -14,7 +14,6 @@
package de.bixilon.minosoft.protocol.protocol; package de.bixilon.minosoft.protocol.protocol;
import de.bixilon.minosoft.game.datatypes.TextComponent; import de.bixilon.minosoft.game.datatypes.TextComponent;
import de.bixilon.minosoft.game.datatypes.entities.Location;
import de.bixilon.minosoft.game.datatypes.inventory.Slot; import de.bixilon.minosoft.game.datatypes.inventory.Slot;
import de.bixilon.minosoft.game.datatypes.world.BlockPosition; import de.bixilon.minosoft.game.datatypes.world.BlockPosition;
import de.bixilon.minosoft.nbt.tag.CompoundTag; import de.bixilon.minosoft.nbt.tag.CompoundTag;
@ -154,7 +153,7 @@ public class OutByteBuffer {
writeString(j.toString()); writeString(j.toString());
} }
public void writePosition(Location location) { public void writePosition(BlockPosition location) {
writeLong((((long) location.getX() & 0x3FFFFFF) << 38) | (((long) location.getZ() & 0x3FFFFFF) << 12) | ((long) location.getY() & 0xFFF)); writeLong((((long) location.getX() & 0x3FFFFFF) << 38) | (((long) location.getZ() & 0x3FFFFFF) << 12) | ((long) location.getY() & 0xFFF));
} }