use of net.glowstone.util.VariableValueArray in project Glowstone by GlowstoneMC.
the class ChunkSection method loadTypeArray.
/**
* Loads the contents of this chunk section from the given type array,
* initializing the palette.
*
* @param types The type array.
*/
public void loadTypeArray(char[] types) {
if (types.length != ARRAY_SIZE) {
throw new IllegalArgumentException("Types array length was not " + ARRAY_SIZE + ": " + types.length);
}
// Build the palette, and the count
this.count = 0;
this.palette = new IntArrayList();
for (char type : types) {
if (type != 0) {
count++;
}
if (!palette.contains(type)) {
palette.add(type);
}
}
// Now that we've built a palette, build the list
int bitsPerBlock = VariableValueArray.calculateNeededBits(palette.size());
if (bitsPerBlock < 4) {
bitsPerBlock = 4;
} else if (bitsPerBlock > 8) {
palette = null;
bitsPerBlock = GLOBAL_PALETTE_BITS_PER_BLOCK;
}
this.data = new VariableValueArray(bitsPerBlock, ARRAY_SIZE);
for (int i = 0; i < ARRAY_SIZE; i++) {
if (palette != null) {
data.set(i, palette.indexOf(types[i]));
} else {
data.set(i, types[i]);
}
}
}
Aggregations