001package net.minecraft.world.gen; 002 003import java.util.Random; 004import net.minecraft.block.Block; 005import net.minecraft.util.MathHelper; 006import net.minecraft.world.World; 007 008public class MapGenRavine extends MapGenBase 009{ 010 private float[] field_75046_d = new float[1024]; 011 012 protected void generateRavine(long par1, int par3, int par4, byte[] par5ArrayOfByte, double par6, double par8, double par10, float par12, float par13, float par14, int par15, int par16, double par17) 013 { 014 Random random = new Random(par1); 015 double d4 = (double)(par3 * 16 + 8); 016 double d5 = (double)(par4 * 16 + 8); 017 float f3 = 0.0F; 018 float f4 = 0.0F; 019 020 if (par16 <= 0) 021 { 022 int j1 = this.range * 16 - 16; 023 par16 = j1 - random.nextInt(j1 / 4); 024 } 025 026 boolean flag = false; 027 028 if (par15 == -1) 029 { 030 par15 = par16 / 2; 031 flag = true; 032 } 033 034 float f5 = 1.0F; 035 036 for (int k1 = 0; k1 < 128; ++k1) 037 { 038 if (k1 == 0 || random.nextInt(3) == 0) 039 { 040 f5 = 1.0F + random.nextFloat() * random.nextFloat() * 1.0F; 041 } 042 043 this.field_75046_d[k1] = f5 * f5; 044 } 045 046 for (; par15 < par16; ++par15) 047 { 048 double d6 = 1.5D + (double)(MathHelper.sin((float)par15 * (float)Math.PI / (float)par16) * par12 * 1.0F); 049 double d7 = d6 * par17; 050 d6 *= (double)random.nextFloat() * 0.25D + 0.75D; 051 d7 *= (double)random.nextFloat() * 0.25D + 0.75D; 052 float f6 = MathHelper.cos(par14); 053 float f7 = MathHelper.sin(par14); 054 par6 += (double)(MathHelper.cos(par13) * f6); 055 par8 += (double)f7; 056 par10 += (double)(MathHelper.sin(par13) * f6); 057 par14 *= 0.7F; 058 par14 += f4 * 0.05F; 059 par13 += f3 * 0.05F; 060 f4 *= 0.8F; 061 f3 *= 0.5F; 062 f4 += (random.nextFloat() - random.nextFloat()) * random.nextFloat() * 2.0F; 063 f3 += (random.nextFloat() - random.nextFloat()) * random.nextFloat() * 4.0F; 064 065 if (flag || random.nextInt(4) != 0) 066 { 067 double d8 = par6 - d4; 068 double d9 = par10 - d5; 069 double d10 = (double)(par16 - par15); 070 double d11 = (double)(par12 + 2.0F + 16.0F); 071 072 if (d8 * d8 + d9 * d9 - d10 * d10 > d11 * d11) 073 { 074 return; 075 } 076 077 if (par6 >= d4 - 16.0D - d6 * 2.0D && par10 >= d5 - 16.0D - d6 * 2.0D && par6 <= d4 + 16.0D + d6 * 2.0D && par10 <= d5 + 16.0D + d6 * 2.0D) 078 { 079 int l1 = MathHelper.floor_double(par6 - d6) - par3 * 16 - 1; 080 int i2 = MathHelper.floor_double(par6 + d6) - par3 * 16 + 1; 081 int j2 = MathHelper.floor_double(par8 - d7) - 1; 082 int k2 = MathHelper.floor_double(par8 + d7) + 1; 083 int l2 = MathHelper.floor_double(par10 - d6) - par4 * 16 - 1; 084 int i3 = MathHelper.floor_double(par10 + d6) - par4 * 16 + 1; 085 086 if (l1 < 0) 087 { 088 l1 = 0; 089 } 090 091 if (i2 > 16) 092 { 093 i2 = 16; 094 } 095 096 if (j2 < 1) 097 { 098 j2 = 1; 099 } 100 101 if (k2 > 120) 102 { 103 k2 = 120; 104 } 105 106 if (l2 < 0) 107 { 108 l2 = 0; 109 } 110 111 if (i3 > 16) 112 { 113 i3 = 16; 114 } 115 116 boolean flag1 = false; 117 int j3; 118 int k3; 119 120 for (j3 = l1; !flag1 && j3 < i2; ++j3) 121 { 122 for (int l3 = l2; !flag1 && l3 < i3; ++l3) 123 { 124 for (int i4 = k2 + 1; !flag1 && i4 >= j2 - 1; --i4) 125 { 126 k3 = (j3 * 16 + l3) * 128 + i4; 127 128 if (i4 >= 0 && i4 < 128) 129 { 130 if (par5ArrayOfByte[k3] == Block.waterMoving.blockID || par5ArrayOfByte[k3] == Block.waterStill.blockID) 131 { 132 flag1 = true; 133 } 134 135 if (i4 != j2 - 1 && j3 != l1 && j3 != i2 - 1 && l3 != l2 && l3 != i3 - 1) 136 { 137 i4 = j2; 138 } 139 } 140 } 141 } 142 } 143 144 if (!flag1) 145 { 146 for (j3 = l1; j3 < i2; ++j3) 147 { 148 double d12 = ((double)(j3 + par3 * 16) + 0.5D - par6) / d6; 149 150 for (k3 = l2; k3 < i3; ++k3) 151 { 152 double d13 = ((double)(k3 + par4 * 16) + 0.5D - par10) / d6; 153 int j4 = (j3 * 16 + k3) * 128 + k2; 154 boolean flag2 = false; 155 156 if (d12 * d12 + d13 * d13 < 1.0D) 157 { 158 for (int k4 = k2 - 1; k4 >= j2; --k4) 159 { 160 double d14 = ((double)k4 + 0.5D - par8) / d7; 161 162 if ((d12 * d12 + d13 * d13) * (double)this.field_75046_d[k4] + d14 * d14 / 6.0D < 1.0D) 163 { 164 byte b0 = par5ArrayOfByte[j4]; 165 166 if (b0 == Block.grass.blockID) 167 { 168 flag2 = true; 169 } 170 171 if (b0 == Block.stone.blockID || b0 == Block.dirt.blockID || b0 == Block.grass.blockID) 172 { 173 if (k4 < 10) 174 { 175 par5ArrayOfByte[j4] = (byte)Block.lavaMoving.blockID; 176 } 177 else 178 { 179 par5ArrayOfByte[j4] = 0; 180 181 if (flag2 && par5ArrayOfByte[j4 - 1] == Block.dirt.blockID) 182 { 183 par5ArrayOfByte[j4 - 1] = this.worldObj.getBiomeGenForCoords(j3 + par3 * 16, k3 + par4 * 16).topBlock; 184 } 185 } 186 } 187 } 188 189 --j4; 190 } 191 } 192 } 193 } 194 195 if (flag) 196 { 197 break; 198 } 199 } 200 } 201 } 202 } 203 } 204 205 /** 206 * Recursively called by generate() (generate) and optionally by itself. 207 */ 208 protected void recursiveGenerate(World par1World, int par2, int par3, int par4, int par5, byte[] par6ArrayOfByte) 209 { 210 if (this.rand.nextInt(50) == 0) 211 { 212 double d0 = (double)(par2 * 16 + this.rand.nextInt(16)); 213 double d1 = (double)(this.rand.nextInt(this.rand.nextInt(40) + 8) + 20); 214 double d2 = (double)(par3 * 16 + this.rand.nextInt(16)); 215 byte b0 = 1; 216 217 for (int i1 = 0; i1 < b0; ++i1) 218 { 219 float f = this.rand.nextFloat() * (float)Math.PI * 2.0F; 220 float f1 = (this.rand.nextFloat() - 0.5F) * 2.0F / 8.0F; 221 float f2 = (this.rand.nextFloat() * 2.0F + this.rand.nextFloat()) * 2.0F; 222 this.generateRavine(this.rand.nextLong(), par4, par5, par6ArrayOfByte, d0, d1, d2, f2, f, f1, 0, 0, 3.0D); 223 } 224 } 225 } 226}