Search in sources :

Example 6 with ChunkCoordIntPair

use of net.minecraft.world.ChunkCoordIntPair in project ArsMagica2 by Mithion.

the class PowerNodeRegistry method saveAll.

public HashMap<ChunkCoordIntPair, NBTTagCompound> saveAll() {
    HashMap<ChunkCoordIntPair, NBTTagCompound> allData = new HashMap<ChunkCoordIntPair, NBTTagCompound>();
    for (ChunkCoordIntPair pair : this.powerNodes.keySet()) {
        NBTTagCompound chunkCompound = new NBTTagCompound();
        SaveChunkToNBT(pair, chunkCompound);
        allData.put(pair, chunkCompound);
    }
    return allData;
}
Also used : ChunkCoordIntPair(net.minecraft.world.ChunkCoordIntPair) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 7 with ChunkCoordIntPair

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

the class RadarMap method remove.

public boolean remove(RadarObject object) {
    ChunkCoordIntPair pair = getChunkValue((int) object.x(), (int) object.z());
    allEntities.remove(object);
    if (chunk_to_entities.containsKey(pair)) {
        List<RadarObject> list = chunk_to_entities.get(pair);
        boolean b = list.remove(object);
        //TODO fire map update event
        if (list.isEmpty()) {
            chunk_to_entities.remove(pair);
        }
        return b;
    }
    return false;
}
Also used : ChunkCoordIntPair(net.minecraft.world.ChunkCoordIntPair) RadarObject(com.builtbroken.mc.lib.world.radar.data.RadarObject)

Example 8 with ChunkCoordIntPair

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

the class RadarMap method update.

/**
     * Called at the end of every world tick to do checks on
     * data stored.
     */
public void update() {
    debug.start("Update", "Objects: " + allEntities.size() + "  Chunks: " + chunk_to_entities.size());
    if (ticks++ >= UPDATE_DELAY && chunk_to_entities.size() > 0) {
        ticks = 0;
        //TODO consider multi-threading if number of entries is too high (need to ensure runs in less than 10ms~)
        debug.start("Looking for invalid radar objects and updating position data");
        HashMap<RadarObject, ChunkCoordIntPair> removeList = new HashMap();
        List<RadarObject> addList = new ArrayList();
        for (Map.Entry<ChunkCoordIntPair, List<RadarObject>> entry : chunk_to_entities.entrySet()) {
            if (entry.getValue() != null) {
                for (RadarObject object : entry.getValue()) {
                    if (entry.getKey() != object.getChunkCoordIntPair()) {
                        debug.log("Removed from map: " + object);
                        removeList.put(object, entry.getKey());
                        if (object.isValid()) {
                            addList.add(object);
                            debug.log("Queued for re-add");
                        }
                    }
                }
            }
        }
        debug.end();
        debug.start("Removing objects from map");
        for (Map.Entry<RadarObject, ChunkCoordIntPair> entry : removeList.entrySet()) {
            allEntities.remove(entry.getKey());
            List<RadarObject> list = chunk_to_entities.get(entry.getValue());
            if (list != null) {
                list.remove(entry.getKey());
                if (list.size() > 0) {
                    chunk_to_entities.put(entry.getValue(), list);
                } else {
                    chunk_to_entities.remove(entry.getValue());
                }
            } else {
                chunk_to_entities.remove(entry.getValue());
            }
        }
        debug.end();
        debug.start("Adding entries: " + addList.size());
        addList.forEach(this::add);
        debug.end();
        debug.start("Removing invalid objects");
        Iterator<RadarObject> it = allEntities.iterator();
        while (it.hasNext()) {
            RadarObject object = it.next();
            if (!object.isValid()) {
                debug.log("Removed: " + object);
                it.remove();
            }
        }
        debug.end();
    }
    debug.end();
}
Also used : ChunkCoordIntPair(net.minecraft.world.ChunkCoordIntPair) RadarObject(com.builtbroken.mc.lib.world.radar.data.RadarObject)

Example 9 with ChunkCoordIntPair

use of net.minecraft.world.ChunkCoordIntPair 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 10 with ChunkCoordIntPair

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

the class ChunkMap method onChunkLoaded.

@SubscribeEvent
public void onChunkLoaded(ChunkEvent.Load event) {
    Chunk chunk = event.getChunk();
    ChunkCoordIntPair coords = chunk.getChunkCoordIntPair();
    if (chunks.containsKey(coords)) {
    //TODO load data into existing object
    } else {
    //TODO load object
    }
}
Also used : ChunkCoordIntPair(net.minecraft.world.ChunkCoordIntPair) Chunk(net.minecraft.world.chunk.Chunk) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

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