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-2024 lax1dude, hoosiertransfer,
 * 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 GenLayerEdge extends GenLayer {
	private final GenLayerEdge.Mode field_151627_c;

	public GenLayerEdge(long parLong1, GenLayer parGenLayer, GenLayerEdge.Mode parMode) {
		super(parLong1);
		this.parent = parGenLayer;
		this.field_151627_c = parMode;
	}

	/**
	 * +
	 * 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.
	 */
	public int[] getInts(int i, int j, int k, int l) {
		switch (this.field_151627_c) {
			case COOL_WARM:
			default:
				return this.getIntsCoolWarm(i, j, k, l);
			case HEAT_ICE:
				return this.getIntsHeatIce(i, j, k, l);
			case SPECIAL:
				return this.getIntsSpecial(i, j, k, l);
		}
	}

	private int[] getIntsCoolWarm(int parInt1, int parInt2, int parInt3, int parInt4) {
		int i = parInt1 - 1;
		int j = parInt2 - 1;
		int k = 1 + parInt3 + 1;
		int l = 1 + parInt4 + 1;
		int[] aint = this.parent.getInts(i, j, k, l);
		int[] aint1 = IntCache.getIntCache(parInt3 * parInt4);

		for (int i1 = 0; i1 < parInt4; ++i1) {
			for (int j1 = 0; j1 < parInt3; ++j1) {
				this.initChunkSeed((long) (j1 + parInt1), (long) (i1 + parInt2));
				int k1 = aint[j1 + 1 + (i1 + 1) * k];
				if (k1 == 1) {
					int l1 = aint[j1 + 1 + (i1 + 1 - 1) * k];
					int i2 = aint[j1 + 1 + 1 + (i1 + 1) * k];
					int j2 = aint[j1 + 1 - 1 + (i1 + 1) * k];
					int k2 = aint[j1 + 1 + (i1 + 1 + 1) * k];
					boolean flag = l1 == 3 || i2 == 3 || j2 == 3 || k2 == 3;
					boolean flag1 = l1 == 4 || i2 == 4 || j2 == 4 || k2 == 4;
					if (flag || flag1) {
						k1 = 2;
					}
				}

				aint1[j1 + i1 * parInt3] = k1;
			}
		}

		return aint1;
	}

	private int[] getIntsHeatIce(int parInt1, int parInt2, int parInt3, int parInt4) {
		int i = parInt1 - 1;
		int j = parInt2 - 1;
		int k = 1 + parInt3 + 1;
		int l = 1 + parInt4 + 1;
		int[] aint = this.parent.getInts(i, j, k, l);
		int[] aint1 = IntCache.getIntCache(parInt3 * parInt4);

		for (int i1 = 0; i1 < parInt4; ++i1) {
			for (int j1 = 0; j1 < parInt3; ++j1) {
				int k1 = aint[j1 + 1 + (i1 + 1) * k];
				if (k1 == 4) {
					int l1 = aint[j1 + 1 + (i1 + 1 - 1) * k];
					int i2 = aint[j1 + 1 + 1 + (i1 + 1) * k];
					int j2 = aint[j1 + 1 - 1 + (i1 + 1) * k];
					int k2 = aint[j1 + 1 + (i1 + 1 + 1) * k];
					boolean flag = l1 == 2 || i2 == 2 || j2 == 2 || k2 == 2;
					boolean flag1 = l1 == 1 || i2 == 1 || j2 == 1 || k2 == 1;
					if (flag1 || flag) {
						k1 = 3;
					}
				}

				aint1[j1 + i1 * parInt3] = k1;
			}
		}

		return aint1;
	}

	private int[] getIntsSpecial(int parInt1, int parInt2, int parInt3, int parInt4) {
		int[] aint = this.parent.getInts(parInt1, parInt2, parInt3, parInt4);
		int[] aint1 = IntCache.getIntCache(parInt3 * parInt4);

		for (int i = 0; i < parInt4; ++i) {
			for (int j = 0; j < parInt3; ++j) {
				this.initChunkSeed((long) (j + parInt1), (long) (i + parInt2));
				int k = aint[j + i * parInt3];
				if (k != 0 && this.nextInt(13) == 0) {
					k |= 1 + this.nextInt(15) << 8 & 3840;
				}

				aint1[j + i * parInt3] = k;
			}
		}

		return aint1;
	}

	public static enum Mode {
		COOL_WARM, HEAT_ICE, SPECIAL;
	}
}