use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.
the class CodecPlayOutMultiBlockChange method encode.
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutMultiBlockChange message) throws CodecException {
ByteBuffer buf = context.byteBufAlloc().buffer();
buf.writeInteger(message.getChunkX());
buf.writeInteger(message.getChunkZ());
Collection<MessagePlayOutBlockChange> changes = message.getChanges();
buf.writeVarInt(changes.size());
for (MessagePlayOutBlockChange change : changes) {
Vector3i position = change.getPosition();
buf.writeByte((byte) ((position.getX() & 0xf) << 4 | position.getZ() & 0xf));
buf.writeByte((byte) position.getY());
buf.writeVarInt(change.getBlockState());
}
return buf;
}
use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.
the class CodecPlayOutNamedSoundEffect method encode.
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutNamedSoundEffect message) throws CodecException {
final ByteBuffer buf = context.byteBufAlloc().buffer();
buf.writeString(message.getType());
buf.writeVarInt(((LanternSoundCategory) message.getCategory()).getInternalId());
final Vector3d pos = message.getPosition();
buf.writeInteger((int) (pos.getX() * 8.0));
buf.writeInteger((int) (pos.getY() * 8.0));
buf.writeInteger((int) (pos.getZ() * 8.0));
buf.writeFloat(message.getVolume());
buf.writeFloat(message.getPitch());
return buf;
}
use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.
the class CodecPlayOutPlayerAbilities method encode.
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutPlayerAbilities message) throws CodecException {
byte bits = 0;
if (message.isInvulnerable()) {
bits |= 0x1;
}
if (message.isFlying()) {
bits |= 0x2;
}
if (message.canFly()) {
bits |= 0x4;
}
if (message.isCreative()) {
bits |= 0x8;
}
final ByteBuffer buf = context.byteBufAlloc().buffer(9);
buf.writeByte(bits);
buf.writeFloat(message.getFlySpeed());
buf.writeFloat(message.getFieldOfView());
return buf;
}
use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.
the class CodecPlayOutPlayerJoinGame method encode.
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutPlayerJoinGame message) throws CodecException {
context.getChannel().attr(PLAYER_ENTITY_ID).set(message.getEntityId());
final ByteBuffer buf = context.byteBufAlloc().buffer();
buf.writeInteger(message.getEntityId());
byte gameMode = (byte) message.getGameMode().getInternalId();
if (message.isHardcore()) {
gameMode |= 0x8;
}
buf.writeByte(gameMode);
buf.writeInteger(message.getDimensionType().getInternalId());
buf.writeByte((byte) message.getDifficulty().getInternalId());
buf.writeByte((byte) Math.min(message.getPlayerListSize(), 255));
buf.writeString(message.isLowHorizon() ? "flat" : "default");
buf.writeBoolean(message.getReducedDebug());
return buf;
}
use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.
the class CodecPlayOutPlayerRespawn method encode.
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutPlayerRespawn message) throws CodecException {
final ByteBuffer buf = context.byteBufAlloc().buffer();
buf.writeInteger(message.getDimensionType().getInternalId());
buf.writeByte((byte) message.getDifficulty().getInternalId());
buf.writeByte((byte) message.getGameMode().getInternalId());
buf.writeString(message.isLowHorizon() ? "flat" : "default");
return buf;
}
Aggregations