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

The following examples show how to use io.netty.buffer.ByteBuf#readFloatLE() . 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: PlayerMovePacket.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void readFromClientData(ConnectionImpl connection, ByteBuf clientdata) {
	this.entityId = VarNumberSerializer.readSVarLong(clientdata);
	this.x = clientdata.readFloatLE();
	this.y = clientdata.readFloatLE();
	this.z = clientdata.readFloatLE();
	this.pitch = clientdata.readFloatLE();
	this.headYaw = clientdata.readFloatLE();
	this.mode = clientdata.readByte();
	this.onGround = clientdata.readBoolean();
	VarNumberSerializer.readVarInt(clientdata);
	if (mode == 2) {
		VarNumberSerializer.readSVarInt(clientdata);
		VarNumberSerializer.readSVarInt(clientdata);
	}
}
 
Example 2
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 6 votes vote down vote up
public static GameRuleData readGameRule(ByteBuf buffer) {
    Preconditions.checkNotNull(buffer, "buffer");

    String name = BedrockUtils.readString(buffer);
    int type = VarInts.readUnsignedInt(buffer);

    switch (type) {
        case 1:
            return new GameRuleData<>(name, buffer.readBoolean());
        case 2:
            return new GameRuleData<>(name, VarInts.readUnsignedInt(buffer));
        case 3:
            return new GameRuleData<>(name, buffer.readFloatLE());
    }
    throw new IllegalStateException("Invalid gamerule type received");
}
 
Example 3
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 6 votes vote down vote up
public static GameRuleData readGameRule(ByteBuf buffer) {
    Preconditions.checkNotNull(buffer, "buffer");

    String name = BedrockUtils.readString(buffer);
    int type = VarInts.readUnsignedInt(buffer);

    switch (type) {
        case 1:
            return new GameRuleData<>(name, buffer.readBoolean());
        case 2:
            return new GameRuleData<>(name, VarInts.readUnsignedInt(buffer));
        case 3:
            return new GameRuleData<>(name, buffer.readFloatLE());
    }
    throw new IllegalStateException("Invalid gamerule type received");
}
 
Example 4
Source File: StructureBlockUpdateSerializer_v354.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, StructureBlockUpdatePacket packet) {
    packet.setBlockPosition(BedrockUtils.readBlockPosition(buffer));
    int structureType = VarInts.readUnsignedInt(buffer);
    // Structure Editor Data start
    String name = BedrockUtils.readString(buffer);
    String dataField = BedrockUtils.readString(buffer);
    Vector3i offset = BedrockUtils.readBlockPosition(buffer);
    Vector3i size = BedrockUtils.readBlockPosition(buffer);
    buffer.readBoolean(); // include entities
    boolean ignoreBlocks = !buffer.readBoolean();
    boolean includePlayers = buffer.readBoolean();
    buffer.readBoolean(); // show air
    // Structure Settings start
    float structureIntegrity = buffer.readFloatLE();
    int integritySeed = VarInts.readUnsignedInt(buffer);
    int mirror = VarInts.readUnsignedInt(buffer);
    int rotation = VarInts.readUnsignedInt(buffer);
    boolean ignoreEntities = buffer.readBoolean();
    buffer.readBoolean(); // ignore structure bocks
    BedrockUtils.readVector3i(buffer); // bounding box min
    BedrockUtils.readVector3i(buffer); // bounding box max
    // Structure Settings end
    // Structure Editor Data end
    boolean boundingBoxVisible = buffer.readBoolean();

    StructureSettings settings = new StructureSettings("", ignoreEntities, ignoreBlocks, size, offset,
            -1, (byte) rotation, (byte) mirror, structureIntegrity, integritySeed);
    StructureEditorData editorData = new StructureEditorData(name, dataField, includePlayers, boundingBoxVisible,
            structureType, settings);

    packet.setEditorData(editorData);
    packet.setPowered(buffer.readBoolean());
}
 
Example 5
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 5 votes vote down vote up
public static Attribute readPlayerAttribute(ByteBuf buffer) {
    Preconditions.checkNotNull(buffer, "buffer");

    float min = buffer.readFloatLE();
    float max = buffer.readFloatLE();
    float val = buffer.readFloatLE();
    float def = buffer.readFloatLE();
    String name = BedrockUtils.readString(buffer);

    return new Attribute(name, min, max, val, def);
}
 
Example 6
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 5 votes vote down vote up
public static Attribute readPlayerAttribute(ByteBuf buffer) {
    Preconditions.checkNotNull(buffer, "buffer");

    float min = buffer.readFloatLE();
    float max = buffer.readFloatLE();
    float val = buffer.readFloatLE();
    float def = buffer.readFloatLE();
    String name = BedrockUtils.readString(buffer);

    return new Attribute(name, min, max, val, def);
}
 
Example 7
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 5 votes vote down vote up
public static Vector3f readVector3f(ByteBuf buffer) {
    Preconditions.checkNotNull(buffer, "buffer");
    float x = buffer.readFloatLE();
    float y = buffer.readFloatLE();
    float z = buffer.readFloatLE();
    return Vector3f.from(x, y, z);
}
 
Example 8
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 5 votes vote down vote up
public static Attribute readPlayerAttribute(ByteBuf buffer) {
    Preconditions.checkNotNull(buffer, "buffer");

    float min = buffer.readFloatLE();
    float max = buffer.readFloatLE();
    float val = buffer.readFloatLE();
    float def = buffer.readFloatLE();
    String name = BedrockUtils.readString(buffer);

    return new Attribute(name, min, max, val, def);
}
 
Example 9
Source File: DoubleCodec.java    From r2dbc-mysql with Apache License 2.0 5 votes vote down vote up
@Override
public Double decode(ByteBuf value, FieldInformation info, Class<?> target, boolean binary, CodecContext context) {
    if (binary) {
        switch (info.getType()) {
            case DataTypes.DOUBLE:
                return value.readDoubleLE();
            case DataTypes.FLOAT:
                return (double) value.readFloatLE();
        }
        // DECIMAL and size less than 16, encoded by text.
    }
    return Double.parseDouble(value.toString(StandardCharsets.US_ASCII));
}
 
Example 10
Source File: StructureBlockUpdateSerializer_v291.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, StructureBlockUpdatePacket packet) {
    packet.setBlockPosition(BedrockUtils.readBlockPosition(buffer));
    int structureType = VarInts.readUnsignedInt(buffer);
    // Structure Editor Data start
    String name = BedrockUtils.readString(buffer);
    String dataField = BedrockUtils.readString(buffer);
    Vector3i offset = BedrockUtils.readBlockPosition(buffer);
    Vector3i size = BedrockUtils.readBlockPosition(buffer);
    buffer.readBoolean(); // include entities
    boolean ignoreBlocks = !buffer.readBoolean();
    boolean includePlayers = buffer.readBoolean();
    buffer.readBoolean(); // show air
    // Structure Settings start
    float structureIntegrity = buffer.readFloatLE();
    int integritySeed = VarInts.readUnsignedInt(buffer);
    int mirror = VarInts.readUnsignedInt(buffer);
    int rotation = VarInts.readUnsignedInt(buffer);
    boolean ignoreEntities = buffer.readBoolean();
    buffer.readBoolean(); // ignore structure bocks
    BedrockUtils.readVector3i(buffer); // bounding box min
    BedrockUtils.readVector3i(buffer); // bounding box max
    // Structure Settings end
    // Structure Editor Data end
    boolean boundingBoxVisible = buffer.readBoolean();

    StructureSettings settings = new StructureSettings("", ignoreEntities, ignoreBlocks, size, offset,
            -1, (byte) rotation, (byte) mirror, structureIntegrity, integritySeed);
    StructureEditorData editorData = new StructureEditorData(name, dataField, includePlayers, boundingBoxVisible,
            structureType, settings);

    packet.setEditorData(editorData);
    packet.setPowered(buffer.readBoolean());
}
 
Example 11
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 5 votes vote down vote up
public static Attribute readEntityAttribute(ByteBuf buffer) {
    Preconditions.checkNotNull(buffer, "buffer");

    String name = BedrockUtils.readString(buffer);
    float min = buffer.readFloatLE();
    float max = buffer.readFloatLE();
    float val = buffer.readFloatLE();

    return new Attribute(name, min, max, val, max);
}
 
Example 12
Source File: FloatCodec.java    From r2dbc-mysql with Apache License 2.0 5 votes vote down vote up
@Override
public Float decode(ByteBuf value, FieldInformation info, Class<?> target, boolean binary, CodecContext context) {
    if (binary && info.getType() == DataTypes.FLOAT) {
        return value.readFloatLE();
    }
    // otherwise encoded by text (must not be DOUBLE).
    return Float.parseFloat(value.toString(StandardCharsets.US_ASCII));
}
 
Example 13
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 5 votes vote down vote up
public static Vector3f readVector3f(ByteBuf buffer) {
    Preconditions.checkNotNull(buffer, "buffer");
    float x = buffer.readFloatLE();
    float y = buffer.readFloatLE();
    float z = buffer.readFloatLE();
    return Vector3f.from(x, y, z);
}
 
Example 14
Source File: FloatCodec.java    From r2dbc-mysql with Apache License 2.0 5 votes vote down vote up
@Override
public Float decode(ByteBuf value, FieldInformation info, Class<?> target, boolean binary, CodecContext context) {
    if (binary && info.getType() == DataTypes.FLOAT) {
        return value.readFloatLE();
    }
    // otherwise encoded by text (must not be DOUBLE).
    return Float.parseFloat(value.toString(StandardCharsets.US_ASCII));
}
 
Example 15
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 4 votes vote down vote up
public static Vector2f readVector2f(ByteBuf buffer) {
    Preconditions.checkNotNull(buffer, "buffer");
    float x = buffer.readFloatLE();
    float y = buffer.readFloatLE();
    return Vector2f.from(x, y);
}
 
Example 16
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 4 votes vote down vote up
public static Vector2f readVector2f(ByteBuf buffer) {
    Preconditions.checkNotNull(buffer, "buffer");
    float x = buffer.readFloatLE();
    float y = buffer.readFloatLE();
    return Vector2f.from(x, y);
}
 
Example 17
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 4 votes vote down vote up
public static Vector2f readVector2f(ByteBuf buffer) {
    Preconditions.checkNotNull(buffer, "buffer");
    float x = buffer.readFloatLE();
    float y = buffer.readFloatLE();
    return Vector2f.from(x, y);
}
 
Example 18
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 4 votes vote down vote up
public static void readEntityData(ByteBuf buffer, EntityDataMap entityDataMap) {
    Preconditions.checkNotNull(buffer, "buffer");
    Preconditions.checkNotNull(entityDataMap, "entityDataDictionary");

    int length = VarInts.readUnsignedInt(buffer);

    for (int i = 0; i < length; i++) {
        int metadataInt = VarInts.readUnsignedInt(buffer);
        EntityData entityData = METADATAS.get(metadataInt);
        EntityData.Type type = METADATA_TYPES.get(VarInts.readUnsignedInt(buffer));
        if (entityData != null && entityData.isFlags()) {
            if (type != Type.LONG) {
                throw new IllegalArgumentException("Expected long value for flags, got " + type.name());
            }
            type = Type.FLAGS;
        }

        Object object;
        switch (type) {
            case BYTE:
                object = buffer.readByte();
                break;
            case SHORT:
                object = buffer.readShortLE();
                break;
            case INT:
                object = VarInts.readInt(buffer);
                break;
            case FLOAT:
                object = buffer.readFloatLE();
                break;
            case STRING:
                object = BedrockUtils.readString(buffer);
                break;
            case NBT:
                object = BedrockUtils.readItemData(buffer);
                break;
            case VECTOR3I:
                object = BedrockUtils.readVector3i(buffer);
                break;
            case FLAGS:
                int index = entityData == FLAGS_2 ? 1 : 0;
                entityDataMap.getOrCreateFlags().set(VarInts.readLong(buffer), index, METADATA_FLAGS);
                continue;
            case LONG:
                object = VarInts.readLong(buffer);
                break;
            case VECTOR3F:
                object = BedrockUtils.readVector3f(buffer);
                break;
            default:
                throw new IllegalArgumentException("Unknown entity data type received");
        }
        if (entityData != null) {
            entityDataMap.put(entityData, object);
        } else {
            log.debug("Unknown entity data: {} type {} value {}", metadataInt, type, object);
        }
    }
}
 
Example 19
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 4 votes vote down vote up
public static void readEntityData(ByteBuf buffer, EntityDataMap entityDataMap) {
    Preconditions.checkNotNull(buffer, "buffer");
    Preconditions.checkNotNull(entityDataMap, "entityDataDictionary");

    int length = VarInts.readUnsignedInt(buffer);

    for (int i = 0; i < length; i++) {
        int metadataInt = VarInts.readUnsignedInt(buffer);
        EntityData entityData = METADATAS.get(metadataInt);
        EntityData.Type type = METADATA_TYPES.get(VarInts.readUnsignedInt(buffer));
        if (entityData != null && entityData.isFlags()) {
            if (type != Type.LONG) {
                throw new IllegalArgumentException("Expected long value for flags, got " + type.name());
            }
            type = Type.FLAGS;
        }

        Object object;
        switch (type) {
            case BYTE:
                object = buffer.readByte();
                break;
            case SHORT:
                object = buffer.readShortLE();
                break;
            case INT:
                object = VarInts.readInt(buffer);
                break;
            case FLOAT:
                object = buffer.readFloatLE();
                break;
            case STRING:
                object = BedrockUtils.readString(buffer);
                break;
            case NBT:
                object = BedrockUtils.readItemData(buffer);
                break;
            case VECTOR3I:
                object = BedrockUtils.readVector3i(buffer);
                break;
            case FLAGS:
                int index = entityData == FLAGS_2 ? 1 : 0;
                entityDataMap.getOrCreateFlags().set(VarInts.readLong(buffer), index, METADATA_FLAGS);
                continue;
            case LONG:
                object = VarInts.readLong(buffer);
                break;
            case VECTOR3F:
                object = BedrockUtils.readVector3f(buffer);
                break;
            default:
                throw new IllegalArgumentException("Unknown entity data type received");
        }
        if (entityData != null) {
            entityDataMap.put(entityData, object);
        } else {
            log.debug("Unknown entity data: {} type {} value {}", metadataInt, type, object);
        }
    }
}
 
Example 20
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 4 votes vote down vote up
public static Vector2f readVector2f(ByteBuf buffer) {
    Preconditions.checkNotNull(buffer, "buffer");
    float x = buffer.readFloatLE();
    float y = buffer.readFloatLE();
    return Vector2f.from(x, y);
}