Search in sources :

Example 16 with ChunkCoordIntPair

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

the class PowerNodeRegistry method registerPowerNodeInternal.

PowerNodeEntry registerPowerNodeInternal(IPowerNode node) {
    ChunkCoordIntPair chunk = getChunkFromNode(node);
    HashMap<AMVector3, PowerNodeEntry> nodeList;
    TileEntity te = ((TileEntity) node);
    World world = te.getWorldObj();
    if (powerNodes.containsKey(chunk)) {
        nodeList = powerNodes.get(chunk);
        LogHelper.trace("Located Power Node list for chunk %d, %d", chunk.chunkXPos, chunk.chunkZPos);
    } else {
        LogHelper.trace("Node list not found.  Checking cache/files for prior data");
        NBTTagCompound compound = PowerNodeCache.instance.getNBTForChunk(world, chunk);
        nodeList = new HashMap<AMVector3, PowerNodeEntry>();
        if (compound == null || !compound.hasKey("AM2PowerData")) {
            powerNodes.put(chunk, nodeList);
            LogHelper.trace("Prior node list not found.  Created Power Node list for chunk %d, %d", chunk.chunkXPos, chunk.chunkZPos);
        } else {
            LoadChunkFromNBT(chunk, compound);
            nodeList = powerNodes.get(chunk);
            //sanity check
            if (nodeList == null)
                nodeList = new HashMap<AMVector3, PowerNodeEntry>();
            LogHelper.trace("Loaded power data for chunk %d, %d", chunk.chunkXPos, chunk.chunkZPos);
        }
    }
    AMVector3 nodeLoc = new AMVector3((TileEntity) node);
    //prevent duplicate registrations
    if (nodeList.containsKey(nodeLoc))
        return nodeList.get(nodeLoc);
    PowerNodeEntry pnd = new PowerNodeEntry();
    nodeList.put(nodeLoc, pnd);
    LogHelper.trace("Successfully registered power node at {%d, %d, %d}", ((TileEntity) node).xCoord, ((TileEntity) node).yCoord, ((TileEntity) node).zCoord);
    return pnd;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) AMVector3(am2.api.math.AMVector3) ChunkCoordIntPair(net.minecraft.world.ChunkCoordIntPair) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) World(net.minecraft.world.World)

Example 17 with ChunkCoordIntPair

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

the class PowerNodeRegistry method getSearchChunks.

private ChunkCoordIntPair[] getSearchChunks(AMVector3 location) {
    //Calculate the chunk X/Z location of the search center
    int chunkX = (int) location.x >> 4;
    int chunkZ = (int) location.z >> 4;
    ArrayList<ChunkCoordIntPair> searchChunks = new ArrayList<ChunkCoordIntPair>();
    //always search the chunk you're already in!
    searchChunks.add(new ChunkCoordIntPair(chunkX, chunkZ));
    for (int i = -1; i <= 1; ++i) {
        for (int j = -1; j <= 1; ++j) {
            //don't include the home chunk, this has already been added.  We're only concerned with neighboring chunks.
            if (i == 0 && j == 0)
                continue;
            //create the new CCIP at the offset location
            ChunkCoordIntPair newPair = new ChunkCoordIntPair(chunkX + i, chunkZ + j);
            //If it matches the new chunk coordinates, we add that chunk to the list of chunks to search.
            if (((int) location.x + (POWER_SEARCH_RADIUS * i)) >> 4 == newPair.chunkXPos && ((int) location.z + (POWER_SEARCH_RADIUS * j)) >> 4 == newPair.chunkZPos) {
                searchChunks.add(newPair);
            }
        }
    }
    return searchChunks.toArray(new ChunkCoordIntPair[searchChunks.size()]);
}
Also used : ChunkCoordIntPair(net.minecraft.world.ChunkCoordIntPair)

Example 18 with ChunkCoordIntPair

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

the class AMWorldEventHandler method onChunkLoaded.

@SubscribeEvent
public void onChunkLoaded(ChunkDataEvent.Load event) {
    int dimensionID = event.world.provider.dimensionId;
    ChunkCoordIntPair chunkLocation = event.getChunk().getChunkCoordIntPair();
    NBTTagCompound compound = (NBTTagCompound) event.getData().getTag("ArsMagica2");
    if (AMCore.config.retroactiveWorldgen() && (compound == null || !compound.hasKey(genKey))) {
        LogHelper.info("Detected a chunk that requires retrogen.  Adding to retrogen list.");
        AMCore.proxy.addQueuedRetrogen(dimensionID, chunkLocation);
    }
}
Also used : ChunkCoordIntPair(net.minecraft.world.ChunkCoordIntPair) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 19 with ChunkCoordIntPair

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

the class PowerNodeCache method cacheToFile.

private void cacheToFile(World world, RegionCoordinates coords) {
    NBTTagCompound cachedRegion = dataCache.get(coords);
    if (!cachedRegion.hasKey("AM2PowerData"))
        return;
    int xBase = coords.x * 32;
    int zBase = coords.z * 32;
    for (int x = 0; x < 32; ++x) {
        for (int z = 0; z < 32; ++z) {
            ChunkCoordIntPair pair = new ChunkCoordIntPair(xBase + x, zBase + z);
            NBTTagCompound compound = cachedRegion.getCompoundTag(getPNDIdentifier(pair));
            if (compound != null) {
                SaveNBTToFile(world, pair, compound, true);
            }
        }
    }
}
Also used : ChunkCoordIntPair(net.minecraft.world.ChunkCoordIntPair) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 20 with ChunkCoordIntPair

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

the class PowerNodeCache method saveWorldToFile.

public void saveWorldToFile(World world) {
    if (world.isRemote)
        return;
    LogHelper.trace("Saving all cached power data for DIM %d to disk", world.provider.dimensionId);
    //cached data to file
    Iterator<RegionCoordinates> it = dataCache.keySet().iterator();
    while (it.hasNext()) {
        RegionCoordinates rc = it.next();
        if (rc.dimension == world.provider.dimensionId) {
            it.remove();
        }
    }
    //live data to file (may override cache, but that's what we want as live would be newer)
    HashMap<ChunkCoordIntPair, NBTTagCompound> saveData = PowerNodeRegistry.For(world).saveAll();
    for (ChunkCoordIntPair pair : saveData.keySet()) {
        SaveNBTToFile(world, pair, saveData.get(pair), true);
    }
    PowerNodeRegistry.For(world).unloadAll();
    saveDirs.remove(world.provider.dimensionId);
}
Also used : ChunkCoordIntPair(net.minecraft.world.ChunkCoordIntPair) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

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