Search in sources :

Example 1 with RadioMap

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();
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IRadioWaveReceiver(com.builtbroken.mc.api.map.radio.IRadioWaveReceiver) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) Cube(com.builtbroken.mc.imp.transform.region.Cube) RadioMap(com.builtbroken.mc.lib.world.radio.RadioMap)

Aggregations

IRadioWaveReceiver (com.builtbroken.mc.api.map.radio.IRadioWaveReceiver)1 Cube (com.builtbroken.mc.imp.transform.region.Cube)1 RadioMap (com.builtbroken.mc.lib.world.radio.RadioMap)1 Entity (net.minecraft.entity.Entity)1 TileEntity (net.minecraft.tileentity.TileEntity)1