Example usage for io.netty.buffer ByteBuf writeFloat

List of usage examples for io.netty.buffer ByteBuf writeFloat

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf writeFloat.

Prototype

public abstract ByteBuf writeFloat(float value);

Source Link

Document

Sets the specified 32-bit floating point number at the current writerIndex and increases the writerIndex by 4 in this buffer.

Usage

From source file:com.builtbroken.atomic.network.packet.PacketBase.java

/**
 * Called to write data without manually defining the write
 *
 * @param object - object to write/*from   w w  w  .j av  a 2  s.  c o m*/
 * @param buffer - location to write to
 */
protected void writeData(Object object, ByteBuf buffer) {
    if (object.getClass().isArray()) {
        for (int i = 0; i < Array.getLength(object); i++) {
            writeData(Array.get(object, i), buffer);
        }
    } else if (object instanceof Collection) {
        for (Object o : (Collection) object) {
            writeData(o, buffer);
        }
    } else if (object instanceof Byte) {
        buffer.writeByte((Byte) object);
    } else if (object instanceof Integer) {
        buffer.writeInt((Integer) object);
    } else if (object instanceof Short) {
        buffer.writeShort((Short) object);
    } else if (object instanceof Long) {
        buffer.writeLong((Long) object);
    } else if (object instanceof Float) {
        buffer.writeFloat((Float) object);
    } else if (object instanceof Double) {
        buffer.writeDouble((Double) object);
    } else if (object instanceof Boolean) {
        buffer.writeBoolean((Boolean) object);
    } else if (object instanceof String) {
        ByteBufUtils.writeUTF8String(buffer, (String) object);
    } else if (object instanceof NBTTagCompound) {
        ByteBufUtils.writeTag(buffer, (NBTTagCompound) object);
    } else if (object instanceof ItemStack) {
        ByteBufUtils.writeItemStack(buffer, (ItemStack) object);
    } else if (object instanceof FluidTank) {
        ByteBufUtils.writeTag(buffer, ((FluidTank) object).writeToNBT(new NBTTagCompound()));
    } else if (object instanceof Pos) {
        ((Pos) object).writeByteBuf(buffer);
    } else if (object instanceof IByteBufWriter) {
        ((IByteBufWriter) object).writeBytes(buffer);
    } else if (object instanceof Enum) {
        buffer.writeInt(((Enum) object).ordinal());
    } else {
        throw new IllegalArgumentException("PacketBase: Unsupported write data type " + object);
    }
}

From source file:com.builtbroken.atomic.network.packet.sync.PacketPlayerRadiation.java

@Override
public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
    buffer.writeFloat(rads);
    buffer.writeFloat(rads_area);/* w  w w .  ja  va 2s.c o m*/
    buffer.writeInt(rad_remove_timer);
}

From source file:com.builtbroken.comecloser.network.SyncSettings.java

@Override
public void toBytes(ByteBuf buf) {
    buf.writeFloat(min);
    buf.writeFloat(max);
    buf.writeBoolean(doRay);
}

From source file:com.builtbroken.icbm.content.missile.tile.TileCrashedMissile.java

@Override
public void writeDescPacket(ByteBuf buf) {
    if (missile != null) {
        ByteBufUtils.writeItemStack(buf, missile.toStack());
    } else {/*www.ja  va  2 s  .  com*/
        ByteBufUtils.writeItemStack(buf, new ItemStack(Items.stone_axe)); //random sync data, set the missile to null
    }
    buf.writeFloat(yaw);
    buf.writeFloat(pitch);
    posOffset.writeByteBuf(buf);
    buf.writeBoolean(block != null);
    if (block != null) {
        ByteBufUtils.writeUTF8String(buf, Block.blockRegistry.getNameForObject(block));
        buf.writeShort(meta);
    }
}

From source file:com.crowsofwar.avatar.common.data.AbilityData.java

License:Open Source License

public void toBytes(ByteBuf buf) {
    buf.writeInt(ability.getId()); // ability ID read from createFromBytes
    buf.writeFloat(xp);
}

From source file:com.crowsofwar.avatar.common.data.Chi.java

License:Open Source License

public void toBytes(ByteBuf buf) {
    buf.writeFloat(max);
    buf.writeFloat(total);
    buf.writeFloat(availableMark);
}

From source file:com.crowsofwar.avatar.common.entity.EntityWallSegment.java

License:Open Source License

@Override
public void writeSpawnData(ByteBuf buf) {
    buf.writeFloat(height);
    buf.writeInt(offset);
}

From source file:com.Da_Technomancer.crossroads.API.packets.Message.java

License:Creative Commons License

private static void writeFloat(float f, ByteBuf buf) {
    buf.writeFloat(f);
}

From source file:com.flowpowered.engine.network.codec.InputSnapshotCodec.java

License:MIT License

@Override
public ByteBuf encode(ByteBuf buf, InputSnapshotMessage message) throws IOException {
    buf.writeInt(message.getKeyEvents().size());
    for (KeyboardEvent e : message.getKeyEvents()) {
        buf.writeByte(e.getKeyId());//w  w  w  .j a  v a2 s. co m
        buf.writeBoolean(e.wasPressedDown());
    }
    buf.writeInt(message.getMouseEvents().size());
    for (MouseEvent e : message.getMouseEvents()) {
        buf.writeInt(e.getX());
        buf.writeInt(e.getY());
        buf.writeInt(e.getDX());
        buf.writeInt(e.getDY());
        buf.writeInt(e.getDWheel());
        buf.writeInt(e.getButton());
        buf.writeBoolean(e.wasPressedDown());
    }
    buf.writeFloat(message.getDt());
    buf.writeBoolean(message.isMouseGrabbed());
    return buf;
}

From source file:com.flowpowered.engine.util.FlowByteBufUtils.java

License:MIT License

public static void writeVector3(ByteBuf buffer, Vector3f vec) {
    buffer.writeFloat(vec.getX());
    buffer.writeFloat(vec.getY());/*  w  w w  .j av a 2s .c o  m*/
    buffer.writeFloat(vec.getZ());
}