cn.nukkit.utils.BlockUpdateEntry Java Examples

The following examples show how to use cn.nukkit.utils.BlockUpdateEntry. 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: BlockUpdateScheduler.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
private void perform(long tick) {
    try {
        lastTick = tick;
        Set<BlockUpdateEntry> updates = pendingUpdates = queuedUpdates.remove(tick);
        if (updates != null) {
            for (BlockUpdateEntry entry : updates) {
                Vector3 pos = entry.pos;
                if (level.isChunkLoaded(NukkitMath.floorDouble(pos.x) >> 4, NukkitMath.floorDouble(pos.z) >> 4)) {
                    Block block = level.getBlock(entry.pos);

                    if (Block.equals(block, entry.block, false)) {
                        block.onUpdate(Level.BLOCK_UPDATE_SCHEDULED);
                    }
                } else {
                    level.scheduleUpdate(entry.block, entry.pos, 0);
                }
            }
        }
    } finally {
        pendingUpdates = null;
    }
}
 
Example #2
Source File: BlockUpdateScheduler.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
private void perform(long tick) {
    try {
        lastTick = tick;
        Set<BlockUpdateEntry> updates = pendingUpdates = queuedUpdates.remove(tick);
        if (updates != null) {
            for (BlockUpdateEntry entry : updates) {
                Vector3 pos = entry.pos;
                if (level.isChunkLoaded(NukkitMath.floorDouble(pos.x) >> 4, NukkitMath.floorDouble(pos.z) >> 4)) {
                    Block block = level.getBlock(entry.pos);

                    if (Block.equals(block, entry.block, false)) {
                        block.onUpdate(level.BLOCK_UPDATE_SCHEDULED);
                    }
                } else {
                    level.scheduleUpdate(entry.block, entry.pos, 0);
                }
            }
        }
    } finally {
        pendingUpdates = null;
    }
}
 
Example #3
Source File: BlockUpdateScheduler.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public Set<BlockUpdateEntry> getPendingBlockUpdates(AxisAlignedBB boundingBox) {
    Set<BlockUpdateEntry> set = null;

    for (Map.Entry<Long, LinkedHashSet<BlockUpdateEntry>> tickEntries : this.queuedUpdates.entrySet()) {
        LinkedHashSet<BlockUpdateEntry> tickSet = tickEntries.getValue();
        for (BlockUpdateEntry update : tickSet) {
            Vector3 pos = update.pos;

            if (pos.getX() >= boundingBox.getMinX() && pos.getX() < boundingBox.getMaxX() && pos.getZ() >= boundingBox.getMinZ() && pos.getZ() < boundingBox.getMaxZ()) {
                if (set == null) {
                    set = new LinkedHashSet<>();
                }

                set.add(update);
            }
        }
    }

    return set;
}
 
Example #4
Source File: BlockUpdateScheduler.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public Set<BlockUpdateEntry> getPendingBlockUpdates(AxisAlignedBB boundingBox) {
    Set<BlockUpdateEntry> set = null;

    for (Map.Entry<Long, LinkedHashSet<BlockUpdateEntry>> tickEntries : this.queuedUpdates.entrySet()) {
        LinkedHashSet<BlockUpdateEntry> tickSet = tickEntries.getValue();
        for (BlockUpdateEntry update : tickSet) {
            Vector3 pos = update.pos;

            if (pos.getX() >= boundingBox.getMinX() && pos.getX() < boundingBox.getMaxX() && pos.getZ() >= boundingBox.getMinZ() && pos.getZ() < boundingBox.getMaxZ()) {
                if (set == null) {
                    set = new LinkedHashSet<>();
                }

                set.add(update);
            }
        }
    }

    return set;
}
 
Example #5
Source File: Level.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public List<BlockUpdateEntry> getPendingBlockUpdates(AxisAlignedBB boundingBox) {
    List<BlockUpdateEntry> list = null;

    Iterator<BlockUpdateEntry> iterator;

    iterator = this.updateQueue.iterator();

    while (iterator.hasNext()) {
        BlockUpdateEntry entry = iterator.next();
        Vector3 pos = entry.pos;

        if (pos.getX() >= boundingBox.minX && pos.getX() < boundingBox.maxX && pos.getZ() >= boundingBox.minZ && pos.getZ() < boundingBox.maxZ) {
            if (list == null) {
                list = new ArrayList<>();
            }

            list.add(entry);
        }
    }

    return list;
}
 
Example #6
Source File: Level.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public List<BlockUpdateEntry> getPendingBlockUpdates(FullChunk chunk) {
    int minX = (chunk.getX() << 4) - 2;
    int maxX = minX + 16 + 2;
    int minZ = (chunk.getZ() << 4) - 2;
    int maxZ = minZ + 16 + 2;

    return this.getPendingBlockUpdates(new AxisAlignedBB(minX, 0, minZ, maxX, 256, maxZ));
}
 
Example #7
Source File: BlockUpdateScheduler.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public boolean contains(BlockUpdateEntry entry) {
    for (Map.Entry<Long, LinkedHashSet<BlockUpdateEntry>> tickUpdateSet : queuedUpdates.entrySet()) {
        if (tickUpdateSet.getValue().contains(entry)) {
            return true;
        }
    }
    return false;
}
 
Example #8
Source File: BlockUpdateScheduler.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void add(BlockUpdateEntry entry) {
    long time = getMinTime(entry);
    LinkedHashSet<BlockUpdateEntry> updateSet = queuedUpdates.get(time);
    if (updateSet == null) {
        LinkedHashSet<BlockUpdateEntry> tmp = queuedUpdates.putIfAbsent(time, updateSet = new LinkedHashSet<>());
        if (tmp != null) updateSet = tmp;
    }
    updateSet.add(entry);
}
 
Example #9
Source File: BlockUpdateScheduler.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public boolean remove(BlockUpdateEntry entry) {
    for (Map.Entry<Long, LinkedHashSet<BlockUpdateEntry>> tickUpdateSet : queuedUpdates.entrySet()) {
        if (tickUpdateSet.getValue().remove(entry)) {
            return true;
        }
    }
    return false;
}
 
Example #10
Source File: Level.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void scheduleUpdate(Block block, Vector3 pos, int delay, int priority, boolean checkArea) {
    if (block.getId() == 0 || (checkArea && !this.isChunkLoaded(block.getFloorX() >> 4, block.getFloorZ() >> 4))) {
        return;
    }

    BlockUpdateEntry entry = new BlockUpdateEntry(pos.floor(), block, ((long) delay) + getCurrentTick(), priority);

    if (!this.updateQueue.contains(entry)) {
        this.updateQueue.add(entry);
    }
}
 
Example #11
Source File: BlockUpdateScheduler.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void add(BlockUpdateEntry entry) {
    long time = getMinTime(entry);
    LinkedHashSet<BlockUpdateEntry> updateSet = queuedUpdates.get(time);
    if (updateSet == null) {
        LinkedHashSet<BlockUpdateEntry> tmp = queuedUpdates.putIfAbsent(time, updateSet = new LinkedHashSet<>());
        if (tmp != null) updateSet = tmp;
    }
    updateSet.add(entry);
}
 
Example #12
Source File: BlockUpdateScheduler.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public boolean contains(BlockUpdateEntry entry) {
    for (Map.Entry<Long, LinkedHashSet<BlockUpdateEntry>> tickUpdateSet : queuedUpdates.entrySet()) {
        if (tickUpdateSet.getValue().contains(entry)) {
            return true;
        }
    }
    return false;
}
 
Example #13
Source File: BlockUpdateScheduler.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public boolean remove(BlockUpdateEntry entry) {
    for (Map.Entry<Long, LinkedHashSet<BlockUpdateEntry>> tickUpdateSet : queuedUpdates.entrySet()) {
        if (tickUpdateSet.getValue().remove(entry)) {
            return true;
        }
    }
    return false;
}
 
Example #14
Source File: BlockUpdateScheduler.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public boolean remove(Vector3 pos) {
    for (Map.Entry<Long, LinkedHashSet<BlockUpdateEntry>> tickUpdateSet : queuedUpdates.entrySet()) {
        if (tickUpdateSet.getValue().remove(pos)) {
            return true;
        }
    }
    return false;
}
 
Example #15
Source File: BlockUpdateScheduler.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public boolean remove(Vector3 pos) {
    for (Map.Entry<Long, LinkedHashSet<BlockUpdateEntry>> tickUpdateSet : queuedUpdates.entrySet()) {
        if (tickUpdateSet.getValue().remove(pos)) {
            return true;
        }
    }
    return false;
}
 
Example #16
Source File: BlockUpdateScheduler.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
private long getMinTime(BlockUpdateEntry entry) {
    return Math.max(entry.delay, lastTick + 1);
}
 
Example #17
Source File: BlockUpdateScheduler.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
private long getMinTime(BlockUpdateEntry entry) {
    return Math.max(entry.delay, lastTick + 1);
}
 
Example #18
Source File: BlockUpdateScheduler.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public boolean isBlockTickPending(Vector3 pos, Block block) {
    Set<BlockUpdateEntry> tmpUpdates = pendingUpdates;
    if (tmpUpdates == null || tmpUpdates.isEmpty()) return false;
    return tmpUpdates.contains(new BlockUpdateEntry(pos, block));
}
 
Example #19
Source File: Chunk.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
@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 #20
Source File: BlockUpdateScheduler.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public boolean isBlockTickPending(Vector3 pos, Block block) {
    Set<BlockUpdateEntry> tmpUpdates = pendingUpdates;
    if (tmpUpdates == null || tmpUpdates.isEmpty()) return false;
    return tmpUpdates.contains(new BlockUpdateEntry(pos, block));
}
 
Example #21
Source File: Chunk.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@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 #22
Source File: Chunk.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@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 #23
Source File: Level.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public boolean isUpdateScheduled(Vector3 pos, Block block) {
    BlockUpdateEntry entry = new BlockUpdateEntry(pos, block);

    return this.updateQueue.contains(entry);
}
 
Example #24
Source File: Level.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public boolean cancelSheduledUpdate(Vector3 pos, Block block) {
    BlockUpdateEntry entry = new BlockUpdateEntry(pos, block);

    return this.updateQueue.remove(entry);
}
 
Example #25
Source File: Chunk.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
@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);
    }
}