    001package net.minecraft.world.gen.layer;
    002
    003public class GenLayerZoom extends GenLayer
    004{
    005    public GenLayerZoom(long par1, GenLayer par3GenLayer)
    006    {
    007        super(par1);
    008        super.parent = par3GenLayer;
    009    }
    010
    011    /**
    012     * Returns a list of integer values generated by this layer. These may be interpreted as temperatures, rainfall
    013     * amounts, or biomeList[] indices based on the particular GenLayer subclass.
    014     */
    015    public int[] getInts(int par1, int par2, int par3, int par4)
    016    {
    017        int i1 = par1 >> 1;
    018        int j1 = par2 >> 1;
    019        int k1 = (par3 >> 1) + 3;
    020        int l1 = (par4 >> 1) + 3;
    021        int[] aint = this.parent.getInts(i1, j1, k1, l1);
    022        int[] aint1 = IntCache.getIntCache(k1 * 2 * l1 * 2);
    023        int i2 = k1 << 1;
    024        int j2;
    025
    026        for (int k2 = 0; k2 < l1 - 1; ++k2)
    027        {
    028            j2 = k2 << 1;
    029            int l2 = j2 * i2;
    030            int i3 = aint[0 + (k2 + 0) * k1];
    031            int j3 = aint[0 + (k2 + 1) * k1];
    032
    033            for (int k3 = 0; k3 < k1 - 1; ++k3)
    034            {
    035                this.initChunkSeed((long)(k3 + i1 << 1), (long)(k2 + j1 << 1));
    036                int l3 = aint[k3 + 1 + (k2 + 0) * k1];
    037                int i4 = aint[k3 + 1 + (k2 + 1) * k1];
    038                aint1[l2] = i3;
    039                aint1[l2++ + i2] = this.choose(i3, j3);
    040                aint1[l2] = this.choose(i3, l3);
    041                aint1[l2++ + i2] = this.modeOrRandom(i3, l3, j3, i4);
    042                i3 = l3;
    043                j3 = i4;
    044            }
    045        }
    046
    047        int[] aint2 = IntCache.getIntCache(par3 * par4);
    048
    049        for (j2 = 0; j2 < par4; ++j2)
    050        {
    051            System.arraycopy(aint1, (j2 + (par2 & 1)) * (k1 << 1) + (par1 & 1), aint2, j2 * par3, par3);
    052        }
    053
    054        return aint2;
    055    }
    056
    057    /**
    058     * Chooses one of the two inputs randomly.
    059     */
    060    protected int choose(int par1, int par2)
    061    {
    062        return this.nextInt(2) == 0 ? par1 : par2;
    063    }
    064
    065    /**
    066     * returns the mode (most frequently occuring number) or a random number from the 4 integers provided
    067     */
    068    protected int modeOrRandom(int par1, int par2, int par3, int par4)
    069    {
    070        if (par2 == par3 && par3 == par4)
    071        {
    072            return par2;
    073        }
    074        else if (par1 == par2 && par1 == par3)
    075        {
    076            return par1;
    077        }
    078        else if (par1 == par2 && par1 == par4)
    079        {
    080            return par1;
    081        }
    082        else if (par1 == par3 && par1 == par4)
    083        {
    084            return par1;
    085        }
    086        else if (par1 == par2 && par3 != par4)
    087        {
    088            return par1;
    089        }
    090        else if (par1 == par3 && par2 != par4)
    091        {
    092            return par1;
    093        }
    094        else if (par1 == par4 && par2 != par3)
    095        {
    096            return par1;
    097        }
    098        else if (par2 == par1 && par3 != par4)
    099        {
    100            return par2;
    101        }
    102        else if (par2 == par3 && par1 != par4)
    103        {
    104            return par2;
    105        }
    106        else if (par2 == par4 && par1 != par3)
    107        {
    108            return par2;
    109        }
    110        else if (par3 == par1 && par2 != par4)
    111        {
    112            return par3;
    113        }
    114        else if (par3 == par2 && par1 != par4)
    115        {
    116            return par3;
    117        }
    118        else if (par3 == par4 && par1 != par2)
    119        {
    120            return par3;
    121        }
    122        else if (par4 == par1 && par2 != par3)
    123        {
    124            return par3;
    125        }
    126        else if (par4 == par2 && par1 != par3)
    127        {
    128            return par3;
    129        }
    130        else if (par4 == par3 && par1 != par2)
    131        {
    132            return par3;
    133        }
    134        else
    135        {
    136            int i1 = this.nextInt(4);
    137            return i1 == 0 ? par1 : (i1 == 1 ? par2 : (i1 == 2 ? par3 : par4));
    138        }
    139    }
    140
    141    public static GenLayer func_75915_a(long par0, GenLayer par2GenLayer, int par3)
    142    {
    143        Object object = par2GenLayer;
    144
    145        for (int k = 0; k < par3; ++k)
    146        {
    147            object = new GenLayerZoom(par0 + (long)k, (GenLayer)object);
    148        }
    149
    150        return (GenLayer)object;
    151    }
    152}