Search in sources :

Example 1 with IRadioWaveSender

use of com.builtbroken.mc.api.map.radio.IRadioWaveSender in project Engine by VoltzEngine-Project.

the class RadioMap method remove.

public boolean remove(IRadioWaveReceiver receiver) {
    if (fullMapRangeReceives.contains(receiver)) {
        fullMapRangeReceives.remove(receiver);
    }
    if (receive_to_chunks.containsKey(receiver)) {
        //Clear cached chunk positions
        for (ChunkCoordIntPair pair : receive_to_chunks.get(receiver)) {
            if (chunk_to_entities.containsKey(pair)) {
                chunk_to_entities.get(pair).remove(receiver);
            }
        }
        //Clear entry in receiver map
        receive_to_chunks.remove(receiver);
        //Update sender cache
        for (IRadioWaveSender sender : sender_to_receivers_cache.keySet()) {
            List<IRadioWaveReceiver> receivers = sender_to_receivers_cache.get(sender);
            if (receivers == null) {
                receivers = new ArrayList();
            }
            if (receivers.contains(receiver)) {
                receivers.remove(receiver);
            }
            sender_to_receivers_cache.put(sender, receivers);
        }
        return true;
    }
    return false;
}
Also used : IRadioWaveReceiver(com.builtbroken.mc.api.map.radio.IRadioWaveReceiver) ChunkCoordIntPair(net.minecraft.world.ChunkCoordIntPair) IRadioWaveSender(com.builtbroken.mc.api.map.radio.IRadioWaveSender) ArrayList(java.util.ArrayList)

Example 2 with IRadioWaveSender

use of com.builtbroken.mc.api.map.radio.IRadioWaveSender in project Engine by VoltzEngine-Project.

the class RadioMap method updateSenderCache.

protected void updateSenderCache(IRadioWaveReceiver receiver, Cube range) {
    if (range != null) {
        //Update sender cache
        for (IRadioWaveSender sender : sender_to_receivers_cache.keySet()) {
            Cube senderRange = sender.getRadioSenderRange();
            if (senderRange.doesOverlap(range)) {
                List<IRadioWaveReceiver> receivers = sender_to_receivers_cache.get(sender);
                if (receivers == null) {
                    receivers = new ArrayList();
                }
                if (!receivers.contains(receiver)) {
                    receivers.add(receiver);
                }
                sender_to_receivers_cache.put(sender, receivers);
            }
        }
    }
}
Also used : IRadioWaveReceiver(com.builtbroken.mc.api.map.radio.IRadioWaveReceiver) Cube(com.builtbroken.mc.imp.transform.region.Cube) IRadioWaveSender(com.builtbroken.mc.api.map.radio.IRadioWaveSender) ArrayList(java.util.ArrayList)

Aggregations

IRadioWaveReceiver (com.builtbroken.mc.api.map.radio.IRadioWaveReceiver)2 IRadioWaveSender (com.builtbroken.mc.api.map.radio.IRadioWaveSender)2 ArrayList (java.util.ArrayList)2 Cube (com.builtbroken.mc.imp.transform.region.Cube)1 ChunkCoordIntPair (net.minecraft.world.ChunkCoordIntPair)1