package net.minecraft.world.gen.layer;

import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.biome.BiomeGenJungle;
import net.minecraft.world.biome.BiomeGenMesa;

/**
 * +
 * 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 GenLayerShore extends GenLayer {
	public GenLayerShore(long parLong1, GenLayer parGenLayer) {
		super(parLong1);
		this.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.
	 */
	public int[] getInts(int i, int j, int k, int l) {
		int[] aint = this.parent.getInts(i - 1, j - 1, k + 2, l + 2);
		int[] aint1 = IntCache.getIntCache(k * l);

		for (int i1 = 0; i1 < l; ++i1) {
			for (int j1 = 0; j1 < k; ++j1) {
				this.initChunkSeed((long) (j1 + i), (long) (i1 + j));
				int k1 = aint[j1 + 1 + (i1 + 1) * (k + 2)];
				BiomeGenBase biomegenbase = BiomeGenBase.getBiome(k1);
				if (k1 == BiomeGenBase.mushroomIsland.biomeID) {
					int j3 = aint[j1 + 1 + (i1 + 1 - 1) * (k + 2)];
					int i4 = aint[j1 + 1 + 1 + (i1 + 1) * (k + 2)];
					int l4 = aint[j1 + 1 - 1 + (i1 + 1) * (k + 2)];
					int k5 = aint[j1 + 1 + (i1 + 1 + 1) * (k + 2)];
					if (j3 != BiomeGenBase.ocean.biomeID && i4 != BiomeGenBase.ocean.biomeID
							&& l4 != BiomeGenBase.ocean.biomeID && k5 != BiomeGenBase.ocean.biomeID) {
						aint1[j1 + i1 * k] = k1;
					} else {
						aint1[j1 + i1 * k] = BiomeGenBase.mushroomIslandShore.biomeID;
					}
				} else if (biomegenbase != null && biomegenbase.getBiomeClass() == BiomeGenJungle.class) {
					int i3 = aint[j1 + 1 + (i1 + 1 - 1) * (k + 2)];
					int l3 = aint[j1 + 1 + 1 + (i1 + 1) * (k + 2)];
					int k4 = aint[j1 + 1 - 1 + (i1 + 1) * (k + 2)];
					int j5 = aint[j1 + 1 + (i1 + 1 + 1) * (k + 2)];
					if (this.func_151631_c(i3) && this.func_151631_c(l3) && this.func_151631_c(k4)
							&& this.func_151631_c(j5)) {
						if (!isBiomeOceanic(i3) && !isBiomeOceanic(l3) && !isBiomeOceanic(k4) && !isBiomeOceanic(j5)) {
							aint1[j1 + i1 * k] = k1;
						} else {
							aint1[j1 + i1 * k] = BiomeGenBase.beach.biomeID;
						}
					} else {
						aint1[j1 + i1 * k] = BiomeGenBase.jungleEdge.biomeID;
					}
				} else if (k1 != BiomeGenBase.extremeHills.biomeID && k1 != BiomeGenBase.extremeHillsPlus.biomeID
						&& k1 != BiomeGenBase.extremeHillsEdge.biomeID) {
					if (biomegenbase != null && biomegenbase.isSnowyBiome()) {
						this.func_151632_a(aint, aint1, j1, i1, k, k1, BiomeGenBase.coldBeach.biomeID);
					} else if (k1 != BiomeGenBase.mesa.biomeID && k1 != BiomeGenBase.mesaPlateau_F.biomeID) {
						if (k1 != BiomeGenBase.ocean.biomeID && k1 != BiomeGenBase.deepOcean.biomeID
								&& k1 != BiomeGenBase.river.biomeID && k1 != BiomeGenBase.swampland.biomeID) {
							int l2 = aint[j1 + 1 + (i1 + 1 - 1) * (k + 2)];
							int k3 = aint[j1 + 1 + 1 + (i1 + 1) * (k + 2)];
							int j4 = aint[j1 + 1 - 1 + (i1 + 1) * (k + 2)];
							int i5 = aint[j1 + 1 + (i1 + 1 + 1) * (k + 2)];
							if (!isBiomeOceanic(l2) && !isBiomeOceanic(k3) && !isBiomeOceanic(j4)
									&& !isBiomeOceanic(i5)) {
								aint1[j1 + i1 * k] = k1;
							} else {
								aint1[j1 + i1 * k] = BiomeGenBase.beach.biomeID;
							}
						} else {
							aint1[j1 + i1 * k] = k1;
						}
					} else {
						int l1 = aint[j1 + 1 + (i1 + 1 - 1) * (k + 2)];
						int i2 = aint[j1 + 1 + 1 + (i1 + 1) * (k + 2)];
						int j2 = aint[j1 + 1 - 1 + (i1 + 1) * (k + 2)];
						int k2 = aint[j1 + 1 + (i1 + 1 + 1) * (k + 2)];
						if (!isBiomeOceanic(l1) && !isBiomeOceanic(i2) && !isBiomeOceanic(j2) && !isBiomeOceanic(k2)) {
							if (this.func_151633_d(l1) && this.func_151633_d(i2) && this.func_151633_d(j2)
									&& this.func_151633_d(k2)) {
								aint1[j1 + i1 * k] = k1;
							} else {
								aint1[j1 + i1 * k] = BiomeGenBase.desert.biomeID;
							}
						} else {
							aint1[j1 + i1 * k] = k1;
						}
					}
				} else {
					this.func_151632_a(aint, aint1, j1, i1, k, k1, BiomeGenBase.stoneBeach.biomeID);
				}
			}
		}

		return aint1;
	}

	private void func_151632_a(int[] parArrayOfInt, int[] parArrayOfInt2, int parInt1, int parInt2, int parInt3,
			int parInt4, int parInt5) {
		if (isBiomeOceanic(parInt4)) {
			parArrayOfInt2[parInt1 + parInt2 * parInt3] = parInt4;
		} else {
			int i = parArrayOfInt[parInt1 + 1 + (parInt2 + 1 - 1) * (parInt3 + 2)];
			int j = parArrayOfInt[parInt1 + 1 + 1 + (parInt2 + 1) * (parInt3 + 2)];
			int k = parArrayOfInt[parInt1 + 1 - 1 + (parInt2 + 1) * (parInt3 + 2)];
			int l = parArrayOfInt[parInt1 + 1 + (parInt2 + 1 + 1) * (parInt3 + 2)];
			if (!isBiomeOceanic(i) && !isBiomeOceanic(j) && !isBiomeOceanic(k) && !isBiomeOceanic(l)) {
				parArrayOfInt2[parInt1 + parInt2 * parInt3] = parInt4;
			} else {
				parArrayOfInt2[parInt1 + parInt2 * parInt3] = parInt5;
			}

		}
	}

	private boolean func_151631_c(int parInt1) {
		return BiomeGenBase.getBiome(parInt1) != null
				&& BiomeGenBase.getBiome(parInt1).getBiomeClass() == BiomeGenJungle.class
						? true
						: parInt1 == BiomeGenBase.jungleEdge.biomeID || parInt1 == BiomeGenBase.jungle.biomeID
								|| parInt1 == BiomeGenBase.jungleHills.biomeID || parInt1 == BiomeGenBase.forest.biomeID
								|| parInt1 == BiomeGenBase.taiga.biomeID || isBiomeOceanic(parInt1);
	}

	private boolean func_151633_d(int parInt1) {
		return BiomeGenBase.getBiome(parInt1) instanceof BiomeGenMesa;
	}
}