Updated packets reader/writer

This commit is contained in:
TheMode 2019-08-31 07:54:53 +02:00
parent d929730a61
commit 666f433ae7
104 changed files with 979 additions and 706 deletions

View File

@ -1,7 +1,7 @@
package fr.themode.minestom;
import fr.themode.minestom.entity.Player;
import fr.themode.minestom.net.PacketWriter;
import fr.themode.minestom.net.PacketWriterUtils;
import fr.themode.minestom.net.packet.server.ServerPacket;
import java.util.Set;
@ -22,7 +22,7 @@ public interface Viewable {
if (getViewers().isEmpty())
return;
PacketWriter.writeCallbackPacket(packet, buffer -> {
PacketWriterUtils.writeCallbackPacket(packet, buffer -> {
int size = getViewers().size();
if (size == 0)
return;
@ -39,7 +39,7 @@ public interface Viewable {
return;
for (ServerPacket packet : packets) {
PacketWriter.writeCallbackPacket(packet, buffer -> {
PacketWriterUtils.writeCallbackPacket(packet, buffer -> {
int size = getViewers().size();
if (size == 0)
return;
@ -61,7 +61,7 @@ public interface Viewable {
}
private void UNSAFE_sendPacketToViewersAndSelf(ServerPacket packet) {
PacketWriter.writeCallbackPacket(packet, buffer -> {
PacketWriterUtils.writeCallbackPacket(packet, buffer -> {
int size = getViewers().size();
buffer.getData().retain(size + 1).markReaderIndex();
((Player) this).getPlayerConnection().writeUnencodedPacket(buffer);

View File

@ -1,6 +1,8 @@
package fr.themode.minestom.collision;
import fr.themode.minestom.entity.Entity;
import fr.themode.minestom.utils.BlockPosition;
import fr.themode.minestom.utils.Position;
/**
* See https://wiki.vg/Entity_metadata#Mobs_2
@ -23,6 +25,31 @@ public class BoundingBox {
(getMinZ() <= boundingBox.getMaxZ() && getMaxZ() >= boundingBox.getMinZ());
}
public boolean intersect(BlockPosition blockPosition) {
final float x = 1f;
final float y = 1;
final float z = 1f;
float minX = blockPosition.getX() - (x / 2) + 0.5f;
float maxX = blockPosition.getX() + (x / 2) + 0.5f;
float minY = blockPosition.getY();
float maxY = blockPosition.getY() + y;
float minZ = blockPosition.getZ() - (z / 2) + 0.5f;
float maxZ = blockPosition.getZ() + (z / 2) + 0.5f;
boolean checkX = getMinX() + x / 2 < maxX && getMaxX() - x / 2 > minX;
boolean checkY = getMinY() + y < maxY && getMaxY() + y > minY;
boolean checkZ = getMinZ() + z / 2 < maxZ && getMaxZ() - z / 2 > minZ;
return checkX && checkY && checkZ;
}
public boolean intersect(Position position) {
return (position.getX() >= getMinX() && position.getX() <= getMaxX()) &&
(position.getY() >= getMinY() && position.getY() <= getMaxY()) &&
(position.getZ() >= getMinZ() && position.getZ() <= getMaxZ());
}
public BoundingBox expand(float x, float y, float z) {
return new BoundingBox(entity, this.x + x, this.y + y, this.z + z);
}
@ -63,4 +90,8 @@ public class BoundingBox {
return entity.getPosition().getZ() + (z / 2);
}
@Override
public String toString() {
return "BoundingBox[" + x + ":" + y + ":" + z + "]";
}
}

View File

@ -153,7 +153,7 @@ public abstract class Entity implements Viewable, DataContainer {
player.viewableEntity.add(this);
PlayerConnection playerConnection = player.getPlayerConnection();
playerConnection.sendPacket(getVelocityPacket());
playerConnection.sendPacket(getPassengersPacket()); // TODO fix synchronization
playerConnection.sendPacket(getPassengersPacket());
}
@Override

View File

@ -94,9 +94,9 @@ public abstract class EntityCreature extends LivingEntity {
spawnMobPacket.entityType = getEntityType();
spawnMobPacket.position = getPosition();
spawnMobPacket.headPitch = 0;
spawnMobPacket.metadata = getMetadataBuffer();
playerConnection.sendPacket(entityPacket);
playerConnection.sendPacket(spawnMobPacket);
playerConnection.sendPacket(getMetadataPacket());
}
@Override

View File

@ -0,0 +1,52 @@
package fr.themode.minestom.entity;
import fr.themode.minestom.net.packet.server.play.SpawnExperienceOrbPacket;
import fr.themode.minestom.net.player.PlayerConnection;
import fr.themode.minestom.utils.EntityUtils;
public class ExperienceOrb extends Entity {
private short experienceCount;
public ExperienceOrb(short experienceCount) {
super(23);
setGravity(0.02f);
setBoundingBox(0.5f, 0.5f, 0.5f);
this.experienceCount = experienceCount;
}
@Override
public void update() {
// TODO slide toward nearest player
}
@Override
public void spawn() {
}
@Override
public boolean isOnGround() {
return EntityUtils.isOnGround(this);
}
@Override
public void addViewer(Player player) {
PlayerConnection playerConnection = player.getPlayerConnection();
SpawnExperienceOrbPacket experienceOrbPacket = new SpawnExperienceOrbPacket();
experienceOrbPacket.entityId = getEntityId();
experienceOrbPacket.position = getPosition();
experienceOrbPacket.expCount = experienceCount;
playerConnection.sendPacket(experienceOrbPacket);
super.addViewer(player); // Add player to viewers list and send velocity packet
}
public short getExperienceCount() {
return experienceCount;
}
public void setExperienceCount(short experienceCount) {
this.experienceCount = experienceCount;
}
}

View File

@ -57,7 +57,7 @@ public abstract class LivingEntity extends Entity {
collectItemPacket.collectorEntityId = getEntityId();
collectItemPacket.pickupItemCount = item.getAmount();
sendPacketToViewersAndSelf(collectItemPacket);
entity.scheduleRemove(500);
entity.remove();
});
}
}

View File

@ -3,8 +3,8 @@ package fr.themode.minestom.entity;
import fr.themode.minestom.Main;
import fr.themode.minestom.bossbar.BossBar;
import fr.themode.minestom.chat.Chat;
import fr.themode.minestom.collision.BoundingBox;
import fr.themode.minestom.data.Data;
import fr.themode.minestom.entity.demo.ChickenCreature;
import fr.themode.minestom.entity.property.Attribute;
import fr.themode.minestom.event.*;
import fr.themode.minestom.instance.Chunk;
@ -65,6 +65,8 @@ public class Player extends LivingEntity {
protected Set<Entity> viewableEntity = new CopyOnWriteArraySet<>();
private PlayerSettings settings;
private float exp;
private int level;
private PlayerInventory inventory;
private short heldSlot;
private Inventory openInventory;
@ -156,10 +158,10 @@ public class Player extends LivingEntity {
setGameMode(GameMode.SURVIVAL);
teleport(new Position(0, 66, 0));
ChickenCreature chickenCreature = new ChickenCreature();
/*ChickenCreature chickenCreature = new ChickenCreature();
chickenCreature.refreshPosition(2, 65, 2);
chickenCreature.setInstance(getInstance());
chickenCreature.addPassenger(this);
chickenCreature.addPassenger(this);*/
/*for (int ix = 0; ix < 4; ix++)
for (int iz = 0; iz < 4; iz++) {
@ -170,6 +172,10 @@ public class Player extends LivingEntity {
//itemEntity.remove();
}*/
ExperienceOrb experienceOrb = new ExperienceOrb((short) 500);
experienceOrb.refreshPosition(5, 66, 0);
experienceOrb.setInstance(getInstance());
getInventory().addItemStack(new ItemStack(1, (byte) 100));
TeamsPacket teamsPacket = new TeamsPacket();
@ -186,6 +192,8 @@ public class Player extends LivingEntity {
setAttribute(Attribute.MAX_HEALTH, 40);
heal();
setExp(0.9f);
});
}
@ -217,6 +225,28 @@ public class Player extends LivingEntity {
}
}
// Experience orb pickup
Chunk chunk = instance.getChunkAt(getPosition()); // TODO check surrounding chunks
Set<Entity> entities = instance.getChunkEntities(chunk);
BoundingBox livingBoundingBox = getBoundingBox().expand(1, 0.5f, 1);
for (Entity entity : entities) {
if (entity instanceof ExperienceOrb) {
ExperienceOrb experienceOrb = (ExperienceOrb) entity;
BoundingBox itemBoundingBox = experienceOrb.getBoundingBox();
if (livingBoundingBox.intersect(itemBoundingBox)) {
synchronized (experienceOrb) {
if (experienceOrb.shouldRemove() || experienceOrb.isRemoveScheduled())
continue;
PickupExperienceEvent pickupExperienceEvent = new PickupExperienceEvent(experienceOrb.getExperienceCount());
callCancellableEvent(PickupExperienceEvent.class, pickupExperienceEvent, () -> {
short experienceCount = pickupExperienceEvent.getExperienceCount(); // TODO give to player
entity.remove();
});
}
}
}
}
// Multiplayer sync
Position position = getPosition();
@ -445,6 +475,25 @@ public class Player extends LivingEntity {
playerConnection.sendPacket(updateHealthPacket);
}
public void setExp(float exp) {
if (exp < 0 || exp > 1)
throw new IllegalArgumentException("Exp should be between 0 and 1");
this.exp = exp;
sendExperienceUpdatePacket();
}
public void setLevel(int level) {
this.level = level;
sendExperienceUpdatePacket();
}
protected void sendExperienceUpdatePacket() {
SetExperiencePacket setExperiencePacket = new SetExperiencePacket();
setExperiencePacket.percentage = exp;
setExperiencePacket.level = level;
playerConnection.sendPacket(setExperiencePacket);
}
protected void onChunkChange(Chunk lastChunk, Chunk newChunk) {
float dx = newChunk.getChunkX() - lastChunk.getChunkX();
float dz = newChunk.getChunkZ() - lastChunk.getChunkZ();

View File

@ -0,0 +1,18 @@
package fr.themode.minestom.event;
public class PickupExperienceEvent extends CancellableEvent {
private short experienceCount;
public PickupExperienceEvent(short experienceCount) {
this.experienceCount = experienceCount;
}
public short getExperienceCount() {
return experienceCount;
}
public void setExperienceCount(short experienceCount) {
this.experienceCount = experienceCount;
}
}

View File

@ -2,10 +2,7 @@ package fr.themode.minestom.instance;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.Main;
import fr.themode.minestom.entity.Entity;
import fr.themode.minestom.entity.EntityCreature;
import fr.themode.minestom.entity.ObjectEntity;
import fr.themode.minestom.entity.Player;
import fr.themode.minestom.entity.*;
import fr.themode.minestom.utils.BlockPosition;
import fr.themode.minestom.utils.ChunkUtils;
import fr.themode.minestom.utils.Position;
@ -20,9 +17,10 @@ public abstract class Instance implements BlockModifier {
protected static final ChunkLoaderIO CHUNK_LOADER_IO = new ChunkLoaderIO();
// Entities present in this instance
protected Set<ObjectEntity> objectEntities = new CopyOnWriteArraySet<>();
protected Set<EntityCreature> creatures = new CopyOnWriteArraySet<>();
protected Set<Player> players = new CopyOnWriteArraySet<>();
protected Set<EntityCreature> creatures = new CopyOnWriteArraySet<>();
protected Set<ObjectEntity> objectEntities = new CopyOnWriteArraySet<>();
protected Set<ExperienceOrb> experienceOrbs = new CopyOnWriteArraySet<>();
// Entities per chunk
protected Map<Long, Set<Entity>> chunkEntities = new ConcurrentHashMap<>();
private UUID uniqueId;
@ -79,16 +77,20 @@ public abstract class Instance implements BlockModifier {
}
//
public Set<ObjectEntity> getObjectEntities() {
return Collections.unmodifiableSet(objectEntities);
public Set<Player> getPlayers() {
return Collections.unmodifiableSet(players);
}
public Set<EntityCreature> getCreatures() {
return Collections.unmodifiableSet(creatures);
}
public Set<Player> getPlayers() {
return Collections.unmodifiableSet(players);
public Set<ObjectEntity> getObjectEntities() {
return Collections.unmodifiableSet(objectEntities);
}
public Set<ExperienceOrb> getExperienceOrbs() {
return Collections.unmodifiableSet(experienceOrbs);
}
public Set<Entity> getChunkEntities(Chunk chunk) {
@ -197,6 +199,8 @@ public abstract class Instance implements BlockModifier {
this.creatures.add((EntityCreature) entity);
} else if (entity instanceof ObjectEntity) {
this.objectEntities.add((ObjectEntity) entity);
} else if (entity instanceof ExperienceOrb) {
this.experienceOrbs.add((ExperienceOrb) entity);
}
}
@ -215,6 +219,8 @@ public abstract class Instance implements BlockModifier {
this.creatures.remove(entity);
} else if (entity instanceof ObjectEntity) {
this.objectEntities.remove(entity);
} else if (entity instanceof ExperienceOrb) {
this.experienceOrbs.remove((ExperienceOrb) entity);
}
}

View File

@ -3,7 +3,7 @@ package fr.themode.minestom.instance;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.entity.Player;
import fr.themode.minestom.event.PlayerBlockBreakEvent;
import fr.themode.minestom.net.PacketWriter;
import fr.themode.minestom.net.PacketWriterUtils;
import fr.themode.minestom.net.packet.server.play.ParticlePacket;
import fr.themode.minestom.utils.BlockPosition;
import fr.themode.minestom.utils.ChunkUtils;
@ -38,7 +38,7 @@ public class InstanceContainer extends Instance {
Chunk chunk = getChunkAt(x, z);
synchronized (chunk) {
chunk.setBlock((byte) (x % 16), (byte) y, (byte) (z % 16), blockId);
PacketWriter.writeCallbackPacket(chunk.getFreshPartialDataPacket(), buffer -> {
PacketWriterUtils.writeCallbackPacket(chunk.getFreshPartialDataPacket(), buffer -> {
chunk.setFullDataPacket(buffer);
sendChunkUpdate(chunk);
});
@ -50,7 +50,7 @@ public class InstanceContainer extends Instance {
Chunk chunk = getChunkAt(x, z);
synchronized (chunk) {
chunk.setCustomBlock((byte) (x % 16), (byte) y, (byte) (z % 16), blockId);
PacketWriter.writeCallbackPacket(chunk.getFreshPartialDataPacket(), buffer -> {
PacketWriterUtils.writeCallbackPacket(chunk.getFreshPartialDataPacket(), buffer -> {
chunk.setFullDataPacket(buffer);
sendChunkUpdate(chunk);
});
@ -216,7 +216,7 @@ public class InstanceContainer extends Instance {
}else{
sendChunkUpdate(player, chunk);
}*/
PacketWriter.writeCallbackPacket(chunk.getFreshFullDataPacket(), buffer -> {
PacketWriterUtils.writeCallbackPacket(chunk.getFreshFullDataPacket(), buffer -> {
chunk.setFullDataPacket(buffer);
sendChunkUpdate(player, chunk);
});

View File

@ -31,23 +31,26 @@ public class BlockPlacementListener {
int offsetZ = blockFace == ClientPlayerDiggingPacket.BlockFace.NORTH ? -1 : blockFace == ClientPlayerDiggingPacket.BlockFace.SOUTH ? 1 : 0;
blockPosition.add(offsetX, offsetY, offsetZ);
PlayerBlockPlaceEvent playerBlockPlaceEvent = new PlayerBlockPlaceEvent((short) 10, blockPosition, packet.hand);
player.callEvent(PlayerBlockPlaceEvent.class, playerBlockPlaceEvent);
if (!playerBlockPlaceEvent.isCancelled()) {
instance.setBlock(blockPosition, "custom_block"); // TODO set useItem's block instead
if (playerBlockPlaceEvent.doesConsumeBlock()) {
usedItem.setAmount((byte) (usedItem.getAmount() - 1));
if (usedItem.getAmount() <= 0)
usedItem = ItemStack.AIR_ITEM;
if (hand == Player.Hand.OFF) {
playerInventory.setItemInOffHand(usedItem);
} else { // Main
playerInventory.setItemInMainHand(usedItem);
boolean intersectPlayer = player.getBoundingBox().intersect(blockPosition);
if (!intersectPlayer) {
PlayerBlockPlaceEvent playerBlockPlaceEvent = new PlayerBlockPlaceEvent((short) 10, blockPosition, packet.hand);
player.callEvent(PlayerBlockPlaceEvent.class, playerBlockPlaceEvent);
if (!playerBlockPlaceEvent.isCancelled()) {
instance.setBlock(blockPosition, "custom_block"); // TODO set useItem's block instead
if (playerBlockPlaceEvent.doesConsumeBlock()) {
usedItem.setAmount((byte) (usedItem.getAmount() - 1));
if (usedItem.getAmount() <= 0)
usedItem = ItemStack.AIR_ITEM;
if (hand == Player.Hand.OFF) {
playerInventory.setItemInOffHand(usedItem);
} else { // Main
playerInventory.setItemInMainHand(usedItem);
}
}
} else {
Chunk chunk = instance.getChunkAt(blockPosition);
instance.sendChunkUpdate(player, chunk);
}
} else {
Chunk chunk = instance.getChunkAt(blockPosition);
instance.sendChunkUpdate(player, chunk);
}
player.getInventory().refreshSlot(player.getHeldSlot());
}

View File

@ -5,6 +5,7 @@ import fr.adamaq01.ozao.net.packet.Packet;
import fr.adamaq01.ozao.net.server.Connection;
import fr.themode.minestom.Main;
import fr.themode.minestom.entity.Player;
import fr.themode.minestom.net.packet.PacketReader;
import fr.themode.minestom.net.packet.client.ClientPlayPacket;
import fr.themode.minestom.net.packet.client.ClientPreplayPacket;
import fr.themode.minestom.net.packet.client.handler.ClientLoginPacketsHandler;
@ -52,11 +53,13 @@ public class PacketProcessor {
//System.out.println("RECEIVED ID: 0x" + Integer.toHexString(id) + " State: " + connectionState);
}
PacketReader packetReader = new PacketReader(buffer);
if (connectionState == ConnectionState.UNKNOWN) {
// Should be handshake packet
if (id == 0) {
HandshakePacket handshakePacket = new HandshakePacket();
handshakePacket.read(buffer);
handshakePacket.read(packetReader);
handshakePacket.process(playerConnection, connectionManager);
}
return;
@ -66,17 +69,17 @@ public class PacketProcessor {
case PLAY:
Player player = connectionManager.getPlayer(playerConnection);
ClientPlayPacket playPacket = (ClientPlayPacket) playPacketsHandler.getPacketInstance(id);
playPacket.read(buffer);
playPacket.read(packetReader);
player.addPacketToQueue(playPacket); // Processed during player tick update
break;
case LOGIN:
ClientPreplayPacket loginPacket = (ClientPreplayPacket) loginPacketsHandler.getPacketInstance(id);
loginPacket.read(buffer);
loginPacket.read(packetReader);
loginPacket.process(playerConnection, connectionManager);
break;
case STATUS:
ClientPreplayPacket statusPacket = (ClientPreplayPacket) statusPacketsHandler.getPacketInstance(id);
statusPacket.read(buffer);
statusPacket.read(packetReader);
statusPacket.process(playerConnection, connectionManager);
break;
case UNKNOWN:

View File

@ -10,7 +10,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Consumer;
public class PacketWriter {
public class PacketWriterUtils {
private static volatile ExecutorService batchesPool = Executors.newFixedThreadPool(Main.THREAD_COUNT_PACKET_WRITER);

View File

@ -0,0 +1,55 @@
package fr.themode.minestom.net.packet;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.utils.BlockPosition;
import fr.themode.minestom.utils.Utils;
public class PacketReader {
private Buffer buffer;
public PacketReader(Buffer buffer) {
this.buffer = buffer;
}
public int readVarInt() {
return Utils.readVarInt(buffer);
}
public boolean readBoolean() {
return buffer.getBoolean();
}
public byte readByte() {
return buffer.getByte();
}
public short readShort() {
return buffer.getShort();
}
public long readLong() {
return buffer.getLong();
}
public float readFloat() {
return buffer.getFloat();
}
public double readDouble() {
return buffer.getDouble();
}
public String readSizedString() {
return Utils.readString(buffer);
}
public byte[] getRemainingBytes() {
return buffer.getAllBytes();
}
public BlockPosition readBlockPosition() {
return Utils.readPosition(buffer);
}
}

View File

@ -0,0 +1,101 @@
package fr.themode.minestom.net.packet;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.item.ItemStack;
import fr.themode.minestom.utils.BlockPosition;
import fr.themode.minestom.utils.Utils;
import java.util.UUID;
public class PacketWriter {
private Buffer buffer;
public PacketWriter(Buffer buffer) {
this.buffer = buffer;
}
public void writeBoolean(boolean b) {
buffer.putBoolean(b);
}
public void writeByte(byte b) {
buffer.putByte(b);
}
public void writeShort(short s) {
buffer.putShort(s);
}
public void writeInt(int i) {
buffer.putInt(i);
}
public void writeLong(long l) {
buffer.putLong(l);
}
public void writeFloat(float f) {
buffer.putFloat(f);
}
public void writeDouble(double d) {
buffer.putDouble(d);
}
public void writeVarInt(int i) {
Utils.writeVarInt(buffer, i);
}
public void writeSizedString(String string) {
Utils.writeString(buffer, string);
}
public void writeVarIntArray(int[] array) {
if (array == null) {
writeVarInt(0);
return;
}
writeVarInt(array.length);
for (int element : array) {
writeVarInt(element);
}
}
public void writeBytes(byte[] bytes) {
buffer.putBytes(bytes);
}
public void writeStringArray(String[] array) {
if (array == null) {
writeVarInt(0);
return;
}
writeVarInt(array.length);
for (String element : array) {
writeSizedString(element);
}
}
public void writeBuffer(Buffer buffer) {
this.buffer.putBuffer(buffer);
}
public void writeUuid(UUID uuid) {
writeLong(uuid.getMostSignificantBits());
writeLong(uuid.getLeastSignificantBits());
}
public void writeBlockPosition(BlockPosition blockPosition) {
Utils.writePosition(buffer, blockPosition);
}
public void writeBlockPosition(int x, int y, int z) {
Utils.writePosition(buffer, x, y, z);
}
public void writeItemStack(ItemStack itemStack) {
Utils.writeItemStack(buffer, itemStack);
}
}

View File

@ -1,9 +1,9 @@
package fr.themode.minestom.net.packet.client;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketReader;
public interface ClientPacket {
void read(Buffer buffer);
void read(PacketReader reader);
}

View File

@ -1,24 +1,21 @@
package fr.themode.minestom.net.packet.client.handshake;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.ConnectionManager;
import fr.themode.minestom.net.ConnectionState;
import fr.themode.minestom.net.packet.PacketReader;
import fr.themode.minestom.net.packet.client.ClientPreplayPacket;
import fr.themode.minestom.net.player.PlayerConnection;
import static fr.themode.minestom.utils.Utils.readString;
import static fr.themode.minestom.utils.Utils.readVarInt;
public class HandshakePacket implements ClientPreplayPacket {
private int nextState;
@Override
public void read(Buffer buffer) {
int protocolVersion = readVarInt(buffer);
String serverAddress = readString(buffer);
short serverPort = buffer.getShort();
this.nextState = readVarInt(buffer);
public void read(PacketReader reader) {
int protocolVersion = reader.readVarInt();
String serverAddress = reader.readSizedString();
short serverPort = reader.readShort();
this.nextState = reader.readVarInt();
}
@Override

View File

@ -1,18 +1,17 @@
package fr.themode.minestom.net.packet.client.login;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.Main;
import fr.themode.minestom.entity.GameMode;
import fr.themode.minestom.entity.Player;
import fr.themode.minestom.net.ConnectionManager;
import fr.themode.minestom.net.ConnectionState;
import fr.themode.minestom.net.packet.PacketReader;
import fr.themode.minestom.net.packet.client.ClientPreplayPacket;
import fr.themode.minestom.net.packet.server.login.JoinGamePacket;
import fr.themode.minestom.net.packet.server.login.LoginSuccessPacket;
import fr.themode.minestom.net.packet.server.play.PlayerInfoPacket;
import fr.themode.minestom.net.packet.server.play.SpawnPositionPacket;
import fr.themode.minestom.net.player.PlayerConnection;
import fr.themode.minestom.utils.Utils;
import fr.themode.minestom.world.Dimension;
import fr.themode.minestom.world.LevelType;
@ -107,7 +106,7 @@ public class LoginStartPacket implements ClientPreplayPacket {
}
@Override
public void read(Buffer buffer) {
this.username = Utils.readString(buffer);
public void read(PacketReader reader) {
this.username = reader.readSizedString();
}
}

View File

@ -1,16 +1,15 @@
package fr.themode.minestom.net.packet.client.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.entity.Player;
import fr.themode.minestom.net.packet.PacketReader;
import fr.themode.minestom.net.packet.client.ClientPlayPacket;
import fr.themode.minestom.utils.Utils;
public class ClientAnimationPacket extends ClientPlayPacket {
public Player.Hand hand;
@Override
public void read(Buffer buffer) {
this.hand = Player.Hand.values()[Utils.readVarInt(buffer)];
public void read(PacketReader reader) {
this.hand = Player.Hand.values()[reader.readVarInt()];
}
}

View File

@ -1,15 +1,14 @@
package fr.themode.minestom.net.packet.client.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketReader;
import fr.themode.minestom.net.packet.client.ClientPlayPacket;
import fr.themode.minestom.utils.Utils;
public class ClientChatMessagePacket extends ClientPlayPacket {
public String message;
@Override
public void read(Buffer buffer) {
this.message = Utils.readString(buffer);
public void read(PacketReader reader) {
this.message = reader.readSizedString();
}
}

View File

@ -1,8 +1,7 @@
package fr.themode.minestom.net.packet.client.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketReader;
import fr.themode.minestom.net.packet.client.ClientPlayPacket;
import fr.themode.minestom.utils.Utils;
public class ClientClickWindowPacket extends ClientPlayPacket {
@ -14,12 +13,12 @@ public class ClientClickWindowPacket extends ClientPlayPacket {
// TODO clicked item
@Override
public void read(Buffer buffer) {
this.windowId = buffer.getByte();
this.slot = buffer.getShort();
this.button = buffer.getByte();
this.actionNumber = buffer.getShort();
this.mode = Utils.readVarInt(buffer);
public void read(PacketReader reader) {
this.windowId = reader.readByte();
this.slot = reader.readShort();
this.button = reader.readByte();
this.actionNumber = reader.readShort();
this.mode = reader.readVarInt();
// TODO read clicked item
}
}

View File

@ -1,15 +1,14 @@
package fr.themode.minestom.net.packet.client.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketReader;
import fr.themode.minestom.net.packet.client.ClientPlayPacket;
import fr.themode.minestom.utils.Utils;
public class ClientCloseWindow extends ClientPlayPacket {
public int windowId;
@Override
public void read(Buffer buffer) {
this.windowId = Utils.readVarInt(buffer);
public void read(PacketReader reader) {
this.windowId = reader.readVarInt();
}
}

View File

@ -1,6 +1,6 @@
package fr.themode.minestom.net.packet.client.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketReader;
import fr.themode.minestom.net.packet.client.ClientPlayPacket;
public class ClientConfirmTransactionPacket extends ClientPlayPacket {
@ -10,7 +10,7 @@ public class ClientConfirmTransactionPacket extends ClientPlayPacket {
public boolean accepted;
@Override
public void read(Buffer buffer) {
public void read(PacketReader reader) {
// TODO
}
}

View File

@ -1,8 +1,7 @@
package fr.themode.minestom.net.packet.client.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketReader;
import fr.themode.minestom.net.packet.client.ClientPlayPacket;
import fr.themode.minestom.utils.Utils;
public class ClientEntityActionPacket extends ClientPlayPacket {
@ -11,10 +10,10 @@ public class ClientEntityActionPacket extends ClientPlayPacket {
public int horseJumpBoost;
@Override
public void read(Buffer buffer) {
this.playerId = Utils.readVarInt(buffer);
this.action = Action.values()[Utils.readVarInt(buffer)];
this.horseJumpBoost = Utils.readVarInt(buffer);
public void read(PacketReader reader) {
this.playerId = reader.readVarInt();
this.action = Action.values()[reader.readVarInt()];
this.horseJumpBoost = reader.readVarInt();
}
public enum Action {

View File

@ -1,6 +1,6 @@
package fr.themode.minestom.net.packet.client.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketReader;
import fr.themode.minestom.net.packet.client.ClientPlayPacket;
public class ClientHeldItemChangePacket extends ClientPlayPacket {
@ -8,7 +8,7 @@ public class ClientHeldItemChangePacket extends ClientPlayPacket {
public short slot;
@Override
public void read(Buffer buffer) {
this.slot = buffer.getShort();
public void read(PacketReader reader) {
this.slot = reader.readShort();
}
}

View File

@ -1,6 +1,6 @@
package fr.themode.minestom.net.packet.client.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketReader;
import fr.themode.minestom.net.packet.client.ClientPlayPacket;
public class ClientKeepAlivePacket extends ClientPlayPacket {
@ -8,7 +8,7 @@ public class ClientKeepAlivePacket extends ClientPlayPacket {
public long id;
@Override
public void read(Buffer buffer) {
this.id = buffer.getLong();
public void read(PacketReader reader) {
this.id = reader.readLong();
}
}

View File

@ -1,6 +1,6 @@
package fr.themode.minestom.net.packet.client.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketReader;
import fr.themode.minestom.net.packet.client.ClientPlayPacket;
public class ClientPlayerAbilitiesPacket extends ClientPlayPacket {
@ -10,9 +10,9 @@ public class ClientPlayerAbilitiesPacket extends ClientPlayPacket {
public float walkingSpeed;
@Override
public void read(Buffer buffer) {
this.flags = buffer.getByte();
this.flyingSpeed = buffer.getFloat();
this.walkingSpeed = buffer.getFloat();
public void read(PacketReader reader) {
this.flags = reader.readByte();
this.flyingSpeed = reader.readFloat();
this.walkingSpeed = reader.readFloat();
}
}

View File

@ -1,10 +1,9 @@
package fr.themode.minestom.net.packet.client.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.entity.Player;
import fr.themode.minestom.net.packet.PacketReader;
import fr.themode.minestom.net.packet.client.ClientPlayPacket;
import fr.themode.minestom.utils.BlockPosition;
import fr.themode.minestom.utils.Utils;
public class ClientPlayerBlockPlacementPacket extends ClientPlayPacket {
@ -15,14 +14,14 @@ public class ClientPlayerBlockPlacementPacket extends ClientPlayPacket {
public boolean insideBlock;
@Override
public void read(Buffer buffer) {
this.hand = Player.Hand.values()[Utils.readVarInt(buffer)];
this.blockPosition = Utils.readPosition(buffer);
this.blockFace = ClientPlayerDiggingPacket.BlockFace.values()[Utils.readVarInt(buffer)];
this.cursorPositionX = buffer.getFloat();
this.cursorPositionY = buffer.getFloat();
this.cursorPositionZ = buffer.getFloat();
this.insideBlock = buffer.getBoolean();
public void read(PacketReader reader) {
this.hand = Player.Hand.values()[reader.readVarInt()];
this.blockPosition = reader.readBlockPosition();
this.blockFace = ClientPlayerDiggingPacket.BlockFace.values()[reader.readVarInt()];
this.cursorPositionX = reader.readFloat();
this.cursorPositionY = reader.readFloat();
this.cursorPositionZ = reader.readFloat();
this.insideBlock = reader.readBoolean();
}
}

View File

@ -1,9 +1,8 @@
package fr.themode.minestom.net.packet.client.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketReader;
import fr.themode.minestom.net.packet.client.ClientPlayPacket;
import fr.themode.minestom.utils.BlockPosition;
import fr.themode.minestom.utils.Utils;
public class ClientPlayerDiggingPacket extends ClientPlayPacket {
@ -12,10 +11,10 @@ public class ClientPlayerDiggingPacket extends ClientPlayPacket {
public BlockFace blockFace;
@Override
public void read(Buffer buffer) {
this.status = Status.values()[Utils.readVarInt(buffer)];
this.blockPosition = Utils.readPosition(buffer);
this.blockFace = BlockFace.values()[Utils.readVarInt(buffer)];
public void read(PacketReader reader) {
this.status = Status.values()[reader.readVarInt()];
this.blockPosition = reader.readBlockPosition();
this.blockFace = BlockFace.values()[reader.readVarInt()];
}
public enum Status {

View File

@ -1,6 +1,6 @@
package fr.themode.minestom.net.packet.client.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketReader;
import fr.themode.minestom.net.packet.client.ClientPlayPacket;
public class ClientPlayerLookPacket extends ClientPlayPacket {
@ -9,9 +9,9 @@ public class ClientPlayerLookPacket extends ClientPlayPacket {
public boolean onGround;
@Override
public void read(Buffer buffer) {
this.yaw = buffer.getFloat();
this.pitch = buffer.getFloat();
this.onGround = buffer.getBoolean();
public void read(PacketReader reader) {
this.yaw = reader.readFloat();
this.pitch = reader.readFloat();
this.onGround = reader.readBoolean();
}
}

View File

@ -1,6 +1,6 @@
package fr.themode.minestom.net.packet.client.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketReader;
import fr.themode.minestom.net.packet.client.ClientPlayPacket;
public class ClientPlayerPacket extends ClientPlayPacket {
@ -8,7 +8,7 @@ public class ClientPlayerPacket extends ClientPlayPacket {
public boolean onGround;
@Override
public void read(Buffer buffer) {
this.onGround = buffer.getBoolean();
public void read(PacketReader reader) {
this.onGround = reader.readBoolean();
}
}

View File

@ -1,6 +1,6 @@
package fr.themode.minestom.net.packet.client.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketReader;
import fr.themode.minestom.net.packet.client.ClientPlayPacket;
public class ClientPlayerPositionAndLookPacket extends ClientPlayPacket {
@ -10,12 +10,12 @@ public class ClientPlayerPositionAndLookPacket extends ClientPlayPacket {
public boolean onGround;
@Override
public void read(Buffer buffer) {
this.x = buffer.getDouble();
this.y = buffer.getDouble();
this.z = buffer.getDouble();
this.yaw = buffer.getFloat();
this.pitch = buffer.getFloat();
this.onGround = buffer.getBoolean();
public void read(PacketReader reader) {
this.x = reader.readDouble();
this.y = reader.readDouble();
this.z = reader.readDouble();
this.yaw = reader.readFloat();
this.pitch = reader.readFloat();
this.onGround = reader.readBoolean();
}
}

View File

@ -1,6 +1,6 @@
package fr.themode.minestom.net.packet.client.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketReader;
import fr.themode.minestom.net.packet.client.ClientPlayPacket;
public class ClientPlayerPositionPacket extends ClientPlayPacket {
@ -9,10 +9,10 @@ public class ClientPlayerPositionPacket extends ClientPlayPacket {
public boolean onGround;
@Override
public void read(Buffer buffer) {
this.x = buffer.getDouble();
this.y = buffer.getDouble();
this.z = buffer.getDouble();
this.onGround = buffer.getBoolean();
public void read(PacketReader reader) {
this.x = reader.readDouble();
this.y = reader.readDouble();
this.z = reader.readDouble();
this.onGround = reader.readBoolean();
}
}

View File

@ -1,8 +1,7 @@
package fr.themode.minestom.net.packet.client.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketReader;
import fr.themode.minestom.net.packet.client.ClientPlayPacket;
import fr.themode.minestom.utils.Utils;
public class ClientPluginMessagePacket extends ClientPlayPacket {
@ -10,8 +9,8 @@ public class ClientPluginMessagePacket extends ClientPlayPacket {
private byte[] data;
@Override
public void read(Buffer buffer) {
this.identifier = Utils.readString(buffer);
this.data = buffer.getAllBytes();
public void read(PacketReader reader) {
this.identifier = reader.readSizedString();
this.data = reader.getRemainingBytes();
}
}

View File

@ -1,9 +1,8 @@
package fr.themode.minestom.net.packet.client.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.entity.Player;
import fr.themode.minestom.net.packet.PacketReader;
import fr.themode.minestom.net.packet.client.ClientPlayPacket;
import fr.themode.minestom.utils.Utils;
public class ClientSettingsPacket extends ClientPlayPacket {
@ -15,12 +14,12 @@ public class ClientSettingsPacket extends ClientPlayPacket {
public Player.MainHand mainHand;
@Override
public void read(Buffer buffer) {
this.locale = Utils.readString(buffer);
this.viewDistance = buffer.getByte();
this.chatMode = Player.ChatMode.values()[Utils.readVarInt(buffer)];
this.chatColors = buffer.getBoolean();
this.displayedSkinParts = buffer.getByte();
this.mainHand = Player.MainHand.values()[Utils.readVarInt(buffer)];
public void read(PacketReader reader) {
this.locale = reader.readSizedString();
this.viewDistance = reader.readByte();
this.chatMode = Player.ChatMode.values()[reader.readVarInt()];
this.chatColors = reader.readBoolean();
this.displayedSkinParts = reader.readByte();
this.mainHand = Player.MainHand.values()[reader.readVarInt()];
}
}

View File

@ -1,16 +1,15 @@
package fr.themode.minestom.net.packet.client.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketReader;
import fr.themode.minestom.net.packet.client.ClientPlayPacket;
import fr.themode.minestom.utils.Utils;
public class ClientStatusPacket extends ClientPlayPacket {
public Action action;
@Override
public void read(Buffer buffer) {
this.action = Action.values()[Utils.readVarInt(buffer)];
public void read(PacketReader reader) {
this.action = Action.values()[reader.readVarInt()];
}
public enum Action {

View File

@ -1,6 +1,6 @@
package fr.themode.minestom.net.packet.client.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketReader;
import fr.themode.minestom.net.packet.client.ClientPlayPacket;
public class ClientSteerVehiclePacket extends ClientPlayPacket {
@ -10,9 +10,9 @@ public class ClientSteerVehiclePacket extends ClientPlayPacket {
public byte flags;
@Override
public void read(Buffer buffer) {
this.sideways = buffer.getFloat();
this.forward = buffer.getFloat();
this.flags = buffer.getByte();
public void read(PacketReader reader) {
this.sideways = reader.readFloat();
this.forward = reader.readFloat();
this.flags = reader.readByte();
}
}

View File

@ -1,15 +1,14 @@
package fr.themode.minestom.net.packet.client.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketReader;
import fr.themode.minestom.net.packet.client.ClientPlayPacket;
import fr.themode.minestom.utils.Utils;
public class ClientTeleportConfirmPacket extends ClientPlayPacket {
public int teleportId;
@Override
public void read(Buffer buffer) {
this.teleportId = Utils.readVarInt(buffer);
public void read(PacketReader reader) {
this.teleportId = reader.readVarInt();
}
}

View File

@ -1,9 +1,8 @@
package fr.themode.minestom.net.packet.client.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.entity.Player;
import fr.themode.minestom.net.packet.PacketReader;
import fr.themode.minestom.net.packet.client.ClientPlayPacket;
import fr.themode.minestom.utils.Utils;
public class ClientUseEntityPacket extends ClientPlayPacket {
@ -15,16 +14,16 @@ public class ClientUseEntityPacket extends ClientPlayPacket {
public Player.Hand hand;
@Override
public void read(Buffer buffer) {
this.targetId = Utils.readVarInt(buffer);
this.type = Type.values()[Utils.readVarInt(buffer)];
public void read(PacketReader reader) {
this.targetId = reader.readVarInt();
this.type = Type.values()[reader.readVarInt()];
if (this.type == Type.INTERACT_AT) {
this.x = buffer.getFloat();
this.y = buffer.getFloat();
this.z = buffer.getFloat();
this.x = reader.readFloat();
this.y = reader.readFloat();
this.z = reader.readFloat();
}
if (type == Type.INTERACT || type == Type.INTERACT_AT)
this.hand = Player.Hand.values()[Utils.readVarInt(buffer)];
this.hand = Player.Hand.values()[reader.readVarInt()];
}
public enum Type {

View File

@ -1,16 +1,15 @@
package fr.themode.minestom.net.packet.client.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.entity.Player;
import fr.themode.minestom.net.packet.PacketReader;
import fr.themode.minestom.net.packet.client.ClientPlayPacket;
import fr.themode.minestom.utils.Utils;
public class ClientUseItemPacket extends ClientPlayPacket {
public Player.Hand hand;
@Override
public void read(Buffer buffer) {
this.hand = Player.Hand.values()[Utils.readVarInt(buffer)];
public void read(PacketReader reader) {
this.hand = Player.Hand.values()[reader.readVarInt()];
}
}

View File

@ -1,7 +1,7 @@
package fr.themode.minestom.net.packet.client.status;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.ConnectionManager;
import fr.themode.minestom.net.packet.PacketReader;
import fr.themode.minestom.net.packet.client.ClientPreplayPacket;
import fr.themode.minestom.net.packet.server.status.PongPacket;
import fr.themode.minestom.net.player.PlayerConnection;
@ -18,7 +18,7 @@ public class PingPacket implements ClientPreplayPacket {
}
@Override
public void read(Buffer buffer) {
this.number = buffer.getLong();
public void read(PacketReader reader) {
this.number = reader.readLong();
}
}

View File

@ -1,7 +1,7 @@
package fr.themode.minestom.net.packet.client.status;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.ConnectionManager;
import fr.themode.minestom.net.packet.PacketReader;
import fr.themode.minestom.net.packet.client.ClientPreplayPacket;
import fr.themode.minestom.net.packet.server.handshake.ResponsePacket;
import fr.themode.minestom.net.player.PlayerConnection;
@ -15,7 +15,7 @@ public class StatusRequestPacket implements ClientPreplayPacket {
}
@Override
public void read(Buffer buffer) {
public void read(PacketReader reader) {
// Empty
}
}

View File

@ -1,10 +1,10 @@
package fr.themode.minestom.net.packet.server;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
public interface ServerPacket {
void write(Buffer buffer);
void write(PacketWriter writer);
int getId();

View File

@ -1,8 +1,7 @@
package fr.themode.minestom.net.packet.server.handshake;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class ResponsePacket implements ServerPacket {
@ -28,8 +27,8 @@ public class ResponsePacket implements ServerPacket {
"}";
@Override
public void write(Buffer buffer) {
Utils.writeString(buffer, JSON_EXAMPLE);
public void write(PacketWriter writer) {
writer.writeSizedString(JSON_EXAMPLE);
}
@Override

View File

@ -1,9 +1,8 @@
package fr.themode.minestom.net.packet.server.login;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.entity.GameMode;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
import fr.themode.minestom.world.Dimension;
import fr.themode.minestom.world.LevelType;
@ -18,18 +17,18 @@ public class JoinGamePacket implements ServerPacket {
public boolean reducedDebugInfo = false;
@Override
public void write(Buffer buffer) {
public void write(PacketWriter writer) {
int gameModeId = gameMode.getId();
if (gameMode.isHardcore())
gameModeId |= 8;
buffer.putInt(entityId);
buffer.putByte((byte) gameModeId);
buffer.putInt(dimension.getId());
buffer.putByte(maxPlayers);
Utils.writeString(buffer, levelType.getType());
Utils.writeVarInt(buffer, viewDistance);
buffer.putBoolean(reducedDebugInfo);
writer.writeInt(entityId);
writer.writeByte((byte) gameModeId);
writer.writeInt(dimension.getId());
writer.writeByte(maxPlayers);
writer.writeSizedString(levelType.getType());
writer.writeVarInt(viewDistance);
writer.writeBoolean(reducedDebugInfo);
}
@Override

View File

@ -1,8 +1,7 @@
package fr.themode.minestom.net.packet.server.login;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
import java.util.UUID;
@ -22,9 +21,9 @@ public class LoginSuccessPacket implements ServerPacket {
}
@Override
public void write(Buffer buffer) {
Utils.writeString(buffer, uuid.toString()); // TODO mojang auth
Utils.writeString(buffer, username);
public void write(PacketWriter writer) {
writer.writeSizedString(uuid.toString()); // TODO mojang auth
writer.writeSizedString(username);
}
@Override

View File

@ -1,10 +1,9 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.client.play.ClientPlayerDiggingPacket;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.BlockPosition;
import fr.themode.minestom.utils.Utils;
public class AcknowledgePlayerDiggingPacket implements ServerPacket {
@ -14,11 +13,11 @@ public class AcknowledgePlayerDiggingPacket implements ServerPacket {
public boolean successful;
@Override
public void write(Buffer buffer) {
Utils.writePosition(buffer, blockPosition);
Utils.writeVarInt(buffer, blockStateId);
Utils.writeVarInt(buffer, status.ordinal());
buffer.putBoolean(successful);
public void write(PacketWriter writer) {
writer.writeBlockPosition(blockPosition);
writer.writeVarInt(blockStateId);
writer.writeVarInt(status.ordinal());
writer.writeBoolean(successful);
}
@Override

View File

@ -1,10 +1,9 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.chat.Chat;
import fr.themode.minestom.item.ItemStack;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class AdvancementsPacket implements ServerPacket {
@ -14,22 +13,19 @@ public class AdvancementsPacket implements ServerPacket {
public ProgressMapping[] progressMappings;
@Override
public void write(Buffer buffer) {
buffer.putBoolean(resetAdvancements);
public void write(PacketWriter writer) {
writer.writeBoolean(resetAdvancements);
Utils.writeVarInt(buffer, advancementMappings.length);
writer.writeVarInt(advancementMappings.length);
for (AdvancementMapping advancementMapping : advancementMappings) {
advancementMapping.write(buffer);
advancementMapping.write(writer);
}
Utils.writeVarInt(buffer, identifiersToRemove.length);
for (String identifierToRemove : identifiersToRemove) {
Utils.writeString(buffer, identifierToRemove);
}
writer.writeStringArray(identifiersToRemove);
Utils.writeVarInt(buffer, progressMappings.length);
writer.writeVarInt(progressMappings.length);
for (ProgressMapping progressMapping : progressMappings) {
progressMapping.write(buffer);
progressMapping.write(writer);
}
}
@ -47,9 +43,9 @@ public class AdvancementsPacket implements ServerPacket {
public String key;
public Advancement value;
private void write(Buffer buffer) {
Utils.writeString(buffer, key);
value.write(buffer);
private void write(PacketWriter writer) {
writer.writeSizedString(key);
value.write(writer);
}
}
@ -63,25 +59,23 @@ public class AdvancementsPacket implements ServerPacket {
public String[] criterions;
public Requirement[] requirements;
private void write(Buffer buffer) {
buffer.putBoolean(hasParent);
private void write(PacketWriter writer) {
writer.writeBoolean(hasParent);
if (identifier != null) {
Utils.writeString(buffer, identifier);
writer.writeSizedString(identifier);
}
buffer.putBoolean(hasDisplay);
writer.writeBoolean(hasDisplay);
if (hasDisplay) {
displayData.write(buffer);
displayData.write(writer);
}
Utils.writeVarInt(buffer, criterions.length);
for (String criterion : criterions) {
Utils.writeString(buffer, criterion);
}
writer.writeStringArray(criterions);
Utils.writeVarInt(buffer, requirements.length);
writer.writeVarInt(requirements.length);
for (Requirement requirement : requirements) {
requirement.write(buffer);
requirement.write(writer);
}
}
}
@ -96,17 +90,17 @@ public class AdvancementsPacket implements ServerPacket {
public float x;
public float y;
private void write(Buffer buffer) {
Utils.writeString(buffer, Chat.rawText(title));
Utils.writeString(buffer, Chat.rawText(description));
Utils.writeItemStack(buffer, icon);
Utils.writeVarInt(buffer, frameType.ordinal());
buffer.putInt(flags);
private void write(PacketWriter writer) {
writer.writeSizedString(Chat.rawText(title));
writer.writeSizedString(Chat.rawText(description));
writer.writeItemStack(icon);
writer.writeVarInt(frameType.ordinal());
writer.writeInt(flags);
if ((flags & 0x1) != 0) {
Utils.writeString(buffer, backgroundTexture);
writer.writeSizedString(backgroundTexture);
}
buffer.putFloat(x);
buffer.putFloat(y);
writer.writeFloat(x);
writer.writeFloat(y);
}
}
@ -115,10 +109,10 @@ public class AdvancementsPacket implements ServerPacket {
public String[] requirements;
private void write(Buffer buffer) {
Utils.writeVarInt(buffer, requirements.length);
private void write(PacketWriter writer) {
writer.writeVarInt(requirements.length);
for (String requirement : requirements) {
Utils.writeString(buffer, requirement);
writer.writeSizedString(requirement);
}
}
}
@ -127,19 +121,19 @@ public class AdvancementsPacket implements ServerPacket {
public String key;
public AdvancementProgress value;
private void write(Buffer buffer) {
Utils.writeString(buffer, key);
value.write(buffer);
private void write(PacketWriter writer) {
writer.writeSizedString(key);
value.write(writer);
}
}
public static class AdvancementProgress {
public Criteria[] criteria;
private void write(Buffer buffer) {
Utils.writeVarInt(buffer, criteria.length);
private void write(PacketWriter writer) {
writer.writeVarInt(criteria.length);
for (Criteria criterion : criteria) {
criterion.write(buffer);
criterion.write(writer);
}
}
}
@ -148,9 +142,9 @@ public class AdvancementsPacket implements ServerPacket {
public String criterionIdentifier;
public CriterionProgress criterionProgress;
private void write(Buffer buffer) {
Utils.writeString(buffer, criterionIdentifier);
criterionProgress.write(buffer);
private void write(PacketWriter writer) {
writer.writeSizedString(criterionIdentifier);
criterionProgress.write(writer);
}
}
@ -158,10 +152,10 @@ public class AdvancementsPacket implements ServerPacket {
public boolean achieved;
public long dateOfAchieving;
private void write(Buffer buffer) {
buffer.putBoolean(achieved);
private void write(PacketWriter writer) {
writer.writeBoolean(achieved);
if (dateOfAchieving != 0)
buffer.putLong(dateOfAchieving);
writer.writeLong(dateOfAchieving);
}
}

View File

@ -1,8 +1,7 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class AnimationPacket implements ServerPacket {
@ -10,9 +9,9 @@ public class AnimationPacket implements ServerPacket {
public Animation animation;
@Override
public void write(Buffer buffer) {
Utils.writeVarInt(buffer, entityId);
buffer.putByte((byte) animation.ordinal());
public void write(PacketWriter writer) {
writer.writeVarInt(entityId);
writer.writeByte((byte) animation.ordinal());
}
@Override

View File

@ -1,9 +1,8 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.BlockPosition;
import fr.themode.minestom.utils.Utils;
public class BlockActionPacket implements ServerPacket {
@ -13,11 +12,11 @@ public class BlockActionPacket implements ServerPacket {
public int blockId;
@Override
public void write(Buffer buffer) {
Utils.writePosition(buffer, blockPosition);
buffer.putByte(actionId);
buffer.putByte(actionParam);
Utils.writeVarInt(buffer, blockId);
public void write(PacketWriter writer) {
writer.writeBlockPosition(blockPosition);
writer.writeByte(actionId);
writer.writeByte(actionParam);
writer.writeVarInt(blockId);
}
@Override

View File

@ -1,9 +1,8 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.BlockPosition;
import fr.themode.minestom.utils.Utils;
public class BlockBreakAnimationPacket implements ServerPacket {
@ -12,10 +11,10 @@ public class BlockBreakAnimationPacket implements ServerPacket {
public byte destroyStage;
@Override
public void write(Buffer buffer) {
Utils.writeVarInt(buffer, entityId);
Utils.writePosition(buffer, blockPosition);
buffer.putByte(destroyStage);
public void write(PacketWriter writer) {
writer.writeVarInt(entityId);
writer.writeBlockPosition(blockPosition);
writer.writeByte(destroyStage);
}
@Override

View File

@ -1,9 +1,8 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.BlockPosition;
import fr.themode.minestom.utils.Utils;
public class BlockChangePacket implements ServerPacket {
@ -11,9 +10,9 @@ public class BlockChangePacket implements ServerPacket {
public int blockId;
@Override
public void write(Buffer buffer) {
Utils.writePosition(buffer, blockPosition.getX(), blockPosition.getY(), blockPosition.getZ());
Utils.writeVarInt(buffer, blockId);
public void write(PacketWriter writer) {
writer.writeBlockPosition(blockPosition);
writer.writeVarInt(blockId);
}
@Override

View File

@ -1,10 +1,9 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.bossbar.BarColor;
import fr.themode.minestom.bossbar.BarDivision;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
import java.util.UUID;
@ -21,33 +20,33 @@ public class BossBarPacket implements ServerPacket {
@Override
public void write(Buffer buffer) {
Utils.writeUuid(buffer, uuid);
Utils.writeVarInt(buffer, action.ordinal());
public void write(PacketWriter writer) {
writer.writeUuid(uuid);
writer.writeVarInt(action.ordinal());
switch (action) {
case ADD:
Utils.writeString(buffer, title);
buffer.putFloat(health);
Utils.writeVarInt(buffer, color.ordinal());
Utils.writeVarInt(buffer, division.ordinal());
buffer.putByte(flags);
writer.writeSizedString(title);
writer.writeFloat(health);
writer.writeVarInt(color.ordinal());
writer.writeVarInt(division.ordinal());
writer.writeByte(flags);
break;
case REMOVE:
break;
case UPDATE_HEALTH:
buffer.putFloat(health);
writer.writeFloat(health);
break;
case UPDATE_TITLE:
Utils.writeString(buffer, title);
writer.writeSizedString(title);
break;
case UPDATE_STYLE:
Utils.writeVarInt(buffer, color.ordinal());
Utils.writeVarInt(buffer, division.ordinal());
writer.writeVarInt(color.ordinal());
writer.writeVarInt(division.ordinal());
break;
case UPDATE_FLAGS:
buffer.putByte(flags);
writer.writeByte(flags);
break;
}
}

View File

@ -1,6 +1,6 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
public class ChangeGameStatePacket implements ServerPacket {
@ -9,9 +9,9 @@ public class ChangeGameStatePacket implements ServerPacket {
public float value;
@Override
public void write(Buffer buffer) {
buffer.putByte((byte) reason.ordinal());
buffer.putFloat(value);
public void write(PacketWriter writer) {
writer.writeByte((byte) reason.ordinal());
writer.writeFloat(value);
}
@Override

View File

@ -1,8 +1,7 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class ChatMessagePacket implements ServerPacket {
@ -15,9 +14,9 @@ public class ChatMessagePacket implements ServerPacket {
}
@Override
public void write(Buffer buffer) {
Utils.writeString(buffer, this.message);
buffer.putByte((byte) this.position.ordinal());
public void write(PacketWriter writer) {
writer.writeSizedString(message);
writer.writeByte((byte) position.ordinal());
}
@Override

View File

@ -2,6 +2,7 @@ package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.instance.Chunk;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.BlockPosition;
import fr.themode.minestom.utils.SerializerUtils;
@ -19,13 +20,12 @@ public class ChunkDataPacket implements ServerPacket {
public boolean fullChunk;
public Chunk chunk;
// TODO nbt tile entities
@Override
public void write(Buffer buffer) {
buffer.putInt(chunk.getChunkX());
buffer.putInt(chunk.getChunkZ());
buffer.putBoolean(fullChunk);
public void write(PacketWriter writer) {
writer.writeInt(chunk.getChunkX());
writer.writeInt(chunk.getChunkZ());
writer.writeBoolean(fullChunk);
int mask = 0;
@ -48,7 +48,7 @@ public class ChunkDataPacket implements ServerPacket {
blocks.putInt(biomeData[i]);
}
}
Utils.writeVarInt(buffer, mask);
writer.writeVarInt(mask);
// Heightmap
int[] motionBlocking = new int[16 * 16];
@ -71,15 +71,15 @@ public class ChunkDataPacket implements ServerPacket {
e.printStackTrace();
}
byte[] data = outputStream.toByteArray();
buffer.putBytes(data);
writer.writeBytes(data);
}
Utils.writeVarInt(buffer, blocks.length());
buffer.putBuffer(blocks);
writer.writeVarInt(blocks.length());
writer.writeBuffer(blocks);
// Block entities
Set<Integer> blockEntities = chunk.getBlockEntities();
Utils.writeVarInt(buffer, blockEntities.size());
writer.writeVarInt(blockEntities.size());
for (Integer index : blockEntities) {
BlockPosition blockPosition = SerializerUtils.indexToChunkBlockPosition(index);
@ -94,7 +94,7 @@ public class ChunkDataPacket implements ServerPacket {
e.printStackTrace();
}
byte[] d = os.toByteArray();
buffer.putBytes(d);
writer.writeBytes(d);
}
}

View File

@ -1,16 +1,15 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class CloseWindowPacket implements ServerPacket {
public int windowId;
@Override
public void write(Buffer buffer) {
Utils.writeVarInt(buffer, windowId);
public void write(PacketWriter writer) {
writer.writeVarInt(windowId);
}
@Override

View File

@ -1,8 +1,7 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class CollectItemPacket implements ServerPacket {
@ -11,10 +10,10 @@ public class CollectItemPacket implements ServerPacket {
public int pickupItemCount;
@Override
public void write(Buffer buffer) {
Utils.writeVarInt(buffer, collectedEntityId);
Utils.writeVarInt(buffer, collectorEntityId);
Utils.writeVarInt(buffer, pickupItemCount);
public void write(PacketWriter writer) {
writer.writeVarInt(collectedEntityId);
writer.writeVarInt(collectorEntityId);
writer.writeVarInt(pickupItemCount);
}
@Override

View File

@ -1,8 +1,7 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class ConfirmTransactionPacket implements ServerPacket {
@ -11,10 +10,10 @@ public class ConfirmTransactionPacket implements ServerPacket {
public boolean accepted;
@Override
public void write(Buffer buffer) {
Utils.writeVarInt(buffer, windowId);
buffer.putShort(actionNumber);
buffer.putBoolean(accepted);
public void write(PacketWriter writer) {
writer.writeVarInt(windowId);
writer.writeShort(actionNumber);
writer.writeBoolean(accepted);
}
@Override

View File

@ -1,8 +1,7 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
import java.util.function.Consumer;
@ -13,12 +12,12 @@ public class DeclareCommandsPacket implements ServerPacket {
public int rootIndex;
@Override
public void write(Buffer buffer) {
Utils.writeVarInt(buffer, nodes.length);
public void write(PacketWriter writer) {
writer.writeVarInt(nodes.length);
for (Node node : nodes) {
node.write(buffer);
node.write(writer);
}
Utils.writeVarInt(buffer, rootIndex);
writer.writeVarInt(rootIndex);
}
@Override
@ -33,33 +32,31 @@ public class DeclareCommandsPacket implements ServerPacket {
public int redirectedNode; // Only if flags & 0x08
public String name; // Only for literal and argument
public String parser; // Only for argument
public Consumer<Buffer> properties; // Only for argument
public Consumer<PacketWriter> properties; // Only for argument
public String suggestionsType; // Only if flags 0x10
private void write(Buffer buffer) {
buffer.putByte(flags);
Utils.writeVarInt(buffer, children.length);
for (int child : children) {
Utils.writeVarInt(buffer, child);
}
private void write(PacketWriter writer) {
writer.writeByte(flags);
writer.writeVarIntArray(children);
if ((flags & 0x08) != 0) {
Utils.writeVarInt(buffer, redirectedNode);
writer.writeVarInt(redirectedNode);
}
if (isLiteral() || isArgument()) {
Utils.writeString(buffer, name);
writer.writeSizedString(name);
}
if (isArgument()) {
Utils.writeString(buffer, parser);
writer.writeSizedString(parser);
if (properties != null) {
properties.accept(buffer);
properties.accept(writer);
}
}
if ((flags & 0x10) != 0) {
Utils.writeString(buffer, suggestionsType);
writer.writeSizedString(suggestionsType);
}
}

View File

@ -1,20 +1,15 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class DestroyEntitiesPacket implements ServerPacket {
public int[] entityIds;
@Override
public void write(Buffer buffer) {
Utils.writeVarInt(buffer, entityIds.length);
for (int i = 0; i < entityIds.length; i++) {
int entityId = entityIds[i];
Utils.writeVarInt(buffer, entityId);
}
public void write(PacketWriter writer) {
writer.writeVarIntArray(entityIds);
}
@Override

View File

@ -1,17 +1,16 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.chat.Chat;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class DisconnectPacket implements ServerPacket {
public String message;
@Override
public void write(Buffer buffer) {
Utils.writeString(buffer, Chat.rawText(message));
public void write(PacketWriter writer) {
writer.writeSizedString(Chat.rawText(message));
}
@Override

View File

@ -1,8 +1,7 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class DisplayScoreboardPacket implements ServerPacket {
@ -10,9 +9,9 @@ public class DisplayScoreboardPacket implements ServerPacket {
public String scoreName;
@Override
public void write(Buffer buffer) {
buffer.putByte(position);
Utils.writeString(buffer, scoreName);
public void write(PacketWriter writer) {
writer.writeByte(position);
writer.writeSizedString(scoreName);
}
@Override

View File

@ -1,8 +1,7 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class EntityEffectPacket implements ServerPacket {
@ -13,12 +12,12 @@ public class EntityEffectPacket implements ServerPacket {
public byte flags;
@Override
public void write(Buffer buffer) {
Utils.writeVarInt(buffer, entityId);
buffer.putByte(effectId);
buffer.putByte(amplifier);
Utils.writeVarInt(buffer, duration);
buffer.putByte(flags);
public void write(PacketWriter writer) {
writer.writeVarInt(entityId);
writer.writeByte(effectId);
writer.writeByte(amplifier);
writer.writeVarInt(duration);
writer.writeByte(flags);
}
@Override

View File

@ -1,9 +1,8 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.item.ItemStack;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class EntityEquipmentPacket implements ServerPacket {
@ -12,10 +11,10 @@ public class EntityEquipmentPacket implements ServerPacket {
public ItemStack itemStack;
@Override
public void write(Buffer buffer) {
Utils.writeVarInt(buffer, entityId);
Utils.writeVarInt(buffer, slot.ordinal());
Utils.writeItemStack(buffer, itemStack);
public void write(PacketWriter writer) {
writer.writeVarInt(entityId);
writer.writeVarInt(slot.ordinal());
writer.writeItemStack(itemStack);
}
@Override

View File

@ -1,8 +1,7 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class EntityHeadLookPacket implements ServerPacket {
@ -10,9 +9,9 @@ public class EntityHeadLookPacket implements ServerPacket {
public float yaw;
@Override
public void write(Buffer buffer) {
Utils.writeVarInt(buffer, entityId);
buffer.putByte((byte) (this.yaw * 256 / 360));
public void write(PacketWriter writer) {
writer.writeVarInt(entityId);
writer.writeByte((byte) (this.yaw * 256 / 360));
}
@Override

View File

@ -1,8 +1,7 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class EntityLookAndRelativeMovePacket implements ServerPacket {
@ -12,14 +11,14 @@ public class EntityLookAndRelativeMovePacket implements ServerPacket {
public boolean onGround;
@Override
public void write(Buffer buffer) {
Utils.writeVarInt(buffer, entityId);
buffer.putShort(deltaX);
buffer.putShort(deltaY);
buffer.putShort(deltaZ);
buffer.putByte((byte) (this.yaw * 256 / 360));
buffer.putByte((byte) (this.pitch * 256 / 360));
buffer.putBoolean(onGround);
public void write(PacketWriter writer) {
writer.writeVarInt(entityId);
writer.writeShort(deltaX);
writer.writeShort(deltaY);
writer.writeShort(deltaZ);
writer.writeByte((byte) (yaw * 256 / 360));
writer.writeByte((byte) (pitch * 256 / 360));
writer.writeBoolean(onGround);
}

View File

@ -1,8 +1,7 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class EntityLookPacket implements ServerPacket {
@ -11,11 +10,11 @@ public class EntityLookPacket implements ServerPacket {
public boolean onGround;
@Override
public void write(Buffer buffer) {
Utils.writeVarInt(buffer, entityId);
buffer.putByte((byte) (this.yaw * 256 / 360));
buffer.putByte((byte) (this.pitch * 256 / 360));
buffer.putBoolean(onGround);
public void write(PacketWriter writer) {
writer.writeVarInt(entityId);
writer.writeByte((byte) (yaw * 256 / 360));
writer.writeByte((byte) (pitch * 256 / 360));
writer.writeBoolean(onGround);
}
@Override

View File

@ -1,8 +1,8 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class EntityMetaDataPacket implements ServerPacket {
@ -10,10 +10,10 @@ public class EntityMetaDataPacket implements ServerPacket {
public Buffer data;
@Override
public void write(Buffer buffer) {
Utils.writeVarInt(buffer, entityId);
buffer.putBuffer(data);
buffer.putByte((byte) 0xFF);
public void write(PacketWriter writer) {
writer.writeVarInt(entityId);
writer.writeBuffer(data);
writer.writeByte((byte) 0xFF);
}
@Override

View File

@ -1,16 +1,15 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class EntityPacket implements ServerPacket {
public int entityId;
@Override
public void write(Buffer buffer) {
Utils.writeVarInt(buffer, entityId);
public void write(PacketWriter writer) {
writer.writeVarInt(entityId);
}
@Override

View File

@ -1,8 +1,7 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class EntityPropertiesPacket implements ServerPacket {
@ -11,11 +10,11 @@ public class EntityPropertiesPacket implements ServerPacket {
@Override
public void write(Buffer buffer) {
Utils.writeVarInt(buffer, entityId);
buffer.putInt(properties.length);
public void write(PacketWriter writer) {
writer.writeVarInt(entityId);
writer.writeInt(properties.length);
for (Property property : properties) {
property.write(buffer);
property.write(writer);
}
}
@ -29,12 +28,12 @@ public class EntityPropertiesPacket implements ServerPacket {
public String key;
public double value;
private void write(Buffer buffer) {
Utils.writeString(buffer, key);
buffer.putDouble(value);
private void write(PacketWriter writer) {
writer.writeSizedString(key);
writer.writeDouble(value);
// TODO Modifiers
Utils.writeVarInt(buffer, 0);
// TODO modifiers
writer.writeVarInt(0);
}
}

View File

@ -1,8 +1,7 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class EntityRelativeMovePacket implements ServerPacket {
@ -11,12 +10,12 @@ public class EntityRelativeMovePacket implements ServerPacket {
public boolean onGround;
@Override
public void write(Buffer buffer) {
Utils.writeVarInt(buffer, entityId);
buffer.putShort(deltaX);
buffer.putShort(deltaY);
buffer.putShort(deltaZ);
buffer.putBoolean(onGround);
public void write(PacketWriter writer) {
writer.writeVarInt(entityId);
writer.writeShort(deltaX);
writer.writeShort(deltaY);
writer.writeShort(deltaZ);
writer.writeBoolean(onGround);
}
@Override

View File

@ -1,6 +1,6 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
public class EntityStatusPacket implements ServerPacket {
@ -9,9 +9,9 @@ public class EntityStatusPacket implements ServerPacket {
public byte status;
@Override
public void write(Buffer buffer) {
buffer.putInt(entityId);
buffer.putByte(status);
public void write(PacketWriter writer) {
writer.writeInt(entityId);
writer.writeByte(status);
}
@Override

View File

@ -1,9 +1,8 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Position;
import fr.themode.minestom.utils.Utils;
public class EntityTeleportPacket implements ServerPacket {
@ -12,14 +11,14 @@ public class EntityTeleportPacket implements ServerPacket {
public boolean onGround;
@Override
public void write(Buffer buffer) {
Utils.writeVarInt(buffer, entityId);
buffer.putDouble(position.getX());
buffer.putDouble(position.getY());
buffer.putDouble(position.getZ());
buffer.putByte((byte) (position.getYaw() * 256f / 360f));
buffer.putByte((byte) (position.getPitch() * 256f / 360f));
buffer.putBoolean(onGround);
public void write(PacketWriter writer) {
writer.writeVarInt(entityId);
writer.writeDouble(position.getX());
writer.writeDouble(position.getY());
writer.writeDouble(position.getZ());
writer.writeByte((byte) (position.getYaw() * 256f / 360f));
writer.writeByte((byte) (position.getPitch() * 256f / 360f));
writer.writeBoolean(onGround);
}
@Override

View File

@ -1,8 +1,7 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class EntityVelocityPacket implements ServerPacket {
@ -10,11 +9,11 @@ public class EntityVelocityPacket implements ServerPacket {
public short velocityX, velocityY, velocityZ;
@Override
public void write(Buffer buffer) {
Utils.writeVarInt(buffer, entityId);
buffer.putShort(velocityX);
buffer.putShort(velocityY);
buffer.putShort(velocityZ);
public void write(PacketWriter writer) {
writer.writeVarInt(entityId);
writer.writeShort(velocityX);
writer.writeShort(velocityY);
writer.writeShort(velocityZ);
}
@Override

View File

@ -1,6 +1,6 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
public class ExplosionPacket implements ServerPacket {
@ -11,17 +11,17 @@ public class ExplosionPacket implements ServerPacket {
public float playerMotionX, playerMotionY, playerMotionZ;
@Override
public void write(Buffer buffer) {
buffer.putFloat(x);
buffer.putFloat(y);
buffer.putFloat(z);
buffer.putFloat(radius);
buffer.putInt(records.length);
public void write(PacketWriter writer) {
writer.writeFloat(x);
writer.writeFloat(y);
writer.writeFloat(z);
writer.writeFloat(radius);
writer.writeInt(records.length);
for (byte record : records)
buffer.putByte(record);
buffer.putFloat(playerMotionX);
buffer.putFloat(playerMotionY);
buffer.putFloat(playerMotionZ);
writer.writeByte(record);
writer.writeFloat(playerMotionX);
writer.writeFloat(playerMotionY);
writer.writeFloat(playerMotionZ);
}
@Override

View File

@ -1,6 +1,6 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
public class HeldItemChangePacket implements ServerPacket {
@ -8,8 +8,8 @@ public class HeldItemChangePacket implements ServerPacket {
public short slot;
@Override
public void write(Buffer buffer) {
buffer.putShort(slot);
public void write(PacketWriter writer) {
writer.writeShort(slot);
}
@Override

View File

@ -1,6 +1,6 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
public class KeepAlivePacket implements ServerPacket {
@ -12,8 +12,8 @@ public class KeepAlivePacket implements ServerPacket {
}
@Override
public void write(Buffer buffer) {
buffer.putLong(id);
public void write(PacketWriter writer) {
writer.writeLong(id);
}
@Override

View File

@ -1,8 +1,7 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class MultiBlockChangePacket implements ServerPacket {
@ -11,18 +10,21 @@ public class MultiBlockChangePacket implements ServerPacket {
public BlockChange[] blockChanges;
@Override
public void write(Buffer buffer) {
buffer.putInt(chunkX);
buffer.putInt(chunkZ);
Utils.writeVarInt(buffer, blockChanges == null ? 0 : blockChanges.length);
public void write(PacketWriter writer) {
writer.writeInt(chunkX);
writer.writeInt(chunkZ);
if (blockChanges != null) {
for (int i = 0; i < blockChanges.length; i++) {
int length = blockChanges.length;
writer.writeVarInt(length);
for (int i = 0; i < length; i++) {
BlockChange blockChange = blockChanges[i];
buffer.putByte(blockChange.positionXZ);
buffer.putByte(blockChange.positionY);
Utils.writeVarInt(buffer, blockChange.newBlockId);
writer.writeByte(blockChange.positionXZ);
writer.writeByte(blockChange.positionY);
writer.writeVarInt(blockChange.newBlockId);
}
} else {
writer.writeVarInt(0);
}
}

View File

@ -1,8 +1,7 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class OpenWindowPacket implements ServerPacket {
@ -11,10 +10,10 @@ public class OpenWindowPacket implements ServerPacket {
public String title;
@Override
public void write(Buffer buffer) {
Utils.writeVarInt(buffer, windowId);
Utils.writeVarInt(buffer, windowType);
Utils.writeString(buffer, "{\"text\": \"" + title + " \"}");
public void write(PacketWriter writer) {
writer.writeVarInt(windowId);
writer.writeVarInt(windowType);
writer.writeSizedString("{\"text\": \"" + title + " \"}");
}
@Override

View File

@ -1,8 +1,7 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class ParticlePacket implements ServerPacket {
@ -16,19 +15,19 @@ public class ParticlePacket implements ServerPacket {
public int blockId;
@Override
public void write(Buffer buffer) {
buffer.putInt(particleId);
buffer.putBoolean(longDistance);
buffer.putFloat(x);
buffer.putFloat(y);
buffer.putFloat(z);
buffer.putFloat(offsetX);
buffer.putFloat(offsetY);
buffer.putFloat(offsetZ);
buffer.putFloat(particleData);
buffer.putInt(particleCount);
public void write(PacketWriter writer) {
writer.writeInt(particleId);
writer.writeBoolean(longDistance);
writer.writeFloat(x);
writer.writeFloat(y);
writer.writeFloat(z);
writer.writeFloat(offsetX);
writer.writeFloat(offsetY);
writer.writeFloat(offsetZ);
writer.writeFloat(particleData);
writer.writeInt(particleCount);
if (particleId == 3)
Utils.writeVarInt(buffer, blockId);
writer.writeVarInt(blockId);
}
@Override

View File

@ -1,9 +1,8 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.entity.GameMode;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
import java.util.ArrayList;
import java.util.UUID;
@ -19,14 +18,14 @@ public class PlayerInfoPacket implements ServerPacket {
}
@Override
public void write(Buffer buffer) {
Utils.writeVarInt(buffer, this.action.ordinal());
Utils.writeVarInt(buffer, this.playerInfos.size());
public void write(PacketWriter writer) {
writer.writeVarInt(action.ordinal());
writer.writeVarInt(playerInfos.size());
for (PlayerInfo playerInfo : this.playerInfos) {
if (!playerInfo.getClass().equals(action.getClazz())) continue;
buffer.putLong(playerInfo.uuid.getMostSignificantBits());
buffer.putLong(playerInfo.uuid.getLeastSignificantBits());
playerInfo.write(buffer);
writer.writeUuid(playerInfo.uuid);
playerInfo.write(writer);
}
}
@ -62,7 +61,7 @@ public class PlayerInfoPacket implements ServerPacket {
this.uuid = uuid;
}
public abstract void write(Buffer buffer);
public abstract void write(PacketWriter writer);
}
public static class AddPlayer extends PlayerInfo {
@ -83,17 +82,17 @@ public class PlayerInfoPacket implements ServerPacket {
}
@Override
public void write(Buffer buffer) {
Utils.writeString(buffer, name);
Utils.writeVarInt(buffer, properties.size());
public void write(PacketWriter writer) {
writer.writeSizedString(name);
writer.writeVarInt(properties.size());
for (Property property : properties) {
property.write(buffer);
property.write(writer);
}
Utils.writeVarInt(buffer, gameMode.getId());
Utils.writeVarInt(buffer, ping);
buffer.putBoolean(hasDisplayName);
writer.writeVarInt(gameMode.getId());
writer.writeVarInt(ping);
writer.writeBoolean(hasDisplayName);
if (hasDisplayName)
Utils.writeString(buffer, displayName);
writer.writeSizedString(displayName);
}
public static class Property {
@ -108,12 +107,12 @@ public class PlayerInfoPacket implements ServerPacket {
this.value = value;
}
public void write(Buffer buffer) {
Utils.writeString(buffer, name);
Utils.writeString(buffer, value);
buffer.putBoolean(signed);
public void write(PacketWriter writer) {
writer.writeSizedString(name);
writer.writeSizedString(value);
writer.writeBoolean(signed);
if (signed)
Utils.writeString(buffer, signature);
writer.writeSizedString(signature);
}
}
}
@ -128,8 +127,8 @@ public class PlayerInfoPacket implements ServerPacket {
}
@Override
public void write(Buffer buffer) {
Utils.writeVarInt(buffer, gameMode.getId());
public void write(PacketWriter writer) {
writer.writeVarInt(gameMode.getId());
}
}
@ -143,8 +142,8 @@ public class PlayerInfoPacket implements ServerPacket {
}
@Override
public void write(Buffer buffer) {
Utils.writeVarInt(buffer, ping);
public void write(PacketWriter writer) {
writer.writeVarInt(ping);
}
}
@ -158,9 +157,9 @@ public class PlayerInfoPacket implements ServerPacket {
}
@Override
public void write(Buffer buffer) {
buffer.putBoolean(true); // ????
Utils.writeString(buffer, displayName);
public void write(PacketWriter writer) {
writer.writeBoolean(true); // ????
writer.writeSizedString(displayName);
}
}
@ -171,7 +170,7 @@ public class PlayerInfoPacket implements ServerPacket {
}
@Override
public void write(Buffer buffer) {
public void write(PacketWriter writer) {
}
}
}

View File

@ -1,9 +1,8 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Position;
import fr.themode.minestom.utils.Utils;
public class PlayerPositionAndLookPacket implements ServerPacket {
@ -13,14 +12,14 @@ public class PlayerPositionAndLookPacket implements ServerPacket {
@Override
public void write(Buffer buffer) {
buffer.putDouble(position.getX());
buffer.putDouble(position.getY());
buffer.putDouble(position.getZ());
buffer.putFloat(position.getYaw());
buffer.putFloat(position.getPitch());
buffer.putBytes(flags);
Utils.writeVarInt(buffer, teleportId);
public void write(PacketWriter writer) {
writer.writeDouble(position.getX());
writer.writeDouble(position.getY());
writer.writeDouble(position.getZ());
writer.writeFloat(position.getYaw());
writer.writeFloat(position.getPitch());
writer.writeByte(flags);
writer.writeVarInt(teleportId);
}
@Override

View File

@ -1,8 +1,7 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class RemoveEntityEffectPacket implements ServerPacket {
@ -10,9 +9,9 @@ public class RemoveEntityEffectPacket implements ServerPacket {
public byte effectId;
@Override
public void write(Buffer buffer) {
Utils.writeVarInt(buffer, entityId);
buffer.putByte(effectId);
public void write(PacketWriter writer) {
writer.writeVarInt(entityId);
writer.writeByte(effectId);
}
@Override

View File

@ -1,9 +1,8 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.entity.GameMode;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
import fr.themode.minestom.world.Dimension;
import fr.themode.minestom.world.LevelType;
@ -14,14 +13,14 @@ public class RespawnPacket implements ServerPacket {
public LevelType levelType;
@Override
public void write(Buffer buffer) {
public void write(PacketWriter writer) {
int gameModeId = gameMode.getId();
if (gameMode.isHardcore())
gameModeId |= 8;
buffer.putByte((byte) gameModeId);
buffer.putInt(dimension.getId());
Utils.writeString(buffer, levelType.getType());
writer.writeByte((byte) gameModeId);
writer.writeInt(dimension.getId());
writer.writeSizedString(levelType.getType());
}
@Override

View File

@ -1,8 +1,7 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class ScoreboardObjectivePacket implements ServerPacket {
@ -12,12 +11,13 @@ public class ScoreboardObjectivePacket implements ServerPacket {
public int type;
@Override
public void write(Buffer buffer) {
Utils.writeString(buffer, objectiveName);
buffer.putByte(mode);
public void write(PacketWriter writer) {
writer.writeSizedString(objectiveName);
writer.writeByte(mode);
if (mode == 0 || mode == 2) {
Utils.writeString(buffer, objectiveValue);
Utils.writeVarInt(buffer, type);
writer.writeSizedString(objectiveValue);
writer.writeVarInt(type);
}
}

View File

@ -1,8 +1,7 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class SetExperiencePacket implements ServerPacket {
@ -11,10 +10,10 @@ public class SetExperiencePacket implements ServerPacket {
public int totalExperience;
@Override
public void write(Buffer buffer) {
buffer.putFloat(percentage);
Utils.writeVarInt(buffer, level);
Utils.writeVarInt(buffer, totalExperience);
public void write(PacketWriter writer) {
writer.writeFloat(percentage);
writer.writeVarInt(level);
writer.writeVarInt(totalExperience);
}
@Override

View File

@ -1,8 +1,7 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class SetPassengersPacket implements ServerPacket {
@ -10,12 +9,9 @@ public class SetPassengersPacket implements ServerPacket {
public int[] passengersId;
@Override
public void write(Buffer buffer) {
Utils.writeVarInt(buffer, vehicleEntityId);
Utils.writeVarInt(buffer, passengersId.length);
for (int passengerId : passengersId) {
Utils.writeVarInt(buffer, passengerId);
}
public void write(PacketWriter writer) {
writer.writeVarInt(vehicleEntityId);
writer.writeVarIntArray(passengersId);
}
@Override

View File

@ -1,9 +1,8 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.item.ItemStack;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class SetSlotPacket implements ServerPacket {
@ -12,10 +11,10 @@ public class SetSlotPacket implements ServerPacket {
public ItemStack itemStack;
@Override
public void write(Buffer buffer) {
buffer.putByte(windowId);
buffer.putShort(slot);
Utils.writeItemStack(buffer, itemStack);
public void write(PacketWriter writer) {
writer.writeByte(windowId);
writer.writeShort(slot);
writer.writeItemStack(itemStack);
}
@Override

View File

@ -0,0 +1,26 @@
package fr.themode.minestom.net.packet.server.play;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Position;
public class SpawnExperienceOrbPacket implements ServerPacket {
public int entityId;
public Position position;
public short expCount;
@Override
public void write(PacketWriter writer) {
writer.writeVarInt(entityId);
writer.writeDouble(position.getX());
writer.writeDouble(position.getY());
writer.writeDouble(position.getZ());
writer.writeShort(expCount);
}
@Override
public int getId() {
return 0x01;
}
}

View File

@ -1,9 +1,9 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Position;
import fr.themode.minestom.utils.Utils;
import java.util.UUID;
@ -15,23 +15,27 @@ public class SpawnMobPacket implements ServerPacket {
public Position position;
public float headPitch;
public short velocityX, velocityY, velocityZ;
// TODO metadata
public Buffer metadata;
@Override
public void write(Buffer buffer) {
Utils.writeVarInt(buffer, entityId);
Utils.writeUuid(buffer, entityUuid);
Utils.writeVarInt(buffer, entityType);
buffer.putDouble(position.getX());
buffer.putDouble(position.getY());
buffer.putDouble(position.getZ());
buffer.putFloat(position.getYaw());
buffer.putFloat(position.getPitch());
buffer.putFloat(headPitch);
buffer.putShort(velocityX);
buffer.putShort(velocityY);
buffer.putShort(velocityZ);
buffer.putByte((byte) 0xff); // TODO metadata
public void write(PacketWriter writer) {
writer.writeVarInt(entityId);
writer.writeUuid(entityUuid);
writer.writeVarInt(entityType);
writer.writeDouble(position.getX());
writer.writeDouble(position.getY());
writer.writeDouble(position.getZ());
writer.writeFloat(position.getYaw());
writer.writeFloat(position.getPitch());
writer.writeFloat(headPitch);
writer.writeShort(velocityX);
writer.writeShort(velocityY);
writer.writeShort(velocityZ);
if (metadata != null) {
writer.writeBuffer(metadata);
} else {
writer.writeByte((byte) 0xff);
}
}
@Override

View File

@ -1,9 +1,8 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Position;
import fr.themode.minestom.utils.Utils;
import java.util.UUID;
@ -16,16 +15,16 @@ public class SpawnObjectPacket implements ServerPacket {
public int data;
@Override
public void write(Buffer buffer) {
Utils.writeVarInt(buffer, entityId);
Utils.writeUuid(buffer, uuid);
Utils.writeVarInt(buffer, type);
buffer.putDouble(position.getX());
buffer.putDouble(position.getY());
buffer.putDouble(position.getZ());
buffer.putFloat(position.getYaw());
buffer.putFloat(position.getPitch());
buffer.putInt(data);
public void write(PacketWriter writer) {
writer.writeVarInt(entityId);
writer.writeUuid(uuid);
writer.writeVarInt(type);
writer.writeDouble(position.getX());
writer.writeDouble(position.getY());
writer.writeDouble(position.getZ());
writer.writeFloat(position.getYaw());
writer.writeFloat(position.getPitch());
writer.writeInt(data);
}
@Override

View File

@ -1,9 +1,9 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Position;
import fr.themode.minestom.utils.Utils;
import java.util.UUID;
@ -15,19 +15,19 @@ public class SpawnPlayerPacket implements ServerPacket {
public Buffer metadata;
@Override
public void write(Buffer buffer) {
Utils.writeVarInt(buffer, entityId);
buffer.putLong(playerUuid.getMostSignificantBits());
buffer.putLong(playerUuid.getLeastSignificantBits());
buffer.putDouble(position.getX());
buffer.putDouble(position.getY());
buffer.putDouble(position.getZ());
buffer.putByte((byte) (position.getYaw() * 256f / 360f));
buffer.putByte((byte) (position.getPitch() * 256f / 360f));
public void write(PacketWriter writer) {
writer.writeVarInt(entityId);
writer.writeUuid(playerUuid);
writer.writeDouble(position.getX());
writer.writeDouble(position.getY());
writer.writeDouble(position.getZ());
writer.writeByte((byte) (position.getYaw() * 256f / 360f));
writer.writeByte((byte) (position.getPitch() * 256f / 360f));
if (metadata != null) {
buffer.putBuffer(metadata);
writer.writeBuffer(metadata);
} else {
buffer.putByte((byte) 0xff);
writer.writeByte((byte) 0xff);
}
}

View File

@ -1,16 +1,15 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class SpawnPositionPacket implements ServerPacket {
public int x, y, z;
@Override
public void write(Buffer buffer) {
Utils.writePosition(buffer, x, y, z);
public void write(PacketWriter writer) {
writer.writeBlockPosition(x, y, z);
}
@Override

View File

@ -1,8 +1,7 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class TeamsPacket implements ServerPacket {
@ -20,20 +19,20 @@ public class TeamsPacket implements ServerPacket {
public String[] entities;
@Override
public void write(Buffer buffer) {
Utils.writeString(buffer, teamName);
buffer.putByte((byte) action.ordinal());
public void write(PacketWriter writer) {
writer.writeSizedString(teamName);
writer.writeByte((byte) action.ordinal());
switch (action) {
case CREATE_TEAM:
case UPDATE_TEAM_INFO:
Utils.writeString(buffer, teamDisplayName);
buffer.putByte(friendlyFlags);
Utils.writeString(buffer, nameTagVisibility);
Utils.writeString(buffer, collisionRule);
Utils.writeVarInt(buffer, teamColor);
Utils.writeString(buffer, teamPrefix);
Utils.writeString(buffer, teamSuffix);
writer.writeSizedString(teamDisplayName);
writer.writeByte(friendlyFlags);
writer.writeSizedString(nameTagVisibility);
writer.writeSizedString(collisionRule);
writer.writeVarInt(teamColor);
writer.writeSizedString(teamPrefix);
writer.writeSizedString(teamSuffix);
break;
case REMOVE_TEAM:
@ -41,15 +40,7 @@ public class TeamsPacket implements ServerPacket {
}
if (action == Action.CREATE_TEAM || action == Action.ADD_PLAYERS_TEAM || action == Action.REMOVE_PLAYERS_TEAM) {
if (entities == null) {
Utils.writeVarInt(buffer, 0);
return;
}
Utils.writeVarInt(buffer, entities.length);
for (String entity : entities) {
Utils.writeString(buffer, entity);
}
writer.writeStringArray(entities);
}
}

View File

@ -1,9 +1,8 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.item.ItemStack;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class TradeListPacket implements ServerPacket {
@ -15,16 +14,16 @@ public class TradeListPacket implements ServerPacket {
public boolean canRestock;
@Override
public void write(Buffer buffer) {
Utils.writeVarInt(buffer, windowId);
buffer.putByte((byte) trades.length);
public void write(PacketWriter writer) {
writer.writeVarInt(windowId);
writer.writeByte((byte) trades.length);
for (Trade trade : trades) {
trade.write(buffer);
trade.write(writer);
}
Utils.writeVarInt(buffer, villagerLevel);
Utils.writeVarInt(buffer, experience);
buffer.putBoolean(regularVillager);
buffer.putBoolean(canRestock);
writer.writeVarInt(villagerLevel);
writer.writeVarInt(experience);
writer.writeBoolean(regularVillager);
writer.writeBoolean(canRestock);
}
@Override
@ -46,19 +45,21 @@ public class TradeListPacket implements ServerPacket {
public int demand;
private void write(Buffer buffer) {
Utils.writeItemStack(buffer, inputItem1);
Utils.writeItemStack(buffer, result);
buffer.putBoolean(inputItem2 != null);
if (inputItem2 != null)
Utils.writeItemStack(buffer, inputItem2);
buffer.putBoolean(tradeDisabled);
buffer.putInt(tradeUsesNumber);
buffer.putInt(maxTradeUsesNumber);
buffer.putInt(exp);
buffer.putInt(specialPrice);
buffer.putFloat(priceMultiplier);
buffer.putInt(demand);
private void write(PacketWriter writer) {
boolean hasSecondItem = inputItem2 != null;
writer.writeItemStack(inputItem1);
writer.writeItemStack(result);
writer.writeBoolean(hasSecondItem);
if (hasSecondItem)
writer.writeItemStack(inputItem2);
writer.writeBoolean(tradeDisabled);
writer.writeInt(tradeUsesNumber);
writer.writeInt(maxTradeUsesNumber);
writer.writeInt(exp);
writer.writeInt(specialPrice);
writer.writeFloat(priceMultiplier);
writer.writeInt(demand);
}
}

View File

@ -1,6 +1,6 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
public class UnloadChunkPacket implements ServerPacket {
@ -8,9 +8,9 @@ public class UnloadChunkPacket implements ServerPacket {
public int chunkX, chunkZ;
@Override
public void write(Buffer buffer) {
buffer.putInt(chunkX);
buffer.putInt(chunkZ);
public void write(PacketWriter writer) {
writer.writeInt(chunkX);
writer.writeInt(chunkZ);
}
@Override

View File

@ -1,8 +1,7 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class UpdateHealthPacket implements ServerPacket {
@ -11,10 +10,10 @@ public class UpdateHealthPacket implements ServerPacket {
public float foodSaturation;
@Override
public void write(Buffer buffer) {
buffer.putFloat(health);
Utils.writeVarInt(buffer, food);
buffer.putFloat(foodSaturation);
public void write(PacketWriter writer) {
writer.writeFloat(health);
writer.writeVarInt(food);
writer.writeFloat(foodSaturation);
}
@Override

View File

@ -1,8 +1,7 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class UpdateScorePacket implements ServerPacket {
@ -12,12 +11,12 @@ public class UpdateScorePacket implements ServerPacket {
public int value;
@Override
public void write(Buffer buffer) {
Utils.writeString(buffer, entityName);
buffer.putByte(action);
Utils.writeString(buffer, objectiveName);
public void write(PacketWriter writer) {
writer.writeSizedString(entityName);
writer.writeByte(action);
writer.writeSizedString(objectiveName);
if (action != 1) {
Utils.writeVarInt(buffer, value);
writer.writeVarInt(value);
}
}

View File

@ -1,9 +1,8 @@
package fr.themode.minestom.net.packet.server.play;
import fr.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.instance.Chunk;
import fr.themode.minestom.net.packet.PacketWriter;
import fr.themode.minestom.net.packet.server.ServerPacket;
import fr.themode.minestom.utils.Utils;
public class UpdateViewPositionPacket implements ServerPacket {
@ -14,9 +13,9 @@ public class UpdateViewPositionPacket implements ServerPacket {
}
@Override
public void write(Buffer buffer) {
Utils.writeVarInt(buffer, chunk.getChunkX());
Utils.writeVarInt(buffer, chunk.getChunkZ());
public void write(PacketWriter writer) {
writer.writeVarInt(chunk.getChunkX());
writer.writeVarInt(chunk.getChunkZ());
}
@Override

Some files were not shown because too many files have changed in this diff Show More