private static void logLoadOnRequest(ChunkProviderServer provider, int x, int z) { long currentTick = MinecraftServer.getServer().getTickCounter(); long lastAccessed = provider.lastAccessed(x, z); long diff = currentTick - lastAccessed; logInfo(" Last accessed: {0, number} Current Tick: {1, number} [{2, number}]", lastAccessed, currentTick, diff); logInfo(" Finding Spawn Point: {0}", provider.worldObj.findingSpawnPoint); logInfo(" Load chunk on request: {0}", provider.loadChunkOnProvideRequest); logInfo(" Calling Forge Tick: {0}", MinecraftServer.callingForgeTick); logInfo(" Load chunk on forge tick: {0}", MinecraftServer.cauldronConfig.loadChunkOnForgeTick.getValue()); long providerTickDiff = currentTick - provider.initialTick; if (providerTickDiff <= 100) { logInfo(" Current Tick - Initial Tick: {0, number}", providerTickDiff); } }
public boolean unloadChunk(ItemStack stack) { if (!stack.hasTagCompound()) return false; NBTTagCompound tag = stack.getTagCompound(); if (tag.getBoolean("ignoreClick")) { tag.removeTag("ignoreClick"); stack.setTagCompound(tag); return false; } int worldId = tag.getInteger("world"); int x = tag.getInteger("x"); int z = tag.getInteger("z"); World world = DimensionManager.getWorld(worldId); if (world==null) return false; IChunkProvider provider = world.getChunkProvider(); Chunk chunk = provider.getLoadedChunk(x, z); if (chunk==null) return false; if (provider instanceof ChunkProviderServer) { ((ChunkProviderServer) provider).queueUnload(chunk); return true; } else { return false; } }
public static void queueChunkLoad(World world, AnvilChunkLoader loader, ChunkProviderServer provider, int x, int z, Runnable runnable) { QueuedChunk key = new QueuedChunk(x, z, world); ChunkIOProvider task = tasks.get(key); if (task == null) { task = new ChunkIOProvider(key, loader, provider); task.addCallback(runnable); // Add before calling execute for thread safety tasks.put(key, task); pool.execute(task); } else { task.addCallback(runnable); } }
@Override public void invalidate() { super.invalidate(); if (this.reference != null) { ChunkProviderServer provider = this.reference.getChunkProvider(); int sX = this.getStart().getX() / 16 - GEN_RANGE; int sZ = this.getStart().getZ() / 16 - GEN_RANGE; int eX = this.getEnd().getX() / 16 + GEN_RANGE; int eZ = this.getEnd().getZ() / 16 + GEN_RANGE; for (int x = sX; x <= eX; x++) for (int z = sZ; z <= eZ; z++) if (provider.chunkExists(x, z)) provider.unload(provider.getLoadedChunk(x, z)); } }
public void loadChunks() { if (this.worldObj.isRemote) return; this.reference = DimensionManager.getWorld(VoidUtils.DIM); if (this.reference == null) { DimensionManager.initDimension(VoidUtils.DIM); this.reference = DimensionManager.getWorld(VoidUtils.DIM); } //We need to load the chunk, and the chunks around it before we start copying, so that the chunk gets decorated. ChunkProviderServer provider = this.reference.getChunkProvider(); int sX = this.getStart().getX() / 16 - GEN_RANGE; int sZ = this.getStart().getZ() / 16 - GEN_RANGE; int eX = this.getEnd().getX() / 16 + GEN_RANGE; int eZ = this.getEnd().getZ() / 16 + GEN_RANGE; for (int x = sX; x <= eX; x++) for (int z = sZ; z <= eZ; z++) provider.loadChunk(x, z); }
private void loadChunksAround(int x, int z, int i, ChunkProviderServer cp) { cp.loadChunk(x >> 4, z >> 4); if ((x + i) >> 4 != x >> 4) { cp.loadChunk((x + i) >> 4, z >> 4); if ((z + i) >> 4 != z >> 4) { cp.loadChunk(x >> 4, (z + i) >> 4); cp.loadChunk((x + i) >> 4, (z + i) >> 4); } } else if ((z + i) >> 4 != z >> 4) { cp.loadChunk(x >> 4, (z + i) >> 4); } }
public boolean providePlayerChunk(boolean canGenerate) { if (!this.loading) { if (this.providingChunk != null) { return true; } else { ChunkProviderServer chunkProvider = this.blockSystem.getChunkProvider(); int x = this.chunkPosition.chunkXPos; int z = this.chunkPosition.chunkZPos; if (canGenerate) { this.providingChunk = (BlockSystemChunk) chunkProvider.provideChunk(x, z); } else { this.providingChunk = (BlockSystemChunk) chunkProvider.loadChunk(x, z); } } } return false; }
private void nucleusLoadChunkForce(int x, int z) { Chunk chunk = this.loadChunkFromFile(x, z); if (chunk == null) { long i = ChunkPos.chunkXZ2Int(x, z); try { chunk = this.chunkGenerator.provideChunk(x, z); } catch (Throwable throwable) { CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Exception generating new chunk"); CrashReportCategory crashreportcategory = crashreport.makeCategory("Chunk to be generated"); crashreportcategory.addCrashSection("Location", String.format("%d,%d", new Object[] {Integer.valueOf(x), Integer.valueOf(z)})); crashreportcategory.addCrashSection("Position hash", Long.valueOf(i)); crashreportcategory.addCrashSection("Generator", this.chunkGenerator); throw new ReportedException(crashreport); } } this.id2ChunkMap.put(ChunkPos.chunkXZ2Int(x, z), chunk); chunk.onChunkLoad(); chunk.populateChunk((ChunkProviderServer)(Object) this, this.chunkGenerator); }
private static void saveChunkData(ChunkProviderServer chunkProviderServer, Chunk chunkIn) { try { chunkIn.setLastSaveTime(chunkIn.getWorld().getTotalWorldTime()); chunkProviderServer.chunkLoader.saveChunk(chunkIn.getWorld(), chunkIn); } catch (IOException ioexception) { //LOGGER.error((String)"Couldn\'t save chunk", (Throwable)ioexception); } catch (MinecraftException minecraftexception) { //LOGGER.error((String)"Couldn\'t save chunk; already in use by another instance of Minecraft?", (Throwable)minecraftexception); } try { chunkProviderServer.chunkLoader.saveExtraChunkData(chunkIn.getWorld(), chunkIn); } catch (Exception exception) { //LOGGER.error((String)"Couldn\'t save entities", (Throwable)exception); } }
@Override public void populate(IChunkProvider chunkprovider, int chunkX, int chunkZ) { checkUnpopulatedQueue(chunkprovider); if (chunkprovider instanceof ChunkProviderServer) { // Don't populate if not all direct neighbours have been populated // Instead put on queue if(!shouldPopulate((ChunkProviderServer)chunkprovider, chunkX, chunkZ)) { synchronized (VCraftWorld.instance.unpopulatedChunks) { VCraftWorld.instance.unpopulatedChunks.add(new BlockPos(chunkX, 0, chunkZ)); } VCraftWorld.instance.setChunkNBT(chunkX, chunkZ, "vcraftpopulated", false); return; } populateNow(chunkprovider, chunkX, chunkZ); } }
@Override public Coord findNearestStructure(VanillaStructure type, Coord pos) { ChunkProviderServer chunkProvider = ((WorldServer)world).getChunkProvider(); String structureName = VanillaStructure.getName(type); BlockPos structurebp = null; try{ structurebp = chunkProvider.getNearestStructurePos(world, structureName, pos.getBlockPos(), false); } catch(NullPointerException e){ // happens for some reason if structure type is disabled in Chunk Generator Settings } if(structurebp == null) return null; return new Coord(structurebp); }
public static void logChunkLoad(ChunkProviderServer provider, String msg, int x, int z, boolean logLoadOnRequest) { if (MinecraftServer.cauldronConfig.chunkLoadLogging.getValue()) { logInfo("{0} Chunk At [{1}] ({2}, {3})", msg, provider.worldObj.provider.dimensionId, x, z); if (logLoadOnRequest) { logLoadOnRequest(provider, x, z); } logStack(); } }
public static void logChunkUnload(ChunkProviderServer provider, int x, int z, String msg) { if (MinecraftServer.cauldronConfig.chunkUnloadLogging.getValue()) { logInfo("{0} [{1}] ({2}, {3})", msg, provider.worldObj.provider.dimensionId, x, z); long currentTick = MinecraftServer.getServer().getTickCounter(); long lastAccessed = provider.lastAccessed(x, z); long diff = currentTick - lastAccessed; logInfo(" Last accessed: {0, number} Current Tick: {1, number} [{2, number}]", lastAccessed, currentTick, diff); } }
/** * Creates the chunk provider for this world. Called in the constructor. Retrieves provider from worldProvider? */ protected IChunkProvider createChunkProvider() { IChunkLoader ichunkloader = this.saveHandler.getChunkLoader(this.provider); this.theChunkProviderServer = new ChunkProviderServer(this, ichunkloader, this.provider.createChunkGenerator()); return this.theChunkProviderServer; }
@Override public ChunkProviderServer getChunkProvider() { if (m_proxyWorld != null && Util.isPrefixInCallStack(m_modPrefix)) { return m_proxyWorld.getChunkProvider(); } else if (m_realWorld != null) { return m_realWorld.getChunkProvider(); } else { return super.getChunkProvider(); } }
@SubscribeEvent public void onChunkLoad(ChunkEvent.Load e) { World world = e.getWorld(); Chunk chunk = e.getChunk(); TileList tileList = TileList.get(world); TilePos tilePos = new TilePos(chunk.getPos()); ChunkPos[][] chunks = Tile.createChunkArray(tilePos); if(tileList.getTileByPos(tilePos)==null) { // Check if all chunks are loaded before creating the tile. // As of right now, null pointers are thrown if not all chunks are loaded // because chunks have to be loaded to get biome information for them. // Need to figure out a way to force-load chunks before checking biomes. for(int i=0; i<4; i++) { for(int j=0; j<4; j++) { int x = chunks[i][j].x; int z = chunks[i][j].z; if(!world.getChunkProvider().isChunkGeneratedAt(x,z)) { try { ((ChunkProviderServer)(world.getChunkProvider())).chunkLoader.loadChunk(world, x, z); } catch (Exception e1) {} return; } } } System.out.println("Adding new tile - x: "+tilePos.x+" z: "+tilePos.z); ////////////////// Tile tile = new Tile(chunk); } }
/** * Saves all chunks to disk while updating progress bar. */ public void saveAllChunks(boolean p_73044_1_, @Nullable IProgressUpdate progressCallback) throws MinecraftException { ChunkProviderServer chunkproviderserver = this.getChunkProvider(); if (chunkproviderserver.canSave()) { if (progressCallback != null) { progressCallback.displaySavingString("Saving level"); } this.saveLevel(); if (progressCallback != null) { progressCallback.displayLoadingString("Saving chunks"); } chunkproviderserver.saveChunks(p_73044_1_); for (Chunk chunk : Lists.newArrayList(chunkproviderserver.getLoadedChunks())) { if (chunk != null && !this.thePlayerManager.contains(chunk.xPosition, chunk.zPosition)) { chunkproviderserver.unload(chunk); } } } }
/** * saves chunk data - currently only called during execution of the Save All command */ public void saveChunkData() { ChunkProviderServer chunkproviderserver = this.getChunkProvider(); if (chunkproviderserver.canSave()) { chunkproviderserver.saveExtraData(); } }
public static Chunk syncChunkLoad(World world, AnvilChunkLoader loader, ChunkProviderServer provider, int x, int z) { QueuedChunk key = new QueuedChunk(x, z, world); ChunkIOProvider task = tasks.remove(key); // Remove task because we will call the sync callbacks directly if (task != null) { if (!pool.remove(task)) // If it wasn't in the pool, and run hasn't finished, then wait for the async thread. { synchronized(task) { while (!task.runFinished()) { try { task.wait(); } catch (InterruptedException e) { e.printStackTrace(); // Something happened? Log it? } } } } else { // If the task was not run yet we still need to load the chunk task.run(); } } else { task = new ChunkIOProvider(key, loader, provider); task.run(); } task.syncCallback(); return task.getChunk(); }
/** * Saves all chunks to disk while updating progress bar. */ public void saveAllChunks(boolean p_73044_1_, @Nullable IProgressUpdate progressCallback) throws MinecraftException { ChunkProviderServer chunkproviderserver = this.getChunkProvider(); if (chunkproviderserver.canSave()) { if (progressCallback != null) { progressCallback.displaySavingString("Saving level"); } this.saveLevel(); if (progressCallback != null) { progressCallback.displayLoadingString("Saving chunks"); } chunkproviderserver.saveChunks(p_73044_1_); net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.WorldEvent.Save(this)); for (Chunk chunk : Lists.newArrayList(chunkproviderserver.getLoadedChunks())) { if (chunk != null && !this.thePlayerManager.contains(chunk.xPosition, chunk.zPosition)) { chunkproviderserver.unload(chunk); } } } }
public void handleWorldSettings(World w) { try { if (w.getChunkProvider() instanceof ChunkProviderServer && w.getWorldType() instanceof WorldTypeExP) { ChunkProviderServer cps = (ChunkProviderServer) w.getChunkProvider(); if (cps.chunkGenerator instanceof ChunkGeneratorOverworld) { ChunkGeneratorOverworld cpo = (ChunkGeneratorOverworld) cps.chunkGenerator; for (Field f : ChunkGeneratorOverworld.class.getDeclaredFields()) { if (f.getType() == ChunkGeneratorSettings.class) { f.setAccessible(true); ChunkGeneratorSettings.Factory factory = new ChunkGeneratorSettings.Factory(); factory.seaLevel = 127; factory.baseSize = 17.25f; f.set(cpo, factory.build()); break; } } } } } catch (Exception ex) { ex.printStackTrace(); } }
/** * Call decoration manually at chunk position * @param chunkX Chunk X position * @param chunkZ Chunk Z position */ public void decorate(int chunkX, int chunkZ) { if (world.getChunkProvider() instanceof ChunkProviderServer) { ChunkProviderServer cps = (ChunkProviderServer) world.getChunkProvider(); world.getChunkFromChunkCoords(chunkX + 1, chunkZ); world.getChunkFromChunkCoords(chunkX + 1, chunkZ + 1); world.getChunkFromChunkCoords(chunkX, chunkZ + 1); world.getChunkFromChunkCoords(chunkX, chunkZ).populateChunk(cps, cps.chunkGenerator); } }
/** * Call decoration manually at chunk position * @param chunkX Chunk X position * @param chunkZ Chunk Z position */ public void decorate(int chunkX, int chunkZ) { if (world.getChunkProvider() instanceof ChunkProviderServer) { ChunkProviderServer cps = (ChunkProviderServer) world.getChunkProvider(); world.getChunkFromChunkCoords(chunkX + 1, chunkZ); world.getChunkFromChunkCoords(chunkX + 1, chunkZ + 1); world.getChunkFromChunkCoords(chunkX, chunkZ + 1); world.getChunkFromChunkCoords(chunkX, chunkZ).populateChunk(cps, cps.currentChunkProvider, chunkX, chunkZ); } }
/** * Call decoration manually at chunk position * @param chunkX Chunk X position * @param chunkZ Chunk Z position */ public void decorate(int chunkX, int chunkZ) { if (world.getChunkProvider() instanceof ChunkProviderServer) { ChunkProviderServer cps = (ChunkProviderServer) world.getChunkProvider(); world.getChunkFromChunkCoords(chunkX + 1, chunkZ); world.getChunkFromChunkCoords(chunkX + 1, chunkZ + 1); world.getChunkFromChunkCoords(chunkX, chunkZ + 1); world.getChunkFromChunkCoords(chunkX, chunkZ).populate(cps, cps.chunkGenerator); } }
private void makeSmallLandingSpot(World world, int x, int z) { this.loadChunksAround(x, z, -1, (ChunkProviderServer) world.getChunkProvider()); for (int k = 255; k > 48; k--) { if (!world.isAirBlock(x, k, z)) { this.makePlatform(world, x, k - 1, z); return; } if (!world.isAirBlock(x - 1, k, z)) { this.makePlatform(world, x - 1, k - 1, z); return; } if (!world.isAirBlock(x - 1, k, z - 1)) { this.makePlatform(world, x - 1, k - 1, z - 1); return; } if (!world.isAirBlock(x, k, z - 1)) { this.makePlatform(world, x, k - 1, z - 1); return; } } this.makePlatform(world, x, 48 + world.rand.nextInt(128), z); return; }
public TileEntity getTileEntityForce(World world) { int chunkx = this.x >> 4; int chunkz = this.z >> 4; if (world.getChunkProvider().chunkExists(chunkx, chunkz)) return world.getTileEntity(this.x, this.y, this.z); Chunk chunk = ((ChunkProviderServer) world.getChunkProvider()).originalLoadChunk(chunkx, chunkz); return chunk.func_150806_e(this.x & 15, this.y, this.z & 15); }
@Override protected boolean isChunkLoaded(int x, int z, boolean allowEmpty) { if(world.isRemote){ return allowEmpty || !this.getChunkProvider().provideChunk(x, z).isEmpty(); } return ((ChunkProviderServer)world.getChunkProvider()).chunkExists(x, z); }