package net.glowstone.net.codec.play.player;
import com.flowpowered.networking.Codec;
import com.flowpowered.networking.util.ByteBufUtils;
import io.netty.buffer.ByteBuf;
import net.glowstone.net.GlowBufUtils;
import net.glowstone.net.message.play.player.UseBedMessage;
import org.bukkit.util.BlockVector;
import java.io.IOException;
public final class UseBedCodec implements Codec<UseBedMessage> {
@Override
public UseBedMessage decode(ByteBuf buf) throws IOException {
int id = ByteBufUtils.readVarInt(buf);
BlockVector pos = GlowBufUtils.readBlockPosition(buf);
return new UseBedMessage(id, pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
}
@Override
public ByteBuf encode(ByteBuf buf, UseBedMessage message) throws IOException {
ByteBufUtils.writeVarInt(buf, message.getId());
GlowBufUtils.writeBlockPosition(buf, message.getX(), message.getY(), message.getZ());
return buf;
}
}