Package net.glowstone.net.codec.play.game

Source Code of net.glowstone.net.codec.play.game.ExperienceCodec

package net.glowstone.net.codec.play.game;

import com.flowpowered.networking.Codec;
import com.flowpowered.networking.util.ByteBufUtils;
import io.netty.buffer.ByteBuf;
import net.glowstone.net.message.play.game.ExperienceMessage;

import java.io.IOException;

public final class ExperienceCodec implements Codec<ExperienceMessage> {
    @Override
    public ExperienceMessage decode(ByteBuf buffer) throws IOException {
        float barValue = buffer.readFloat();
        int level = ByteBufUtils.readVarInt(buffer);
        int totalExp = ByteBufUtils.readVarInt(buffer);
        return new ExperienceMessage(barValue, level, totalExp);
    }

    @Override
    public ByteBuf encode(ByteBuf buf, ExperienceMessage message) throws IOException {
        buf.writeFloat(message.getBarValue());
        ByteBufUtils.writeVarInt(buf, message.getLevel());
        ByteBufUtils.writeVarInt(buf, message.getTotalExp());
        return buf;
    }
}
TOP

Related Classes of net.glowstone.net.codec.play.game.ExperienceCodec

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.