Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.halestormxv.worldALT;
- import static net.minecraftforge.event.terraingen.InitMapGenEvent.EventType.CAVE;
- import static net.minecraftforge.event.terraingen.InitMapGenEvent.EventType.RAVINE;
- import static net.minecraftforge.event.terraingen.InitMapGenEvent.EventType.SCATTERED_FEATURE;
- import static net.minecraftforge.event.terraingen.PopulateChunkEvent.Populate.EventType.ANIMALS;
- import static net.minecraftforge.event.terraingen.PopulateChunkEvent.Populate.EventType.DUNGEON;
- import static net.minecraftforge.event.terraingen.PopulateChunkEvent.Populate.EventType.ICE;
- import static net.minecraftforge.event.terraingen.PopulateChunkEvent.Populate.EventType.LAKE;
- import static net.minecraftforge.event.terraingen.PopulateChunkEvent.Populate.EventType.LAVA;
- import java.util.List;
- import java.util.Random;
- import java.util.logging.Level;
- import com.halestormxv.blocks.CelestialCraft_blocks;
- import com.halestormxv.utilities.GameLogHelper;
- import com.halestormxv.worldALT.biomes.ModBiomes;
- import net.minecraft.block.Block;
- import net.minecraft.block.BlockFalling;
- import net.minecraft.entity.EnumCreatureType;
- import net.minecraft.init.Blocks;
- import net.minecraft.util.IProgressUpdate;
- import net.minecraft.util.MathHelper;
- import net.minecraft.world.ChunkPosition;
- import net.minecraft.world.SpawnerAnimals;
- import net.minecraft.world.World;
- import net.minecraft.world.WorldType;
- import net.minecraft.world.biome.BiomeGenBase;
- import net.minecraft.world.chunk.Chunk;
- import net.minecraft.world.chunk.IChunkProvider;
- import net.minecraft.world.gen.MapGenBase;
- import net.minecraft.world.gen.MapGenCaves;
- import net.minecraft.world.gen.MapGenRavine;
- import net.minecraft.world.gen.NoiseGenerator;
- import net.minecraft.world.gen.NoiseGeneratorOctaves;
- import net.minecraft.world.gen.NoiseGeneratorPerlin;
- import net.minecraft.world.gen.feature.WorldGenDungeons;
- import net.minecraft.world.gen.feature.WorldGenLakes;
- import net.minecraft.world.gen.structure.MapGenScatteredFeature;
- import net.minecraftforge.common.MinecraftForge;
- import net.minecraftforge.event.terraingen.ChunkProviderEvent;
- import net.minecraftforge.event.terraingen.PopulateChunkEvent;
- import net.minecraftforge.event.terraingen.TerrainGen;
- import cpw.mods.fml.common.eventhandler.Event.Result;
- public class ChunkProviderForest implements IChunkProvider {
- /** RNG. */
- private Random rand;
- /** A NoiseGeneratorOctaves used in generating terrain */
- private NoiseGeneratorOctaves noiseGen1;
- private NoiseGeneratorOctaves noiseGen2;
- private NoiseGeneratorOctaves noiseGen3;
- private NoiseGeneratorPerlin noisePerl;
- /** A NoiseGeneratorOctaves used in generating terrain */
- public NoiseGeneratorOctaves noiseGen5;
- /** A NoiseGeneratorOctaves used in generating terrain */
- public NoiseGeneratorOctaves noiseGen6;
- public NoiseGeneratorOctaves mobSpawnerNoise;
- /** Reference to the World object. */
- private World worldObj;
- /** are map structures going to be generated (e.g. strongholds) */
- private final boolean mapFeaturesEnabled;
- private WorldType worldType;
- private final double[] noiseArray;
- private final float[] parabolicField;
- private double[] stoneNoise = new double[256];
- private MapGenBase caveGenerator = new MapGenCaves();
- private MapGenScatteredFeature scatteredFeatureGenerator = new MapGenScatteredFeature();
- /** Holds ravine generator */
- private MapGenBase ravineGenerator = new MapGenRavine();
- /** The biomes that are used to generate the chunk */
- private BiomeGenBase[] biomesForGeneration;
- /** A double array that hold terrain noise */
- double[] noise3;
- double[] noise1;
- double[] noise2;
- double[] noise5;
- int[][] field_73219_j = new int[32][32];
- {
- caveGenerator = TerrainGen.getModdedMapGen(caveGenerator, CAVE);
- scatteredFeatureGenerator = (MapGenScatteredFeature) TerrainGen.getModdedMapGen(scatteredFeatureGenerator, SCATTERED_FEATURE);
- ravineGenerator = TerrainGen.getModdedMapGen(ravineGenerator, RAVINE);
- }
- public ChunkProviderForest(World world, long seed, boolean mapFeaturesEnabled)
- {
- GameLogHelper.writeToLog(Level.INFO, "Loading Chunk Provider for dmension.");
- this.worldObj = world;
- this.mapFeaturesEnabled = mapFeaturesEnabled;
- this.worldType = world.getWorldInfo().getTerrainType();
- this.rand = new Random(seed);
- this.noiseGen1 = new NoiseGeneratorOctaves(this.rand, 16);
- this.noiseGen2 = new NoiseGeneratorOctaves(this.rand, 16);
- this.noiseGen3 = new NoiseGeneratorOctaves(this.rand, 8);
- this.noisePerl = new NoiseGeneratorPerlin(this.rand, 4);
- this.noiseGen5 = new NoiseGeneratorOctaves(this.rand, 10);
- this.noiseGen6 = new NoiseGeneratorOctaves(this.rand, 16);
- this.mobSpawnerNoise = new NoiseGeneratorOctaves(this.rand, 8);
- this.noiseArray = new double[825];
- this.parabolicField = new float[25];
- for (int j = -2; j <= 2; ++j) {
- for (int k = -2; k <= 2; ++k) {
- float f = 10.0F / MathHelper.sqrt_float((float)(j * j + k * k) + 0.2F);
- this.parabolicField[j + 2 + (k + 2) * 5] = f;
- }
- }
- NoiseGenerator[] noiseGens = {noiseGen1, noiseGen2, noiseGen3, noisePerl, noiseGen5, noiseGen6, mobSpawnerNoise};
- noiseGens = TerrainGen.getModdedNoiseGenerators(world, this.rand, noiseGens);
- this.noiseGen1 = (NoiseGeneratorOctaves)noiseGens[0];
- this.noiseGen2 = (NoiseGeneratorOctaves)noiseGens[1];
- this.noiseGen3 = (NoiseGeneratorOctaves)noiseGens[2];
- this.noisePerl = (NoiseGeneratorPerlin)noiseGens[3];
- this.noiseGen5 = (NoiseGeneratorOctaves)noiseGens[4];
- this.noiseGen6 = (NoiseGeneratorOctaves)noiseGens[5];
- this.mobSpawnerNoise = (NoiseGeneratorOctaves)noiseGens[6];
- }
- /**
- * Generates the shape of the terrain for the chunk though its all stone
- * though the water is frozen if the temperature is low enough
- */
- // TODO: generateTerrain?
- public void func_147424_a(int par1, int par2, Block[] blocks) {
- //DONT EDIT THS METHOD UNLES YOU KNOW WHAT UR DOING OR MAKE A COPY INCASE U MESS IT UP....
- //YOU HAVE BE WARNED !!!!!
- byte b0 = 63;
- this.biomesForGeneration = this.worldObj.getWorldChunkManager().getBiomesForGeneration(this.biomesForGeneration, par1 * 4 - 2, par2 * 4 - 2, 10, 10);
- this.func_147423_a(par1 * 4, 0, par2 * 4);
- for (int k = 0; k < 4; ++k) {
- int l = k * 5;
- int i1 = (k + 1) * 5;
- for (int j1 = 0; j1 < 4; ++j1) {
- int k1 = (l + j1) * 33;
- int l1 = (l + j1 + 1) * 33;
- int i2 = (i1 + j1) * 33;
- int j2 = (i1 + j1 + 1) * 33;
- for (int k2 = 0; k2 < 32; ++k2) {
- double d0 = 0.125D;
- double d1 = this.noiseArray[k1 + k2];
- double d2 = this.noiseArray[l1 + k2];
- double d3 = this.noiseArray[i2 + k2];
- double d4 = this.noiseArray[j2 + k2];
- double d5 = (this.noiseArray[k1 + k2 + 1] - d1) * d0;
- double d6 = (this.noiseArray[l1 + k2 + 1] - d2) * d0;
- double d7 = (this.noiseArray[i2 + k2 + 1] - d3) * d0;
- double d8 = (this.noiseArray[j2 + k2 + 1] - d4) * d0;
- for (int l2 = 0; l2 < 8; ++l2) {
- double d9 = 0.25D;
- double d10 = d1;
- double d11 = d2;
- double d12 = (d3 - d1) * d9;
- double d13 = (d4 - d2) * d9;
- for (int i3 = 0; i3 < 4; ++i3) {
- int j3 = i3 + k * 4 << 12 | 0 + j1 * 4 << 8 | k2 * 8 + l2;
- short short1 = 256;
- j3 -= short1;
- double d14 = 0.25D;
- double d16 = (d11 - d10) * d14;
- double d15 = d10 - d16;
- for (int k3 = 0; k3 < 4; ++k3) {
- if ((d15 += d16) > 0.0D) {
- blocks[j3 += short1] = CelestialCraft_blocks.CelFillStone;//these can be set to custom blocks
- } else if (k2 * 8 + l2 < b0) {
- blocks[j3 += short1] = Blocks.water;//these can be set to custom blocks
- } else {
- blocks[j3 += short1] = null;//this is the air block i think.
- }
- }
- d10 += d12;
- d11 += d13;
- }
- d1 += d5;
- d2 += d6;
- d3 += d7;
- d4 += d8;
- }
- }
- }
- }
- }
- public void replaceBlocksForBiome(int par1, int par2, Block[] blocks, byte[] par3ArrayOfByte, BiomeGenBase[] par4ArrayOfBiomeGenBase) {
- GameLogHelper.writeToLog(Level.INFO, "Replacing block for biome.");
- @SuppressWarnings("deprecation")
- ChunkProviderEvent.ReplaceBiomeBlocks event = new ChunkProviderEvent.ReplaceBiomeBlocks(this, par1, par2, blocks, par3ArrayOfByte, par4ArrayOfBiomeGenBase);
- MinecraftForge.EVENT_BUS.post(event);
- if (event.getResult() == Result.DENY) return;
- double d0 = 0.03125D;
- this.stoneNoise = this.noisePerl.func_151599_a(this.stoneNoise, (double)(par1 * 16), (double)(par2 * 16), 16, 16, d0 * 2.0D, d0 * 2.0D, 1.0D);
- for (int k = 0; k < 16; ++k) {
- for (int l = 0; l < 16; ++l) {
- ModBiomes biomegenbase = (ModBiomes) par4ArrayOfBiomeGenBase[l + k * 16];
- biomegenbase.genTerrainBlocks(this.worldObj, this.rand, blocks, par3ArrayOfByte, par1 * 16 + k, par2 * 16 + l, this.stoneNoise[l + k * 16]);
- }
- }
- }
- /**
- * loads or generates the chunk at the chunk location specified
- */
- @Override
- public Chunk loadChunk(int par1, int par2) {
- return this.provideChunk(par1, par2);
- }
- /**
- * Will return back a chunk, if it doesn't exist and its not a MP client it will generates all the blocks for the
- * specified chunk from the map seed and chunk seed
- */
- @Override
- public Chunk provideChunk(int par1, int par2) {
- this.rand.setSeed((long)par1 * 341873128712L + (long)par2 * 132897987541L);
- Block[] ablock = new Block[65536];
- byte[] abyte = new byte[65536];
- this.func_147424_a(par1, par2, ablock);
- this.biomesForGeneration = this.worldObj.getWorldChunkManager().loadBlockGeneratorData(this.biomesForGeneration, par1 * 16, par2 * 16, 16, 16);
- this.replaceBlocksForBiome(par1, par2, ablock, abyte, this.biomesForGeneration);
- this.caveGenerator.func_151539_a(this, this.worldObj, par1, par2, ablock);
- this.ravineGenerator.func_151539_a(this, this.worldObj, par1, par2, ablock);
- if (this.mapFeaturesEnabled) {
- this.scatteredFeatureGenerator.func_151539_a(this, this.worldObj, par1, par2, ablock);
- }
- Chunk chunk = new Chunk(this.worldObj, ablock, abyte, par1, par2);
- byte[] abyte1 = chunk.getBiomeArray();
- for (int k = 0; k < abyte1.length; ++k){
- abyte1[k] = (byte)this.biomesForGeneration[k].biomeID;
- }
- chunk.generateSkylightMap();
- return chunk;
- }
- /**
- * generates a subset of the level's terrain data. Takes 7 arguments: the
- * [empty] noise array, the position, and the size.
- */
- // TODO: initializeNoiseField?
- private void func_147423_a(int p_147423_1_, int p_147423_2_, int p_147423_3_) {
- //DONT EDIT THS METHOD UNLES YOU KNOW WHAT UR DOING OR MAKE A COPY INCASE U MESS IT UP....
- //YOU HAVE BE WARNED !!!!!
- this.noise5 = this.noiseGen6.generateNoiseOctaves(this.noise5, p_147423_1_, p_147423_3_, 5, 5, 200.0D, 200.0D, 0.5D);
- this.noise3 = this.noiseGen3.generateNoiseOctaves(this.noise3, p_147423_1_, p_147423_2_, p_147423_3_, 5, 33, 5, 8.555150000000001D, 4.277575000000001D, 8.555150000000001D);
- this.noise1 = this.noiseGen1.generateNoiseOctaves(this.noise1, p_147423_1_, p_147423_2_, p_147423_3_, 5, 33, 5, 684.412D, 684.412D, 684.412D);
- this.noise2 = this.noiseGen2.generateNoiseOctaves(this.noise2, p_147423_1_, p_147423_2_, p_147423_3_, 5, 33, 5, 684.412D, 684.412D, 684.412D);
- int l = 0;
- int i1 = 0;
- for (int j1 = 0; j1 < 5; ++j1) {
- for (int k1 = 0; k1 < 5; ++k1) {
- float f = 0.0F;
- float f1 = 0.0F;
- float f2 = 0.0F;
- byte b0 = 2;
- BiomeGenBase biomegenbase = this.biomesForGeneration[j1 + 2 + (k1 + 2) * 10];
- for (int l1 = -b0; l1 <= b0; ++l1) {
- for (int i2 = -b0; i2 <= b0; ++i2) {
- BiomeGenBase biomegenbase1 = this.biomesForGeneration[j1 + l1 + 2 + (k1 + i2 + 2) * 10];
- float f3 = biomegenbase1.rootHeight;
- float f4 = biomegenbase1.heightVariation;
- if (this.worldType == WorldType.AMPLIFIED && f3 > 0.0F) {
- f3 = 1.0F + f3 * 2.0F;
- f4 = 1.0F + f4 * 4.0F;
- }
- float f5 = this.parabolicField[l1 + 2 + (i2 + 2) * 5] / (f3 + 2.0F);
- if (biomegenbase1.rootHeight > biomegenbase.rootHeight) {
- f5 /= 2.0F;
- }
- f += f4 * f5;
- f1 += f3 * f5;
- f2 += f5;
- }
- }
- f /= f2;
- f1 /= f2;
- f = f * 0.9F + 0.1F;
- f1 = (f1 * 4.0F - 1.0F) / 8.0F;
- double d12 = this.noise5[i1] / 8000.0D;
- if (d12 < 0.0D) {
- d12 = -d12 * 0.3D;
- }
- d12 = d12 * 3.0D - 2.0D;
- if (d12 < 0.0D) {
- d12 /= 2.0D;
- if (d12 < -1.0D) {
- d12 = -1.0D;
- }
- d12 /= 1.4D;
- d12 /= 2.0D;
- } else {
- if (d12 > 1.0D) {
- d12 = 1.0D;
- }
- d12 /= 8.0D;
- }
- ++i1;
- double d13 = (double)f1;
- double d14 = (double)f;
- d13 += d12 * 0.2D;
- d13 = d13 * 8.5D / 8.0D;
- double d5 = 8.5D + d13 * 4.0D;
- for (int j2 = 0; j2 < 33; ++j2) {
- double d6 = ((double)j2 - d5) * 12.0D * 128.0D / 256.0D / d14;
- if (d6 < 0.0D) {
- d6 *= 4.0D;
- }
- double d7 = this.noise1[l] / 512.0D;
- double d8 = this.noise2[l] / 512.0D;
- double d9 = (this.noise3[l] / 10.0D + 1.0D) / 2.0D;
- double d10 = MathHelper.denormalizeClamp(d7, d8, d9) - d6;
- if (j2 > 29) {
- double d11 = (double)((float)(j2 - 29) / 3.0F);
- d10 = d10 * (1.0D - d11) + -10.0D * d11;
- }
- this.noiseArray[l] = d10;
- ++l;
- }
- }
- }
- }
- /**
- * Checks to see if a chunk exists at x, y
- */
- @Override
- public boolean chunkExists(int par1, int par2) {
- return true;
- }
- /**
- * Populates chunk with ores etc etc
- */
- @Override
- public void populate(IChunkProvider par1IChunkProvider, int par2, int par3) {
- BlockFalling.fallInstantly = true;
- int k = par2 * 16;
- int l = par3 * 16;
- BiomeGenBase biomegenbase = this.worldObj.getBiomeGenForCoords(k + 16, l + 16);
- this.rand.setSeed(this.worldObj.getSeed());
- long i1 = this.rand.nextLong() / 2L * 2L + 1L;
- long j1 = this.rand.nextLong() / 2L * 2L + 1L;
- this.rand.setSeed((long)par2 * i1 + (long)par3 * j1 ^ this.worldObj.getSeed());
- boolean flag = false;
- MinecraftForge.EVENT_BUS.post(new PopulateChunkEvent.Pre(par1IChunkProvider, worldObj, rand, par2, par3, flag));
- //Enable map features ??
- if (this.mapFeaturesEnabled) {
- this.scatteredFeatureGenerator.generateStructuresInChunk(this.worldObj, this.rand, par2, par3);
- }
- int k1;
- int l1;
- int i2;
- //Add Lakes ??
- if (biomegenbase != BiomeGenBase.desert && biomegenbase != BiomeGenBase.desertHills && !flag && this.rand.nextInt(4) == 0
- && TerrainGen.populate(par1IChunkProvider, worldObj, rand, par2, par3, flag, LAKE)) {
- k1 = k + this.rand.nextInt(16) + 8;
- l1 = this.rand.nextInt(256);
- i2 = l + this.rand.nextInt(16) + 8;
- (new WorldGenLakes(Blocks.water)).generate(this.worldObj, this.rand, k1, l1, i2);
- }
- //Add Lakes ??
- if (TerrainGen.populate(par1IChunkProvider, worldObj, rand, par2, par3, flag, LAVA) && !flag && this.rand.nextInt(8) == 0) {
- k1 = k + this.rand.nextInt(16) + 8;
- l1 = this.rand.nextInt(this.rand.nextInt(248) + 8);
- i2 = l + this.rand.nextInt(16) + 8;
- if (l1 < 63 || this.rand.nextInt(10) == 0) {
- (new WorldGenLakes(Blocks.lava)).generate(this.worldObj, this.rand, k1, l1, i2);
- }
- }
- //Add Dungeons ??
- boolean doGen = TerrainGen.populate(par1IChunkProvider, worldObj, rand, par2, par3, flag, DUNGEON);
- for (k1 = 0; doGen && k1 < 8; ++k1) {
- l1 = k + this.rand.nextInt(16) + 8;
- i2 = this.rand.nextInt(256);
- int j2 = l + this.rand.nextInt(16) + 8;
- (new WorldGenDungeons()).generate(this.worldObj, this.rand, l1, i2, j2);
- }
- //Add Animals ??
- biomegenbase.decorate(this.worldObj, this.rand, k, l);
- if (TerrainGen.populate(par1IChunkProvider, worldObj, rand, par2, par3, flag, ANIMALS)) {
- SpawnerAnimals.performWorldGenSpawning(this.worldObj, biomegenbase, k + 8, l + 8, 16, 16, this.rand);
- }
- k += 8;
- l += 8;
- //Creates snow and ice in world.
- doGen = TerrainGen.populate(par1IChunkProvider, worldObj, rand, par2, par3, flag, ICE);
- for (k1 = 0; doGen && k1 < 16; ++k1) {
- for (l1 = 0; l1 < 16; ++l1) {
- i2 = this.worldObj.getPrecipitationHeight(k + k1, l + l1);
- if (this.worldObj.isBlockFreezable(k1 + k, i2 - 1, l1 + l)) {
- this.worldObj.setBlock(k1 + k, i2 - 1, l1 + l, Blocks.ice, 0, 2);
- }
- if (this.worldObj.func_147478_e(k1 + k, i2, l1 + l, true)) {
- this.worldObj.setBlock(k1 + k, i2, l1 + l, Blocks.snow_layer, 0, 2);
- }
- }
- }
- MinecraftForge.EVENT_BUS.post(new PopulateChunkEvent.Post(par1IChunkProvider, worldObj, rand, par2, par3, flag));
- BlockFalling.fallInstantly = false;
- }
- /**
- * Two modes of operation: if passed true, save all Chunks in one go. If passed false, save up to two chunks.
- * Return true if all chunks have been saved.
- */
- @Override
- public boolean saveChunks(boolean par1, IProgressUpdate par2IProgressUpdate) {
- return true;
- }
- /**
- * Save extra data not associated with any Chunk. Not saved during autosave, only during world unload. Currently
- * unimplemented.
- */
- @Override
- public void saveExtraData() {}
- /**
- * Unloads chunks that are marked to be unloaded. This is not guaranteed to unload every such chunk.
- */
- @Override
- public boolean unloadQueuedChunks() {
- return false;
- }
- /**
- * Returns if the IChunkProvider supports saving.
- */
- @Override
- public boolean canSave() {
- return true;
- }
- /**
- * Converts the instance data to a readable string.
- */
- @Override
- public String makeString() {
- return "RandomLevelSource";
- }
- /**
- * Returns a list of creatures of the specified type that can spawn at the given location.
- */
- @SuppressWarnings("rawtypes")
- @Override
- public List getPossibleCreatures(EnumCreatureType par1EnumCreatureType, int par2, int par3, int par4) {
- BiomeGenBase biomegenbase = this.worldObj.getBiomeGenForCoords(par2, par4);
- return par1EnumCreatureType == EnumCreatureType.monster && this.scatteredFeatureGenerator.func_143030_a(par2, par3, par4) ? this.scatteredFeatureGenerator.getScatteredFeatureSpawnList() : biomegenbase.getSpawnableList(par1EnumCreatureType);
- }
- @Override
- public int getLoadedChunkCount() {
- return 0;
- }
- @Override
- public void recreateStructures(int par1, int par2) {
- if (this.mapFeaturesEnabled) {
- //this.scatteredFeatureGenerator.func_151539_a(this, this.worldObj, par1, par2, (Block[])null);
- }
- }
- /**
- * Returns the location of the closest structure of the specified type. If
- * not found returns null.
- */
- @Override
- // TODO: findClosestStructure
- public ChunkPosition func_147416_a(World world, String arg1, int arg2, int arg3, int arg4) {
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment