List of usage examples for io.netty.buffer ByteBuf writeFloat
public abstract ByteBuf writeFloat(float value);
From source file:appeng.core.sync.packets.PacketClick.java
License:Open Source License
public PacketClick(final BlockPos pos, final EnumFacing side, final float hitX, final float hitY, final float hitZ, final EnumHand hand) { final ByteBuf data = Unpooled.buffer(); data.writeInt(this.getPacketID()); data.writeInt(this.x = pos.getX()); data.writeInt(this.y = pos.getY()); data.writeInt(this.z = pos.getZ()); if (side == null) { data.writeByte(-1);/*from ww w .ja v a 2 s . co m*/ } else { data.writeByte(side.ordinal()); } data.writeFloat(this.hitX = hitX); data.writeFloat(this.hitY = hitY); data.writeFloat(this.hitZ = hitZ); data.writeByte(hand.ordinal()); this.configureWrite(data); }
From source file:appeng.core.sync.packets.PacketLightning.java
License:Open Source License
public PacketLightning(final double x, final double y, final double z) { this.x = x;/* w w w. j ava 2 s .c o m*/ this.y = y; this.z = z; final ByteBuf data = Unpooled.buffer(); data.writeInt(this.getPacketID()); data.writeFloat((float) x); data.writeFloat((float) y); data.writeFloat((float) z); this.configureWrite(data); }
From source file:appeng.core.sync.packets.PacketMatterCannon.java
License:Open Source License
public PacketMatterCannon(final double x, final double y, final double z, final float dx, final float dy, final float dz, final byte len) { final float dl = dx * dx + dy * dy + dz * dz; final float dlz = (float) Math.sqrt(dl); this.x = x;//from w w w . j a va 2s . c o m this.y = y; this.z = z; this.dx = dx / dlz; this.dy = dy / dlz; this.dz = dz / dlz; this.len = len; final ByteBuf data = Unpooled.buffer(); data.writeInt(this.getPacketID()); data.writeFloat((float) x); data.writeFloat((float) y); data.writeFloat((float) z); data.writeFloat((float) this.dx); data.writeFloat((float) this.dy); data.writeFloat((float) this.dz); data.writeByte(len); this.configureWrite(data); }
From source file:appeng.core.sync.packets.PacketPartPlacement.java
License:Open Source License
public PacketPartPlacement(final BlockPos pos, final EnumFacing face, final float eyeHeight, final EnumHand hand) { final ByteBuf data = Unpooled.buffer(); data.writeInt(this.getPacketID()); data.writeInt(pos.getX());/*from w w w .j a v a 2 s. c om*/ data.writeInt(pos.getY()); data.writeInt(pos.getZ()); data.writeByte(face.ordinal()); data.writeFloat(eyeHeight); data.writeByte(hand.ordinal()); this.configureWrite(data); }
From source file:appeng.core.sync.packets.PacketTransitionEffect.java
License:Open Source License
public PacketTransitionEffect(final double x, final double y, final double z, final AEPartLocation dir, final boolean wasBlock) { this.x = x;// ww w . j a va2s .c om this.y = y; this.z = z; this.d = dir; this.mode = wasBlock; final ByteBuf data = Unpooled.buffer(); data.writeInt(this.getPacketID()); data.writeFloat((float) x); data.writeFloat((float) y); data.writeFloat((float) z); data.writeByte(this.d.ordinal()); data.writeBoolean(wasBlock); this.configureWrite(data); }
From source file:buildcraft.builders.TileQuarry.java
License:Minecraft Mod Public
@Override public void writeData(ByteBuf stream) { super.writeData(stream); box.writeData(stream);// w w w. j av a2 s .c o m stream.writeInt(targetX); stream.writeShort(targetY); stream.writeInt(targetZ); stream.writeDouble(headPosX); stream.writeDouble(headPosY); stream.writeDouble(headPosZ); stream.writeFloat((float) speed); stream.writeFloat(headTrajectory); int flags = stage.ordinal(); flags |= movingHorizontally ? 0x10 : 0; flags |= movingVertically ? 0x20 : 0; stream.writeByte(flags); ledState = (hasWork() && mode != Mode.Off && getTicksSinceEnergyReceived() < 12 ? 16 : 0) | (getBattery().getEnergyStored() * 15 / getBattery().getMaxEnergyStored()); stream.writeByte(ledState); }
From source file:buildcraft.core.network.PacketPayloadArrays.java
License:Minecraft Mod Public
@Override public void writeData(ByteBuf data) { data.writeInt(intPayload.length);// www . j a v a 2s.com data.writeInt(floatPayload.length); data.writeInt(stringPayload.length); for (int intData : intPayload) { data.writeInt(intData); } for (float floatData : floatPayload) { data.writeFloat(floatData); } for (String stringData : stringPayload) { Utils.writeUTF(data, stringData); } }
From source file:buildcraft.core.network.RPCHandler.java
License:Minecraft Mod Public
private void writeParameters(String method, ByteBuf data, Object... actuals) throws IOException, IllegalArgumentException, IllegalAccessException { if (!methodsMap.containsKey(method)) { throw new RuntimeException(method + " is not a callable method of " + getClass().getName()); }// w w w .jav a2 s. co m int methodIndex = methodsMap.get(method); MethodMapping m = methods[methodIndex]; Class[] formals = m.parameters; int expectedParameters = m.hasInfo ? formals.length - 1 : formals.length; if (expectedParameters != actuals.length) { // We accept formals + 1 as an argument, in order to support the // special last argument RPCMessageInfo throw new RuntimeException(getClass().getName() + "." + method + " expects " + m.parameters.length + " parameters, not " + actuals.length); } data.writeShort(methodIndex); SerializationContext context = new SerializationContext(); for (int i = 0; i < actuals.length; ++i) { if (int.class.equals(formals[i])) { data.writeInt((Integer) actuals[i]); } else if (float.class.equals(formals[i])) { data.writeFloat((Float) actuals[i]); } else if (char.class.equals(formals[i])) { data.writeChar((Character) actuals[i]); } else { m.mappings[i].write(data, actuals[i], context); } } }
From source file:buildcraft.core.network.serializers.ClassMapping.java
License:Minecraft Mod Public
@SuppressWarnings("rawtypes") void writeClass(Object obj, ByteBuf data, SerializationContext context) throws IllegalArgumentException, IllegalAccessException { Class realClass = obj.getClass(); if (realClass.equals(this.mappedClass)) { data.writeByte(0);/*from w ww. jav a 2 s . c om*/ } else { ClassMapping delegateMapping; if (context.classToId.containsKey(realClass.getCanonicalName())) { int index = context.classToId.get(realClass.getCanonicalName()) + 1; data.writeByte(index); delegateMapping = (ClassMapping) context.idToClass.get(index - 1); } else { int index = context.classToId.size() + 1; delegateMapping = (ClassMapping) get(realClass); data.writeByte(index); Utils.writeUTF(data, realClass.getCanonicalName()); context.classToId.put(realClass.getCanonicalName(), context.classToId.size()); context.idToClass.add(delegateMapping); } delegateMapping.writeClass(obj, data, context); return; } for (Field f : shortFields) { data.writeShort(f.getShort(obj)); } for (Field f : intFields) { data.writeInt(f.getInt(obj)); } for (Field f : booleanFields) { data.writeBoolean(f.getBoolean(obj)); } for (Field f : enumFields) { data.writeByte(((Enum) f.get(obj)).ordinal()); } for (Field f : floatFields) { data.writeFloat(f.getFloat(obj)); } for (Field f : doubleFields) { data.writeDouble(f.getDouble(obj)); } for (FieldObject f : objectFields) { Object cpt = f.field.get(obj); f.mapping.write(data, cpt, context); } }
From source file:buildcraft.core.network.serializers.ClassMapping.java
License:Minecraft Mod Public
private void writeArray(Object obj, ByteBuf data, SerializationContext context) throws IllegalArgumentException, IllegalAccessException { Class<? extends Object> cpt = mappedClass.getComponentType(); switch (cptType) { case Byte: { byte[] arr = (byte[]) obj; data.writeInt(arr.length);/*from w w w . j av a2 s . c om*/ data.writeBytes(arr); break; } case Float: { float[] arr = (float[]) obj; data.writeInt(arr.length); for (float element : arr) { data.writeFloat(element); } break; } case Double: { double[] arr = (double[]) obj; data.writeInt(arr.length); for (double element : arr) { data.writeDouble(element); } break; } case Short: { short[] arr = (short[]) obj; data.writeInt(arr.length); for (short element : arr) { data.writeShort(element); } break; } case Int: { int[] arr = (int[]) obj; data.writeInt(arr.length); for (int element : arr) { data.writeInt(element); } break; } case Boolean: { boolean[] arr = (boolean[]) obj; data.writeInt(arr.length); for (boolean element : arr) { data.writeBoolean(element); } break; } case Object: { Object[] arr = (Object[]) obj; data.writeInt(arr.length); for (Object element : arr) { cptMapping.write(data, element, context); } break; } } }