コード例 #1
0
 public void overloadColorConnectedTo(
     CrystalTransmitter te, CrystalElement color, int num, boolean recursive) {
   ArrayList<CrystalReceiver> li = this.getAllColorConnectedTo(te, color, recursive);
   if (li.isEmpty()) return;
   WeightedRandom<CrystalNetworkTile> w = new WeightedRandom();
   for (CrystalReceiver r : li) {
     if (r instanceof NaturalCrystalSource) continue;
     double wt = 1;
     if (r instanceof CrystalFuse) {
       wt = ((CrystalFuse) r).getFailureWeight(color);
     }
     w.addEntry(r, wt * 10);
   }
   for (int i = 0; i < num; i++) {
     CrystalNetworkTile tile = w.getRandomEntry();
     if (tile instanceof CrystalFuse) {
       ((CrystalFuse) tile).overload(color);
     } else {
       double x = tile.getX() + 0.5;
       double y = tile.getY() + 0.5;
       double z = tile.getZ() + 0.5;
       tile.getWorld().setBlock(tile.getX(), tile.getY(), tile.getZ(), Blocks.air);
       tile.getWorld().createExplosion(null, x, y, z, 1.5F + rand.nextFloat() * 1.5F, true);
     }
   }
 }
コード例 #2
0
  public CrystalNetworkTile getNearestTileOfType(
      CrystalNetworkTile te, Class<? extends CrystalNetworkTile> type, int range) {
    CrystalNetworkTile ret = null;
    double dist = Double.POSITIVE_INFINITY;
    HashSet<WorldLocation> rem = new HashSet();
    for (WorldLocation c : tiles.keySet()) {
      CrystalNetworkTile tile = tiles.get(c);
      if (tile == null) {
        ChromatiCraft.logger.logError("Null tile at " + c + " but still cached?!");
        // c.setBlock(Blocks.brick_block);
        rem.add(c);
      } else if (tile == te) {

      } else if (te.getWorld().provider.dimensionId == c.dimensionID) {
        if (type.isAssignableFrom(tile.getClass())) {
          double d = tile.getDistanceSqTo(te.getX(), te.getY(), te.getZ());
          if (d <= range * range && d < dist) {
            dist = d;
            ret = tile;
          }
        }
      }
    }
    for (WorldLocation loc : rem) {
      tiles.remove(loc);
    }
    return ret;
  }
コード例 #3
0
 private void verifyTileAt(CrystalNetworkTile te, WorldLocation loc) {
   UUID key = te.getUniqueID();
   WorldLocation prev = verifier.get(key);
   if (prev != null && !prev.equals(loc)) {
     te.getWorld().setBlockToAir(te.getX(), te.getY(), te.getZ());
     throw new InvalidLocationException(te, loc, prev);
   } else verifier.put(key, loc);
 }
コード例 #4
0
 public Collection<CrystalNetworkTile> getNearTilesOfType(
     CrystalNetworkTile te, Class<? extends CrystalNetworkTile> type, int range) {
   return this.getNearTilesOfType(te.getWorld(), te.getX(), te.getY(), te.getZ(), type, range);
 }