package save import ( "fmt" "math" ) // BitStorage implement the compacted data array used in chunk storage. // https://wiki.vg/Chunk_Format // This implement the format since Minecraft 1.16 type BitStorage struct { data []uint64 mask uint64 bits, size int valuesPerLong int } // NewBitStorage create a new BitStorage. // bits is the number of bits per value. // size is the number of values. // arrl is optional data for initializing. // It's length must match the bits and size if it's not nil. func NewBitStorage(bits, size int, arrl []uint64) (b *BitStorage) { b = &BitStorage{ mask: 1< b.size-1 || v < 0 || uint64(v) > b.mask { panic("out of bounds") } c, offset := b.calcIndex(i) l := b.data[c] old = int(l >> offset & b.mask) b.data[c] = l&(b.mask< b.size-1 || v < 0 || uint64(v) > b.mask { panic("out of bounds") } c, offset := b.calcIndex(i) l := b.data[c] b.data[c] = l&(b.mask< b.size-1 { panic("out of bounds") } c, offset := b.calcIndex(i) l := b.data[c] return int(l >> offset & b.mask) }