/* Save generated parameters in a binary file */
  public void saveParam(String fileName, HTSPStream par, HMMData.FeatureType type) {
    int t, m, i;
    try {

      if (type == HMMData.FeatureType.LF0) {
        fileName += ".f0";
        DataOutputStream data_out = new DataOutputStream(new FileOutputStream(fileName));
        i = 0;
        for (t = 0; t < voiced.length; t++) {
            /* here par.getT are just the voiced!!! */
          if (voiced[t]) {
            data_out.writeFloat((float) Math.exp(par.getPar(i, 0)));
            i++;
          } else data_out.writeFloat((float) 0.0);
        }
        data_out.close();

      } else if (type == HMMData.FeatureType.MGC) {
        fileName += ".mgc";
        DataOutputStream data_out = new DataOutputStream(new FileOutputStream(fileName));
        for (t = 0; t < par.getT(); t++)
          for (m = 0; m < par.getOrder(); m++) data_out.writeFloat((float) par.getPar(t, m));
        data_out.close();
      }

      logger.info("saveParam in file: " + fileName);

    } catch (IOException e) {
      logger.info("IO exception = " + e);
    }
  }
Ejemplo n.º 2
0
  public static Packet buildSoundPacket(double x, double y, double z, String s, boolean distort) {
    Packet250CustomPayload packet = new Packet250CustomPayload();
    packet.channel = channelFlan;

    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    DataOutputStream data = new DataOutputStream(bytes);
    try {
      data.write(packetID); // this is the packet ID. identifies it as a BreakSoundPacket
      data.writeFloat((float) x);
      data.writeFloat((float) y);
      data.writeFloat((float) z);
      data.writeUTF(s);
      data.writeBoolean(distort);

      packet.data = bytes.toByteArray();
      packet.length = packet.data.length;

      data.close();
      bytes.close();
    } catch (Exception e) {
      e.printStackTrace();
    }

    return packet;
  }
Ejemplo n.º 3
0
 /**
  * Write this chunk texture to an output stream
  *
  * @param out
  * @throws IOException
  */
 public void store(DataOutputStream out) throws IOException {
   for (int i = 0; i < Chunk.X_MAX * Chunk.Z_MAX; ++i) {
     out.writeFloat(data[i][0]);
     out.writeFloat(data[i][1]);
     out.writeFloat(data[i][2]);
   }
 }
 private void writeFloat32(DataOutputStream output, Float f) throws IOException {
   if (f == null) output.writeFloat(Float.MIN_VALUE);
   else if (f.floatValue() == Float.MIN_VALUE)
     throw new SerializationException(
         "Underflow: attempt to store "
             + Float.MIN_VALUE
             + " in float32, but that value is reserved for null.");
   else output.writeFloat(f.floatValue());
 }
Ejemplo n.º 5
0
 public void marshal(DataOutputStream dos) {
   try {
     dos.writeFloat((float) x);
     dos.writeFloat((float) y);
     dos.writeFloat((float) z);
   } // end try
   catch (Exception e) {
     System.out.println(e);
   }
 } // end of marshal method
Ejemplo n.º 6
0
  public void sendPacket(
      double posX, double posY, double posZ, float strength, List list, Vec3 vec3) {
    if (worldObj.isRemote) {
      return;
    }

    final ByteArrayOutputStream bos = new ByteArrayOutputStream(140);
    final DataOutputStream dos = new DataOutputStream(bos);
    try {
      dos.writeInt(1);
      dos.writeDouble(posX);
      dos.writeDouble(posY);
      dos.writeDouble(posZ);
      dos.writeFloat(strength);
      dos.write(list.size());

      final int var2 = (int) posX;
      final int var3 = (int) posY;
      final int var4 = (int) posZ;
      final Iterator var5 = list.iterator();

      while (var5.hasNext()) {
        final ChunkPosition var6 = (ChunkPosition) var5.next();
        final int var7 = var6.x - var2;
        final int var8 = var6.y - var3;
        final int var9 = var6.z - var4;
        dos.writeByte(var7);
        dos.writeByte(var8);
        dos.writeByte(var9);
      }

      if (vec3 != null) {
        dos.writeFloat((float) vec3.xCoord);
        dos.writeFloat((float) vec3.yCoord);
        dos.writeFloat((float) vec3.xCoord);
      } else {

        dos.writeFloat(0.0F);
        dos.writeFloat(0.0F);
        dos.writeFloat(0.0F);
      }
    } catch (final IOException e) {
      // UNPOSSIBLE?
    }
    final Packet250CustomPayload packet = new Packet250CustomPayload();
    packet.channel = "MetallurgyBase";
    packet.data = bos.toByteArray();
    packet.length = bos.size();
    packet.isChunkDataPacket = true;

    if (packet != null) {
      PacketDispatcher.sendPacketToAllAround(
          posX, posY, posZ, 16, worldObj.provider.dimensionId, packet);
    }
  }
 public void func_73273_a(DataOutputStream p_73273_1_) throws IOException {
   func_73271_a(this.field_98209_a, p_73273_1_);
   p_73273_1_.writeFloat(this.field_98207_b);
   p_73273_1_.writeFloat(this.field_98208_c);
   p_73273_1_.writeFloat(this.field_98205_d);
   p_73273_1_.writeFloat(this.field_98206_e);
   p_73273_1_.writeFloat(this.field_98203_f);
   p_73273_1_.writeFloat(this.field_98204_g);
   p_73273_1_.writeFloat(this.field_98210_h);
   p_73273_1_.writeInt(this.field_98211_i);
 }
 public void serializeObject(Object o, DataOutputStream stream) throws IOException {
   if (o instanceof BrushSettings) {
     BrushSettings v = (BrushSettings) o;
     SerializationManager.writeObject(v.getBrushShape(), stream);
     stream.writeFloat(v.getOuterWidth());
     stream.writeFloat(v.getOuterHeight());
     stream.writeFloat(v.getInnerWidth());
     stream.writeFloat(v.getInnerHeight());
     stream.writeInt(v.getFlowRate());
   }
 }
Ejemplo n.º 9
0
 public static void writeBlockHeader(DataOutputStream dout, FidBlockHeader blockHeader)
     throws IOException {
   dout.writeShort(blockHeader.scale);
   dout.writeShort(blockHeader.status);
   dout.writeShort(blockHeader.index);
   dout.writeShort(blockHeader.mode);
   dout.writeInt(blockHeader.ctcount);
   dout.writeFloat(blockHeader.lpval);
   dout.writeFloat(blockHeader.rpval);
   dout.writeFloat(blockHeader.lvl);
   dout.writeFloat(blockHeader.tlt);
 }
Ejemplo n.º 10
0
  public void Serialize(DataOutputStream stream) throws IOException {
    stream.writeInt(TCDefaultValues.ProtocolVersion.intValue());

    WriteStringToStream(stream, this.WorldName);

    stream.writeInt(this.GenerationDepth);
    stream.writeInt(this.BiomeRarityScale);
    stream.writeInt(this.LandRarity);
    stream.writeInt(this.LandSize);
    stream.writeInt(this.LandFuzzy);
    stream.writeInt(this.IceRarity);
    stream.writeInt(this.IceSize);
    stream.writeBoolean(this.FrozenOcean);
    stream.writeBoolean(this.FrozenRivers);
    stream.writeInt(this.RiverRarity);
    stream.writeInt(this.RiverSize);
    stream.writeBoolean(this.RiversEnabled);

    stream.writeDouble(this.oldBiomeSize);

    stream.writeFloat(this.minTemperature);
    stream.writeFloat(this.maxTemperature);
    stream.writeFloat(this.minMoisture);
    stream.writeFloat(this.maxMoisture);

    stream.writeInt(this.WorldFog);
    stream.writeInt(this.WorldNightFog);

    stream.writeInt(this.CustomBiomes.size());
    for (String name : this.CustomBiomes) {
      WriteStringToStream(stream, name);
      stream.writeInt(this.CustomBiomeIds.get(name));
    }

    stream.writeInt(this.biomes.size());
    for (BiomeConfig config : this.biomes) {
      stream.writeInt(config.Biome.getId());
      config.Serialize(stream);
    }

    stream.writeInt(this.NormalBiomes.size());
    for (String biome : this.NormalBiomes) WriteStringToStream(stream, biome);

    stream.writeInt(this.IceBiomes.size());
    for (String biome : this.IceBiomes) WriteStringToStream(stream, biome);

    stream.writeInt(this.IsleBiomes.size());
    for (String biome : this.IsleBiomes) WriteStringToStream(stream, biome);

    stream.writeInt(this.BorderBiomes.size());
    for (String biome : this.BorderBiomes) WriteStringToStream(stream, biome);
  }
Ejemplo n.º 11
0
  @Override
  public void writeData(DataOutputStream dataStream) throws IOException {
    dataStream.writeInt(x);
    dataStream.writeInt(y);
    dataStream.writeInt(z);

    dataStream.writeFloat(xMin);
    dataStream.writeFloat(yMin);
    dataStream.writeFloat(zMin);
    dataStream.writeFloat(xMax);
    dataStream.writeFloat(yMax);
    dataStream.writeFloat(zMax);
  }
Ejemplo n.º 12
0
  /**
   * Converts file format from gv Mary format 4 to Mary 5, the converted file will have the same
   * input name
   *
   * @param gvInFile gvInFile
   * @throws IOException IOException
   */
  public void convertGvBinaryFile(File gvInFile) throws IOException {
    int i;
    String gvInFileString = gvInFile.getName();
    // the destination file name will be the same as the input file so
    String gvOutFile = gvInFile.getAbsolutePath();
    String path = gvInFile.getParent();
    // I make a copy or the original file
    FileUtils.copy(gvInFile.getAbsolutePath(), path + "/tmp");
    gvInFile = new File(path + "/tmp");

    DataInputStream dataIn;
    DataOutputStream dataOut;
    dataIn = new DataInputStream(new BufferedInputStream(new FileInputStream(gvInFile)));

    // int numMix = data_in.readShort(); /* --NOT USED -- first short is the number of mixtures in
    // Gaussian model */
    int order = dataIn.readShort(); /* second short is the order of static vector */
    float gvmean[] = new float[order]; /* allocate memory of this size */
    float gvcov[] = new float[order];
    logger.debug("Reading from file " + gvInFileString + " order=" + order);

    for (i = 0; i < order; i++) {
      gvmean[i] = dataIn.readFloat();
      // System.out.format("gvmean[%d]=%f\n",i,gvmean[i]);
    }
    for (i = 0; i < order; i++) {
      gvcov[i] = dataIn.readFloat();
      // System.out.format("gvcov[%d]=%f\n",i,gvcov[i]);
    }
    dataIn.close();

    dataOut = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(gvOutFile)));
    /* This is the format in version 2.0 */
    // numMSDFlag
    dataOut.writeInt(0);
    // numStream
    dataOut.writeInt(1);
    // vectorSize
    dataOut.writeInt(order);
    // numDurPdf
    dataOut.writeInt(1);

    for (i = 0; i < order; i++) {
      dataOut.writeFloat(gvmean[i]);
      dataOut.writeFloat(gvcov[i]);
    }

    dataOut.close();
    gvInFile.delete();
    logger.debug("Updated format in file " + gvOutFile);
  }
Ejemplo n.º 13
0
  @Override
  public byte[] asBytes() {
    if (allocationMode == AllocationMode.HEAP) {
      ByteArrayOutputStream bos = new ByteArrayOutputStream(getElementSize() * length());
      DataOutputStream dos = new DataOutputStream(bos);

      if (dataType() == Type.DOUBLE) {
        if (doubleData == null) throw new IllegalStateException("Double array is null!");

        try {
          for (int i = 0; i < doubleData.length; i++) dos.writeDouble(doubleData[i]);
        } catch (IOException e) {
          throw new RuntimeException(e);
        }

      } else {
        if (floatData == null) throw new IllegalStateException("Double array is null!");

        try {
          for (int i = 0; i < floatData.length; i++) dos.writeFloat(floatData[i]);
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return bos.toByteArray();

    } else {
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      DataOutputStream dos = new DataOutputStream(bos);
      if (dataType() == Type.DOUBLE) {
        for (int i = 0; i < length(); i++) {
          try {
            dos.writeDouble(getDouble(i));
          } catch (IOException e) {
            e.printStackTrace();
          }
        }
      } else {
        for (int i = 0; i < length(); i++) {
          try {
            dos.writeFloat(getFloat(i));
          } catch (IOException e) {
            e.printStackTrace();
          }
        }
      }
      return bos.toByteArray();
    }
  }
Ejemplo n.º 14
0
  public void writeTimsMsgBody(OutputStream out) throws IOException {
    DataOutputStream dataOut = new DataOutputStream(out);

    dataOut.writeInt(recordingTime);
    dataOut.writeInt(duration);
    dataOut.writeInt(maxRange);
    dataOut.writeFloat(startAngle);
    dataOut.writeFloat(endAngle);
    dataOut.writeInt(pointNum);

    for (int i = 0; i < pointNum; i++) {
      point[i].writeDataOut(dataOut);
    }
  }
Ejemplo n.º 15
0
 public static void convertSingleSiftDataToBin(File textSiftFile) {
   File binSiftFile = new File(textSiftFile.getAbsolutePath() + ".bin");
   // System.out.println(binSiftFile.getAbsolutePath());
   DataOutputStream dos = null;
   try {
     dos =
         new DataOutputStream(new BufferedOutputStream(new FileOutputStream(binSiftFile), 100000));
   } catch (FileNotFoundException e) {
     e
         .printStackTrace(); // To change body of catch statement use File | Settings | File
                             // Templates.
   }
   Scanner scanner = null;
   try {
     scanner = new Scanner(textSiftFile, "UTF-8");
     int featureDimension = scanner.nextInt();
     dos.writeInt(featureDimension);
     if (featureDimension != 1) {
       scanner.close();
       return;
     }
     int featureCount = scanner.nextInt();
     dos.writeInt(featureCount);
     String pixX;
     String pixY;
     String ellipseParam1;
     String ellipseParam2;
     String ellipseParam3;
     int cluster;
     for (int i = 0; i < featureCount; i++) {
       pixX = scanner.next();
       pixY = scanner.next();
       ellipseParam1 = scanner.next();
       ellipseParam2 = scanner.next();
       ellipseParam3 = scanner.next();
       cluster = scanner.nextInt();
       dos.writeFloat(Float.parseFloat(pixX));
       dos.writeFloat(Float.parseFloat(pixY));
       dos.writeFloat(Float.parseFloat(ellipseParam1));
       dos.writeFloat(Float.parseFloat(ellipseParam2));
       dos.writeFloat(Float.parseFloat(ellipseParam3));
       dos.writeInt(cluster);
     }
     dos.close();
     scanner.close();
   } catch (Exception ex) {
     ex.printStackTrace();
     if (scanner != null) scanner.close();
   }
 }
Ejemplo n.º 16
0
 /**
  * Dump the map to a DataOutputStream
  *
  * @param dos the stream
  * @throws IOException
  */
 public void dumpMap(DataOutputStream dos) throws IOException {
   dos.writeInt(lines.length);
   for (int i = 0; i < lines.length; i++) {
     dos.writeFloat(lines[i].x1);
     dos.writeFloat(lines[i].y1);
     dos.writeFloat(lines[i].x2);
     dos.writeFloat(lines[i].y2);
     dos.flush();
   }
   dos.writeInt(boundingRect.x);
   dos.writeInt(boundingRect.y);
   dos.writeInt(boundingRect.width);
   dos.writeInt(boundingRect.height);
   dos.flush();
 }
  /** {@inheritDoc} */
  public synchronized int addColumn(double[] column) {
    if (isFinished)
      throw new IllegalStateException("Cannot add columns to a MatrixBuilder that is finished");

    // Update the size of the matrix based on the size of the array
    if (column.length > numRows) numRows = column.length;

    // Identify how many non-zero values are present in the column
    int nonZero = 0;
    for (int i = 0; i < column.length; ++i) {
      if (column[i] != 0d) nonZero++;
    }

    // Update the total number of non-zero values for the entire matrix
    nonZeroValues += nonZero;

    // Write the column to file
    try {
      matrixDos.writeInt(nonZero);
      for (int i = 0; i < column.length; ++i) {
        if (column[i] != 0d) {
          matrixDos.writeInt(i); // write the row index
          matrixDos.writeFloat((float) column[i]);
        }
      }
    } catch (IOException ioe) {
      throw new IOError(ioe);
    }

    return ++curCol;
  }
Ejemplo n.º 18
0
 public void convertWeightsToBin() {
   File weightsTextFile = new File(WebCBIR.baseFolder, "index/weights-idf.txt");
   File weightsBinFile = new File(WebCBIR.baseFolder, "index/weights-idf.bin");
   DataOutputStream dos = null;
   try {
     dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(weightsBinFile)));
   } catch (FileNotFoundException e) {
     e
         .printStackTrace(); // To change body of catch statement use File | Settings | File
                             // Templates.
   }
   Scanner scanner = null;
   try {
     scanner = new Scanner(weightsTextFile, "UTF-8");
     int featureCount = scanner.nextInt();
     dos.writeInt(featureCount);
     for (int i = 0; i < featureCount; i++) {
       String val = scanner.next();
       float idf = Float.parseFloat(val);
       dos.writeFloat(idf);
     }
     scanner.close();
     dos.close();
   } catch (Exception ex) {
     ex.printStackTrace();
     if (scanner != null) scanner.close();
   }
 }
  /** {@inheritDoc} */
  public synchronized int addColumn(SparseArray<? extends Number> column) {
    if (isFinished)
      throw new IllegalStateException("Cannot add columns to a MatrixBuilder that is finished");

    if (column.length() > numRows) numRows = column.length();

    // SparseArray instances can take on the maximum possible array size
    // when the array length isn't specified.  This ruins the matrix size
    // specification since the matrix shouldn't actually be that big.
    // However, because this is an implementation artifact, we can't check
    // for it explicitly with an exception.  Therefore, put in an assert to
    // indicate what is likely going on if asserts are enabled for debugging
    // they symptoms.
    assert column.length() != Integer.MAX_VALUE
        : "adding a column whose "
            + "length is Integer.MAX_VALUE (was likley left unspecified in the "
            + " constructor).";

    int[] nonZero = column.getElementIndices();
    nonZeroValues += nonZero.length;
    try {
      matrixDos.writeInt(nonZero.length);
      for (int i : nonZero) {
        matrixDos.writeInt(i); // write the row index
        matrixDos.writeFloat(column.get(i).floatValue());
      }
    } catch (IOException ioe) {
      throw new IOError(ioe);
    }
    return ++curCol;
  }
Ejemplo n.º 20
0
  @Override
  public void save() throws Exception {
    File file = Game.getInstance().getRelativeFile(Game.FILE_BASE_USER_DATA, "${world}/world.dat");

    DataOutputStream dos =
        new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file)));

    dos.writeFloat(_world.getTime());

    IOUtilities.writeVec3f(dos, _spawnPoint);

    writeDataPointList(dos, _rawHeights);
    writeDataPointList(dos, _heights);
    writeDataPointList(dos, _humidities);
    writeDataPointList(dos, _temperatures);

    /* Tree Definitions */
    {
      dos.writeInt(_trees.size());
      for (int i = 0; i < _trees.size(); ++i) {
        TreeDefinition dp2d = _trees.get(i);
        dos.writeInt(dp2d.x);
        dos.writeInt(dp2d.y);
        dos.writeInt(dp2d.z);
        dos.writeByte(dp2d.type);
      }
    }

    dos.flush();
    dos.close();
  }
Ejemplo n.º 21
0
  public static void main(String[] args) throws IOException {
    // Create a FileOutputStream.
    FileOutputStream outputFile = new FileOutputStream("primitives.data");

    // Create a DataOutputStream which is chained to the FileOutputStream.
    DataOutputStream outputStream = new DataOutputStream(outputFile);

    // Write Java primitive values in binary representation:
    outputStream.writeBoolean(true);
    outputStream.writeChar('A'); // int written as Unicode char
    outputStream.writeByte(Byte.MAX_VALUE); // int written as 8-bits byte
    outputStream.writeShort(Short.MIN_VALUE); // int written as 16-bits short
    outputStream.writeInt(Integer.MAX_VALUE);
    outputStream.writeLong(Long.MIN_VALUE);
    outputStream.writeFloat(Float.MAX_VALUE);
    outputStream.writeDouble(Math.PI);

    // Close the output stream, which also closes the underlying stream.
    outputStream.flush();
    outputStream.close();

    // Create a FileInputStream.
    FileInputStream inputFile = new FileInputStream("primitives.data");

    // Create a DataInputStream which is chained to the FileInputStream.
    DataInputStream inputStream = new DataInputStream(inputFile);

    // Read the binary representation of Java primitive values
    // in the same order they were written out:
    boolean v = inputStream.readBoolean();
    char c = inputStream.readChar();
    byte b = inputStream.readByte();
    short s = inputStream.readShort();
    int i = inputStream.readInt();
    long l = inputStream.readLong();
    float f = inputStream.readFloat();
    double d = inputStream.readDouble();

    // Check for end of stream:
    try {
      int value = inputStream.readByte();
      System.out.println("More input: " + value);
    } catch (EOFException eofe) {
      System.out.println("End of stream");
    } finally {
      // Close the input stream, which also closes the underlying stream.
      inputStream.close();
    }

    // Write the values read to the standard input stream:
    System.out.println("Values read:");
    System.out.println(v);
    System.out.println(c);
    System.out.println(b);
    System.out.println(s);
    System.out.println(i);
    System.out.println(l);
    System.out.println(f);
    System.out.println(d);
  }
Ejemplo n.º 22
0
  public static void main(String args[]) {
    OutputStream f = null;
    try {
      f = new FileOutputStream(args[0]);
    } catch (IOException e) {
      System.out.println("Apertura fallita");
      e.printStackTrace();
      // System.exit(1);
    }

    String a = "grgregre";

    DataOutputStream df = new DataOutputStream(f);

    float f1 = 5.1415F;
    char c1 = 'X';
    boolean b1 = true;
    double d1 = 1.4141;
    try {

      df.writeFloat(f1);
      df.writeBoolean(b1);
      df.writeDouble(d1);
      df.writeChar(c1);
      df.writeInt(11);
      df.close();
    } catch (IOException e) {
      e.printStackTrace();
      System.out.println("Scrittura fallita");

      // System.exit(1);
    }
  }
Ejemplo n.º 23
0
 @Override
 public boolean hitEntity(
     ItemStack par1ItemStack,
     EntityLivingBase par2EntityLivingBase,
     EntityLivingBase par3EntityLivingBase) {
   if (par3EntityLivingBase instanceof EntityClientPlayerMP) {
     // System.out.println("Atk: " + par2EntityLivingBase.hurtTime);
     // EntityClientPlayerMP player = (EntityClientPlayerMP)par3EntityLivingBase;
     // player.heal(1.0F);
     // player.setHealth(player.getHealth()+1);
     if (par2EntityLivingBase.hurtTime == 0) {
       ByteArrayOutputStream bt = new ByteArrayOutputStream();
       DataOutputStream out = new DataOutputStream(bt);
       try {
         // System.out.println("Building packet...");
         out.writeInt(1);
         out.writeFloat(1);
         Packet250CustomPayload packet = new Packet250CustomPayload("Artifacts", bt.toByteArray());
         Player player = (Player) par3EntityLivingBase;
         // System.out.println("Sending packet..." + player);
         PacketDispatcher.sendPacketToServer(packet);
         par1ItemStack.damageItem(1, par3EntityLivingBase);
       } catch (IOException ex) {
         System.out.println("couldnt send packet!");
       }
     }
   }
   return false;
 }
Ejemplo n.º 24
0
 private void writeFloat(Float v) {
   try {
     outStream.writeFloat(v);
   } catch (IOException e) {
     IOError();
   }
 }
 @Override
 protected void onWriteTransmissionData(final DataOutputStream pDataOutputStream)
     throws IOException {
   pDataOutputStream.writeInt(this.mID);
   pDataOutputStream.writeFloat(this.mX);
   pDataOutputStream.writeFloat(this.mY);
 }
Ejemplo n.º 26
0
 public void write(DataOutputStream out) throws IOException {
   out.writeUTF(shader);
   out.writeInt(numVertices);
   out.writeInt(numWeights);
   out.writeInt(numTriangles);
   out.writeInt(floatsPerVertex);
   out.writeInt(floatsPerWeight);
   for (int i = 0; i < vertices.length; i++) {
     out.writeFloat(vertices[i]);
   }
   for (int i = 0; i < indices.length; i++) {
     out.writeShort(indices[i]);
   }
   for (int i = 0; i < weights.length; i++) {
     out.writeFloat(weights[i]);
   }
 }
  public void sendLaserPacket(
      Vector3 source, Vector3 dest, float r, float g, float b, int age, int energy, int radius) {
    Side side = FMLCommonHandler.instance().getEffectiveSide();

    if (side == Side.SERVER) {
      ByteArrayOutputStream bos = new ByteArrayOutputStream(8);
      DataOutputStream outputStream = new DataOutputStream(bos);

      try {
        // Write source vector
        outputStream.writeDouble(source.x);
        outputStream.writeDouble(source.y);
        outputStream.writeDouble(source.z);
        // Write target vector
        outputStream.writeDouble(dest.x);
        outputStream.writeDouble(dest.y);
        outputStream.writeDouble(dest.z);
        // Write r, g, b of laser
        outputStream.writeFloat(r);
        outputStream.writeFloat(g);
        outputStream.writeFloat(b);
        // Write age
        outputStream.writeByte(age);
        // Write energy value
        outputStream.writeInt(energy);
      } catch (Exception ex) {
        ex.printStackTrace();
      }

      Packet250CustomPayload packet = new Packet250CustomPayload();
      packet.channel = "WarpDriveBeam";
      packet.data = bos.toByteArray();
      packet.length = bos.size();

      // Send packet to all players within cloaked area
      List<Entity> list =
          worldObj.getEntitiesWithinAABB(
              EntityPlayerMP.class,
              AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ));
      for (Entity e : list) {
        if (e != null && e instanceof EntityPlayer) {
          ((EntityPlayerMP) e).playerNetServerHandler.sendPacketToPlayer(packet);
        }
      }
    }
  }
Ejemplo n.º 28
0
 /** Append a float as a four byte number. */
 public void appendFloat(float x) {
   ByteArrayOutputStream buffer = new ByteArrayOutputStream(4);
   DataOutputStream bufout = new DataOutputStream(buffer);
   try {
     bufout.writeFloat(x);
     appendBytes(buffer.toByteArray(), 0, 4);
   } catch (IOException e) {
     throw new AssertionError("write");
   }
 }
Ejemplo n.º 29
0
 protected void write(DataOutputStream out) throws IOException {
   out.writeUTF(allocationMode.name());
   out.writeInt(length());
   out.writeUTF(dataType().name());
   if (dataType() == Type.DOUBLE) {
     for (int i = 0; i < length(); i++) out.writeDouble(getDouble(i));
   } else {
     for (int i = 0; i < length(); i++) out.writeFloat(getFloat(i));
   }
 }
Ejemplo n.º 30
0
 /**
  * @param x
  * @return a byte array
  */
 public static byte[] serializeFloat(float x) {
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   DataOutputStream w = new DataOutputStream(baos);
   try {
     w.writeFloat(x);
     w.flush();
     w.close();
   } catch (IOException e) {
     return null;
   }
   return baos.toByteArray();
 }