cn.nukkit.level.format.generic.EmptyChunkSection Java Examples
The following examples show how to use
cn.nukkit.level.format.generic.EmptyChunkSection.
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: Chunk.java From Jupiter with GNU General Public License v3.0 | 5 votes |
public static Chunk getEmptyChunk(int chunkX, int chunkZ, LevelProvider provider) { try { Chunk chunk; if (provider != null) { chunk = new Chunk(provider, null); } else { chunk = new Chunk(Anvil.class, null); } chunk.x = chunkX; chunk.z = chunkZ; chunk.sections = new cn.nukkit.level.format.ChunkSection[16]; for (int y = 0; y < 16; ++y) { chunk.sections[y] = new EmptyChunkSection(y); } chunk.heightMap = new int[256]; chunk.biomeColors = new int[256]; chunk.nbt.putByte("V", 1); chunk.nbt.putLong("InhabitedTime", 0); chunk.nbt.putBoolean("TerrainGenerated", false); chunk.nbt.putBoolean("TerrainPopulated", false); chunk.nbt.putBoolean("LightPopulated", false); return chunk; } catch (Exception e) { return null; } }
Example #2
Source File: ChunkSection.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public byte[] getSkyLightArray() { if (this.skyLight != null) return skyLight; if (hasSkyLight) { if (compressedLight != null) { inflate(); return this.skyLight; } return EmptyChunkSection.EMPTY_SKY_LIGHT_ARR; } else { return EmptyChunkSection.EMPTY_LIGHT_ARR; } }
Example #3
Source File: ChunkSection.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public byte[] getLightArray() { if (this.blockLight != null) return blockLight; if (hasBlockLight) { inflate(); return this.blockLight; } else { return EmptyChunkSection.EMPTY_LIGHT_ARR; } }
Example #4
Source File: ChunkSection.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public boolean compress() { if (blockLight != null) { byte[] arr1 = blockLight; hasBlockLight = !Utils.isByteArrayEmpty(arr1); byte[] arr2; if (skyLight != null) { arr2 = skyLight; hasSkyLight = !Utils.isByteArrayEmpty(arr2); } else if (hasSkyLight) { arr2 = EmptyChunkSection.EMPTY_SKY_LIGHT_ARR; } else { arr2 = EmptyChunkSection.EMPTY_LIGHT_ARR; hasSkyLight = false; } blockLight = null; skyLight = null; byte[] toDeflate = null; if (hasBlockLight && hasSkyLight && arr2 != EmptyChunkSection.EMPTY_SKY_LIGHT_ARR) { toDeflate = Binary.appendBytes(arr1, arr2); } else if (hasBlockLight) { toDeflate = arr1; } if (toDeflate != null) { try { compressedLight = Zlib.deflate(toDeflate, 1); } catch (Exception e) { e.printStackTrace(); } } return true; } return false; }
Example #5
Source File: Chunk.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public static Chunk getEmptyChunk(int chunkX, int chunkZ, LevelProvider provider) { try { Chunk chunk; if (provider != null) { chunk = new Chunk(provider, null); } else { chunk = new Chunk(Anvil.class, null); } chunk.setPosition(chunkX, chunkZ); chunk.sections = new cn.nukkit.level.format.ChunkSection[16]; for (int y = 0; y < 16; ++y) { chunk.sections[y] = EmptyChunkSection.EMPTY[y]; } chunk.heightMap = new byte[256]; chunk.biomeColors = new int[256]; chunk.nbt.putByte("V", 1); chunk.nbt.putLong("InhabitedTime", 0); chunk.nbt.putBoolean("TerrainGenerated", false); chunk.nbt.putBoolean("TerrainPopulated", false); chunk.nbt.putBoolean("LightPopulated", false); return chunk; } catch (Exception e) { return null; } }
Example #6
Source File: ChunkSection.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public byte[] getSkyLightArray() { if (this.skyLight != null) return skyLight; if (hasSkyLight) { inflate(); return this.skyLight; } else { return EmptyChunkSection.EMPTY_LIGHT_ARR; } }
Example #7
Source File: ChunkSection.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public byte[] getLightArray() { if (this.blockLight != null) return blockLight; if (hasBlockLight) { inflate(); return this.blockLight; } else { return EmptyChunkSection.EMPTY_LIGHT_ARR; } }
Example #8
Source File: ChunkSection.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public boolean compress() { if (!palette.compress()) { if (blockLight != null) { byte[] arr1 = blockLight; hasBlockLight = !Utils.isByteArrayEmpty(arr1); byte[] arr2; if (skyLight != null) { arr2 = skyLight; hasSkyLight = !Utils.isByteArrayEmpty(skyLight); } else { arr2 = EmptyChunkSection.EMPTY_LIGHT_ARR; hasSkyLight = false; } blockLight = null; skyLight = null; if (hasBlockLight && hasSkyLight) { try { compressedLight = Zlib.deflate(Binary.appendBytes(arr1, arr2), 1); } catch (Exception e) { e.printStackTrace(); } } return true; } return false; } return true; }
Example #9
Source File: Chunk.java From Jupiter with GNU General Public License v3.0 | 4 votes |
@Override public byte[] toFastBinary() { CompoundTag nbt = this.getNBT().copy(); nbt.putInt("xPos", this.x); nbt.putInt("zPos", this.z); nbt.putIntArray("BiomeColors", this.getBiomeColorArray()); nbt.putIntArray("HeightMap", this.getHeightMapArray()); for (cn.nukkit.level.format.ChunkSection section : this.getSections()) { if (section instanceof EmptyChunkSection) { continue; } CompoundTag s = new CompoundTag(null); s.putByte("Y", section.getY()); s.putByteArray("Blocks", section.getIdArray()); s.putByteArray("Data", section.getDataArray()); s.putByteArray("BlockLight", section.getLightArray()); s.putByteArray("SkyLight", section.getSkyLightArray()); nbt.getList("Sections", CompoundTag.class).add(s); } ArrayList<CompoundTag> entities = new ArrayList<>(); for (Entity entity : this.getEntities().values()) { if (!(entity instanceof Player) && !entity.closed) { entity.saveNBT(); entities.add(entity.namedTag); } } ListTag<CompoundTag> entityListTag = new ListTag<>("Entities"); entityListTag.setAll(entities); nbt.putList(entityListTag); ArrayList<CompoundTag> tiles = new ArrayList<>(); for (BlockEntity blockEntity : this.getBlockEntities().values()) { blockEntity.saveNBT(); tiles.add(blockEntity.namedTag); } ListTag<CompoundTag> tileListTag = new ListTag<>("TileEntities"); tileListTag.setAll(tiles); nbt.putList(tileListTag); List<BlockUpdateEntry> entries = this.provider.getLevel().getPendingBlockUpdates(this); if (entries != null) { ListTag<CompoundTag> tileTickTag = new ListTag<>("TileTicks"); long totalTime = this.provider.getLevel().getCurrentTick(); for (BlockUpdateEntry entry : entries) { CompoundTag entryNBT = new CompoundTag() .putString("i", entry.block.getClass().getSimpleName()) .putInt("x", entry.pos.getFloorX()) .putInt("y", entry.pos.getFloorY()) .putInt("z", entry.pos.getFloorZ()) .putInt("t", (int) (entry.delay - totalTime)) .putInt("p", entry.priority); tileTickTag.add(entryNBT); } nbt.putList(tileTickTag); } BinaryStream extraData = new BinaryStream(); Map<Integer, Integer> extraDataArray = this.getBlockExtraDataArray(); extraData.putInt(extraDataArray.size()); for (Integer key : extraDataArray.keySet()) { extraData.putInt(key); extraData.putShort(extraDataArray.get(key)); } nbt.putByteArray("ExtraData", extraData.getBuffer()); CompoundTag chunk = new CompoundTag(""); chunk.putCompound("Level", nbt); try { return NBTIO.write(chunk, ByteOrder.BIG_ENDIAN); } catch (IOException e) { throw new RuntimeException(e); } }
Example #10
Source File: Chunk.java From Jupiter with GNU General Public License v3.0 | 4 votes |
@Override public byte[] toBinary() { CompoundTag nbt = this.getNBT().copy(); nbt.putInt("xPos", this.x); nbt.putInt("zPos", this.z); ListTag<CompoundTag> sectionList = new ListTag<>("Sections"); for (cn.nukkit.level.format.ChunkSection section : this.getSections()) { if (section instanceof EmptyChunkSection) { continue; } CompoundTag s = new CompoundTag(null); s.putByte("Y", (section.getY())); s.putByteArray("Blocks", section.getIdArray()); s.putByteArray("Data", section.getDataArray()); s.putByteArray("BlockLight", section.getLightArray()); s.putByteArray("SkyLight", section.getSkyLightArray()); sectionList.add(s); } nbt.putList(sectionList); nbt.putIntArray("BiomeColors", this.getBiomeColorArray()); nbt.putIntArray("HeightMap", this.getHeightMapArray()); ArrayList<CompoundTag> entities = new ArrayList<>(); for (Entity entity : this.getEntities().values()) { if (!(entity instanceof Player) && !entity.closed) { entity.saveNBT(); entities.add(entity.namedTag); } } ListTag<CompoundTag> entityListTag = new ListTag<>("Entities"); entityListTag.setAll(entities); nbt.putList(entityListTag); ArrayList<CompoundTag> tiles = new ArrayList<>(); for (BlockEntity blockEntity : this.getBlockEntities().values()) { blockEntity.saveNBT(); tiles.add(blockEntity.namedTag); } ListTag<CompoundTag> tileListTag = new ListTag<>("TileEntities"); tileListTag.setAll(tiles); nbt.putList(tileListTag); List<BlockUpdateEntry> entries = this.provider.getLevel().getPendingBlockUpdates(this); if (entries != null) { ListTag<CompoundTag> tileTickTag = new ListTag<>("TileTicks"); long totalTime = this.provider.getLevel().getCurrentTick(); for (BlockUpdateEntry entry : entries) { CompoundTag entryNBT = new CompoundTag() .putString("i", entry.block.getClass().getSimpleName()) .putInt("x", entry.pos.getFloorX()) .putInt("y", entry.pos.getFloorY()) .putInt("z", entry.pos.getFloorZ()) .putInt("t", (int) (entry.delay - totalTime)) .putInt("p", entry.priority); tileTickTag.add(entryNBT); } nbt.putList(tileTickTag); } BinaryStream extraData = new BinaryStream(); Map<Integer, Integer> extraDataArray = this.getBlockExtraDataArray(); extraData.putInt(extraDataArray.size()); for (Integer key : extraDataArray.keySet()) { extraData.putInt(key); extraData.putShort(extraDataArray.get(key)); } nbt.putByteArray("ExtraData", extraData.getBuffer()); CompoundTag chunk = new CompoundTag(""); chunk.putCompound("Level", nbt); try { return Zlib.deflate(NBTIO.write(chunk, ByteOrder.BIG_ENDIAN), RegionLoader.COMPRESSION_LEVEL); } catch (Exception e) { throw new RuntimeException(e); } }
Example #11
Source File: Chunk.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public byte[] toFastBinary() { CompoundTag nbt = this.getNBT().copy(); nbt.remove("BiomeColors"); nbt.putInt("xPos", this.getX()); nbt.putInt("zPos", this.getZ()); nbt.putByteArray("Biomes", this.getBiomeIdArray()); int[] heightInts = new int[256]; byte[] heightBytes = this.getHeightMapArray(); for (int i = 0; i < heightInts.length; i++) { heightInts[i] = heightBytes[i] & 0xFF; } for (cn.nukkit.level.format.ChunkSection section : this.getSections()) { if (section instanceof EmptyChunkSection) { continue; } CompoundTag s = new CompoundTag(null); s.putByte("Y", section.getY()); s.putByteArray("Blocks", section.getIdArray()); s.putByteArray("Data", section.getDataArray()); s.putByteArray("BlockLight", section.getLightArray()); s.putByteArray("SkyLight", section.getSkyLightArray()); nbt.getList("Sections", CompoundTag.class).add(s); } ArrayList<CompoundTag> entities = new ArrayList<>(); for (Entity entity : this.getEntities().values()) { if (!(entity instanceof Player) && !entity.closed) { entity.saveNBT(); entities.add(entity.namedTag); } } ListTag<CompoundTag> entityListTag = new ListTag<>("Entities"); entityListTag.setAll(entities); nbt.putList(entityListTag); ArrayList<CompoundTag> tiles = new ArrayList<>(); for (BlockEntity blockEntity : this.getBlockEntities().values()) { blockEntity.saveNBT(); tiles.add(blockEntity.namedTag); } ListTag<CompoundTag> tileListTag = new ListTag<>("TileEntities"); tileListTag.setAll(tiles); nbt.putList(tileListTag); Set<BlockUpdateEntry> entries = this.provider.getLevel().getPendingBlockUpdates(this); if (entries != null) { ListTag<CompoundTag> tileTickTag = new ListTag<>("TileTicks"); long totalTime = this.provider.getLevel().getCurrentTick(); for (BlockUpdateEntry entry : entries) { CompoundTag entryNBT = new CompoundTag() .putString("i", entry.block.getSaveId()) .putInt("x", entry.pos.getFloorX()) .putInt("y", entry.pos.getFloorY()) .putInt("z", entry.pos.getFloorZ()) .putInt("t", (int) (entry.delay - totalTime)) .putInt("p", entry.priority); tileTickTag.add(entryNBT); } nbt.putList(tileTickTag); } BinaryStream extraData = new BinaryStream(); Map<Integer, Integer> extraDataArray = this.getBlockExtraDataArray(); extraData.putInt(extraDataArray.size()); for (Integer key : extraDataArray.keySet()) { extraData.putInt(key); extraData.putShort(extraDataArray.get(key)); } nbt.putByteArray("ExtraData", extraData.getBuffer()); CompoundTag chunk = new CompoundTag(""); chunk.putCompound("Level", nbt); try { return NBTIO.write(chunk, ByteOrder.BIG_ENDIAN); } catch (IOException e) { throw new RuntimeException(e); } }
Example #12
Source File: Chunk.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public byte[] toBinary() { CompoundTag nbt = this.getNBT().copy(); nbt.remove("BiomeColors"); nbt.putInt("xPos", this.getX()); nbt.putInt("zPos", this.getZ()); ListTag<CompoundTag> sectionList = new ListTag<>("Sections"); for (cn.nukkit.level.format.ChunkSection section : this.getSections()) { if (section instanceof EmptyChunkSection) { continue; } CompoundTag s = new CompoundTag(null); s.putByte("Y", (section.getY())); s.putByteArray("Blocks", section.getIdArray()); s.putByteArray("Data", section.getDataArray()); s.putByteArray("BlockLight", section.getLightArray()); s.putByteArray("SkyLight", section.getSkyLightArray()); sectionList.add(s); } nbt.putList(sectionList); nbt.putByteArray("Biomes", this.getBiomeIdArray()); int[] heightInts = new int[256]; byte[] heightBytes = this.getHeightMapArray(); for (int i = 0; i < heightInts.length; i++) { heightInts[i] = heightBytes[i] & 0xFF; } nbt.putIntArray("HeightMap", heightInts); ArrayList<CompoundTag> entities = new ArrayList<>(); for (Entity entity : this.getEntities().values()) { if (!(entity instanceof Player) && !entity.closed) { entity.saveNBT(); entities.add(entity.namedTag); } } ListTag<CompoundTag> entityListTag = new ListTag<>("Entities"); entityListTag.setAll(entities); nbt.putList(entityListTag); ArrayList<CompoundTag> tiles = new ArrayList<>(); for (BlockEntity blockEntity : this.getBlockEntities().values()) { blockEntity.saveNBT(); tiles.add(blockEntity.namedTag); } ListTag<CompoundTag> tileListTag = new ListTag<>("TileEntities"); tileListTag.setAll(tiles); nbt.putList(tileListTag); Set<BlockUpdateEntry> entries = this.provider.getLevel().getPendingBlockUpdates(this); if (entries != null) { ListTag<CompoundTag> tileTickTag = new ListTag<>("TileTicks"); long totalTime = this.provider.getLevel().getCurrentTick(); for (BlockUpdateEntry entry : entries) { CompoundTag entryNBT = new CompoundTag() .putString("i", entry.block.getSaveId()) .putInt("x", entry.pos.getFloorX()) .putInt("y", entry.pos.getFloorY()) .putInt("z", entry.pos.getFloorZ()) .putInt("t", (int) (entry.delay - totalTime)) .putInt("p", entry.priority); tileTickTag.add(entryNBT); } nbt.putList(tileTickTag); } BinaryStream extraData = new BinaryStream(); Map<Integer, Integer> extraDataArray = this.getBlockExtraDataArray(); extraData.putInt(extraDataArray.size()); for (Integer key : extraDataArray.keySet()) { extraData.putInt(key); extraData.putShort(extraDataArray.get(key)); } nbt.putByteArray("ExtraData", extraData.getBuffer()); CompoundTag chunk = new CompoundTag(""); chunk.putCompound("Level", nbt); try { return Zlib.deflate(NBTIO.write(chunk, ByteOrder.BIG_ENDIAN), RegionLoader.COMPRESSION_LEVEL); } catch (Exception e) { throw new RuntimeException(e); } }
Example #13
Source File: Chunk.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public byte[] toFastBinary() { CompoundTag nbt = this.getNBT().copy(); nbt.putInt("xPos", this.getX()); nbt.putInt("zPos", this.getZ()); nbt.putIntArray("BiomeColors", this.getBiomeColorArray()); int[] heightInts = new int[256]; byte[] heightBytes = this.getHeightMapArray(); for (int i = 0; i < heightInts.length; i++) { heightInts[i] = heightBytes[i] & 0xFF; } for (cn.nukkit.level.format.ChunkSection section : this.getSections()) { if (section instanceof EmptyChunkSection) { continue; } CompoundTag s = new CompoundTag(null); s.putByte("Y", section.getY()); s.putByteArray("Blocks", section.getIdArray()); s.putByteArray("Data", section.getDataArray()); s.putByteArray("BlockLight", section.getLightArray()); s.putByteArray("SkyLight", section.getSkyLightArray()); nbt.getList("Sections", CompoundTag.class).add(s); } ArrayList<CompoundTag> entities = new ArrayList<>(); for (Entity entity : this.getEntities().values()) { if (!(entity instanceof Player) && !entity.closed) { entity.saveNBT(); entities.add(entity.namedTag); } } ListTag<CompoundTag> entityListTag = new ListTag<>("Entities"); entityListTag.setAll(entities); nbt.putList(entityListTag); ArrayList<CompoundTag> tiles = new ArrayList<>(); for (BlockEntity blockEntity : this.getBlockEntities().values()) { blockEntity.saveNBT(); tiles.add(blockEntity.namedTag); } ListTag<CompoundTag> tileListTag = new ListTag<>("TileEntities"); tileListTag.setAll(tiles); nbt.putList(tileListTag); Set<BlockUpdateEntry> entries = this.provider.getLevel().getPendingBlockUpdates(this); if (entries != null) { ListTag<CompoundTag> tileTickTag = new ListTag<>("TileTicks"); long totalTime = this.provider.getLevel().getCurrentTick(); for (BlockUpdateEntry entry : entries) { CompoundTag entryNBT = new CompoundTag() .putString("i", entry.block.getSaveId()) .putInt("x", entry.pos.getFloorX()) .putInt("y", entry.pos.getFloorY()) .putInt("z", entry.pos.getFloorZ()) .putInt("t", (int) (entry.delay - totalTime)) .putInt("p", entry.priority); tileTickTag.add(entryNBT); } nbt.putList(tileTickTag); } BinaryStream extraData = new BinaryStream(); Map<Integer, Integer> extraDataArray = this.getBlockExtraDataArray(); extraData.putInt(extraDataArray.size()); for (Integer key : extraDataArray.keySet()) { extraData.putInt(key); extraData.putShort(extraDataArray.get(key)); } nbt.putByteArray("ExtraData", extraData.getBuffer()); CompoundTag chunk = new CompoundTag(""); chunk.putCompound("Level", nbt); try { return NBTIO.write(chunk, ByteOrder.BIG_ENDIAN); } catch (IOException e) { throw new RuntimeException(e); } }
Example #14
Source File: Chunk.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public byte[] toBinary() { CompoundTag nbt = this.getNBT().copy(); nbt.putInt("xPos", this.getX()); nbt.putInt("zPos", this.getZ()); ListTag<CompoundTag> sectionList = new ListTag<>("Sections"); for (cn.nukkit.level.format.ChunkSection section : this.getSections()) { if (section instanceof EmptyChunkSection) { continue; } CompoundTag s = new CompoundTag(null); s.putByte("Y", (section.getY())); s.putByteArray("Blocks", section.getIdArray()); s.putByteArray("Data", section.getDataArray()); s.putByteArray("BlockLight", section.getLightArray()); s.putByteArray("SkyLight", section.getSkyLightArray()); sectionList.add(s); } nbt.putList(sectionList); nbt.putIntArray("BiomeColors", this.getBiomeColorArray()); int[] heightInts = new int[256]; byte[] heightBytes = this.getHeightMapArray(); for (int i = 0; i < heightInts.length; i++) { heightInts[i] = heightBytes[i] & 0xFF; } nbt.putIntArray("HeightMap", heightInts); ArrayList<CompoundTag> entities = new ArrayList<>(); for (Entity entity : this.getEntities().values()) { if (!(entity instanceof Player) && !entity.closed) { entity.saveNBT(); entities.add(entity.namedTag); } } ListTag<CompoundTag> entityListTag = new ListTag<>("Entities"); entityListTag.setAll(entities); nbt.putList(entityListTag); ArrayList<CompoundTag> tiles = new ArrayList<>(); for (BlockEntity blockEntity : this.getBlockEntities().values()) { blockEntity.saveNBT(); tiles.add(blockEntity.namedTag); } ListTag<CompoundTag> tileListTag = new ListTag<>("TileEntities"); tileListTag.setAll(tiles); nbt.putList(tileListTag); Set<BlockUpdateEntry> entries = this.provider.getLevel().getPendingBlockUpdates(this); if (entries != null) { ListTag<CompoundTag> tileTickTag = new ListTag<>("TileTicks"); long totalTime = this.provider.getLevel().getCurrentTick(); for (BlockUpdateEntry entry : entries) { CompoundTag entryNBT = new CompoundTag() .putString("i", entry.block.getSaveId()) .putInt("x", entry.pos.getFloorX()) .putInt("y", entry.pos.getFloorY()) .putInt("z", entry.pos.getFloorZ()) .putInt("t", (int) (entry.delay - totalTime)) .putInt("p", entry.priority); tileTickTag.add(entryNBT); } nbt.putList(tileTickTag); } BinaryStream extraData = new BinaryStream(); Map<Integer, Integer> extraDataArray = this.getBlockExtraDataArray(); extraData.putInt(extraDataArray.size()); for (Integer key : extraDataArray.keySet()) { extraData.putInt(key); extraData.putShort(extraDataArray.get(key)); } nbt.putByteArray("ExtraData", extraData.getBuffer()); CompoundTag chunk = new CompoundTag(""); chunk.putCompound("Level", nbt); try { return Zlib.deflate(NBTIO.write(chunk, ByteOrder.BIG_ENDIAN), RegionLoader.COMPRESSION_LEVEL); } catch (Exception e) { throw new RuntimeException(e); } }