use of com.builtbroken.mc.lib.world.radio.RadioMap in project Engine by VoltzEngine-Project.
the class WirelessNetwork method updateConnections.
/**
* Called to update all connections
*/
public void updateConnections() {
//Update list if we still have a sender
if (hub != null && hub.getWirelessCoverageArea() != null) {
//================================
//==Discovery Phase===============
//================================
//Get all receivers in range
Cube range = hub.getWirelessCoverageArea();
RadioMap map = RadioRegistry.getRadioMapForWorld(hub.world());
List<IRadioWaveReceiver> receivers = map.getReceiversInRange(range, hub instanceof IRadioWaveReceiver ? (IRadioWaveReceiver) hub : null);
//Loop threw receivers
if (!receivers.isEmpty()) {
for (IRadioWaveReceiver receiver : receivers) {
if (receiver instanceof IWirelessConnector) {
if (!addConnector((IWirelessConnector) receiver) && wirelessConnectors.contains(receiver)) {
//Update connection list as connector is not going to update every tick
for (IWirelessNetworkObject object : ((IWirelessConnector) receiver).getWirelessNetworkObjects()) {
addConnection(((IWirelessConnector) receiver), object);
}
}
}
}
}
//Ensure we have added the primary sender if it is a connector
if (getPrimarySender() instanceof IWirelessConnector) {
addConnector((IWirelessConnector) getPrimarySender());
}
//================================
//==Clean Up Phase================
//================================
//Clear invalid connectors
Iterator<IWirelessConnector> it2 = wirelessConnectors.iterator();
while (it2.hasNext()) {
IWirelessConnector con = it2.next();
if (con instanceof TileEntity && ((TileEntity) con).isInvalid() || con instanceof Entity && !((Entity) con).isEntityAlive()) {
it2.remove();
clearConnections(con);
con.removeWirelessNetwork(this, ConnectionRemovedReason.TILE_INVALIDATE);
}
}
//Clear invalid attached devices
Iterator<IWirelessNetworkObject> it = attachedDevices.iterator();
while (it.hasNext()) {
IWirelessNetworkObject obj = it.next();
if (obj instanceof TileEntity && ((TileEntity) obj).isInvalid() || obj instanceof Entity && !((Entity) obj).isEntityAlive()) {
it.remove();
obj.removeWirelessNetwork(this, ConnectionRemovedReason.TILE_INVALIDATE);
if (obj instanceof IWirelessDataPoint) {
dataPoints.remove(obj);
//TODO notify listeners
}
}
}
} else {
kill();
}
}
Aggregations