    001package net.minecraft.world.chunk;
    002
    003public class NibbleArray
    004{
    005    /**
    006     * Byte array of data stored in this holder. Possibly a light map or some chunk data. Data is accessed in 4-bit
    007     * pieces.
    008     */
    009    public final byte[] data;
    010
    011    /**
    012     * Log base 2 of the chunk height (128); applied as a shift on Z coordinate
    013     */
    014    private final int depthBits;
    015
    016    /**
    017     * Log base 2 of the chunk height (128) * width (16); applied as a shift on X coordinate
    018     */
    019    private final int depthBitsPlusFour;
    020
    021    public NibbleArray(int par1, int par2)
    022    {
    023        this.data = new byte[par1 >> 1];
    024        this.depthBits = par2;
    025        this.depthBitsPlusFour = par2 + 4;
    026    }
    027
    028    public NibbleArray(byte[] par1ArrayOfByte, int par2)
    029    {
    030        this.data = par1ArrayOfByte;
    031        this.depthBits = par2;
    032        this.depthBitsPlusFour = par2 + 4;
    033    }
    034
    035    /**
    036     * Returns the nibble of data corresponding to the passed in x, y, z. y is at most 6 bits, z is at most 4.
    037     */
    038    public int get(int par1, int par2, int par3)
    039    {
    040        int var4 = par2 << this.depthBitsPlusFour | par3 << this.depthBits | par1;
    041        int var5 = var4 >> 1;
    042        int var6 = var4 & 1;
    043        return var6 == 0 ? this.data[var5] & 15 : this.data[var5] >> 4 & 15;
    044    }
    045
    046    /**
    047     * Arguments are x, y, z, val. Sets the nibble of data at x << 11 | z << 7 | y to val.
    048     */
    049    public void set(int par1, int par2, int par3, int par4)
    050    {
    051        int var5 = par2 << this.depthBitsPlusFour | par3 << this.depthBits | par1;
    052        int var6 = var5 >> 1;
    053        int var7 = var5 & 1;
    054
    055        if (var7 == 0)
    056        {
    057            this.data[var6] = (byte)(this.data[var6] & 240 | par4 & 15);
    058        }
    059        else
    060        {
    061            this.data[var6] = (byte)(this.data[var6] & 15 | (par4 & 15) << 4);
    062        }
    063    }
    064}