cn.nukkit.level.format.LevelProvider Java Examples
The following examples show how to use
cn.nukkit.level.format.LevelProvider.
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 Nukkit with GNU General Public License v3.0 | 6 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.heightMap = new byte[256]; chunk.inhabitedTime = 0; chunk.terrainGenerated = false; chunk.terrainPopulated = false; // chunk.lightPopulated = false; return chunk; } catch (Exception e) { return null; } }
Example #2
Source File: BaseRegionLoader.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public BaseRegionLoader(LevelProvider level, int regionX, int regionZ, String ext) { try { this.x = regionX; this.z = regionZ; this.levelProvider = level; String filePath = this.levelProvider.getPath() + "region/r." + regionX + "." + regionZ + "." + ext; File file = new File(filePath); boolean exists = file.exists(); if (!exists) { file.createNewFile(); } // TODO: buffering is a temporary solution to chunk reading/writing being poorly optimized // - need to fix the code where it reads single bytes at a time from disk this.randomAccessFile = new BufferedRandomAccessFile(filePath, "rw", 1024); if (!exists) { this.createBlank(); } else { this.loadLocationTable(); } this.lastUsed = System.currentTimeMillis(); } catch (IOException e) { throw new RuntimeException(e); } }
Example #3
Source File: BaseRegionLoader.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public BaseRegionLoader(LevelProvider level, int regionX, int regionZ, String ext) { try { this.x = regionX; this.z = regionZ; this.levelProvider = level; String filePath = this.levelProvider.getPath() + "region/r." + regionX + "." + regionZ + "." + ext; File file = new File(filePath); boolean exists = file.exists(); if (!exists) { file.createNewFile(); } // TODO: buffering is a temporary solution to chunk reading/writing being poorly optimized // - need to fix the code where it reads single bytes at a time from disk this.randomAccessFile = new RandomAccessFile(filePath, "rw"); if (!exists) { this.createBlank(); } else { this.loadLocationTable(); } this.lastUsed = System.currentTimeMillis(); } catch (IOException e) { throw new RuntimeException(e); } }
Example #4
Source File: Chunk.java From Jupiter with GNU General Public License v3.0 | 6 votes |
public static Chunk getEmptyChunk(int chunkX, int chunkZ, LevelProvider provider) { try { Chunk chunk; if (provider != null) { chunk = new Chunk(provider, chunkX, chunkZ, new byte[DATA_LENGTH]); } else { chunk = new Chunk(LevelDB.class, chunkX, chunkZ, new byte[DATA_LENGTH]); } byte[] skyLight = new byte[16384]; Arrays.fill(skyLight, (byte) 0xff); chunk.skyLight = skyLight; return chunk; } catch (Exception e) { throw new RuntimeException(e); } }
Example #5
Source File: BaseRegionLoader.java From Jupiter with GNU General Public License v3.0 | 6 votes |
public BaseRegionLoader(LevelProvider level, int regionX, int regionZ, String ext) { try { this.x = regionX; this.z = regionZ; this.levelProvider = level; this.filePath = this.levelProvider.getPath() + "region/r." + regionX + "." + regionZ + "." + ext; this.file = new File(this.filePath); boolean exists = this.file.exists(); if (!exists) { file.createNewFile(); } this.randomAccessFile = new RandomAccessFile(this.filePath, "rw"); if (!exists) { this.createBlank(); } else { this.loadLocationTable(); } this.lastUsed = System.currentTimeMillis(); } catch (IOException e) { throw new RuntimeException(e); } }
Example #6
Source File: Chunk.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public static Chunk getEmptyChunk(int chunkX, int chunkZ, LevelProvider provider) { try { Chunk chunk; if (provider != null) { chunk = new Chunk(provider, chunkX, chunkZ, new byte[DATA_LENGTH]); } else { chunk = new Chunk(LevelDB.class, chunkX, chunkZ, new byte[DATA_LENGTH]); } byte[] skyLight = new byte[16384]; Arrays.fill(skyLight, (byte) 0xff); chunk.skyLight = skyLight; return chunk; } catch (Exception e) { throw new RuntimeException(e); } }
Example #7
Source File: Chunk.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public static Chunk getEmptyChunk(int chunkX, int chunkZ, LevelProvider provider) { try { Chunk chunk; if (provider != null) { chunk = new Chunk(provider, chunkX, chunkZ, new byte[DATA_LENGTH]); } else { chunk = new Chunk(LevelDB.class, chunkX, chunkZ, new byte[DATA_LENGTH]); } byte[] skyLight = new byte[16384]; Arrays.fill(skyLight, (byte) 0xff); chunk.skyLight = skyLight; return chunk; } catch (Exception e) { throw new RuntimeException(e); } }
Example #8
Source File: LevelProviderConverter.java From Nukkit with GNU General Public License v3.0 | 5 votes |
LevelProviderConverter to(Class<? extends LevelProvider> toClass) { if (toClass != Anvil.class) { throw new IllegalArgumentException("To type can be only Anvil"); } this.toClass = toClass; return this; }
Example #9
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(McRegion.class, null); } chunk.x = chunkX; chunk.z = chunkZ; chunk.data = new byte[16384]; chunk.blocks = new byte[32768]; byte[] skyLight = new byte[16384]; Arrays.fill(skyLight, (byte) 0xff); chunk.skyLight = skyLight; chunk.blockLight = chunk.data; 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) { throw new RuntimeException(e); } }
Example #10
Source File: Chunk.java From Jupiter with GNU General Public License v3.0 | 5 votes |
public static Chunk fromFastBinary(byte[] data, LevelProvider provider) { try { int offset = 0; Chunk chunk = new Chunk(provider != null ? provider : McRegion.class.newInstance(), null); chunk.provider = provider; chunk.x = Binary.readInt(Arrays.copyOfRange(data, offset, offset + 3)); offset += 4; chunk.z = Binary.readInt(Arrays.copyOfRange(data, offset, offset + 3)); offset += 4; chunk.blocks = Arrays.copyOfRange(data, offset, offset + 32767); offset += 32768; chunk.data = Arrays.copyOfRange(data, offset, offset + 16383); offset += 16384; chunk.skyLight = Arrays.copyOfRange(data, offset, offset + 16383); offset += 16384; chunk.blockLight = Arrays.copyOfRange(data, offset, offset + 16383); offset += 16384; chunk.heightMap = new int[256]; for (int i = 0; i < 256; i++) { chunk.heightMap[i] = data[offset] & 0xff; offset++; } chunk.biomeColors = new int[256]; for (int i = 0; i < 256; i++) { chunk.biomeColors[i] = Binary.readInt(Arrays.copyOfRange(data, offset, offset + 3)); offset += 4; } byte flags = data[offset++]; chunk.nbt.putByte("TerrainGenerated", (flags & 0b1)); chunk.nbt.putByte("TerrainPopulated", ((flags >> 1) & 0b1)); chunk.nbt.putByte("LightPopulated", ((flags >> 2) & 0b1)); return chunk; } catch (Exception e) { throw new RuntimeException(e); } }
Example #11
Source File: Chunk.java From Jupiter with GNU General Public License v3.0 | 5 votes |
public static Chunk fromBinary(byte[] data, LevelProvider provider) { try { CompoundTag chunk = NBTIO.read(new ByteArrayInputStream(Zlib.inflate(data)), ByteOrder.BIG_ENDIAN); if (!chunk.contains("Level") || !(chunk.get("Level") instanceof CompoundTag)) { return null; } return new Chunk(provider != null ? provider : McRegion.class.newInstance(), chunk.getCompound("Level")); } catch (Exception e) { return null; } }
Example #12
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(McRegion.class, null); } chunk.setPosition(chunkX, chunkZ); chunk.data = new byte[16384]; chunk.blocks = new byte[32768]; byte[] skyLight = new byte[16384]; Arrays.fill(skyLight, (byte) 0xff); chunk.skyLight = skyLight; chunk.blockLight = chunk.data; 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) { throw new RuntimeException(e); } }
Example #13
Source File: Chunk.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public static Chunk fromBinary(byte[] data, LevelProvider provider) { try { CompoundTag chunk = NBTIO.read(new ByteArrayInputStream(Zlib.inflate(data)), ByteOrder.BIG_ENDIAN); if (!chunk.contains("Level") || !(chunk.get("Level") instanceof CompoundTag)) { return null; } return new Chunk(provider != null ? provider : McRegion.class.newInstance(), chunk.getCompound("Level")); } catch (Exception e) { return null; } }
Example #14
Source File: Chunk.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public static Chunk fromFastBinary(byte[] data, LevelProvider provider) { try { CompoundTag chunk = NBTIO.read(new DataInputStream(new ByteArrayInputStream(data)), ByteOrder.BIG_ENDIAN); if (!chunk.contains("Level") || !(chunk.get("Level") instanceof CompoundTag)) { return null; } return new Chunk(provider, chunk.getCompound("Level")); } catch (Exception e) { return null; } }
Example #15
Source File: Chunk.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public static Chunk fromFastBinary(byte[] data, LevelProvider provider) { try { int offset = 0; Chunk chunk = new Chunk(provider != null ? provider : McRegion.class.newInstance(), null); chunk.provider = provider; int chunkX = (Binary.readInt(Arrays.copyOfRange(data, offset, offset + 3))); offset += 4; int chunkZ = (Binary.readInt(Arrays.copyOfRange(data, offset, offset + 3))); chunk.setPosition(chunkX, chunkZ); offset += 4; chunk.blocks = Arrays.copyOfRange(data, offset, offset + 32767); offset += 32768; chunk.data = Arrays.copyOfRange(data, offset, offset + 16383); offset += 16384; chunk.skyLight = Arrays.copyOfRange(data, offset, offset + 16383); offset += 16384; chunk.blockLight = Arrays.copyOfRange(data, offset, offset + 16383); offset += 16384; chunk.heightMap = Arrays.copyOfRange(data, offset, offset + 256); offset += 256; chunk.biomes = Arrays.copyOfRange(data, offset, offset + 256); offset += 256; byte flags = data[offset++]; chunk.nbt.putByte("TerrainGenerated", (flags & 0b1)); chunk.nbt.putByte("TerrainPopulated", ((flags >> 1) & 0b1)); chunk.nbt.putByte("LightPopulated", ((flags >> 2) & 0b1)); return chunk; } catch (Exception e) { throw new RuntimeException(e); } }
Example #16
Source File: Chunk.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public static Chunk fromBinary(byte[] data, LevelProvider provider) { try { CompoundTag chunk = NBTIO.read(new ByteArrayInputStream(Zlib.inflate(data)), ByteOrder.BIG_ENDIAN); if (!chunk.contains("Level") || !(chunk.get("Level") instanceof CompoundTag)) { return null; } return new Chunk(provider != null ? provider : McRegion.class.newInstance(), chunk.getCompound("Level")); } catch (Exception e) { return null; } }
Example #17
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(McRegion.class, null); } chunk.setPosition(chunkX, chunkZ); chunk.data = new byte[16384]; chunk.blocks = new byte[32768]; byte[] skyLight = new byte[16384]; Arrays.fill(skyLight, (byte) 0xff); chunk.skyLight = skyLight; chunk.blockLight = chunk.data; chunk.heightMap = new byte[256]; chunk.biomes = new byte[16 * 16]; 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) { throw new RuntimeException(e); } }
Example #18
Source File: Chunk.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public static Chunk fromBinary(byte[] data, LevelProvider provider) { try { CompoundTag chunk = NBTIO.read(new ByteArrayInputStream(Zlib.inflate(data)), ByteOrder.BIG_ENDIAN); if (!chunk.contains("Level") || !(chunk.get("Level") instanceof CompoundTag)) { return null; } return new Chunk(provider, chunk.getCompound("Level")); } catch (Exception e) { Server.getInstance().getLogger().logException(e); return null; } }
Example #19
Source File: LevelProviderConverter.java From Nukkit with GNU General Public License v3.0 | 5 votes |
LevelProviderConverter to(Class<? extends LevelProvider> toClass) { if (toClass != Anvil.class) { throw new IllegalArgumentException("To type can be only Anvil"); } this.toClass = toClass; return this; }
Example #20
Source File: Chunk.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public static Chunk fromFastBinary(byte[] data, LevelProvider provider) { try { int offset = 0; Chunk chunk = new Chunk(provider != null ? provider : McRegion.class.newInstance(), null); chunk.provider = provider; int chunkX = (Binary.readInt(Arrays.copyOfRange(data, offset, offset + 3))); offset += 4; int chunkZ = (Binary.readInt(Arrays.copyOfRange(data, offset, offset + 3))); chunk.setPosition(chunkX, chunkZ); offset += 4; chunk.blocks = Arrays.copyOfRange(data, offset, offset + 32767); offset += 32768; chunk.data = Arrays.copyOfRange(data, offset, offset + 16383); offset += 16384; chunk.skyLight = Arrays.copyOfRange(data, offset, offset + 16383); offset += 16384; chunk.blockLight = Arrays.copyOfRange(data, offset, offset + 16383); offset += 16384; chunk.heightMap = Arrays.copyOfRange(data, offset, offset + 256); offset += 256; chunk.biomeColors = new int[256]; for (int i = 0; i < 256; i++) { chunk.biomeColors[i] = Binary.readInt(Arrays.copyOfRange(data, offset, offset + 3)); offset += 4; } byte flags = data[offset++]; chunk.nbt.putByte("TerrainGenerated", (flags & 0b1)); chunk.nbt.putByte("TerrainPopulated", ((flags >> 1) & 0b1)); chunk.nbt.putByte("LightPopulated", ((flags >> 2) & 0b1)); return chunk; } catch (Exception e) { throw new RuntimeException(e); } }
Example #21
Source File: Chunk.java From Jupiter with GNU General Public License v3.0 | 5 votes |
public static Chunk fromBinary(byte[] data, LevelProvider provider) { try { CompoundTag chunk = NBTIO.read(new ByteArrayInputStream(Zlib.inflate(data)), ByteOrder.BIG_ENDIAN); if (!chunk.contains("Level") || !(chunk.get("Level") instanceof CompoundTag)) { return null; } return new Chunk(provider, chunk.getCompound("Level")); } catch (Exception e) { Server.getInstance().getLogger().logException(e); return null; } }
Example #22
Source File: Chunk.java From Jupiter with GNU General Public License v3.0 | 5 votes |
public static Chunk fromFastBinary(byte[] data, LevelProvider provider) { try { CompoundTag chunk = NBTIO.read(new DataInputStream(new ByteArrayInputStream(data)), ByteOrder.BIG_ENDIAN); if (!chunk.contains("Level") || !(chunk.get("Level") instanceof CompoundTag)) { return null; } return new Chunk(provider, chunk.getCompound("Level")); } catch (Exception e) { return null; } }
Example #23
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 #24
Source File: LevelProviderConverter.java From Jupiter with GNU General Public License v3.0 | 5 votes |
LevelProviderConverter from(LevelProvider provider) { if (!(provider instanceof McRegion) && !(provider instanceof LevelDB)) { throw new IllegalArgumentException("From type can be only McRegion or LevelDB"); } this.provider = provider; return this; }
Example #25
Source File: LevelProviderConverter.java From Jupiter with GNU General Public License v3.0 | 5 votes |
LevelProviderConverter to(Class<? extends LevelProvider> toClass) { if (toClass != Anvil.class) { throw new IllegalArgumentException("To type can be only Anvil"); } this.toClass = toClass; return this; }
Example #26
Source File: Chunk.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public static Chunk fromFastBinary(byte[] data, LevelProvider provider) { try { CompoundTag chunk = NBTIO.read(new DataInputStream(new ByteArrayInputStream(data)), ByteOrder.BIG_ENDIAN); if (!chunk.contains("Level") || !(chunk.get("Level") instanceof CompoundTag)) { return null; } return new Chunk(provider, chunk.getCompound("Level")); } catch (Exception e) { return null; } }
Example #27
Source File: BaseFullChunk.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public LevelProvider getProvider() { return provider; }
Example #28
Source File: Chunk.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public Chunk(LevelProvider level, CompoundTag nbt) { this.provider = level; if (level != null) { this.providerClass = level.getClass(); } if (nbt == null) { return; } this.nbt = nbt; if (!(this.nbt.contains("Entities") && (this.nbt.get("Entities") instanceof ListTag))) { this.nbt.putList(new ListTag<CompoundTag>("Entities")); } if (!(this.nbt.contains("TileEntities") && (this.nbt.get("TileEntities") instanceof ListTag))) { this.nbt.putList(new ListTag<CompoundTag>("TileEntities")); } if (!(this.nbt.contains("TileTicks") && (this.nbt.get("TileTicks") instanceof ListTag))) { this.nbt.putList(new ListTag<CompoundTag>("TileTicks")); } if (!(this.nbt.contains("Biomes") && (this.nbt.get("Biomes") instanceof ByteArrayTag))) { this.nbt.putByteArray("Biomes", new byte[256]); } if (!(this.nbt.contains("HeightMap") && (this.nbt.get("HeightMap") instanceof IntArrayTag))) { this.nbt.putIntArray("HeightMap", new int[256]); } if (!(this.nbt.contains("Blocks"))) { this.nbt.putByteArray("Blocks", new byte[32768]); } if (!(this.nbt.contains("Data"))) { this.nbt.putByteArray("Data", new byte[16384]); this.nbt.putByteArray("SkyLight", new byte[16384]); this.nbt.putByteArray("BlockLight", new byte[16384]); } Map<Integer, Integer> extraData = new HashMap<>(); if (!this.nbt.contains("ExtraData") || !(this.nbt.get("ExtraData") instanceof ByteArrayTag)) { this.nbt.putByteArray("ExtraData", Binary.writeInt(0)); } else { BinaryStream stream = new BinaryStream(this.nbt.getByteArray("ExtraData")); for (int i = 0; i < stream.getInt(); i++) { int key = stream.getInt(); extraData.put(key, stream.getShort()); } } this.setPosition(this.nbt.getInt("xPos"), this.nbt.getInt("zPos")); this.blocks = this.nbt.getByteArray("Blocks"); this.data = this.nbt.getByteArray("Data"); this.skyLight = this.nbt.getByteArray("SkyLight"); this.blockLight = this.nbt.getByteArray("BlockLight"); if (this.nbt.contains("BiomeColors")) { this.biomes = new byte[16 * 16]; int[] biomeColors = this.nbt.getIntArray("BiomeColors"); if (biomeColors.length == 256) { BiomePalette palette = new BiomePalette(biomeColors); for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { this.biomes[(x << 4) | z] = (byte) (palette.get(x, z) >> 24); } } } } else { this.biomes = this.nbt.getByteArray("Biomes"); } int[] heightMap = this.nbt.getIntArray("HeightMap"); this.heightMap = new byte[256]; if (heightMap.length != 256) { Arrays.fill(this.heightMap, (byte) 255); } else { for (int i = 0; i < heightMap.length; i++) { this.heightMap[i] = (byte) heightMap[i]; } } if (!extraData.isEmpty()) this.extraData = extraData; this.NBTentities = ((ListTag<CompoundTag>) this.nbt.getList("Entities")).getAll(); this.NBTtiles = ((ListTag<CompoundTag>) this.nbt.getList("TileEntities")).getAll(); this.nbt.remove("Blocks"); this.nbt.remove("Data"); this.nbt.remove("SkyLight"); this.nbt.remove("BlockLight"); this.nbt.remove("BiomeColors"); this.nbt.remove("HeightMap"); this.nbt.remove("Biomes"); }
Example #29
Source File: Chunk.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public Chunk(Class<? extends LevelProvider> providerClass, CompoundTag nbt) { this((LevelProvider) null, nbt); this.providerClass = providerClass; }
Example #30
Source File: Chunk.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public Chunk(Class<? extends LevelProvider> providerClass) { this((LevelProvider) null, null); this.providerClass = providerClass; }