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

View File

@ -1,6 +1,8 @@
package fr.themode.minestom.collision; package fr.themode.minestom.collision;
import fr.themode.minestom.entity.Entity; 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 * See https://wiki.vg/Entity_metadata#Mobs_2
@ -23,6 +25,31 @@ public class BoundingBox {
(getMinZ() <= boundingBox.getMaxZ() && getMaxZ() >= boundingBox.getMinZ()); (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) { public BoundingBox expand(float x, float y, float z) {
return new BoundingBox(entity, this.x + x, this.y + y, this.z + 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); 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); player.viewableEntity.add(this);
PlayerConnection playerConnection = player.getPlayerConnection(); PlayerConnection playerConnection = player.getPlayerConnection();
playerConnection.sendPacket(getVelocityPacket()); playerConnection.sendPacket(getVelocityPacket());
playerConnection.sendPacket(getPassengersPacket()); // TODO fix synchronization playerConnection.sendPacket(getPassengersPacket());
} }
@Override @Override

View File

@ -94,9 +94,9 @@ public abstract class EntityCreature extends LivingEntity {
spawnMobPacket.entityType = getEntityType(); spawnMobPacket.entityType = getEntityType();
spawnMobPacket.position = getPosition(); spawnMobPacket.position = getPosition();
spawnMobPacket.headPitch = 0; spawnMobPacket.headPitch = 0;
spawnMobPacket.metadata = getMetadataBuffer();
playerConnection.sendPacket(entityPacket); playerConnection.sendPacket(entityPacket);
playerConnection.sendPacket(spawnMobPacket); playerConnection.sendPacket(spawnMobPacket);
playerConnection.sendPacket(getMetadataPacket());
} }
@Override @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.collectorEntityId = getEntityId();
collectItemPacket.pickupItemCount = item.getAmount(); collectItemPacket.pickupItemCount = item.getAmount();
sendPacketToViewersAndSelf(collectItemPacket); 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.Main;
import fr.themode.minestom.bossbar.BossBar; import fr.themode.minestom.bossbar.BossBar;
import fr.themode.minestom.chat.Chat; import fr.themode.minestom.chat.Chat;
import fr.themode.minestom.collision.BoundingBox;
import fr.themode.minestom.data.Data; import fr.themode.minestom.data.Data;
import fr.themode.minestom.entity.demo.ChickenCreature;
import fr.themode.minestom.entity.property.Attribute; import fr.themode.minestom.entity.property.Attribute;
import fr.themode.minestom.event.*; import fr.themode.minestom.event.*;
import fr.themode.minestom.instance.Chunk; import fr.themode.minestom.instance.Chunk;
@ -65,6 +65,8 @@ public class Player extends LivingEntity {
protected Set<Entity> viewableEntity = new CopyOnWriteArraySet<>(); protected Set<Entity> viewableEntity = new CopyOnWriteArraySet<>();
private PlayerSettings settings; private PlayerSettings settings;
private float exp;
private int level;
private PlayerInventory inventory; private PlayerInventory inventory;
private short heldSlot; private short heldSlot;
private Inventory openInventory; private Inventory openInventory;
@ -156,10 +158,10 @@ public class Player extends LivingEntity {
setGameMode(GameMode.SURVIVAL); setGameMode(GameMode.SURVIVAL);
teleport(new Position(0, 66, 0)); teleport(new Position(0, 66, 0));
ChickenCreature chickenCreature = new ChickenCreature(); /*ChickenCreature chickenCreature = new ChickenCreature();
chickenCreature.refreshPosition(2, 65, 2); chickenCreature.refreshPosition(2, 65, 2);
chickenCreature.setInstance(getInstance()); chickenCreature.setInstance(getInstance());
chickenCreature.addPassenger(this); chickenCreature.addPassenger(this);*/
/*for (int ix = 0; ix < 4; ix++) /*for (int ix = 0; ix < 4; ix++)
for (int iz = 0; iz < 4; iz++) { for (int iz = 0; iz < 4; iz++) {
@ -170,6 +172,10 @@ public class Player extends LivingEntity {
//itemEntity.remove(); //itemEntity.remove();
}*/ }*/
ExperienceOrb experienceOrb = new ExperienceOrb((short) 500);
experienceOrb.refreshPosition(5, 66, 0);
experienceOrb.setInstance(getInstance());
getInventory().addItemStack(new ItemStack(1, (byte) 100)); getInventory().addItemStack(new ItemStack(1, (byte) 100));
TeamsPacket teamsPacket = new TeamsPacket(); TeamsPacket teamsPacket = new TeamsPacket();
@ -186,6 +192,8 @@ public class Player extends LivingEntity {
setAttribute(Attribute.MAX_HEALTH, 40); setAttribute(Attribute.MAX_HEALTH, 40);
heal(); 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 // Multiplayer sync
Position position = getPosition(); Position position = getPosition();
@ -445,6 +475,25 @@ public class Player extends LivingEntity {
playerConnection.sendPacket(updateHealthPacket); 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) { protected void onChunkChange(Chunk lastChunk, Chunk newChunk) {
float dx = newChunk.getChunkX() - lastChunk.getChunkX(); float dx = newChunk.getChunkX() - lastChunk.getChunkX();
float dz = newChunk.getChunkZ() - lastChunk.getChunkZ(); 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.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.Main; import fr.themode.minestom.Main;
import fr.themode.minestom.entity.Entity; import fr.themode.minestom.entity.*;
import fr.themode.minestom.entity.EntityCreature;
import fr.themode.minestom.entity.ObjectEntity;
import fr.themode.minestom.entity.Player;
import fr.themode.minestom.utils.BlockPosition; import fr.themode.minestom.utils.BlockPosition;
import fr.themode.minestom.utils.ChunkUtils; import fr.themode.minestom.utils.ChunkUtils;
import fr.themode.minestom.utils.Position; 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(); protected static final ChunkLoaderIO CHUNK_LOADER_IO = new ChunkLoaderIO();
// Entities present in this instance // 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<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 // Entities per chunk
protected Map<Long, Set<Entity>> chunkEntities = new ConcurrentHashMap<>(); protected Map<Long, Set<Entity>> chunkEntities = new ConcurrentHashMap<>();
private UUID uniqueId; private UUID uniqueId;
@ -79,16 +77,20 @@ public abstract class Instance implements BlockModifier {
} }
// //
public Set<ObjectEntity> getObjectEntities() { public Set<Player> getPlayers() {
return Collections.unmodifiableSet(objectEntities); return Collections.unmodifiableSet(players);
} }
public Set<EntityCreature> getCreatures() { public Set<EntityCreature> getCreatures() {
return Collections.unmodifiableSet(creatures); return Collections.unmodifiableSet(creatures);
} }
public Set<Player> getPlayers() { public Set<ObjectEntity> getObjectEntities() {
return Collections.unmodifiableSet(players); return Collections.unmodifiableSet(objectEntities);
}
public Set<ExperienceOrb> getExperienceOrbs() {
return Collections.unmodifiableSet(experienceOrbs);
} }
public Set<Entity> getChunkEntities(Chunk chunk) { public Set<Entity> getChunkEntities(Chunk chunk) {
@ -197,6 +199,8 @@ public abstract class Instance implements BlockModifier {
this.creatures.add((EntityCreature) entity); this.creatures.add((EntityCreature) entity);
} else if (entity instanceof ObjectEntity) { } else if (entity instanceof ObjectEntity) {
this.objectEntities.add((ObjectEntity) entity); 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); this.creatures.remove(entity);
} else if (entity instanceof ObjectEntity) { } else if (entity instanceof ObjectEntity) {
this.objectEntities.remove(entity); 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.adamaq01.ozao.net.Buffer;
import fr.themode.minestom.entity.Player; import fr.themode.minestom.entity.Player;
import fr.themode.minestom.event.PlayerBlockBreakEvent; 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.net.packet.server.play.ParticlePacket;
import fr.themode.minestom.utils.BlockPosition; import fr.themode.minestom.utils.BlockPosition;
import fr.themode.minestom.utils.ChunkUtils; import fr.themode.minestom.utils.ChunkUtils;
@ -38,7 +38,7 @@ public class InstanceContainer extends Instance {
Chunk chunk = getChunkAt(x, z); Chunk chunk = getChunkAt(x, z);
synchronized (chunk) { synchronized (chunk) {
chunk.setBlock((byte) (x % 16), (byte) y, (byte) (z % 16), blockId); chunk.setBlock((byte) (x % 16), (byte) y, (byte) (z % 16), blockId);
PacketWriter.writeCallbackPacket(chunk.getFreshPartialDataPacket(), buffer -> { PacketWriterUtils.writeCallbackPacket(chunk.getFreshPartialDataPacket(), buffer -> {
chunk.setFullDataPacket(buffer); chunk.setFullDataPacket(buffer);
sendChunkUpdate(chunk); sendChunkUpdate(chunk);
}); });
@ -50,7 +50,7 @@ public class InstanceContainer extends Instance {
Chunk chunk = getChunkAt(x, z); Chunk chunk = getChunkAt(x, z);
synchronized (chunk) { synchronized (chunk) {
chunk.setCustomBlock((byte) (x % 16), (byte) y, (byte) (z % 16), blockId); chunk.setCustomBlock((byte) (x % 16), (byte) y, (byte) (z % 16), blockId);
PacketWriter.writeCallbackPacket(chunk.getFreshPartialDataPacket(), buffer -> { PacketWriterUtils.writeCallbackPacket(chunk.getFreshPartialDataPacket(), buffer -> {
chunk.setFullDataPacket(buffer); chunk.setFullDataPacket(buffer);
sendChunkUpdate(chunk); sendChunkUpdate(chunk);
}); });
@ -216,7 +216,7 @@ public class InstanceContainer extends Instance {
}else{ }else{
sendChunkUpdate(player, chunk); sendChunkUpdate(player, chunk);
}*/ }*/
PacketWriter.writeCallbackPacket(chunk.getFreshFullDataPacket(), buffer -> { PacketWriterUtils.writeCallbackPacket(chunk.getFreshFullDataPacket(), buffer -> {
chunk.setFullDataPacket(buffer); chunk.setFullDataPacket(buffer);
sendChunkUpdate(player, chunk); 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; int offsetZ = blockFace == ClientPlayerDiggingPacket.BlockFace.NORTH ? -1 : blockFace == ClientPlayerDiggingPacket.BlockFace.SOUTH ? 1 : 0;
blockPosition.add(offsetX, offsetY, offsetZ); blockPosition.add(offsetX, offsetY, offsetZ);
PlayerBlockPlaceEvent playerBlockPlaceEvent = new PlayerBlockPlaceEvent((short) 10, blockPosition, packet.hand); boolean intersectPlayer = player.getBoundingBox().intersect(blockPosition);
player.callEvent(PlayerBlockPlaceEvent.class, playerBlockPlaceEvent); if (!intersectPlayer) {
if (!playerBlockPlaceEvent.isCancelled()) { PlayerBlockPlaceEvent playerBlockPlaceEvent = new PlayerBlockPlaceEvent((short) 10, blockPosition, packet.hand);
instance.setBlock(blockPosition, "custom_block"); // TODO set useItem's block instead player.callEvent(PlayerBlockPlaceEvent.class, playerBlockPlaceEvent);
if (playerBlockPlaceEvent.doesConsumeBlock()) { if (!playerBlockPlaceEvent.isCancelled()) {
usedItem.setAmount((byte) (usedItem.getAmount() - 1)); instance.setBlock(blockPosition, "custom_block"); // TODO set useItem's block instead
if (usedItem.getAmount() <= 0) if (playerBlockPlaceEvent.doesConsumeBlock()) {
usedItem = ItemStack.AIR_ITEM; usedItem.setAmount((byte) (usedItem.getAmount() - 1));
if (hand == Player.Hand.OFF) { if (usedItem.getAmount() <= 0)
playerInventory.setItemInOffHand(usedItem); usedItem = ItemStack.AIR_ITEM;
} else { // Main if (hand == Player.Hand.OFF) {
playerInventory.setItemInMainHand(usedItem); 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()); 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.adamaq01.ozao.net.server.Connection;
import fr.themode.minestom.Main; import fr.themode.minestom.Main;
import fr.themode.minestom.entity.Player; 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.ClientPlayPacket;
import fr.themode.minestom.net.packet.client.ClientPreplayPacket; import fr.themode.minestom.net.packet.client.ClientPreplayPacket;
import fr.themode.minestom.net.packet.client.handler.ClientLoginPacketsHandler; 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); //System.out.println("RECEIVED ID: 0x" + Integer.toHexString(id) + " State: " + connectionState);
} }
PacketReader packetReader = new PacketReader(buffer);
if (connectionState == ConnectionState.UNKNOWN) { if (connectionState == ConnectionState.UNKNOWN) {
// Should be handshake packet // Should be handshake packet
if (id == 0) { if (id == 0) {
HandshakePacket handshakePacket = new HandshakePacket(); HandshakePacket handshakePacket = new HandshakePacket();
handshakePacket.read(buffer); handshakePacket.read(packetReader);
handshakePacket.process(playerConnection, connectionManager); handshakePacket.process(playerConnection, connectionManager);
} }
return; return;
@ -66,17 +69,17 @@ public class PacketProcessor {
case PLAY: case PLAY:
Player player = connectionManager.getPlayer(playerConnection); Player player = connectionManager.getPlayer(playerConnection);
ClientPlayPacket playPacket = (ClientPlayPacket) playPacketsHandler.getPacketInstance(id); ClientPlayPacket playPacket = (ClientPlayPacket) playPacketsHandler.getPacketInstance(id);
playPacket.read(buffer); playPacket.read(packetReader);
player.addPacketToQueue(playPacket); // Processed during player tick update player.addPacketToQueue(playPacket); // Processed during player tick update
break; break;
case LOGIN: case LOGIN:
ClientPreplayPacket loginPacket = (ClientPreplayPacket) loginPacketsHandler.getPacketInstance(id); ClientPreplayPacket loginPacket = (ClientPreplayPacket) loginPacketsHandler.getPacketInstance(id);
loginPacket.read(buffer); loginPacket.read(packetReader);
loginPacket.process(playerConnection, connectionManager); loginPacket.process(playerConnection, connectionManager);
break; break;
case STATUS: case STATUS:
ClientPreplayPacket statusPacket = (ClientPreplayPacket) statusPacketsHandler.getPacketInstance(id); ClientPreplayPacket statusPacket = (ClientPreplayPacket) statusPacketsHandler.getPacketInstance(id);
statusPacket.read(buffer); statusPacket.read(packetReader);
statusPacket.process(playerConnection, connectionManager); statusPacket.process(playerConnection, connectionManager);
break; break;
case UNKNOWN: case UNKNOWN:

View File

@ -10,7 +10,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.function.Consumer; import java.util.function.Consumer;
public class PacketWriter { public class PacketWriterUtils {
private static volatile ExecutorService batchesPool = Executors.newFixedThreadPool(Main.THREAD_COUNT_PACKET_WRITER); 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; package fr.themode.minestom.net.packet.client;
import fr.adamaq01.ozao.net.Buffer; import fr.themode.minestom.net.packet.PacketReader;
public interface ClientPacket { 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; 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.ConnectionManager;
import fr.themode.minestom.net.ConnectionState; 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.client.ClientPreplayPacket;
import fr.themode.minestom.net.player.PlayerConnection; 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 { public class HandshakePacket implements ClientPreplayPacket {
private int nextState; private int nextState;
@Override @Override
public void read(Buffer buffer) { public void read(PacketReader reader) {
int protocolVersion = readVarInt(buffer); int protocolVersion = reader.readVarInt();
String serverAddress = readString(buffer); String serverAddress = reader.readSizedString();
short serverPort = buffer.getShort(); short serverPort = reader.readShort();
this.nextState = readVarInt(buffer); this.nextState = reader.readVarInt();
} }
@Override @Override

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
package fr.themode.minestom.net.packet.server.play; 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.net.packet.server.ServerPacket;
public class HeldItemChangePacket implements ServerPacket { public class HeldItemChangePacket implements ServerPacket {
@ -8,8 +8,8 @@ public class HeldItemChangePacket implements ServerPacket {
public short slot; public short slot;
@Override @Override
public void write(Buffer buffer) { public void write(PacketWriter writer) {
buffer.putShort(slot); writer.writeShort(slot);
} }
@Override @Override

View File

@ -1,6 +1,6 @@
package fr.themode.minestom.net.packet.server.play; 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.net.packet.server.ServerPacket;
public class KeepAlivePacket implements ServerPacket { public class KeepAlivePacket implements ServerPacket {
@ -12,8 +12,8 @@ public class KeepAlivePacket implements ServerPacket {
} }
@Override @Override
public void write(Buffer buffer) { public void write(PacketWriter writer) {
buffer.putLong(id); writer.writeLong(id);
} }
@Override @Override

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
package fr.themode.minestom.net.packet.server.play; 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.net.packet.server.ServerPacket;
public class UnloadChunkPacket implements ServerPacket { public class UnloadChunkPacket implements ServerPacket {
@ -8,9 +8,9 @@ public class UnloadChunkPacket implements ServerPacket {
public int chunkX, chunkZ; public int chunkX, chunkZ;
@Override @Override
public void write(Buffer buffer) { public void write(PacketWriter writer) {
buffer.putInt(chunkX); writer.writeInt(chunkX);
buffer.putInt(chunkZ); writer.writeInt(chunkZ);
} }
@Override @Override

View File

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

View File

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

View File

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

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