// api
  public PacketMatterCannon(double x, double y, double z, float dx, float dy, float dz, byte len) {
    float dl = dx * dx + dy * dy + dz * dz;
    float dlz = (float) Math.sqrt(dl);

    this.x = x;
    this.y = y;
    this.z = z;
    this.dx = dx / dlz;
    this.dy = dy / dlz;
    this.dz = dz / dlz;
    this.len = len;

    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);
  }
 public void writeData(ByteBuf data) {
   data.writeByte(getDataTypeID());
   data.writeShort(id);
   data.writeShort(getDataFlags());
   data.writeByte(getDataSides());
   data.writeFloat(dX);
   data.writeFloat(dY);
   data.writeFloat(dZ);
 }
Example #3
0
 public ByteBuf encode(ByteBuf buf, PositionRotationMessage message) throws IOException {
   buf.writeDouble(message.getX());
   buf.writeDouble(message.getY());
   buf.writeDouble(message.getZ());
   buf.writeFloat(message.getRotation());
   buf.writeFloat(message.getPitch());
   buf.writeBoolean(message.isOnGround());
   return buf;
 }
Example #4
0
 public ByteBuf encode(ByteBuf buf, PlayerPositionLookMessage message) throws IOException {
   buf.writeDouble(message.getX());
   buf.writeDouble(message.getY());
   buf.writeDouble(message.getHeadY());
   buf.writeDouble(message.getZ());
   buf.writeFloat(message.getYaw());
   buf.writeFloat(message.getPitch());
   buf.writeBoolean(message.getOnGround());
   return buf;
 }
  @Override
  public void encode(ByteBuf buf) {
    buf.writeDouble(this.location.getX());
    buf.writeDouble(this.location.getY());
    buf.writeDouble(this.location.getZ());

    buf.writeFloat(this.location.getYaw());
    buf.writeFloat(this.location.getPitch());

    buf.writeByte((int) this.flags);
  }
Example #6
0
 @Override
 public void toBytes(ByteBuf buf) {
   buf.writeInt(x);
   buf.writeInt(y);
   buf.writeInt(z);
   buf.writeFloat(storedEnergy);
 }
Example #7
0
  @Override
  public void toBytes(ByteBuf buf) {
    buf.writeInt(posX);
    buf.writeInt(posY);
    buf.writeInt(posZ);
    buf.writeInt(data.size());

    for (int i = 0; i < data.size(); i++) {
      Object obj = data.get(i);
      if (obj instanceof Character) {
        buf.writeByte(0x00);
        buf.writeChar((Character) obj);
      } else if (obj instanceof String) {
        buf.writeByte(0x01);
        writeString(buf, (String) obj);
      } else if (obj instanceof Float) {
        buf.writeByte(0x02);
        buf.writeFloat((Float) obj);
      } else if (obj instanceof Double) {
        buf.writeByte(0x03);
        buf.writeDouble((Double) obj);
      } else if (obj instanceof Byte) {
        buf.writeByte(0x04);
        buf.writeByte((Byte) obj);
      } else if (obj instanceof Long) {
        buf.writeByte(0x05);
        buf.writeLong((Long) obj);
      } else {
        buf.writeByte(0x0F);
        buf.writeInt((Integer) obj);
      }
    }
  }
 @Override
 public void toBytes(ByteBuf buf) {
   buf.writeInt(entityID);
   buf.writeInt(componentID);
   buf.writeBoolean(ident != null);
   if (ident != null) ident.serializeBuf(buf);
   buf.writeFloat(progress);
 }
 @Override
 public void toBytes(ByteBuf buf) {
   buf.writeDouble(this.posX);
   buf.writeDouble(this.posY);
   buf.writeDouble(this.posZ);
   buf.writeFloat(this.strength);
   buf.writeBoolean(this.showParticles);
 }
 @Override
 public void toBytes(ByteBuf buf) {
   buf.writeInt(vehicleID);
   buf.writeDouble(posX);
   buf.writeDouble(posY);
   buf.writeDouble(posZ);
   buf.writeDouble(motX);
   buf.writeDouble(motY);
   buf.writeDouble(motZ);
   buf.writeFloat(yaw);
   buf.writeFloat(pitch);
   buf.writeFloat(roll);
   buf.writeDouble(throttle);
   buf.writeFloat(steeringAngle);
   buf.writeInt(ticksSinceEntered);
   buf.writeInt(ticksSinceLeft);
 }
  @Override
  public void encode(ByteBuf buf) {
    buf.writeInt(this.particleId);
    buf.writeBoolean(this.distance);

    buf.writeFloat((float) this.loc.getX());
    buf.writeFloat((float) this.loc.getY());
    buf.writeFloat((float) this.loc.getZ());

    buf.writeFloat((float) this.offset.getX());
    buf.writeFloat((float) this.offset.getY());
    buf.writeFloat((float) this.offset.getZ());

    buf.writeFloat(this.particleData);
    buf.writeInt(this.data.length);

    for (int i : this.data) {
      Codec.writeVarInt32(buf, i);
    }
  }
Example #12
0
  @SuppressWarnings("unchecked")
  public static void writeMetadata(ByteBuf out, MetaParam<?>[] parameters) throws IOException {
    Objects.requireNonNull(parameters, "Metadata cannot be null!");

    for (MetaParam<?> parameter : parameters) {
      if (parameter
          == null) // Parameter on current index is not set, continue to see if the next index has
                   // some parameter.
      continue;

      int type = (parameter.getType().getId() << 5 | parameter.getIndex() & 31) & 255;
      out.writeByte(type);

      switch (parameter.getType()) {
        case BYTE:
          out.writeByte(((MetaParam<Byte>) parameter).getValue());
          break;

        case SHORT:
          out.writeShort(((MetaParam<Short>) parameter).getValue());
          break;

        case INT:
          out.writeInt(((MetaParam<Integer>) parameter).getValue());
          break;

        case FLOAT:
          out.writeFloat(((MetaParam<Float>) parameter).getValue());
          break;

        case STRING:
          writeString(((MetaParam<String>) parameter).getValue(), out);
          break;

        case ITEM:
          ItemStack item = ((MetaParam<ItemStack>) parameter).getValue();
          writeItemstack(item, out);
          break;

        case COORDINATE:
          Position coord = ((MetaParam<Position>) parameter).getValue();
          writePosIntegers(coord.intX(), coord.intY(), coord.intZ(), out);
      }
    }
    out.writeByte(127);
  }
 @Override
 public MessageBuffer<ByteBuf> writeFloat(float value) {
   buffer.writeFloat(value);
   return this;
 }
Example #14
0
 @Override
 public ByteBuf writeFloat(float value) {
   return buf.writeFloat(value);
 }
 @Override
 public void encode(ByteBuf buf) {
   buf.writeFloat(this.health);
   Codec.writeVarInt32(buf, this.food);
   buf.writeFloat(this.foodSaturation);
 }
Example #16
0
 public void writeToStream(ByteBuf out) {
   out.writeFloat(x);
   out.writeFloat(y);
   out.writeFloat(z);
 }
 @Override
 public void write(ByteBuf buf) throws Exception {
   buf.writeFloat(x);
   buf.writeFloat(y);
   buf.writeFloat(z);
 }
 @Override
 public void toBytes(ByteBuf buf) {
   buf.writeInt(rfPerTick);
   buf.writeFloat(power);
 }
Example #19
0
  @Override
  public void encode(ByteBuf buf) {
    // For testing purposes using default dummy entity :)
    /*boolean dummy = false;
    if (name.contains("dummy")) dummy = true;*/

    buf.writeLong(id); // Ulong but whatever
    buf.writeBytes(bitSet.toByteArray());
    buf.writeBytes(
        new byte
            [8 - bitSet.toByteArray().length]); // BitSet/BitArray are the stupidest classes ever :(
    if (bitSet.get(0)) {
      writeLongVector3(buf, position);
    }
    if (bitSet.get(1)) {
      writeOrientation(buf, orientation);
    }
    if (bitSet.get(2)) {
      writeFloatVector3(buf, velocity);
    }
    if (bitSet.get(3)) {
      writeFloatVector3(buf, accel);
    }
    if (bitSet.get(4)) {
      writeFloatVector3(buf, extraVel);
    }
    if (bitSet.get(5)) {
      buf.writeFloat(lookPitch);
    }
    if (bitSet.get(6)) {
      buf.writeInt((int) physicsFlags);
    }
    if (bitSet.get(7)) {
      buf.writeByte(hostileType);
    }
    if (bitSet.get(8)) {
      buf.writeInt((int) entityType);
    }
    if (bitSet.get(9)) {
      buf.writeByte(currentMode);
    }
    if (bitSet.get(10)) {
      buf.writeInt((int) lastShootTime);
    }
    if (bitSet.get(11)) {
      buf.writeInt((int) hitCounter);
    }
    if (bitSet.get(12)) {
      buf.writeInt((int) lastHitTime);
    }
    if (bitSet.get(13)) {
      app.encode(buf);
    }
    if (bitSet.get(14)) {
      buf.writeByte(flags1);
      buf.writeByte(flags2);
    }
    if (bitSet.get(15)) {
      buf.writeInt((int) rollTime);
    }
    if (bitSet.get(16)) {
      buf.writeInt(stunTime);
    }
    if (bitSet.get(17)) {
      buf.writeInt((int) slowedTime);
    }
    if (bitSet.get(18)) {
      buf.writeInt((int) makeBlueTime);
    }
    if (bitSet.get(19)) {
      buf.writeInt((int) speedUpTime);
    }
    if (bitSet.get(20)) {
      buf.writeFloat(slowPatchTime);
    }
    if (bitSet.get(21)) {
      buf.writeByte(classType);
    }
    if (bitSet.get(22)) {
      buf.writeByte(specialization);
    }
    if (bitSet.get(23)) {
      buf.writeFloat(chargedMP);
    }
    if (bitSet.get(24)) {
      buf.writeInt((int) nu1);
      buf.writeInt((int) nu2);
      buf.writeInt((int) nu3);
    }
    if (bitSet.get(25)) {
      buf.writeInt((int) nu4);
      buf.writeInt((int) nu5);
      buf.writeInt((int) nu6);
    }
    if (bitSet.get(26)) {
      writeFloatVector3(buf, rayHit);
    }
    if (bitSet.get(27)) {
      buf.writeFloat(HP);
    }
    if (bitSet.get(28)) {
      buf.writeFloat(MP);
    }
    if (bitSet.get(29)) {
      buf.writeFloat(blockPower);
    }
    if (bitSet.get(30)) {
      buf.writeFloat(maxHPMultiplier);
      buf.writeFloat(shootSpeed);
      buf.writeFloat(damageMultiplier);
      buf.writeFloat(armorMultiplier);
      buf.writeFloat(resistanceMultiplier);
    }
    if (bitSet.get(31)) {
      buf.writeByte(nu7);
    }
    if (bitSet.get(32)) {
      buf.writeByte(nu8);
    }
    if (bitSet.get(33)) {
      buf.writeInt((int) level);
    }
    if (bitSet.get(34)) {
      buf.writeInt((int) currentXP);
    }
    if (bitSet.get(35)) {
      buf.writeLong(parentOwner);
    }
    if (bitSet.get(36)) {
      buf.writeInt((int) na1);
      buf.writeInt((int) na2);
    }
    if (bitSet.get(37)) {
      buf.writeByte(na3);
    }
    if (bitSet.get(38)) {
      buf.writeInt((int) na4);
    }
    if (bitSet.get(39)) {
      buf.writeInt((int) na5);
      buf.writeInt((int) nu11);
      buf.writeInt((int) nu12);
    }
    if (bitSet.get(40)) {
      writeLongVector3(buf, spawnPosition);
    }
    if (bitSet.get(41)) {
      buf.writeInt((int) nu20);
      buf.writeInt((int) nu21);
      buf.writeInt((int) nu22);
    }
    if (bitSet.get(42)) {
      buf.writeByte(nu19);
    }
    if (bitSet.get(43)) {
      itemData.encode(buf);
    }
    if (bitSet.get(44)) {
      for (int i = 0; i < 13; i++) {
        GItem item = equipment[i];
        item.encode(buf);
      }
    }
    if (bitSet.get(45)) {
      byte[] ascii = name.getBytes(Charsets.US_ASCII);
      buf.writeBytes(ascii);
      buf.writeBytes(new byte[16 - name.length()]);
    }
    if (bitSet.get(46)) {
      for (int i = 0; i < 11; i++) {
        buf.writeInt((int) skills[i]);
      }
    }
    if (bitSet.get(47)) {
      buf.writeInt((int) iceBlockFour);
    }

    buf.capacity(buf.writerIndex() + 1);
    if (buf.readerIndex() > 0) {
      Glydar.getServer().getLogger().warning("Data read during encode.");
    }
  }
 public void setFloat(float value) {
   data.writeFloat(value);
 }
 @Override
 public ByteBuf writeFloat(float var1) {
   return a.writeFloat(var1);
 }
Example #22
0
 /**
  * Appends the specified {@code float} to the end of the Buffer. The buffer will expand as
  * necessary to accommodate any bytes written.
  *
  * <p>Returns a reference to {@code this} so multiple operations can be appended together.
  */
 public Buffer appendFloat(float f) {
   buffer.writeFloat(f);
   return this;
 }
Example #23
0
  @SuppressWarnings("restriction")
  @Override
  public void encode(ByteBuf buf) {
    buf.writeLong(id); // Ulong but whatever
    // TODO: Not sure exactly how to approach writing unsigned ints!
    BitArray bitArray = new BitArray(8 * bitmask.length, bitmask); // Size in bits, byte[]
    buf.writeBytes(bitmask);

    if (bitArray.get(0)) {
      buf.writeLong(posX);
      buf.writeLong(posY);
      buf.writeLong(posZ);
    }
    if (bitArray.get(1)) {
      buf.writeFloat(pitch);
      buf.writeFloat(roll);
      buf.writeFloat(yaw);
    }
    if (bitArray.get(2)) {
      velocity.encode(buf);
    }
    if (bitArray.get(3)) {
      accel.encode(buf);
    }
    if (bitArray.get(4)) {
      extraVel.encode(buf);
    }
    if (bitArray.get(5)) {
      buf.writeFloat(lookPitch);
    }
    if (bitArray.get(6)) {
      buf.writeInt((int) physicsFlags);
    }
    if (bitArray.get(7)) {
      buf.writeByte(speedFlags);
    }
    if (bitArray.get(8)) {
      buf.writeInt((int) entityType);
    }
    if (bitArray.get(9)) {
      buf.writeByte(currentMode);
    }
    if (bitArray.get(10)) {
      buf.writeInt((int) lastShootTime);
    }
    if (bitArray.get(11)) {
      buf.writeInt((int) hitCounter);
    }
    if (bitArray.get(12)) {
      buf.writeInt((int) lastHitTime);
    }
    if (bitArray.get(13)) {
      app.encode(buf);
    }
    if (bitArray.get(14)) {
      buf.writeByte(flags1);
      buf.writeByte(flags2);
    }
    if (bitArray.get(15)) {
      buf.writeInt((int) rollTime);
    }
    if (bitArray.get(16)) {
      buf.writeInt(stunTime);
    }
    if (bitArray.get(17)) {
      buf.writeInt((int) slowedTime);
    }
    if (bitArray.get(18)) {
      buf.writeInt((int) makeBlueTime);
    }
    if (bitArray.get(19)) {
      buf.writeInt((int) speedUpTime);
    }
    if (bitArray.get(20)) {
      buf.writeFloat(slowPatchTime);
    }
    if (bitArray.get(21)) {
      buf.writeByte(classType);
    }
    if (bitArray.get(22)) {
      buf.writeByte(specialization);
    }
    if (bitArray.get(23)) {
      buf.writeFloat(chargedMP);
    }
    if (bitArray.get(24)) {
      buf.writeInt((int) nu1);
      buf.writeInt((int) nu2);
      buf.writeInt((int) nu3);
    }
    if (bitArray.get(25)) {
      buf.writeInt((int) nu4);
      buf.writeInt((int) nu5);
      buf.writeInt((int) nu6);
    }
    if (bitArray.get(26)) {
      rayHit.encode(buf);
    }
    if (bitArray.get(27)) {
      buf.writeFloat(HP);
    }
    if (bitArray.get(28)) {
      buf.writeFloat(MP);
    }
    if (bitArray.get(29)) {
      buf.writeFloat(blockPower);
    }
    if (bitArray.get(30)) {
      buf.writeFloat(maxHPMultiplier);
      buf.writeFloat(shootSpeed);
      buf.writeFloat(damageMultiplier);
      buf.writeFloat(armorMultiplier);
      buf.writeFloat(resistanceMultiplier);
    }
    if (bitArray.get(31)) {
      buf.writeByte(nu7);
    }
    if (bitArray.get(32)) {
      buf.writeByte(nu8);
    }
    if (bitArray.get(33)) {
      buf.writeInt((int) level);
    }
    if (bitArray.get(34)) {
      buf.writeInt((int) currentXP);
    }
    if (bitArray.get(35)) {
      buf.writeLong(parentOwner);
    }
    if (bitArray.get(36)) {
      buf.writeInt((int) na1);
      buf.writeInt((int) na2);
    }
    if (bitArray.get(37)) {
      buf.writeByte(na3);
    }
    if (bitArray.get(38)) {
      buf.writeInt((int) na4);
    }
    if (bitArray.get(39)) {
      buf.writeInt((int) na5);
      buf.writeInt((int) nu11);
      buf.writeInt((int) nu12);
    }
    if (bitArray.get(40)) {
      buf.writeInt((int) nu13);
      buf.writeInt((int) nu14);
      buf.writeInt((int) nu15);
      buf.writeInt((int) nu16);
      buf.writeInt((int) nu17);
      buf.writeInt((int) nu18);
    }
    if (bitArray.get(41)) {
      buf.writeInt((int) nu20);
      buf.writeInt((int) nu21);
      buf.writeInt((int) nu22);
    }
    if (bitArray.get(42)) {
      buf.writeByte(nu19);
    }
    if (bitArray.get(43)) {
      itemData.encode(buf);
    }
    if (bitArray.get(44)) {
      for (int i = 0; i < 13; i++) {
        GItem item = equipment[i];
        item.encode(buf);
      }
    }
    if (bitArray.get(45)) {
      byte[] utf8 = name.getBytes(Charsets.UTF_8);
      buf.writeBytes(new byte[4]); // TODO But why?
      buf.writeBytes(utf8);
      buf.writeBytes(new byte[16 - name.length()]);
    }
    if (bitArray.get(46)) {
      for (int i = 0; i < 11; i++) {
        buf.writeInt((int) skills[i]);
      }
    }
    if (bitArray.get(47)) {
      buf.writeInt((int) iceBlockFour);
    }

    buf.capacity(buf.writerIndex() + 1);
    if (buf.readerIndex() > 0) {
      System.out.println("I read something during an encode?!");
    }
  }