All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fastasyncworldedit.core.jnbt.CompressedCompoundTag Maven / Gradle / Ivy

Go to download

Blazingly fast Minecraft world manipulation for artists, builders and everyone else.

There is a newer version: 2.9.2
Show newest version
package com.fastasyncworldedit.core.jnbt;

import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.NBTInputStream;
import com.sk89q.jnbt.Tag;
import net.jpountz.lz4.LZ4BlockInputStream;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public abstract class CompressedCompoundTag extends CompoundTag {

    private T in;

    public CompressedCompoundTag(T in) {
        super(new HashMap<>());
        this.in = in;
    }

    @Override
    public Map getValue() {
        if (in != null) {
            decompress();
        }
        return super.getValue();
    }

    public abstract LZ4BlockInputStream adapt(T src) throws IOException;

    public T getSource() {
        return in;
    }

    private void decompress() {
        try (NBTInputStream nbtIn = new NBTInputStream(adapt(in))) {
            in = null;
            CompoundTag tag = (CompoundTag) nbtIn.readTag();
            Map value = tag.getValue();
            Map raw = super.getValue();
            raw.putAll(value);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy