use of cn.nukkit.level.format.generic.BaseRegionLoader in project Nukkit by Nukkit.
the class Anvil method doGarbageCollection.
@Override
public void doGarbageCollection() {
int limit = (int) (System.currentTimeMillis() - 50);
for (Map.Entry<Long, BaseRegionLoader> entry : this.regions.entrySet()) {
long index = entry.getKey();
BaseRegionLoader region = entry.getValue();
if (region.lastUsed <= limit) {
try {
region.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
this.regions.remove(index);
}
}
}
use of cn.nukkit.level.format.generic.BaseRegionLoader in project Nukkit by Nukkit.
the class McRegion method loadChunk.
@Override
public BaseFullChunk loadChunk(long index, int chunkX, int chunkZ, boolean create) {
int regionX = getRegionIndexX(chunkX);
int regionZ = getRegionIndexZ(chunkZ);
BaseRegionLoader region = this.loadRegion(regionX, regionZ);
this.level.timings.syncChunkLoadDataTimer.startTiming();
BaseFullChunk chunk;
try {
chunk = region.readChunk(chunkX - regionX * 32, chunkZ - regionZ * 32);
} catch (IOException e) {
throw new RuntimeException(e);
}
if (chunk == null) {
if (create) {
chunk = this.getEmptyChunk(chunkX, chunkZ);
putChunk(index, chunk);
}
} else {
putChunk(index, chunk);
}
this.level.timings.syncChunkLoadDataTimer.stopTiming();
return chunk;
}
use of cn.nukkit.level.format.generic.BaseRegionLoader in project Nukkit by Nukkit.
the class McRegion method loadRegion.
protected BaseRegionLoader loadRegion(int x, int z) {
BaseRegionLoader tmp = lastRegion;
if (tmp != null && x == tmp.getX() && z == tmp.getZ()) {
return tmp;
}
long index = Level.chunkHash(x, z);
BaseRegionLoader region = this.regions.get(index);
if (region == null) {
region = new RegionLoader(this, x, z);
this.regions.put(index, region);
return lastRegion = region;
} else {
return lastRegion = region;
}
}
use of cn.nukkit.level.format.generic.BaseRegionLoader in project Nukkit by Nukkit.
the class Anvil method loadChunk.
@Override
public BaseFullChunk loadChunk(long index, int chunkX, int chunkZ, boolean create) {
int regionX = getRegionIndexX(chunkX);
int regionZ = getRegionIndexZ(chunkZ);
BaseRegionLoader region = this.loadRegion(regionX, regionZ);
this.level.timings.syncChunkLoadDataTimer.startTiming();
BaseFullChunk chunk;
try {
chunk = region.readChunk(chunkX - regionX * 32, chunkZ - regionZ * 32);
} catch (IOException e) {
throw new RuntimeException(e);
}
if (chunk == null) {
if (create) {
chunk = this.getEmptyChunk(chunkX, chunkZ);
putChunk(index, chunk);
}
} else {
putChunk(index, chunk);
}
this.level.timings.syncChunkLoadDataTimer.stopTiming();
return chunk;
}
use of cn.nukkit.level.format.generic.BaseRegionLoader in project Nukkit by Nukkit.
the class Anvil method loadRegion.
protected BaseRegionLoader loadRegion(int x, int z) {
BaseRegionLoader tmp = lastRegion;
if (tmp != null && x == tmp.getX() && z == tmp.getZ()) {
return tmp;
}
long index = Level.chunkHash(x, z);
BaseRegionLoader region = this.regions.get(index);
if (region == null) {
try {
region = new RegionLoader(this, x, z);
} catch (IOException e) {
throw new RuntimeException(e);
}
this.regions.put(index, region);
return lastRegion = region;
} else {
return lastRegion = region;
}
}
Aggregations