use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.
the class CodecPlayOutWindowProperty method encode.
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutWindowProperty message) throws CodecException {
ByteBuffer buf = context.byteBufAlloc().buffer(9);
buf.writeByte((byte) message.getWindowId());
buf.writeShort((short) message.getProperty());
buf.writeShort((short) message.getValue());
return buf;
}
use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.
the class CodecPlayOutWorldTime method encode.
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutWorldTime message) throws CodecException {
final ByteBuffer buf = context.byteBufAlloc().buffer(LENGTH);
// The time also uses a negative tag
long time = message.getTime();
while (time < 0) {
time += TimeUniverse.TICKS_IN_A_DAY;
}
time %= TimeUniverse.TICKS_IN_A_DAY;
time += message.getMoonPhase().ordinal() * TimeUniverse.TICKS_IN_A_DAY;
if (!message.getEnabled()) {
time = time == 0 ? -1 : -time;
}
buf.writeLong(message.getAge());
buf.writeLong(time);
return buf;
}
use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.
the class CodecPlayOutSetWindowSlot method encode.
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutSetWindowSlot message) throws CodecException {
final ByteBuffer buf = context.byteBufAlloc().buffer();
buf.writeByte((byte) message.getWindow());
buf.writeShort((short) message.getIndex());
final Object item = message.getItem();
if (item instanceof ItemStack) {
buf.write(Types.ITEM_STACK, (ItemStack) item);
} else if (item instanceof RawItemStack || item == null) {
buf.write(Types.RAW_ITEM_STACK, (RawItemStack) item);
} else {
throw new EncoderException("Invalid item type:" + item.getClass().getName());
}
return buf;
}
use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.
the class CodecPlayOutSoundEffect method encode.
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutSoundEffect message) throws CodecException {
final ByteBuffer buf = context.byteBufAlloc().buffer();
buf.writeVarInt(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 CodecPlayOutSpawnExperienceOrb method encode.
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutSpawnExperienceOrb message) throws CodecException {
final ByteBuffer buf = context.byteBufAlloc().buffer();
buf.writeVarInt(message.getEntityId());
final Vector3d position = message.getPosition();
buf.writeDouble(position.getX());
buf.writeDouble(position.getY());
buf.writeDouble(position.getZ());
buf.writeShort((short) Math.min(message.getQuantity(), Short.MAX_VALUE));
return buf;
}
Aggregations