| 1 | package net.minecraft.world.gen;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import java.util.Random;
|
| 5 | import net.minecraft.block.BlockFalling;
|
| 6 | import net.minecraft.block.material.Material;
|
| 7 | import net.minecraft.block.state.IBlockState;
|
| 8 | import net.minecraft.entity.EnumCreatureType;
|
| 9 | import net.minecraft.init.Blocks;
|
| 10 | import net.minecraft.util.BlockPos;
|
| 11 | import net.minecraft.util.IProgressUpdate;
|
| 12 | import net.minecraft.util.MathHelper;
|
| 13 | import net.minecraft.world.World;
|
| 14 | import net.minecraft.world.biome.BiomeGenBase;
|
| 15 | import net.minecraft.world.chunk.Chunk;
|
| 16 | import net.minecraft.world.chunk.ChunkPrimer;
|
| 17 | import net.minecraft.world.chunk.IChunkProvider;
|
| 18 |
|
| 19 | public class ChunkProviderEnd implements IChunkProvider
|
| 20 | {
|
| 21 | private Random endRNG;
|
| 22 | private NoiseGeneratorOctaves noiseGen1;
|
| 23 | private NoiseGeneratorOctaves noiseGen2;
|
| 24 | private NoiseGeneratorOctaves noiseGen3;
|
| 25 | public NoiseGeneratorOctaves noiseGen4;
|
| 26 | public NoiseGeneratorOctaves noiseGen5;
|
| 27 | private World endWorld;
|
| 28 | private double[] densities;
|
| 29 |
|
| 30 | /** The biomes that are used to generate the chunk */
|
| 31 | private BiomeGenBase[] biomesForGeneration;
|
| 32 | double[] noiseData1;
|
| 33 | double[] noiseData2;
|
| 34 | double[] noiseData3;
|
| 35 | double[] noiseData4;
|
| 36 | double[] noiseData5;
|
| 37 |
|
| 38 | public ChunkProviderEnd(World worldIn, long seed)
|
| 39 | {
|
| 40 | this.endWorld = worldIn;
|
| 41 | this.endRNG = new Random(seed);
|
| 42 | this.noiseGen1 = new NoiseGeneratorOctaves(this.endRNG, 16);
|
| 43 | this.noiseGen2 = new NoiseGeneratorOctaves(this.endRNG, 16);
|
| 44 | this.noiseGen3 = new NoiseGeneratorOctaves(this.endRNG, 8);
|
| 45 | this.noiseGen4 = new NoiseGeneratorOctaves(this.endRNG, 10);
|
| 46 | this.noiseGen5 = new NoiseGeneratorOctaves(this.endRNG, 16);
|
| 47 | }
|
| 48 |
|
| 49 | public void func_180520_a(int p_180520_1_, int p_180520_2_, ChunkPrimer p_180520_3_)
|
| 50 | {
|
| 51 | int i = 2;
|
| 52 | int j = i + 1;
|
| 53 | int k = 33;
|
| 54 | int l = i + 1;
|
| 55 | this.densities = this.initializeNoiseField(this.densities, p_180520_1_ * i, 0, p_180520_2_ * i, j, k, l);
|
| 56 |
|
| 57 | for (int i1 = 0; i1 < i; ++i1)
|
| 58 | {
|
| 59 | for (int j1 = 0; j1 < i; ++j1)
|
| 60 | {
|
| 61 | for (int k1 = 0; k1 < 32; ++k1)
|
| 62 | {
|
| 63 | double d0 = 0.25D;
|
| 64 | double d1 = this.densities[((i1 + 0) * l + j1 + 0) * k + k1 + 0];
|
| 65 | double d2 = this.densities[((i1 + 0) * l + j1 + 1) * k + k1 + 0];
|
| 66 | double d3 = this.densities[((i1 + 1) * l + j1 + 0) * k + k1 + 0];
|
| 67 | double d4 = this.densities[((i1 + 1) * l + j1 + 1) * k + k1 + 0];
|
| 68 | double d5 = (this.densities[((i1 + 0) * l + j1 + 0) * k + k1 + 1] - d1) * d0;
|
| 69 | double d6 = (this.densities[((i1 + 0) * l + j1 + 1) * k + k1 + 1] - d2) * d0;
|
| 70 | double d7 = (this.densities[((i1 + 1) * l + j1 + 0) * k + k1 + 1] - d3) * d0;
|
| 71 | double d8 = (this.densities[((i1 + 1) * l + j1 + 1) * k + k1 + 1] - d4) * d0;
|
| 72 |
|
| 73 | for (int l1 = 0; l1 < 4; ++l1)
|
| 74 | {
|
| 75 | double d9 = 0.125D;
|
| 76 | double d10 = d1;
|
| 77 | double d11 = d2;
|
| 78 | double d12 = (d3 - d1) * d9;
|
| 79 | double d13 = (d4 - d2) * d9;
|
| 80 |
|
| 81 | for (int i2 = 0; i2 < 8; ++i2)
|
| 82 | {
|
| 83 | double d14 = 0.125D;
|
| 84 | double d15 = d10;
|
| 85 | double d16 = (d11 - d10) * d14;
|
| 86 |
|
| 87 | for (int j2 = 0; j2 < 8; ++j2)
|
| 88 | {
|
| 89 | IBlockState iblockstate = null;
|
| 90 |
|
| 91 | if (d15 > 0.0D)
|
| 92 | {
|
| 93 | iblockstate = Blocks.end_stone.getDefaultState();
|
| 94 | }
|
| 95 |
|
| 96 | int k2 = i2 + i1 * 8;
|
| 97 | int l2 = l1 + k1 * 4;
|
| 98 | int i3 = j2 + j1 * 8;
|
| 99 | p_180520_3_.setBlockState(k2, l2, i3, iblockstate);
|
| 100 | d15 += d16;
|
| 101 | }
|
| 102 |
|
| 103 | d10 += d12;
|
| 104 | d11 += d13;
|
| 105 | }
|
| 106 |
|
| 107 | d1 += d5;
|
| 108 | d2 += d6;
|
| 109 | d3 += d7;
|
| 110 | d4 += d8;
|
| 111 | }
|
| 112 | }
|
| 113 | }
|
| 114 | }
|
| 115 | }
|
| 116 |
|
| 117 | public void func_180519_a(ChunkPrimer p_180519_1_)
|
| 118 | {
|
| 119 | for (int i = 0; i < 16; ++i)
|
| 120 | {
|
| 121 | for (int j = 0; j < 16; ++j)
|
| 122 | {
|
| 123 | int k = 1;
|
| 124 | int l = -1;
|
| 125 | IBlockState iblockstate = Blocks.end_stone.getDefaultState();
|
| 126 | IBlockState iblockstate1 = Blocks.end_stone.getDefaultState();
|
| 127 |
|
| 128 | for (int i1 = 127; i1 >= 0; --i1)
|
| 129 | {
|
| 130 | IBlockState iblockstate2 = p_180519_1_.getBlockState(i, i1, j);
|
| 131 |
|
| 132 | if (iblockstate2.getBlock().getMaterial() == Material.air)
|
| 133 | {
|
| 134 | l = -1;
|
| 135 | }
|
| 136 | else if (iblockstate2.getBlock() == Blocks.stone)
|
| 137 | {
|
| 138 | if (l == -1)
|
| 139 | {
|
| 140 | if (k <= 0)
|
| 141 | {
|
| 142 | iblockstate = Blocks.air.getDefaultState();
|
| 143 | iblockstate1 = Blocks.end_stone.getDefaultState();
|
| 144 | }
|
| 145 |
|
| 146 | l = k;
|
| 147 |
|
| 148 | if (i1 >= 0)
|
| 149 | {
|
| 150 | p_180519_1_.setBlockState(i, i1, j, iblockstate);
|
| 151 | }
|
| 152 | else
|
| 153 | {
|
| 154 | p_180519_1_.setBlockState(i, i1, j, iblockstate1);
|
| 155 | }
|
| 156 | }
|
| 157 | else if (l > 0)
|
| 158 | {
|
| 159 | --l;
|
| 160 | p_180519_1_.setBlockState(i, i1, j, iblockstate1);
|
| 161 | }
|
| 162 | }
|
| 163 | }
|
| 164 | }
|
| 165 | }
|
| 166 | }
|
| 167 |
|
| 168 | /**
|
| 169 | * Will return back a chunk, if it doesn't exist and its not a MP client it will generates all the blocks for the
|
| 170 | * specified chunk from the map seed and chunk seed
|
| 171 | */
|
| 172 | public Chunk provideChunk(int x, int z)
|
| 173 | {
|
| 174 | this.endRNG.setSeed((long)x * 341873128712L + (long)z * 132897987541L);
|
| 175 | ChunkPrimer chunkprimer = new ChunkPrimer();
|
| 176 | this.biomesForGeneration = this.endWorld.getWorldChunkManager().loadBlockGeneratorData(this.biomesForGeneration, x * 16, z * 16, 16, 16);
|
| 177 | this.func_180520_a(x, z, chunkprimer);
|
| 178 | this.func_180519_a(chunkprimer);
|
| 179 | Chunk chunk = new Chunk(this.endWorld, chunkprimer, x, z);
|
| 180 | byte[] abyte = chunk.getBiomeArray();
|
| 181 |
|
| 182 | for (int i = 0; i < abyte.length; ++i)
|
| 183 | {
|
| 184 | abyte[i] = (byte)this.biomesForGeneration[i].biomeID;
|
| 185 | }
|
| 186 |
|
| 187 | chunk.generateSkylightMap();
|
| 188 | return chunk;
|
| 189 | }
|
| 190 |
|
| 191 | /**
|
| 192 | * generates a subset of the level's terrain data. Takes 7 arguments: the [empty] noise array, the position, and the
|
| 193 | * size.
|
| 194 | */
|
| 195 | private double[] initializeNoiseField(double[] p_73187_1_, int p_73187_2_, int p_73187_3_, int p_73187_4_, int p_73187_5_, int p_73187_6_, int p_73187_7_)
|
| 196 | {
|
| 197 | if (p_73187_1_ == null)
|
| 198 | {
|
| 199 | p_73187_1_ = new double[p_73187_5_ * p_73187_6_ * p_73187_7_];
|
| 200 | }
|
| 201 |
|
| 202 | double d0 = 684.412D;
|
| 203 | double d1 = 684.412D;
|
| 204 | this.noiseData4 = this.noiseGen4.generateNoiseOctaves(this.noiseData4, p_73187_2_, p_73187_4_, p_73187_5_, p_73187_7_, 1.121D, 1.121D, 0.5D);
|
| 205 | this.noiseData5 = this.noiseGen5.generateNoiseOctaves(this.noiseData5, p_73187_2_, p_73187_4_, p_73187_5_, p_73187_7_, 200.0D, 200.0D, 0.5D);
|
| 206 | d0 = d0 * 2.0D;
|
| 207 | this.noiseData1 = this.noiseGen3.generateNoiseOctaves(this.noiseData1, p_73187_2_, p_73187_3_, p_73187_4_, p_73187_5_, p_73187_6_, p_73187_7_, d0 / 80.0D, d1 / 160.0D, d0 / 80.0D);
|
| 208 | this.noiseData2 = this.noiseGen1.generateNoiseOctaves(this.noiseData2, p_73187_2_, p_73187_3_, p_73187_4_, p_73187_5_, p_73187_6_, p_73187_7_, d0, d1, d0);
|
| 209 | this.noiseData3 = this.noiseGen2.generateNoiseOctaves(this.noiseData3, p_73187_2_, p_73187_3_, p_73187_4_, p_73187_5_, p_73187_6_, p_73187_7_, d0, d1, d0);
|
| 210 | int i = 0;
|
| 211 |
|
| 212 | for (int j = 0; j < p_73187_5_; ++j)
|
| 213 | {
|
| 214 | for (int k = 0; k < p_73187_7_; ++k)
|
| 215 | {
|
| 216 | float f = (float)(j + p_73187_2_) / 1.0F;
|
| 217 | float f1 = (float)(k + p_73187_4_) / 1.0F;
|
| 218 | float f2 = 100.0F - MathHelper.sqrt_float(f * f + f1 * f1) * 8.0F;
|
| 219 |
|
| 220 | if (f2 > 80.0F)
|
| 221 | {
|
| 222 | f2 = 80.0F;
|
| 223 | }
|
| 224 |
|
| 225 | if (f2 < -100.0F)
|
| 226 | {
|
| 227 | f2 = -100.0F;
|
| 228 | }
|
| 229 |
|
| 230 | for (int l = 0; l < p_73187_6_; ++l)
|
| 231 | {
|
| 232 | double d2 = 0.0D;
|
| 233 | double d3 = this.noiseData2[i] / 512.0D;
|
| 234 | double d4 = this.noiseData3[i] / 512.0D;
|
| 235 | double d5 = (this.noiseData1[i] / 10.0D + 1.0D) / 2.0D;
|
| 236 |
|
| 237 | if (d5 < 0.0D)
|
| 238 | {
|
| 239 | d2 = d3;
|
| 240 | }
|
| 241 | else if (d5 > 1.0D)
|
| 242 | {
|
| 243 | d2 = d4;
|
| 244 | }
|
| 245 | else
|
| 246 | {
|
| 247 | d2 = d3 + (d4 - d3) * d5;
|
| 248 | }
|
| 249 |
|
| 250 | d2 = d2 - 8.0D;
|
| 251 | d2 = d2 + (double)f2;
|
| 252 | int i1 = 2;
|
| 253 |
|
| 254 | if (l > p_73187_6_ / 2 - i1)
|
| 255 | {
|
| 256 | double d6 = (double)((float)(l - (p_73187_6_ / 2 - i1)) / 64.0F);
|
| 257 | d6 = MathHelper.clamp_double(d6, 0.0D, 1.0D);
|
| 258 | d2 = d2 * (1.0D - d6) + -3000.0D * d6;
|
| 259 | }
|
| 260 |
|
| 261 | i1 = 8;
|
| 262 |
|
| 263 | if (l < i1)
|
| 264 | {
|
| 265 | double d7 = (double)((float)(i1 - l) / ((float)i1 - 1.0F));
|
| 266 | d2 = d2 * (1.0D - d7) + -30.0D * d7;
|
| 267 | }
|
| 268 |
|
| 269 | p_73187_1_[i] = d2;
|
| 270 | ++i;
|
| 271 | }
|
| 272 | }
|
| 273 | }
|
| 274 |
|
| 275 | return p_73187_1_;
|
| 276 | }
|
| 277 |
|
| 278 | /**
|
| 279 | * Checks to see if a chunk exists at x, z
|
| 280 | */
|
| 281 | public boolean chunkExists(int x, int z)
|
| 282 | {
|
| 283 | return true;
|
| 284 | }
|
| 285 |
|
| 286 | /**
|
| 287 | * Populates chunk with ores etc etc
|
| 288 | */
|
| 289 | public void populate(IChunkProvider chunkProvider, int x, int z)
|
| 290 | {
|
| 291 | BlockFalling.fallInstantly = true;
|
| 292 | BlockPos blockpos = new BlockPos(x * 16, 0, z * 16);
|
| 293 | this.endWorld.getBiomeGenForCoords(blockpos.add(16, 0, 16)).decorate(this.endWorld, this.endWorld.rand, blockpos);
|
| 294 | BlockFalling.fallInstantly = false;
|
| 295 | }
|
| 296 |
|
| 297 | public boolean populateChunk(IChunkProvider chunkProvider, Chunk chunkIn, int x, int z)
|
| 298 | {
|
| 299 | return false;
|
| 300 | }
|
| 301 |
|
| 302 | /**
|
| 303 | * Two modes of operation: if passed true, save all Chunks in one go. If passed false, save up to two chunks.
|
| 304 | * Return true if all chunks have been saved.
|
| 305 | */
|
| 306 | public boolean saveChunks(boolean saveAllChunks, IProgressUpdate progressCallback)
|
| 307 | {
|
| 308 | return true;
|
| 309 | }
|
| 310 |
|
| 311 | /**
|
| 312 | * Save extra data not associated with any Chunk. Not saved during autosave, only during world unload. Currently
|
| 313 | * unimplemented.
|
| 314 | */
|
| 315 | public void saveExtraData()
|
| 316 | {
|
| 317 | }
|
| 318 |
|
| 319 | /**
|
| 320 | * Unloads chunks that are marked to be unloaded. This is not guaranteed to unload every such chunk.
|
| 321 | */
|
| 322 | public boolean unloadQueuedChunks()
|
| 323 | {
|
| 324 | return false;
|
| 325 | }
|
| 326 |
|
| 327 | /**
|
| 328 | * Returns if the IChunkProvider supports saving.
|
| 329 | */
|
| 330 | public boolean canSave()
|
| 331 | {
|
| 332 | return true;
|
| 333 | }
|
| 334 |
|
| 335 | /**
|
| 336 | * Converts the instance data to a readable string.
|
| 337 | */
|
| 338 | public String makeString()
|
| 339 | {
|
| 340 | return "RandomLevelSource";
|
| 341 | }
|
| 342 |
|
| 343 | public List<BiomeGenBase.SpawnListEntry> getPossibleCreatures(EnumCreatureType creatureType, BlockPos pos)
|
| 344 | {
|
| 345 | return this.endWorld.getBiomeGenForCoords(pos).getSpawnableList(creatureType);
|
| 346 | }
|
| 347 |
|
| 348 | public BlockPos getStrongholdGen(World worldIn, String structureName, BlockPos position)
|
| 349 | {
|
| 350 | return null;
|
| 351 | }
|
| 352 |
|
| 353 | public int getLoadedChunkCount()
|
| 354 | {
|
| 355 | return 0;
|
| 356 | }
|
| 357 |
|
| 358 | public void recreateStructures(Chunk chunkIn, int x, int z)
|
| 359 | {
|
| 360 | }
|
| 361 |
|
| 362 | public Chunk provideChunk(BlockPos blockPosIn)
|
| 363 | {
|
| 364 | return this.provideChunk(blockPosIn.getX() >> 4, blockPosIn.getZ() >> 4);
|
| 365 | }
|
| 366 | }
|
| 367 |
|