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; }
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; }
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 int countLoweredRods() { int count = 0; for (WorldLocation c : controls.keySet()) { TileEntityControlRod rod = controls.get(c); if (rod.isActive()) count++; } return count; }
public void SCRAM() { int iter = 0; for (WorldLocation c : controls.keySet()) { TileEntityControlRod rod = controls.get(c); rod.drop(iter == 0); iter++; } }
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; }
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; }
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; }
@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(); } }
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; }
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 getControlRodAtAbsolutePosition(World world, int x, int y, int z) { return controls.get(new WorldLocation(world, x, y, z)); }
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)); }