Search in sources :

Example 21 with ChunkCoordIntPair

use of net.minecraft.world.ChunkCoordIntPair in project Engine by VoltzEngine-Project.

the class ChunkMap method onChunkUnloaded.

@SubscribeEvent
public void onChunkUnloaded(ChunkEvent.Unload event) {
    Chunk chunk = event.getChunk();
    ChunkCoordIntPair coords = chunk.getChunkCoordIntPair();
    if (chunks.containsKey(coords)) {
        //TODO save data
        chunks.remove(coords);
    }
}
Also used : ChunkCoordIntPair(net.minecraft.world.ChunkCoordIntPair) Chunk(net.minecraft.world.chunk.Chunk) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 22 with ChunkCoordIntPair

use of net.minecraft.world.ChunkCoordIntPair in project Engine by VoltzEngine-Project.

the class RadarMap method add.

public boolean add(RadarObject object) {
    if (!allEntities.contains(object) && object.isValid()) {
        allEntities.add(object);
        ChunkCoordIntPair pair = getChunkValue((int) object.x(), (int) object.z());
        List<RadarObject> list;
        //Get list or make new
        if (chunk_to_entities.containsKey(pair)) {
            list = chunk_to_entities.get(pair);
        } else {
            list = new ArrayList();
        }
        //Check if object is not already added
        if (!list.contains(object)) {
            list.add(object);
            //TODO fire map update event
            //TODO fire map add event
            //Update map
            chunk_to_entities.put(pair, list);
            return true;
        }
    }
    return false;
}
Also used : ChunkCoordIntPair(net.minecraft.world.ChunkCoordIntPair) RadarObject(com.builtbroken.mc.lib.world.radar.data.RadarObject)

Example 23 with ChunkCoordIntPair

use of net.minecraft.world.ChunkCoordIntPair in project Engine by VoltzEngine-Project.

the class RadioMap method popMessage.

/**
     * Called to send a message over the network
     *
     * @param sender - object that sent the message
     * @param hz     - frequency of the message
     * @param header - descriptive header of the message, mainly an ID system
     * @param data   - data being sent in the message
     */
public void popMessage(IRadioWaveSender sender, float hz, String header, Object[] data) {
    //Cache for senders that know they will be active
    if (sender_to_receivers_cache.containsKey(sender)) {
        for (IRadioWaveReceiver receiver : sender_to_receivers_cache.get(sender)) {
            receiver.receiveRadioWave(hz, sender, header, data);
        }
        return;
    }
    //Receivers that have full map range, used for legacy systems mainly
    for (IRadioWaveReceiver receiver : fullMapRangeReceives) {
        receiver.receiveRadioWave(hz, sender, header, data);
    }
    //Slow way to update receives with messages
    Cube range = sender.getRadioSenderRange();
    if (range != null) {
        //Use simpler method if the range of number of entries is small
        if (//20 chunks
        receive_to_chunks.size() < 200 || range.getSizeX() > 320 || range.getSizeY() > 320) {
            for (IRadioWaveReceiver receiver : receive_to_chunks.keySet()) {
                if (receiver != null && receiver != sender) {
                    Cube receiverRange = receiver.getRadioReceiverRange();
                    if (range.doesOverlap(receiverRange) || receiverRange.doesOverlap(range)) {
                        receiver.receiveRadioWave(hz, sender, header, data);
                    }
                }
            }
        } else //Complex method only used if number of receive is very high, e.g. is faster~ish than the above method
        {
            List<ChunkCoordIntPair> coords = range.getChunkCoords();
            List<IRadioWaveReceiver> receivers = new ArrayList();
            for (ChunkCoordIntPair pair : coords) {
                List<IRadioWaveReceiver> l = chunk_to_entities.get(pair);
                if (l != null && l.size() > 0) {
                    for (IRadioWaveReceiver r : l) {
                        if (r != null && r != sender && !receivers.contains(r)) {
                            receivers.add(r);
                        }
                    }
                }
            }
            for (IRadioWaveReceiver receiver : receivers) {
                receiver.receiveRadioWave(hz, sender, header, data);
            }
        }
    }
}
Also used : IRadioWaveReceiver(com.builtbroken.mc.api.map.radio.IRadioWaveReceiver) ChunkCoordIntPair(net.minecraft.world.ChunkCoordIntPair) Cube(com.builtbroken.mc.imp.transform.region.Cube) ArrayList(java.util.ArrayList)

Example 24 with ChunkCoordIntPair

use of net.minecraft.world.ChunkCoordIntPair in project Engine by VoltzEngine-Project.

the class RadioMap method updateChunkCache.

protected void updateChunkCache(IRadioWaveReceiver receiver, Cube range) {
    List<ChunkCoordIntPair> list = range.getChunkCoords();
    //Update chunk position map
    for (ChunkCoordIntPair pair : list) {
        List<IRadioWaveReceiver> receivers = chunk_to_entities.get(pair);
        if (receivers == null) {
            receivers = new ArrayList();
        }
        if (!receivers.contains(receiver)) {
            receivers.add(receiver);
        }
        chunk_to_entities.put(pair, receivers);
    }
    //Update receiver map
    receive_to_chunks.put(receiver, list);
}
Also used : IRadioWaveReceiver(com.builtbroken.mc.api.map.radio.IRadioWaveReceiver) ChunkCoordIntPair(net.minecraft.world.ChunkCoordIntPair) ArrayList(java.util.ArrayList)

Aggregations

ChunkCoordIntPair (net.minecraft.world.ChunkCoordIntPair)24 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)8 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)4 ArrayList (java.util.ArrayList)4 TileEntity (net.minecraft.tileentity.TileEntity)4 AMVector3 (am2.api.math.AMVector3)3 IRadioWaveReceiver (com.builtbroken.mc.api.map.radio.IRadioWaveReceiver)3 RadarObject (com.builtbroken.mc.lib.world.radar.data.RadarObject)3 Chunk (net.minecraft.world.chunk.Chunk)3 Ticket (net.minecraftforge.common.ForgeChunkManager.Ticket)3 PlayerCollectionList (logisticspipes.utils.PlayerCollectionList)2 World (net.minecraft.world.World)2 IPowerNode (am2.api.power.IPowerNode)1 IRadioWaveSender (com.builtbroken.mc.api.map.radio.IRadioWaveSender)1 Cube (com.builtbroken.mc.imp.transform.region.Cube)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1