Ejemplo n.º 1
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;
  }
Ejemplo n.º 2
0
 ArrayList<CrystalReceiver> getNearbyReceivers(CrystalTransmitter r, CrystalElement e) {
   ArrayList<CrystalReceiver> li = new ArrayList();
   try {
     for (WorldLocation c : tiles.keySet()) {
       if (c.dimensionID == r.getWorld().provider.dimensionId) {
         CrystalNetworkTile tile = tiles.get(c);
         if (tile instanceof CrystalReceiver && r != tile) {
           CrystalReceiver te = (CrystalReceiver) tile;
           if (te.canConduct() && r.canTransmitTo(te)) {
             if (e == null || te.isConductingElement(e)) {
               double d = te.getDistanceSqTo(r.getX(), r.getY(), r.getZ());
               // ReikaJavaLibrary.pConsole(e+": "+d+": "+te);
               double send = r.getSendRange();
               double dist = te.getReceiveRange();
               if (d <= Math.min(dist * dist, send * send)) {
                 li.add(te);
               }
             }
           }
         }
       }
     }
   } catch (ConcurrentModificationException ex) {
     ex.printStackTrace();
     ChromatiCraft.logger.logError(
         "CME when trying to pathfind on the crystal network. This indicates a deeper issue.");
   }
   return li;
 }
Ejemplo n.º 3
0
  public void removeTile(CrystalNetworkTile te) {
    tiles.remove(PylonFinder.getLocation(te));

    if (te instanceof NotifiedNetworkTile) {
      notifyCache.remove(te);
    }
    for (NotifiedNetworkTile tile : notifyCache) {
      tile.onTileNetworkTopologyChange(te, true);
    }

    if (te instanceof TileEntityCrystalPylon) {
      TileEntityCrystalPylon tile = (TileEntityCrystalPylon) te;
      TileEntityCache<TileEntityCrystalPylon> c = pylons.get(tile.getColor());
      if (c != null) c.remove(tile);
    }
    Collection<CrystalFlow> li = flows.get(te.getWorld().provider.dimensionId);
    Iterator<CrystalFlow> it = li.iterator();
    while (it.hasNext()) {
      CrystalFlow p = it.next();
      if (p.contains(te)) {
        CrystalNetworkLogger.logFlowBreak(p, FlowFail.TILE);
        p.resetTiles();
        p.receiver.onPathBroken(p, FlowFail.TILE);
        it.remove();
      }
    }
    PylonFinder.removePathsWithTile(te);
    WorldCrystalNetworkData.initNetworkData(te.getWorld()).setDirty(true); // was false
    if (te instanceof TileEntityCrystalPylon) {
      PylonLocationData.initNetworkData(te.getWorld()).setDirty(true);
    }
  }
Ejemplo n.º 4
0
  public void addTile(CrystalNetworkTile te) {
    if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
      WorldLocation loc = PylonFinder.getLocation(te);
      CrystalNetworkTile old = tiles.get(loc);
      if (old != null) { // cache cleaning; old TEs may get out of sync for things like charge
        this.removeTile(old);
      }
      tiles.put(loc, te);
      if (te instanceof TileEntityCrystalPylon) {
        this.addPylon((TileEntityCrystalPylon) te);
      }
      this.verifyTileAt(te, loc);

      for (NotifiedNetworkTile tile : notifyCache) {
        tile.onTileNetworkTopologyChange(te, false);
      }

      if (te instanceof NotifiedNetworkTile) {
        notifyCache.add((NotifiedNetworkTile) te);
      }

      WorldCrystalNetworkData.initNetworkData(te.getWorld()).setDirty(true);
      if (te instanceof TileEntityCrystalPylon) {
        PylonLocationData.initNetworkData(te.getWorld()).setDirty(true);
      }
    }
  }
 public void SCRAM() {
   int iter = 0;
   for (WorldLocation c : controls.keySet()) {
     TileEntityControlRod rod = controls.get(c);
     rod.drop(iter == 0);
     iter++;
   }
 }
 public int countLoweredRods() {
   int count = 0;
   for (WorldLocation c : controls.keySet()) {
     TileEntityControlRod rod = controls.get(c);
     if (rod.isActive()) count++;
   }
   return count;
 }
Ejemplo n.º 7
0
 private void addPylon(TileEntityCrystalPylon te) {
   CrystalElement e = te.getColor();
   TileEntityCache<TileEntityCrystalPylon> c = pylons.get(e);
   if (c == null) {
     c = new TileEntityCache();
     pylons.put(e, c);
   }
   c.put(te);
 }
Ejemplo n.º 8
0
  private void load(NBTTagCompound NBT) {
    NBTTagCompound tag = NBT.getCompoundTag(NBT_TAG);
    tiles.readFromNBT(tag);

    for (CrystalNetworkTile te : tiles.values()) {
      if (te instanceof TileEntityCrystalPylon) {
        TileEntityCrystalPylon tile = (TileEntityCrystalPylon) te;
        this.addPylon(tile);
      }
    }
    // ReikaJavaLibrary.pConsole(tiles+" from "+tag, Side.SERVER);
  }
Ejemplo n.º 9
0
 ArrayList<CrystalSource> getAllSourcesFor(CrystalElement e, boolean activeOnly) {
   ArrayList<CrystalSource> li = new ArrayList();
   for (WorldLocation c : tiles.keySet()) {
     CrystalNetworkTile tile = tiles.get(c);
     if (tile instanceof CrystalSource) {
       CrystalSource te = (CrystalSource) tile;
       if (te.canConduct() || !activeOnly) {
         if (e == null || te.isConductingElement(e)) {
           li.add(te);
         }
       }
     }
   }
   return li;
 }
Ejemplo n.º 10
0
 public Collection<TileEntityCrystalPylon> getNearbyPylons(
     World world, int x, int y, int z, CrystalElement e, int range, boolean LOS) {
   TileEntityCache<TileEntityCrystalPylon> c = pylons.get(e);
   Collection<TileEntityCrystalPylon> li = new ArrayList();
   if (c != null) {
     for (WorldLocation loc : c.keySet()) {
       if (loc.dimensionID == world.provider.dimensionId && loc.getDistanceTo(x, y, z) <= range) {
         if (!LOS || PylonFinder.lineOfSight(world, x, y, z, loc.xCoord, loc.yCoord, loc.zCoord)) {
           li.add(c.get(loc));
         }
       }
     }
   }
   return li;
 }
Ejemplo n.º 11
0
 public Collection<TileEntityCrystalPylon> getAllNearbyPylons(
     World world, int x, int y, int z, double range) {
   Collection<TileEntityCrystalPylon> li = new ArrayList();
   for (CrystalElement e : pylons.keySet()) {
     TileEntityCache<TileEntityCrystalPylon> c = pylons.get(e);
     if (c != null) {
       for (WorldLocation loc : c.keySet()) {
         if (loc.dimensionID == world.provider.dimensionId
             && loc.getDistanceTo(x, y, z) <= range) {
           li.add(c.get(loc));
         }
       }
     }
   }
   return li;
 }
 public void addControlRod(TileEntityControlRod rod) {
   if (minX > rod.xCoord) minX = rod.xCoord;
   if (maxX < rod.xCoord) maxX = rod.xCoord;
   if (minY > rod.yCoord) minY = rod.yCoord;
   if (maxY < rod.yCoord) maxY = rod.yCoord;
   if (minZ > rod.zCoord) minZ = rod.zCoord;
   if (maxZ < rod.zCoord) maxZ = rod.zCoord;
   controls.put(rod);
 }
 public void clear() {
   controls.clear();
   minX = Integer.MAX_VALUE;
   minY = Integer.MAX_VALUE;
   minZ = Integer.MAX_VALUE;
   maxX = Integer.MIN_VALUE;
   maxY = Integer.MIN_VALUE;
   maxZ = Integer.MIN_VALUE;
 }
 public void readFromNBT(NBTTagCompound NBT) {
   controls.readFromNBT(NBT);
   controller = WorldLocation.readFromNBT("control", NBT);
   maxX = NBT.getInteger("maxx");
   maxY = NBT.getInteger("maxy");
   maxZ = NBT.getInteger("maxz");
   minX = NBT.getInteger("minx");
   minY = NBT.getInteger("miny");
   minZ = NBT.getInteger("minz");
 }
 public void writeToNBT(NBTTagCompound NBT) {
   controls.writeToNBT(NBT);
   controller.writeToNBT("control", NBT);
   NBT.setInteger("maxx", maxX);
   NBT.setInteger("maxy", maxY);
   NBT.setInteger("maxz", maxZ);
   NBT.setInteger("minx", minX);
   NBT.setInteger("miny", minY);
   NBT.setInteger("minz", minZ);
 }
Ejemplo n.º 16
0
 @SubscribeEvent
 public void clearOnUnload(WorldEvent.Unload evt) {
   PylonFinder.stopAllSearches();
   int dim = evt.world.provider.dimensionId;
   ChromatiCraft.logger.debug("Unloading dimension " + dim + ", clearing crystal network.");
   try {
     this.clear(dim);
     for (WorldLocation c : tiles.keySet()) {
       CrystalNetworkTile te = tiles.get(c);
       PylonFinder.removePathsWithTile(te);
       if (te instanceof CrystalTransmitter) ((CrystalTransmitter) te).clearTargets(true);
     }
     tiles.removeWorld(evt.world);
     for (TileEntityCache c : pylons.values()) c.removeWorld(evt.world);
   } catch (ConcurrentModificationException e) {
     ChromatiCraft.logger.logError(
         "Clearing the crystal network on world unload caused a CME. This is indicative of a deeper problem.");
     e.printStackTrace();
   }
 }
Ejemplo n.º 17
0
 ArrayList<CrystalTransmitter> getTransmittersTo(CrystalReceiver r, CrystalElement e) {
   ArrayList<CrystalTransmitter> li = new ArrayList();
   for (WorldLocation c : tiles.keySet()) {
     if (c.dimensionID == r.getWorld().provider.dimensionId) {
       CrystalNetworkTile tile = tiles.get(c);
       if (tile instanceof CrystalTransmitter && r != tile) {
         CrystalTransmitter te = (CrystalTransmitter) tile;
         if (te.canConduct() && te.canTransmitTo(r)) {
           if (e == null || te.isConductingElement(e)) {
             double d = te.getDistanceSqTo(r.getX(), r.getY(), r.getZ());
             // ReikaJavaLibrary.pConsole(e+": "+d+": "+te);
             double send = te.getSendRange();
             double dist = r.getReceiveRange();
             if (d <= Math.min(dist * dist, send * send)) {
               li.add(te);
             }
           }
         }
       }
     }
   }
   return li;
 }
Ejemplo n.º 18
0
 public Collection<CrystalNetworkTile> getNearTilesOfType(
     World world, int x, int y, int z, Class<? extends CrystalNetworkTile> type, int range) {
   Collection<CrystalNetworkTile> ret = new ArrayList();
   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 (world.provider.dimensionId == c.dimensionID) {
       if (type.isAssignableFrom(tile.getClass())) {
         double d = tile.getDistanceSqTo(x, y, z);
         if (d <= range * range) {
           ret.add(tile);
         }
       }
     }
   }
   for (WorldLocation loc : rem) {
     tiles.remove(loc);
   }
   return ret;
 }
 public TileEntityControlRod getControlRodAtRelativePosition(World world, int x, int y, int z) {
   return controls.get(
       new WorldLocation(
           world, x + controller.xCoord, y + controller.yCoord, z + controller.zCoord));
 }
 public TileEntityControlRod getControlRodAtAbsolutePosition(World world, int x, int y, int z) {
   return controls.get(new WorldLocation(world, x, y, z));
 }
Ejemplo n.º 21
0
 private void save(NBTTagCompound NBT) {
   NBTTagCompound tag = NBT.getCompoundTag(NBT_TAG);
   tiles.writeToNBT(tag);
   NBT.setTag(NBT_TAG, tag);
   // ReikaJavaLibrary.pConsole(tiles+" to "+tag, Side.SERVER);
 }
 public long getMinPower() {
   return DragonAPICore.debugtest ? 0 : this.getPowerPerRod() * controls.size();
 }
 public int getNumberRods() {
   return controls.size();
 }
 public boolean isEmpty() {
   return controls.isEmpty();
 }
 public Collection<TileEntityControlRod> getAllRods() {
   return Collections.unmodifiableCollection(controls.values());
 }