Search in sources :

Example 1 with PackedIntegerArray

use of net.modificationstation.stationapi.api.util.collection.PackedIntegerArray in project StationAPI by ModificationStation.

the class PalettedContainer method setPaletteSize.

private void setPaletteSize(int size) {
    if (size != this.paletteSize) {
        this.paletteSize = size;
        if (this.paletteSize <= 4) {
            this.paletteSize = 4;
            this.palette = new ArrayPalette<>(this.idList, this.paletteSize, this, this.elementDeserializer);
        } else if (this.paletteSize < 9) {
            this.palette = new BiMapPalette<>(this.idList, this.paletteSize, this, this.elementDeserializer, this.elementSerializer);
        } else {
            this.palette = this.fallbackPalette;
            this.paletteSize = MathHelper.log2DeBruijn(this.idList.size());
        }
        this.palette.getIndex(this.defaultValue);
        this.data = new PackedIntegerArray(this.paletteSize, 4096);
    }
}
Also used : PackedIntegerArray(net.modificationstation.stationapi.api.util.collection.PackedIntegerArray)

Example 2 with PackedIntegerArray

use of net.modificationstation.stationapi.api.util.collection.PackedIntegerArray in project StationAPI by ModificationStation.

the class PalettedContainer method read.

public void read(ListTag paletteTag, long[] data) {
    this.lock();
    int i = Math.max(4, MathHelper.log2DeBruijn(paletteTag.size()));
    if (i != this.paletteSize) {
        this.setPaletteSize(i);
    }
    this.palette.fromTag(paletteTag);
    int j = data.length * 64 / 4096;
    if (this.palette == this.fallbackPalette) {
        Palette<T> palette = new BiMapPalette<>(this.idList, i, this.noOpPaletteResizeHandler, this.elementDeserializer, this.elementSerializer);
        palette.fromTag(paletteTag);
        PackedIntegerArray packedIntegerArray = new PackedIntegerArray(i, 4096, data);
        for (int k = 0; k < 4096; ++k) {
            this.data.set(k, this.fallbackPalette.getIndex(palette.getByIndex(packedIntegerArray.get(k))));
        }
    } else if (j == this.paletteSize) {
        System.arraycopy(data, 0, this.data.getStorage(), 0, data.length);
    } else {
        PackedIntegerArray packedIntegerArray2 = new PackedIntegerArray(j, 4096, data);
        for (int l = 0; l < 4096; ++l) {
            this.data.set(l, packedIntegerArray2.get(l));
        }
    }
    this.unlock();
}
Also used : PackedIntegerArray(net.modificationstation.stationapi.api.util.collection.PackedIntegerArray)

Example 3 with PackedIntegerArray

use of net.modificationstation.stationapi.api.util.collection.PackedIntegerArray in project StationAPI by ModificationStation.

the class PalettedContainer method write.

public void write(CompoundTag compoundTag, String string, String string2) {
    this.lock();
    BiMapPalette<T> biMapPalette = new BiMapPalette<>(this.idList, this.paletteSize, this.noOpPaletteResizeHandler, this.elementDeserializer, this.elementSerializer);
    T object = this.defaultValue;
    int i = biMapPalette.getIndex(this.defaultValue);
    int[] is = new int[4096];
    for (int j = 0; j < 4096; ++j) {
        T object2 = this.get(j);
        if (object2 != object) {
            object = object2;
            i = biMapPalette.getIndex(object2);
        }
        is[j] = i;
    }
    ListTag listTag = new ListTag();
    biMapPalette.toTag(listTag);
    compoundTag.put(string, listTag);
    int k = Math.max(4, MathHelper.log2DeBruijn(listTag.size()));
    PackedIntegerArray packedIntegerArray = new PackedIntegerArray(k, 4096);
    for (int l = 0; l < is.length; ++l) {
        packedIntegerArray.set(l, is[l]);
    }
    ((LongArrayCompound) compoundTag).put(string2, packedIntegerArray.getStorage());
    this.unlock();
}
Also used : PackedIntegerArray(net.modificationstation.stationapi.api.util.collection.PackedIntegerArray) ListTag(net.minecraft.util.io.ListTag) LongArrayCompound(net.modificationstation.stationapi.impl.nbt.LongArrayCompound)

Example 4 with PackedIntegerArray

use of net.modificationstation.stationapi.api.util.collection.PackedIntegerArray in project StationAPI by ModificationStation.

the class PalettedContainer method onResize.

public int onResize(int i, T object) {
    this.lock();
    PackedIntegerArray packedIntegerArray = this.data;
    Palette<T> palette = this.palette;
    this.setPaletteSize(i);
    int j;
    for (j = 0; j < packedIntegerArray.getSize(); ++j) {
        T object2 = palette.getByIndex(packedIntegerArray.get(j));
        if (object2 != null) {
            this.set(j, object2);
        }
    }
    j = this.palette.getIndex(object);
    this.unlock();
    return j;
}
Also used : PackedIntegerArray(net.modificationstation.stationapi.api.util.collection.PackedIntegerArray)

Aggregations

PackedIntegerArray (net.modificationstation.stationapi.api.util.collection.PackedIntegerArray)4 ListTag (net.minecraft.util.io.ListTag)1 LongArrayCompound (net.modificationstation.stationapi.impl.nbt.LongArrayCompound)1