@Override public void setBlockExtraData(int x, int y, int z, int data) { if (data == 0) { this.extraData.remove(Level.chunkBlockHash(x, y, z)); } else { this.extraData.put(Level.chunkBlockHash(x, y, z), data); } this.setChanged(true); }
@Override public boolean loadChunk(int chunkX, int chunkZ, boolean create) { String index = Level.chunkHash(chunkX, chunkZ); if (this.chunks.containsKey(index)) { return true; } int regionX = getRegionIndexX(chunkX); int regionZ = getRegionIndexZ(chunkZ); this.loadRegion(regionX, regionZ); Chunk chunk; try { chunk = this.getRegion(regionX, regionZ).readChunk(chunkX - regionX * 32, chunkZ - regionZ * 32); } catch (IOException e) { throw new RuntimeException(e); } if (chunk == null && create) { chunk = this.getEmptyChunk(chunkX, chunkZ); } if (chunk != null) { this.chunks.put(index, chunk); return true; } return false; }
@Override public int getBlockExtraData(int x, int y, int z) { int index = Level.chunkBlockHash(x, y, z); if (this.extraData.containsKey(index)) { return this.extraData.get(index); } return 0; }
protected void loadRegion(int x, int z) { String index = Level.chunkHash(x, z); if (!this.regions.containsKey(index)) { try { this.regions.put(index, new RegionLoader(this, x, z)); } catch (IOException e) { throw new RuntimeException(e); } } }
@Override public Chunk getChunk(int chunkX, int chunkZ, boolean create) { String index = Level.chunkHash(chunkX, chunkZ); if (this.chunks.containsKey(index)) { return this.chunks.get(index); } else { this.loadChunk(chunkX, chunkZ, create); return this.chunks.containsKey(index) ? this.chunks.get(index) : null; } }
@Override public boolean unloadChunk(int X, int Z, boolean safe) { String 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; }
@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 = getRegionIndexX(chunkX); int regionZ = getRegionIndexZ(chunkZ); this.loadRegion(regionX, regionZ); chunk.setX(chunkX); chunk.setZ(chunkZ); String index = Level.chunkHash(chunkX, chunkZ); this.chunks.put(index, (Chunk) chunk); }
public void spawnTo(Player player) { if (!this.hasSpawned.containsKey(player.getLoaderId()) && player.usedChunks.containsKey(Level.chunkHash(this.chunk.getX(), this.chunk.getZ()))) { this.hasSpawned.put(player.getLoaderId(), player); } }
protected RegionLoader getRegion(int x, int z) { String index = Level.chunkHash(x, z); return this.regions.containsKey(index) ? this.regions.get(index) : null; }
@Override public boolean isChunkLoaded(int X, int Z) { return this.chunks.containsKey(Level.chunkHash(X, Z)); }