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

The following examples show how to use io.netty.buffer.ByteBuf#writeFloat() . 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: MessageAddEffects.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void toBytes(ByteBuf buf)
{
    buf.writeByte(this.effectType);
    buf.writeByte(this.flags);
    buf.writeFloat((float) this.x);
    buf.writeFloat((float) this.y);
    buf.writeFloat((float) this.z);

    if (this.effectType == EFFECT_SOUND_EVENT)
    {
        buf.writeShort((short) this.soundEventId);
        buf.writeFloat(this.pitch);
        buf.writeFloat(this.volume);
        buf.writeBoolean(this.repeat);
    }
    else
    {
        buf.writeShort(this.particleCount);
        buf.writeFloat((float) this.offset);
        buf.writeFloat((float) this.velocity);
    }
}
 
Example 2
Source File: MsgAssembleResult.java    From archimedes-ships with MIT License 6 votes vote down vote up
@Override
public void encodeInto(ChannelHandlerContext ctx, ByteBuf buf)
{
	buf.writeBoolean(prevFlag);
	if (result == null)
	{
		buf.writeByte(AssembleResult.RESULT_NONE);
	} else
	{
		buf.writeByte(result.getCode());
		buf.writeInt(result.getBlockCount());
		buf.writeInt(result.getBalloonCount());
		buf.writeInt(result.getTileEntityCount());
		buf.writeFloat(result.getMass());
	}
}
 
Example 3
Source File: TilePlanetaryHologram.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public void writeDataToNetwork(ByteBuf out, byte id) {
	if(id == SCALEPACKET) {
		out.writeFloat(size);
	}
	if(id == STATEUPDATE) {
		out.writeByte(state.ordinal());
	}

}
 
Example 4
Source File: PacketUpdateGui.java    From Signals with GNU General Public License v3.0 5 votes vote down vote up
public static void writeField(ByteBuf buf, Object value, int type){

        switch(type){
            case 0:
                buf.writeInt((Integer)value);
                break;
            case 1:
                buf.writeFloat((Float)value);
                break;
            case 2:
                buf.writeDouble((Double)value);
                break;
            case 3:
                buf.writeBoolean((Boolean)value);
                break;
            case 4:
                ByteBufUtils.writeUTF8String(buf, (String)value);
                break;
            case 5:
                buf.writeByte((Byte)value);
                break;
            case 6:
                ByteBufUtils.writeItemStack(buf, (ItemStack)value);
                break;
            case 7:
                buf.writeBoolean(value != null);
                if(value != null) {
                    FluidStack stack = (FluidStack)value;
                    ByteBufUtils.writeUTF8String(buf, stack.getFluid().getName());
                    buf.writeInt(stack.amount);
                    ByteBufUtils.writeTag(buf, stack.tag);
                }
                break;
        }
    }
 
Example 5
Source File: BossBar.java    From Velocity with MIT License 5 votes vote down vote up
@Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
  if (uuid == null) {
    throw new IllegalStateException("No boss bar UUID specified");
  }
  ProtocolUtils.writeUuid(buf, uuid);
  ProtocolUtils.writeVarInt(buf, action);
  switch (action) {
    case ADD:
      if (name == null) {
        throw new IllegalStateException("No name specified!");
      }
      ProtocolUtils.writeString(buf, name);
      buf.writeFloat(percent);
      ProtocolUtils.writeVarInt(buf, color);
      ProtocolUtils.writeVarInt(buf, overlay);
      buf.writeByte(flags);
      break;
    case REMOVE:
      break;
    case UPDATE_PERCENT:
      buf.writeFloat(percent);
      break;
    case UPDATE_NAME:
      if (name == null) {
        throw new IllegalStateException("No name specified!");
      }
      ProtocolUtils.writeString(buf, name);
      break;
    case UPDATE_STYLE:
      ProtocolUtils.writeVarInt(buf, color);
      ProtocolUtils.writeVarInt(buf, overlay);
      break;
    case UPDATE_PROPERTIES:
      buf.writeByte(flags);
      break;
    default:
      throw new UnsupportedOperationException("Unknown action " + action);
  }
}
 
Example 6
Source File: ParamFlowRequestDataWriter.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
private void encodeValue(Object param, ByteBuf target) {
    // Handle primitive type.
    if (param instanceof Integer || int.class.isInstance(param)) {
        target.writeByte(ClusterConstants.PARAM_TYPE_INTEGER);
        target.writeInt((Integer) param);
    } else if (param instanceof String) {
        encodeString((String) param, target);
    } else if (boolean.class.isInstance(param) || param instanceof Boolean) {
        target.writeByte(ClusterConstants.PARAM_TYPE_BOOLEAN);
        target.writeBoolean((Boolean) param);
    } else if (long.class.isInstance(param) || param instanceof Long) {
        target.writeByte(ClusterConstants.PARAM_TYPE_LONG);
        target.writeLong((Long) param);
    } else if (double.class.isInstance(param) || param instanceof Double) {
        target.writeByte(ClusterConstants.PARAM_TYPE_DOUBLE);
        target.writeDouble((Double) param);
    } else if (float.class.isInstance(param) || param instanceof Float) {
        target.writeByte(ClusterConstants.PARAM_TYPE_FLOAT);
        target.writeFloat((Float) param);
    } else if (byte.class.isInstance(param) || param instanceof Byte) {
        target.writeByte(ClusterConstants.PARAM_TYPE_BYTE);
        target.writeByte((Byte) param);
    } else if (short.class.isInstance(param) || param instanceof Short) {
        target.writeByte(ClusterConstants.PARAM_TYPE_SHORT);
        target.writeShort((Short) param);
    } else {
        // Unexpected type, drop.
    }
}
 
Example 7
Source File: PacketTCNodeBolt.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void toBytes(ByteBuf buf) {
    buf.writeFloat(x);
    buf.writeFloat(y);
    buf.writeFloat(z);
    buf.writeFloat(targetX);
    buf.writeFloat(targetY);
    buf.writeFloat(targetZ);
    buf.writeInt(type);
    buf.writeBoolean(mightGetLong);
}
 
Example 8
Source File: MixMessageEncoder.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Override
protected void encode(ChannelHandlerContext ctx, MixMessage msg, ByteBuf out) throws Exception {
    int startIdx = out.writerIndex();
    out.writeBytes(LENGTH_PLACEHOLDER);

    MixEventName event = msg.getEvent();
    byte b = event.getID();
    out.writeByte(b);

    Object feature = msg.getFeature();
    encodeObject(feature, out);

    float weight = msg.getWeight();
    out.writeFloat(weight);

    float covariance = msg.getCovariance();
    out.writeFloat(covariance);

    short clock = msg.getClock();
    out.writeShort(clock);

    int deltaUpdates = msg.getDeltaUpdates();
    out.writeInt(deltaUpdates);

    boolean cancelRequest = msg.isCancelRequest();
    out.writeBoolean(cancelRequest);

    String groupId = msg.getGroupID();
    writeString(groupId, out);

    int endIdx = out.writerIndex();
    out.setInt(startIdx, endIdx - startIdx - 4);
}
 
Example 9
Source File: ParamFlowRequestDataWriter.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
private void encodeValue(Object param, ByteBuf target) {
    // Handle primitive type.
    if (param instanceof Integer || int.class.isInstance(param)) {
        target.writeByte(ClusterConstants.PARAM_TYPE_INTEGER);
        target.writeInt((Integer) param);
    } else if (param instanceof String) {
        encodeString((String) param, target);
    } else if (boolean.class.isInstance(param) || param instanceof Boolean) {
        target.writeByte(ClusterConstants.PARAM_TYPE_BOOLEAN);
        target.writeBoolean((Boolean) param);
    } else if (long.class.isInstance(param) || param instanceof Long) {
        target.writeByte(ClusterConstants.PARAM_TYPE_LONG);
        target.writeLong((Long) param);
    } else if (double.class.isInstance(param) || param instanceof Double) {
        target.writeByte(ClusterConstants.PARAM_TYPE_DOUBLE);
        target.writeDouble((Double) param);
    } else if (float.class.isInstance(param) || param instanceof Float) {
        target.writeByte(ClusterConstants.PARAM_TYPE_FLOAT);
        target.writeFloat((Float) param);
    } else if (byte.class.isInstance(param) || param instanceof Byte) {
        target.writeByte(ClusterConstants.PARAM_TYPE_BYTE);
        target.writeByte((Byte) param);
    } else if (short.class.isInstance(param) || param instanceof Short) {
        target.writeByte(ClusterConstants.PARAM_TYPE_SHORT);
        target.writeShort((Short) param);
    } else {
        // Unexpected type, drop.
    }
}
 
Example 10
Source File: OutPlayerPositionAndLookCodec.java    From Cleanstone with MIT License 5 votes vote down vote up
@Override
public ByteBuf encode(ByteBuf byteBuf, OutPlayerPositionAndLookPacket packet) {

    byteBuf.writeDouble(packet.getPosition().getX());
    byteBuf.writeDouble(packet.getPosition().getY());
    byteBuf.writeDouble(packet.getPosition().getZ());
    byteBuf.writeFloat(packet.getPosition().getRotation().getYaw());
    byteBuf.writeFloat(packet.getPosition().getRotation().getPitch());
    byteBuf.writeByte(packet.getFlags());
    ByteBufUtils.writeVarInt(byteBuf, packet.getTeleportID());

    return byteBuf;
}
 
Example 11
Source File: CFoodPacket.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void toBytes(ByteBuf buffer)
{
	buffer.writeFloat(nutritionFruit);
	buffer.writeFloat(nutritionVeg);
	buffer.writeFloat(nutritionGrain);
	buffer.writeFloat(nutritionProtein);
	buffer.writeFloat(nutritionDairy);
	buffer.writeFloat(waterLevel);
}
 
Example 12
Source File: PacketPlaySound.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void toBytes(ByteBuf buffer){
    super.toBytes(buffer);
    ByteBufUtils.writeUTF8String(buffer, sound);
    buffer.writeFloat(volume);
    buffer.writeFloat(pitch);
    buffer.writeBoolean(bool);
}
 
Example 13
Source File: MessageExplode.java    From AdvancedMod with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void toBytes(ByteBuf buf){
    buf.writeFloat(explosionSize);
}
 
Example 14
Source File: NetworkEntityMetadataObjectVector3f.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void writeToStream(ByteBuf to, ProtocolVersion version, String locale) {
	to.writeFloat((float) value.getX());
	to.writeFloat((float) value.getY());
	to.writeFloat((float) value.getZ());
}
 
Example 15
Source File: FloatType.java    From ViaVersion with MIT License 4 votes vote down vote up
public void writePrimitive(ByteBuf buffer, float object) {
    buffer.writeFloat(object);
}
 
Example 16
Source File: MultiblockTurbineSimulator.java    From reactor_simulator with MIT License 4 votes vote down vote up
/**
 * Used when dispatching update packets from the server.
 * @param buf ByteBuf into which the turbine's full status should be written
 */
public void serialize(ByteBuf buf) {
  // Capture compacted fluid data first
  int inputFluidID, inputFluidAmt, outputFluidID, outputFluidAmt;
  {
    FluidStack inputFluid, outputFluid;
    inputFluid = tanks[TANK_INPUT].getFluid();
    outputFluid = tanks[TANK_OUTPUT].getFluid();

    if (inputFluid == null || inputFluid.amount <= 0) {
      inputFluidID = FLUID_NONE;
      inputFluidAmt = 0;
    } else {
      inputFluidID = inputFluid.getFluid().getID();
      inputFluidAmt = inputFluid.amount;
    }

    if (outputFluid == null || outputFluid.amount <= 0) {
      outputFluidID = FLUID_NONE;
      outputFluidAmt = 0;
    } else {
      outputFluidID = outputFluid.getFluid().getID();
      outputFluidAmt = outputFluid.amount;
    }
  }

  // User settings
  buf.writeBoolean(active);
  buf.writeBoolean(inductorEngaged);
  buf.writeInt(ventStatus.ordinal());
  buf.writeInt(maxIntakeRate);

  // Basic stats
  buf.writeFloat(energyStored);
  buf.writeFloat(rotorEnergy);

  // Reportage statistics
  buf.writeFloat(energyGeneratedLastTick);
  buf.writeInt(fluidConsumedLastTick);
  buf.writeFloat(rotorEfficiencyLastTick);

  // Fluid data
  buf.writeInt(inputFluidID);
  buf.writeInt(inputFluidAmt);
  buf.writeInt(outputFluidID);
  buf.writeInt(outputFluidAmt);
}
 
Example 17
Source File: PacketSendMana.java    From YouTubeModdingTutorial with MIT License 4 votes vote down vote up
@Override
public void toBytes(ByteBuf buf) {
    buf.writeFloat(mana);
    buf.writeFloat(influence);
    buf.writeFloat(playerMana);
}
 
Example 18
Source File: FloatType.java    From ViaVersion with MIT License 4 votes vote down vote up
/**
 * @deprecated use {@link #writePrimitive(ByteBuf, float)} for manual reading to avoid wrapping
 */
@Override
@Deprecated
public void write(ByteBuf buffer, Float object) {
    buffer.writeFloat(object);
}
 
Example 19
Source File: PacketStationUpdate.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
@Override
public void write(ByteBuf out) {
	out.writeInt(stationNumber);
	out.writeInt(type.ordinal());

	switch(type) {
	case DEST_ORBIT_UPDATE:
		out.writeInt(spaceObject.getDestOrbitingBody());
		break;
	case ORBIT_UPDATE:
		out.writeInt(spaceObject.getOrbitingPlanetId());
		break;
	case FUEL_UPDATE:
		if(spaceObject instanceof SpaceObject)
			out.writeInt(((SpaceObject)spaceObject).getFuelAmount());
		break;
	case ROTANGLE_UPDATE:
		out.writeDouble(spaceObject.getRotation(EnumFacing.EAST));
		out.writeDouble(spaceObject.getRotation(EnumFacing.UP));
		out.writeDouble(spaceObject.getRotation(EnumFacing.NORTH));
		out.writeDouble(spaceObject.getDeltaRotation(EnumFacing.EAST));
		out.writeDouble(spaceObject.getDeltaRotation(EnumFacing.UP));
		out.writeDouble(spaceObject.getDeltaRotation(EnumFacing.NORTH));
		break;
	case ALTITUDE_UPDATE:
		out.writeFloat(spaceObject.getOrbitalDistance());
		break;
	case DIM_PROPERTY_UPDATE:
		NBTTagCompound nbt = new NBTTagCompound();
		try {
			spaceObject.getProperties().writeToNBT(nbt);
			PacketBuffer packetBuffer = new PacketBuffer(out);
			packetBuffer.writeCompoundTag(nbt);
		} catch(NullPointerException e) {
			out.writeBoolean(true);
			Logger.getLogger("advancedRocketry").warning("Dimension " + stationNumber + " has thrown an exception trying to write NBT, deleting!");
			DimensionManager.getInstance().deleteDimension(stationNumber);
		}
	default:
	}
}
 
Example 20
Source File: RealType.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public int writeAsBinary(ByteBuf buffer, @Nonnull Float value) {
    buffer.writeInt(TYPE_LEN);
    buffer.writeFloat(value);
    return INT32_BYTE_SIZE + TYPE_LEN;
}