Java Code Examples for io.netty.buffer.ByteBuf#writeFloatLE()

The following examples show how to use io.netty.buffer.ByteBuf#writeFloatLE() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 6 votes vote down vote up
public static void writeSkin(ByteBuf buffer, SerializedSkin skin) {
    Preconditions.checkNotNull(buffer, "buffer");
    Preconditions.checkNotNull(skin, "skin");

    BedrockUtils.writeString(buffer, skin.getSkinId());
    BedrockUtils.writeString(buffer, skin.getSkinResourcePatch());
    BedrockUtils.writeImageData(buffer, skin.getSkinData());

    List<AnimationData> animations = skin.getAnimations();
    buffer.writeIntLE(animations.size());
    for (AnimationData animation : animations) {
        BedrockUtils.writeImageData(buffer, animation.getImage());
        buffer.writeIntLE(animation.getType());
        buffer.writeFloatLE(animation.getFrames());
    }

    BedrockUtils.writeImageData(buffer, skin.getCapeData());
    BedrockUtils.writeString(buffer, skin.getGeometryData());
    BedrockUtils.writeString(buffer, skin.getAnimationData());
    buffer.writeBoolean(skin.isPremium());
    buffer.writeBoolean(skin.isPersona());
    buffer.writeBoolean(skin.isCapeOnClassic());
    BedrockUtils.writeString(buffer, skin.getCapeId());
    BedrockUtils.writeString(buffer, skin.getFullSkinId());
}
 
Example 2
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 6 votes vote down vote up
public static void writeGameRule(ByteBuf buffer, GameRuleData gameRule) {
    Preconditions.checkNotNull(buffer, "buffer");
    Preconditions.checkNotNull(gameRule, "gameRule");

    Object value = gameRule.getValue();
    int type = GameRulesChangedSerializer_v313.RULE_TYPES.get(value.getClass());

    BedrockUtils.writeString(buffer, gameRule.getName());
    VarInts.writeUnsignedInt(buffer, type);

    switch (type) {
        case 1:
            buffer.writeBoolean((boolean) value);
            break;
        case 2:
            VarInts.writeUnsignedInt(buffer, (int) value);
            break;
        case 3:
            buffer.writeFloatLE((float) value);
            break;
    }
}
 
Example 3
Source File: BossEventSerializer_v291.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, BossEventPacket packet) {
    VarInts.writeLong(buffer, packet.getBossUniqueEntityId());
    VarInts.writeUnsignedInt(buffer, packet.getAction().ordinal());

    switch (packet.getAction()) {
        case REGISTER_PLAYER:
        case UNREGISTER_PLAYER:
            VarInts.writeLong(buffer, packet.getPlayerUniqueEntityId());
            break;
        case SHOW:
            BedrockUtils.writeString(buffer, packet.getTitle());
            buffer.writeFloatLE(packet.getHealthPercentage());
            // fall through
        case DARKEN_SKY:
            buffer.writeShortLE(packet.getDarkenSky());
            // fall through
        case OVERLAY:
            VarInts.writeUnsignedInt(buffer, packet.getColor());
            VarInts.writeUnsignedInt(buffer, packet.getOverlay());
            break;
        case HEALTH_PERCENTAGE:
            buffer.writeFloatLE(packet.getHealthPercentage());
            break;
        case TITLE:
            BedrockUtils.writeString(buffer, packet.getTitle());
            break;
        default:
            throw new RuntimeException("BossEvent transactionType was unknown!");
    }
}
 
Example 4
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 5 votes vote down vote up
public static void writePlayerAttribute(ByteBuf buffer, Attribute attribute) {
    Preconditions.checkNotNull(buffer, "buffer");
    Preconditions.checkNotNull(attribute, "attribute");

    buffer.writeFloatLE(attribute.getMinimum());
    buffer.writeFloatLE(attribute.getMaximum());
    buffer.writeFloatLE(attribute.getValue());
    buffer.writeFloatLE(attribute.getDefaultValue());
    BedrockUtils.writeString(buffer, attribute.getName());
}
 
Example 5
Source File: AnimateSerializer_v361.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, AnimatePacket packet) {
    Action action = packet.getAction();
    VarInts.writeInt(buffer, types.get(action));
    VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId());
    if (action == Action.ROW_LEFT || action == Action.ROW_RIGHT) {
        buffer.writeFloatLE(packet.getRowingTime());
    }
}
 
Example 6
Source File: VideoStreamConnectSerializer_v361.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, VideoStreamConnectPacket packet) {
    BedrockUtils.writeString(buffer, packet.getAddress());
    buffer.writeFloatLE(packet.getScreenshotFrequency());
    buffer.writeByte(packet.getAction().ordinal());
    buffer.writeIntLE(packet.getWidth());
    buffer.writeIntLE(packet.getHeight());
}
 
Example 7
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 5 votes vote down vote up
public static void writePlayerAttribute(ByteBuf buffer, Attribute attribute) {
    Preconditions.checkNotNull(buffer, "buffer");
    Preconditions.checkNotNull(attribute, "attribute");

    buffer.writeFloatLE(attribute.getMinimum());
    buffer.writeFloatLE(attribute.getMaximum());
    buffer.writeFloatLE(attribute.getValue());
    buffer.writeFloatLE(attribute.getDefaultValue());
    BedrockUtils.writeString(buffer, attribute.getName());
}
 
Example 8
Source File: PlayerMovePacket.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void toData(ConnectionImpl connection, ByteBuf serializer) {
	VarNumberSerializer.writeSVarLong(serializer, entityId);
	serializer.writeFloatLE(x);
	serializer.writeFloatLE(y);
	serializer.writeFloatLE(z);
	serializer.writeFloatLE(pitch);
	serializer.writeFloatLE(headYaw);
	serializer.writeFloatLE(yaw);
	serializer.writeByte(mode);
	serializer.writeBoolean(onGround);
	VarNumberSerializer.writeVarLong(serializer, 0);
}
 
Example 9
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 5 votes vote down vote up
public static void writeEntityAttribute(ByteBuf buffer, Attribute attribute) {
    Preconditions.checkNotNull(buffer, "buffer");
    Preconditions.checkNotNull(attribute, "attribute");

    BedrockUtils.writeString(buffer, attribute.getName());
    buffer.writeFloatLE(attribute.getMinimum());
    buffer.writeFloatLE(attribute.getMaximum());
    buffer.writeFloatLE(attribute.getValue());
}
 
Example 10
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 5 votes vote down vote up
public static void writeVector3f(ByteBuf buffer, Vector3f vector3f) {
    Preconditions.checkNotNull(buffer, "buffer");
    Preconditions.checkNotNull(vector3f, "vector3f");
    buffer.writeFloatLE(vector3f.getX());
    buffer.writeFloatLE(vector3f.getY());
    buffer.writeFloatLE(vector3f.getZ());
}
 
Example 11
Source File: BossEventSerializer_v361.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, BossEventPacket packet) {
    VarInts.writeLong(buffer, packet.getBossUniqueEntityId());
    VarInts.writeUnsignedInt(buffer, packet.getAction().ordinal());

    switch (packet.getAction()) {
        case REGISTER_PLAYER:
        case UNREGISTER_PLAYER:
            VarInts.writeLong(buffer, packet.getPlayerUniqueEntityId());
            break;
        case SHOW:
            BedrockUtils.writeString(buffer, packet.getTitle());
            buffer.writeFloatLE(packet.getHealthPercentage());
            // fall through
        case DARKEN_SKY:
            buffer.writeShortLE(packet.getDarkenSky());
            // fall through
        case OVERLAY:
            VarInts.writeUnsignedInt(buffer, packet.getColor());
            VarInts.writeUnsignedInt(buffer, packet.getOverlay());
            break;
        case HEALTH_PERCENTAGE:
            buffer.writeFloatLE(packet.getHealthPercentage());
            break;
        case TITLE:
            BedrockUtils.writeString(buffer, packet.getTitle());
            break;
        default:
            throw new RuntimeException("BossEvent transactionType was unknown!");
    }
}
 
Example 12
Source File: PlaySoundSerializer_v354.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, PlaySoundPacket packet) {
    BedrockUtils.writeString(buffer, packet.getSound());
    BedrockUtils.writeBlockPosition(buffer, packet.getPosition().mul(8).toInt());
    buffer.writeFloatLE(packet.getVolume());
    buffer.writeFloatLE(packet.getPitch());
}
 
Example 13
Source File: AnimateSerializer_v354.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, AnimatePacket packet) {
    Action action = packet.getAction();
    VarInts.writeInt(buffer, types.get(action));
    VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId());
    if (action == Action.ROW_LEFT || action == Action.ROW_RIGHT) {
        buffer.writeFloatLE(packet.getRowingTime());
    }
}
 
Example 14
Source File: AnimateSerializer_v388.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, AnimatePacket packet) {
    Action action = packet.getAction();
    VarInts.writeInt(buffer, types.get(action));
    VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId());
    if (action == Action.ROW_LEFT || action == Action.ROW_RIGHT) {
        buffer.writeFloatLE(packet.getRowingTime());
    }
}
 
Example 15
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 5 votes vote down vote up
public static void writeStructureSettings(ByteBuf buffer, StructureSettings structureSettings) {
    Preconditions.checkNotNull(buffer, "buffer");
    Preconditions.checkNotNull(structureSettings, "structureSettings");

    BedrockUtils.writeString(buffer, structureSettings.getPaletteName());
    buffer.writeBoolean(structureSettings.isIgnoreEntities());
    buffer.writeBoolean(structureSettings.isIgnoreBlocks());
    BedrockUtils.writeBlockPosition(buffer, structureSettings.getStructureSize());
    BedrockUtils.writeBlockPosition(buffer, structureSettings.getStructureOffset());
    VarInts.writeLong(buffer, structureSettings.getLastTouchedByEntityId());
    buffer.writeByte(structureSettings.getRotation());
    buffer.writeByte(structureSettings.getMirror());
    buffer.writeFloatLE(structureSettings.getIntegrityValue());
    VarInts.writeUnsignedInt(buffer, structureSettings.getIntegritySeed());
}
 
Example 16
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 5 votes vote down vote up
public static void writePlayerAttribute(ByteBuf buffer, Attribute attribute) {
    Preconditions.checkNotNull(buffer, "buffer");
    Preconditions.checkNotNull(attribute, "attribute");

    buffer.writeFloatLE(attribute.getMinimum());
    buffer.writeFloatLE(attribute.getMaximum());
    buffer.writeFloatLE(attribute.getValue());
    buffer.writeFloatLE(attribute.getDefaultValue());
    BedrockUtils.writeString(buffer, attribute.getName());
}
 
Example 17
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 5 votes vote down vote up
public static void writeEntityAttribute(ByteBuf buffer, Attribute attribute) {
    Preconditions.checkNotNull(buffer, "buffer");
    Preconditions.checkNotNull(attribute, "attribute");

    BedrockUtils.writeString(buffer, attribute.getName());
    buffer.writeFloatLE(attribute.getMinimum());
    buffer.writeFloatLE(attribute.getMaximum());
    buffer.writeFloatLE(attribute.getValue());
}
 
Example 18
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 4 votes vote down vote up
public static void writeEntityData(ByteBuf buffer, EntityDataMap entityDataMap) {
    Preconditions.checkNotNull(buffer, "buffer");
    Preconditions.checkNotNull(entityDataMap, "entityDataDictionary");

    VarInts.writeUnsignedInt(buffer, entityDataMap.size());

    for (Map.Entry<EntityData, Object> entry : entityDataMap.entrySet()) {
        int index = buffer.writerIndex();
        VarInts.writeUnsignedInt(buffer, METADATAS.get(entry.getKey()));
        Object object = entry.getValue();
        EntityData.Type type = EntityData.Type.from(object);
        VarInts.writeUnsignedInt(buffer, METADATA_TYPES.get(type));

        switch (type) {
            case BYTE:
                buffer.writeByte((byte) object);
                break;
            case SHORT:
                buffer.writeShortLE((short) object);
                break;
            case INT:
                VarInts.writeInt(buffer, (int) object);
                break;
            case FLOAT:
                buffer.writeFloatLE((float) object);
                break;
            case STRING:
                BedrockUtils.writeString(buffer, (String) object);
                break;
            case NBT:
                ItemData item;
                if (object instanceof CompoundTag) {
                    item = ItemData.of(1, (short) 0, 1, (CompoundTag) object);
                } else {
                    item = (ItemData) object;
                }
                BedrockUtils.writeItemData(buffer, item);
                break;
            case VECTOR3I:
                BedrockUtils.writeVector3i(buffer, (Vector3i) object);
                break;
            case FLAGS:
                int flagsIndex = entry.getKey() == FLAGS_2 ? 1 : 0;
                object = ((EntityFlags) object).get(flagsIndex, METADATA_FLAGS);
            case LONG:
                VarInts.writeLong(buffer, (long) object);
                break;
            case VECTOR3F:
                BedrockUtils.writeVector3f(buffer, (Vector3f) object);
                break;
            default:
                buffer.writerIndex(index);
                break;
        }
    }
}
 
Example 19
Source File: EntityFallSerializer_v340.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, EntityFallPacket packet) {
    VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId());
    buffer.writeFloatLE(packet.getFallDistance());
    buffer.writeBoolean(packet.isInVoid());
}
 
Example 20
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 4 votes vote down vote up
public static void writeEntityData(ByteBuf buffer, EntityDataMap entityDataMap) {
    Preconditions.checkNotNull(buffer, "buffer");
    Preconditions.checkNotNull(entityDataMap, "entityDataDictionary");

    VarInts.writeUnsignedInt(buffer, entityDataMap.size());

    for (Map.Entry<EntityData, Object> entry : entityDataMap.entrySet()) {
        int index = buffer.writerIndex();
        VarInts.writeUnsignedInt(buffer, METADATAS.get(entry.getKey()));
        Object object = entry.getValue();
        EntityData.Type type = EntityData.Type.from(object);
        VarInts.writeUnsignedInt(buffer, METADATA_TYPES.get(type));

        switch (type) {
            case BYTE:
                buffer.writeByte((byte) object);
                break;
            case SHORT:
                buffer.writeShortLE((short) object);
                break;
            case INT:
                VarInts.writeInt(buffer, (int) object);
                break;
            case FLOAT:
                buffer.writeFloatLE((float) object);
                break;
            case STRING:
                BedrockUtils.writeString(buffer, (String) object);
                break;
            case NBT:
                ItemData item;
                if (object instanceof CompoundTag) {
                    item = ItemData.of(1, (short) 0, 1, (CompoundTag) object);
                } else {
                    item = (ItemData) object;
                }
                BedrockUtils.writeItemData(buffer, item);
                break;
            case VECTOR3I:
                BedrockUtils.writeVector3i(buffer, (Vector3i) object);
                break;
            case FLAGS:
                int flagsIndex = entry.getKey() == FLAGS_2 ? 1 : 0;
                object = ((EntityFlags) object).get(flagsIndex, METADATA_FLAGS);
            case LONG:
                VarInts.writeLong(buffer, (long) object);
                break;
            case VECTOR3F:
                BedrockUtils.writeVector3f(buffer, (Vector3f) object);
                break;
            default:
                buffer.writerIndex(index);
                break;
        }
    }
}