Java Code Examples for cn.nukkit.level.Level#chunkHash()

The following examples show how to use cn.nukkit.level.Level#chunkHash() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LevelDB.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean loadChunk(int x, int z, boolean create) {
    long index = Level.chunkHash(x, z);
    if (this.chunks.containsKey(index)) {
        return true;
    }

    this.level.timings.syncChunkLoadDataTimer.startTiming();
    Chunk chunk = this.readChunk(x, z);
    if (chunk == null && create) {
        chunk = Chunk.getEmptyChunk(x, z, this);
    }
    this.level.timings.syncChunkLoadDataTimer.stopTiming();
    if (chunk != null) {
        this.chunks.put(index, chunk);
        return true;
    }

    return false;
}
 
Example 2
Source File: Anvil.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
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;
    }
}
 
Example 3
Source File: LevelDB.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void setChunk(int chunkX, int chunkZ, FullChunk chunk) {
    if (!(chunk instanceof Chunk)) {
        throw new ChunkException("Invalid Chunk class");
    }
    chunk.setProvider(this);

    chunk.setX(chunkX);
    chunk.setZ(chunkZ);
    long index = Level.chunkHash(chunkX, chunkZ);

    if (this.chunks.containsKey(index) && !this.chunks.get(index).equals(chunk)) {
        this.unloadChunk(chunkX, chunkZ, false);
    }

    this.chunks.put(index, (Chunk) chunk);
}
 
Example 4
Source File: McRegion.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void setChunk(int chunkX, int chunkZ, FullChunk chunk) {
    if (!(chunk instanceof Chunk)) {
        throw new ChunkException("Invalid Chunk class");
    }
    chunk.setProvider(this);
    int regionX = chunkX >> 5;
    int regionZ = chunkZ >> 5;
    this.loadRegion(regionX, regionZ);
    chunk.setX(chunkX);
    chunk.setZ(chunkZ);
    long index = Level.chunkHash(chunkX, chunkZ);
    if (this.chunks.containsKey(index) && !this.chunks.get(index).equals(chunk)) {
        this.unloadChunk(chunkX, chunkZ, false);
    }
    this.chunks.put(index, (Chunk) chunk);
}
 
Example 5
Source File: Anvil.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
protected synchronized BaseRegionLoader loadRegion(int x, int z) {
    BaseRegionLoader tmp = lastRegion.get();
    if (tmp != null && x == tmp.getX() && z == tmp.getZ()) {
        return tmp;
    }
    long index = Level.chunkHash(x, z);
    synchronized (regions) {
        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);
        }
        lastRegion.set(region);
        return region;
    }
}
 
Example 6
Source File: Anvil.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean loadChunk(int x, int z, boolean create) {
    long index = Level.chunkHash(x, z);
    if (this.chunks.containsKey(index)) {
        return true;
    }
    int regionX = x >> 5;
    int regionZ = z >> 5;
    this.loadRegion(regionX, regionZ);
    Chunk chunk;
    try {
        chunk = this.getRegion(regionX, regionZ).readChunk(x & 0x1f, z & 0x1f);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    if (chunk == null && create) {
        chunk = this.getEmptyChunk(x, z);
    }
    if (chunk != null) {
        this.chunks.put(index, chunk);
        return true;
    }
    return false;
}
 
Example 7
Source File: BaseLevelProvider.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public BaseFullChunk getChunk(int chunkX, int chunkZ, boolean create) {
    BaseFullChunk tmp = lastChunk;
    if (tmp != null && tmp.getX() == chunkX && tmp.getZ() == chunkZ) {
        return tmp;
    }
    long index = Level.chunkHash(chunkX, chunkZ);
    lastChunk = tmp = chunks.get(index);
    if (tmp != null) {
        return tmp;
    } else {
        tmp = this.loadChunk(index, chunkX, chunkZ, create);
        lastChunk = tmp;
        return tmp;
    }
}
 
Example 8
Source File: McRegion.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
protected BaseRegionLoader loadRegion(int x, int z) {
    BaseRegionLoader tmp = lastRegion.get();
    if (tmp != null && x == tmp.getX() && z == tmp.getZ()) {
        return tmp;
    }
    long index = Level.chunkHash(x, z);
    synchronized (regions) {
        BaseRegionLoader region = this.regions.get(index);
        if (region == null) {
            region = new RegionLoader(this, x, z);
            this.regions.put(index, region);
        }
        lastRegion.set(region);
        return region;
    }
}
 
Example 9
Source File: BaseLevelProvider.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean unloadChunk(int X, int Z, boolean safe) {
    long index = Level.chunkHash(X, Z);
    BaseFullChunk chunk = this.chunks.get(index);
    if (chunk != null && chunk.unload(false, safe)) {
        lastChunk = null;
        this.chunks.remove(index, chunk);
        return true;
    }
    return false;
}
 
Example 10
Source File: BaseLevelProvider.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean unloadChunk(int X, int Z, boolean safe) {
    long index = Level.chunkHash(X, Z);
    synchronized (chunks) {
        BaseFullChunk chunk = this.chunks.get(index);
        if (chunk != null && chunk.unload(false, safe)) {
            lastChunk.set(null);
            this.chunks.remove(index, chunk);
            return true;
        }
    }
    return false;
}
 
Example 11
Source File: LevelDB.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean unloadChunk(int x, int z, boolean safe) {
    long index = Level.chunkHash(x, z);
    Chunk chunk = this.chunks.containsKey(index) ? this.chunks.get(index) : null;
    if (chunk != null && chunk.unload(false, safe)) {
        this.chunks.remove(index);
        return true;
    }

    return false;
}
 
Example 12
Source File: McRegion.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
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;
    }
}
 
Example 13
Source File: Anvil.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Chunk getChunk(int x, int z, boolean create) {
    long index = Level.chunkHash(x, z);
    if (this.chunks.containsKey(index)) {
        return this.chunks.get(index);
    } else {
        this.loadChunk(x, z, create);
        return this.chunks.containsKey(index) ? this.chunks.get(index) : null;
    }
}
 
Example 14
Source File: BaseLevelProvider.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean loadChunk(int chunkX, int chunkZ, boolean create) {
    long index = Level.chunkHash(chunkX, chunkZ);
    if (this.chunks.containsKey(index)) {
        return true;
    }
    return loadChunk(index, chunkX, chunkZ, create) != null;
}
 
Example 15
Source File: McRegion.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean unloadChunk(int x, int z, boolean safe) {
    long index = Level.chunkHash(x, z);
    Chunk chunk = this.chunks.containsKey(index) ? this.chunks.get(index) : null;
    if (chunk != null && chunk.unload(false, safe)) {
        this.chunks.remove(index);
        return true;
    }
    return false;
}
 
Example 16
Source File: LevelDB.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Chunk getChunk(int x, int z, boolean create) {
    long index = Level.chunkHash(x, z);
    if (this.chunks.containsKey(index)) {
        return this.chunks.get(index);
    } else {
        this.loadChunk(x, z, create);
        return this.chunks.containsKey(index) ? this.chunks.get(index) : null;
    }
}
 
Example 17
Source File: BaseFullChunk.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setPosition(int x, int z) {
    this.x = x;
    this.z = z;
    this.hash = Level.chunkHash(x, z);
}
 
Example 18
Source File: McRegion.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
protected RegionLoader getRegion(int x, int z) {
    long index = Level.chunkHash(x, z);
    return this.regions.containsKey(index) ? this.regions.get(index) : null;
}
 
Example 19
Source File: BaseFullChunk.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public final void setZ(int z) {
    this.z = z;
    this.hash = Level.chunkHash(getX(), z);
}
 
Example 20
Source File: BaseLevelProvider.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public BaseRegionLoader getRegion(int x, int z) {
    long index = Level.chunkHash(x, z);
    return this.regions.get(index);
}