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;
}
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()]);
}
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);
}
}
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);
}
}
}
}
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);
}
Aggregations