package net.minecraft.world.gen.layer;

/**
 * + This portion of EaglercraftX contains deobfuscated Minecraft 1.8 source
 * code.
 *
 * Minecraft 1.8.8 bytecode is (c) 2015 Mojang AB. "Do not distribute!" Mod
 * Coder Pack v9.18 deobfuscation configs are (c) Copyright by the MCP Team
 *
 * EaglercraftX 1.8 patch files (c) 2022-2025 lax1dude, ayunami2000. All Rights
 * Reserved.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */
public class GenLayerVoronoiZoom extends GenLayer {
	public GenLayerVoronoiZoom(long parLong1, GenLayer parGenLayer) {
		super(parLong1);
		super.parent = parGenLayer;
	}

	/**
	 * + Returns a list of integer values generated by this layer. These may be
	 * interpreted as temperatures, rainfall amounts, or biomeList[] indices based
	 * on the particular GenLayer subclass.
	 */
	@Override
	public int[] getInts(int i, int j, int k, int l) {
		i = i - 2;
		j = j - 2;
		int i1 = i >> 2;
		int j1 = j >> 2;
		int k1 = (k >> 2) + 2;
		int l1 = (l >> 2) + 2;
		int[] aint = this.parent.getInts(i1, j1, k1, l1);
		int i2 = k1 - 1 << 2;
		int j2 = l1 - 1 << 2;
		int[] aint1 = IntCache.getIntCache(i2 * j2);

		for (int k2 = 0; k2 < l1 - 1; ++k2) {
			int l2 = 0;
			int i3 = aint[l2 + 0 + (k2 + 0) * k1];

			for (int j3 = aint[l2 + 0 + (k2 + 1) * k1]; l2 < k1 - 1; ++l2) {
				double d0 = 3.6D;
				this.initChunkSeed((long) (l2 + i1 << 2), (long) (k2 + j1 << 2));
				double d1 = ((double) this.nextInt(1024) / 1024.0D - 0.5D) * 3.6D;
				double d2 = ((double) this.nextInt(1024) / 1024.0D - 0.5D) * 3.6D;
				this.initChunkSeed((long) (l2 + i1 + 1 << 2), (long) (k2 + j1 << 2));
				double d3 = ((double) this.nextInt(1024) / 1024.0D - 0.5D) * 3.6D + 4.0D;
				double d4 = ((double) this.nextInt(1024) / 1024.0D - 0.5D) * 3.6D;
				this.initChunkSeed((long) (l2 + i1 << 2), (long) (k2 + j1 + 1 << 2));
				double d5 = ((double) this.nextInt(1024) / 1024.0D - 0.5D) * 3.6D;
				double d6 = ((double) this.nextInt(1024) / 1024.0D - 0.5D) * 3.6D + 4.0D;
				this.initChunkSeed((long) (l2 + i1 + 1 << 2), (long) (k2 + j1 + 1 << 2));
				double d7 = ((double) this.nextInt(1024) / 1024.0D - 0.5D) * 3.6D + 4.0D;
				double d8 = ((double) this.nextInt(1024) / 1024.0D - 0.5D) * 3.6D + 4.0D;
				int k3 = aint[l2 + 1 + (k2 + 0) * k1] & 255;
				int l3 = aint[l2 + 1 + (k2 + 1) * k1] & 255;

				for (int i4 = 0; i4 < 4; ++i4) {
					int j4 = ((k2 << 2) + i4) * i2 + (l2 << 2);

					for (int k4 = 0; k4 < 4; ++k4) {
						double d9 = ((double) i4 - d2) * ((double) i4 - d2) + ((double) k4 - d1) * ((double) k4 - d1);
						double d10 = ((double) i4 - d4) * ((double) i4 - d4) + ((double) k4 - d3) * ((double) k4 - d3);
						double d11 = ((double) i4 - d6) * ((double) i4 - d6) + ((double) k4 - d5) * ((double) k4 - d5);
						double d12 = ((double) i4 - d8) * ((double) i4 - d8) + ((double) k4 - d7) * ((double) k4 - d7);
						if (d9 < d10 && d9 < d11 && d9 < d12) {
							aint1[j4++] = i3;
						} else if (d10 < d9 && d10 < d11 && d10 < d12) {
							aint1[j4++] = k3;
						} else if (d11 < d9 && d11 < d10 && d11 < d12) {
							aint1[j4++] = j3;
						} else {
							aint1[j4++] = l3;
						}
					}
				}

				i3 = k3;
				j3 = l3;
			}
		}

		int[] aint2 = IntCache.getIntCache(k * l);

		for (int l4 = 0; l4 < l; ++l4) {
			System.arraycopy(aint1, (l4 + (j & 3)) * i2 + (i & 3), aint2, l4 * k, k);
		}

		return aint2;
	}
}
