cn.nukkit.level.format.leveldb.key.EntitiesKey Java Examples
The following examples show how to use
cn.nukkit.level.format.leveldb.key.EntitiesKey.
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 | 4 votes |
public byte[] toBinary(boolean saveExtra) { try { LevelProvider provider = this.getProvider(); if (saveExtra && provider instanceof LevelDB) { List<CompoundTag> entities = new ArrayList<>(); for (Entity entity : this.getEntities().values()) { if (!(entity instanceof Player) && !entity.closed) { entity.saveNBT(); entities.add(entity.namedTag); } } EntitiesKey entitiesKey = EntitiesKey.create(this.getX(), this.getZ()); if (!entities.isEmpty()) { ((LevelDB) provider).getDatabase().put(entitiesKey.toArray(), NBTIO.write(entities)); } else { ((LevelDB) provider).getDatabase().delete(entitiesKey.toArray()); } List<CompoundTag> tiles = new ArrayList<>(); for (BlockEntity blockEntity : this.getBlockEntities().values()) { if (!blockEntity.closed) { blockEntity.saveNBT(); entities.add(blockEntity.namedTag); } } TilesKey tilesKey = TilesKey.create(this.getX(), this.getZ()); if (!tiles.isEmpty()) { ((LevelDB) provider).getDatabase().put(tilesKey.toArray(), NBTIO.write(tiles)); } else { ((LevelDB) provider).getDatabase().delete(tilesKey.toArray()); } ExtraDataKey extraDataKey = ExtraDataKey.create(this.getX(), this.getZ()); if (!this.getBlockExtraDataArray().isEmpty()) { 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)); } ((LevelDB) provider).getDatabase().put(extraDataKey.toArray(), extraData.getBuffer()); } else { ((LevelDB) provider).getDatabase().delete(extraDataKey.toArray()); } } byte[] heightMap = new byte[this.getHeightMapArray().length]; for (int i = 0; i < this.getHeightMapArray().length; i++) { heightMap[i] = (byte) this.getHeightMapArray()[i]; } byte[] biomeColors = new byte[this.getBiomeColorArray().length * 4]; for (int i = 0; i < this.getBiomeColorArray().length; i++) { byte[] bytes = Binary.writeInt(this.getBiomeColorArray()[i]); biomeColors[i * 4] = bytes[0]; biomeColors[i * 4 + 1] = bytes[1]; biomeColors[i * 4 + 2] = bytes[2]; biomeColors[i * 4 + 3] = bytes[3]; } return Binary.appendBytes( Binary.writeLInt(this.getX()), Binary.writeLInt(this.getZ()), this.getBlockIdArray(), this.getBlockDataArray(), this.getBlockSkyLightArray(), this.getBlockLightArray(), heightMap, biomeColors, new byte[]{(byte) (((this.isLightPopulated ? 0x04 : 0) | (this.isPopulated() ? 0x02 : 0) | (this.isGenerated() ? 0x01 : 0)) & 0xff)} ); } catch (Exception e) { throw new RuntimeException(e); } }
Example #2
Source File: Chunk.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public byte[] toBinary(boolean saveExtra) { try { LevelProvider provider = this.getProvider(); if (saveExtra && provider instanceof LevelDB) { List<CompoundTag> entities = new ArrayList<>(); for (Entity entity : this.getEntities().values()) { if (!(entity instanceof Player) && !entity.closed) { entity.saveNBT(); entities.add(entity.namedTag); } } EntitiesKey entitiesKey = EntitiesKey.create(this.getX(), this.getZ()); if (!entities.isEmpty()) { ((LevelDB) provider).getDatabase().put(entitiesKey.toArray(), NBTIO.write(entities)); } else { ((LevelDB) provider).getDatabase().delete(entitiesKey.toArray()); } List<CompoundTag> tiles = new ArrayList<>(); for (BlockEntity blockEntity : this.getBlockEntities().values()) { if (!blockEntity.closed) { blockEntity.saveNBT(); tiles.add(blockEntity.namedTag); } } TilesKey tilesKey = TilesKey.create(this.getX(), this.getZ()); if (!tiles.isEmpty()) { ((LevelDB) provider).getDatabase().put(tilesKey.toArray(), NBTIO.write(tiles)); } else { ((LevelDB) provider).getDatabase().delete(tilesKey.toArray()); } ExtraDataKey extraDataKey = ExtraDataKey.create(this.getX(), this.getZ()); if (!this.getBlockExtraDataArray().isEmpty()) { 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)); } ((LevelDB) provider).getDatabase().put(extraDataKey.toArray(), extraData.getBuffer()); } else { ((LevelDB) provider).getDatabase().delete(extraDataKey.toArray()); } } byte[] heightMap = this.getHeightMapArray(); byte[] biomeColors = new byte[this.biomes.length * 4]; for (int i = 0; i < this.biomes.length; i++) { byte[] bytes = Binary.writeInt(this.biomes[i] << 24); biomeColors[i * 4] = bytes[0]; biomeColors[i * 4 + 1] = bytes[1]; biomeColors[i * 4 + 2] = bytes[2]; biomeColors[i * 4 + 3] = bytes[3]; } return Binary.appendBytes( Binary.writeLInt(this.getX()), Binary.writeLInt(this.getZ()), this.getBlockIdArray(), this.getBlockDataArray(), this.getBlockSkyLightArray(), this.getBlockLightArray(), heightMap, biomeColors, new byte[]{(byte) (((this.isLightPopulated ? 0x04 : 0) | (this.isPopulated() ? 0x02 : 0) | (this.isGenerated() ? 0x01 : 0)) & 0xff)} ); } catch (Exception e) { throw new RuntimeException(e); } }
Example #3
Source File: Chunk.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public byte[] toBinary(boolean saveExtra) { try { LevelProvider provider = this.getProvider(); if (saveExtra && provider instanceof LevelDB) { List<CompoundTag> entities = new ArrayList<>(); for (Entity entity : this.getEntities().values()) { if (!(entity instanceof Player) && !entity.closed) { entity.saveNBT(); entities.add(entity.namedTag); } } EntitiesKey entitiesKey = EntitiesKey.create(this.getX(), this.getZ()); if (!entities.isEmpty()) { ((LevelDB) provider).getDatabase().put(entitiesKey.toArray(), NBTIO.write(entities)); } else { ((LevelDB) provider).getDatabase().delete(entitiesKey.toArray()); } List<CompoundTag> tiles = new ArrayList<>(); for (BlockEntity blockEntity : this.getBlockEntities().values()) { if (!blockEntity.closed) { blockEntity.saveNBT(); entities.add(blockEntity.namedTag); } } TilesKey tilesKey = TilesKey.create(this.getX(), this.getZ()); if (!tiles.isEmpty()) { ((LevelDB) provider).getDatabase().put(tilesKey.toArray(), NBTIO.write(tiles)); } else { ((LevelDB) provider).getDatabase().delete(tilesKey.toArray()); } ExtraDataKey extraDataKey = ExtraDataKey.create(this.getX(), this.getZ()); if (!this.getBlockExtraDataArray().isEmpty()) { 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)); } ((LevelDB) provider).getDatabase().put(extraDataKey.toArray(), extraData.getBuffer()); } else { ((LevelDB) provider).getDatabase().delete(extraDataKey.toArray()); } } byte[] heightMap = this.getHeightMapArray(); byte[] biomeColors = new byte[this.getBiomeColorArray().length * 4]; for (int i = 0; i < this.getBiomeColorArray().length; i++) { byte[] bytes = Binary.writeInt(this.getBiomeColorArray()[i]); biomeColors[i * 4] = bytes[0]; biomeColors[i * 4 + 1] = bytes[1]; biomeColors[i * 4 + 2] = bytes[2]; biomeColors[i * 4 + 3] = bytes[3]; } return Binary.appendBytes( Binary.writeLInt(this.getX()), Binary.writeLInt(this.getZ()), this.getBlockIdArray(), this.getBlockDataArray(), this.getBlockSkyLightArray(), this.getBlockLightArray(), heightMap, biomeColors, new byte[]{(byte) (((this.isLightPopulated ? 0x04 : 0) | (this.isPopulated() ? 0x02 : 0) | (this.isGenerated() ? 0x01 : 0)) & 0xff)} ); } catch (Exception e) { throw new RuntimeException(e); } }