Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import net.minecraft.block.BlockFalling;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.entity.EnumCreatureType;
- import net.minecraft.init.Blocks;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.util.math.MathHelper;
- import net.minecraft.world.World;
- import net.minecraft.world.WorldEntitySpawner;
- import net.minecraft.world.biome.Biome;
- import net.minecraft.world.chunk.Chunk;
- import net.minecraft.world.chunk.ChunkPrimer;
- import net.minecraft.world.gen.IChunkGenerator;
- import net.minecraft.world.gen.MapGenBase;
- import net.minecraft.world.gen.NoiseGeneratorOctaves;
- import net.minecraft.world.gen.NoiseGeneratorPerlin;
- import net.minecraft.world.gen.feature.WorldGenLakes;
- import net.minecraftforge.event.ForgeEventFactory;
- import net.minecraftforge.event.terraingen.PopulateChunkEvent;
- import javax.annotation.Nonnull;
- import javax.annotation.Nullable;
- import javax.annotation.ParametersAreNonnullByDefault;
- import java.util.List;
- import java.util.Random;
- public class ChunkGeneratorDarkness implements IChunkGenerator {
- public static final IBlockState ROCK = Blocks.STONE.getDefaultState();
- public static final IBlockState OCEAN_BLOCK = Blocks.WATER.getDefaultState();
- private final Random rand;
- private NoiseGeneratorOctaves minLimitPerlinNoise;
- private NoiseGeneratorOctaves maxLimitPerlinNoise;
- private NoiseGeneratorOctaves mainPerlinNoise;
- private NoiseGeneratorPerlin surfaceNoise;
- public NoiseGeneratorOctaves scaleNoise;
- public NoiseGeneratorOctaves depthNoise;
- public NoiseGeneratorOctaves forestNoise;
- private final World world;
- private final double[] heightMap;
- private final float[] biomeWeights;
- private double[] depthBuffer = new double[256];
- private Biome[] biomesForGeneration;
- double[] mainNoiseRegion;
- double[] minLimitRegion;
- double[] maxLimitRegion;
- double[] depthRegion;
- public ChunkGeneratorDarkness(World world){
- this.world = world;
- this.rand = new Random(world.getSeed());
- this.minLimitPerlinNoise = new NoiseGeneratorOctaves(this.rand,16);
- this.maxLimitPerlinNoise = new NoiseGeneratorOctaves(this.rand,16);
- this.surfaceNoise = new NoiseGeneratorPerlin(this.rand, 4);
- this.scaleNoise = new NoiseGeneratorOctaves(this.rand, 10);
- this.depthNoise = new NoiseGeneratorOctaves(this.rand, 16);
- this.forestNoise = new NoiseGeneratorOctaves(this.rand, 8);
- this.heightMap = new double[825];
- this.biomeWeights = new float[25];
- for (int i = -2; i <= 2; ++i) {
- for (int j = -2; j <= 2; ++j) {
- float f = 10.0F / MathHelper.sqrt((float) (i * i + j * j) + 0.2F);
- this.biomeWeights[i + 2 + (j + 2) * 5] = f;
- }
- }
- net.minecraftforge.event.terraingen.InitNoiseGensEvent.ContextOverworld ctx = new net.minecraftforge.event.terraingen.InitNoiseGensEvent.ContextOverworld(minLimitPerlinNoise, maxLimitPerlinNoise, mainPerlinNoise, surfaceNoise, scaleNoise, depthNoise, forestNoise);
- ctx = net.minecraftforge.event.terraingen.TerrainGen.getModdedNoiseGenerators(world, this.rand, ctx);
- this.minLimitPerlinNoise = ctx.getLPerlin1();
- this.maxLimitPerlinNoise = ctx.getLPerlin2();
- this.mainPerlinNoise = ctx.getPerlin();
- this.surfaceNoise = ctx.getHeight();
- this.scaleNoise = ctx.getScale();
- this.depthNoise = ctx.getDepth();
- this.forestNoise = ctx.getForest();
- }
- public void setBlocksInChunk(int x, int z, ChunkPrimer primer) {
- this.biomesForGeneration = this.world.getBiomeProvider().getBiomesForGeneration(this.biomesForGeneration, x * 4 - 2, z * 4 - 2, 10, 10);
- this.generateHeightmap(x * 4, z * 4);
- for (int i = 0; i < 4; ++i) {
- int j = i * 5;
- int k = (i + 1) * 5;
- for (int l = 0; l < 4; ++l) {
- int i1 = (j + l) * 33;
- int j1 = (j + l + 1) * 33;
- int k1 = (k + l) * 33;
- int l1 = (k + l + 1) * 33;
- for (int i2 = 0; i2 < 32; ++i2) {
- //double d0 = 0.125D;
- double d1 = this.heightMap[i1 + i2];
- double d2 = this.heightMap[j1 + i2];
- double d3 = this.heightMap[k1 + i2];
- double d4 = this.heightMap[l1 + i2];
- double d5 = (this.heightMap[i1 + i2 + 1] - d1) * 0.125D;
- double d6 = (this.heightMap[j1 + i2 + 1] - d2) * 0.125D;
- double d7 = (this.heightMap[k1 + i2 + 1] - d3) * 0.125D;
- double d8 = (this.heightMap[l1 + i2 + 1] - d4) * 0.125D;
- for (int j2 = 0; j2 < 8; ++j2) {
- //double d9 = 0.25D;
- double d10 = d1;
- double d11 = d2;
- double d12 = (d3 - d1) * 0.25D;
- double d13 = (d4 - d2) * 0.25D;
- for (int k2 = 0; k2 < 4; ++k2) {
- //double d14 = 0.25D;
- double d16 = (d11 - d10) * 0.25D;
- double lvt_45_1_ = d10 - d16;
- for (int l2 = 0; l2 < 4; ++l2) {
- if ((lvt_45_1_ += d16) > 0.0D) {
- primer.setBlockState(i * 4 + k2, i2 * 8 + j2, l * 4 + l2, ROCK);
- } else if (i2 * 8 + j2 < world.getSeaLevel()) {
- primer.setBlockState(i * 4 + k2, i2 * 8 + j2, l * 4 + l2, OCEAN_BLOCK);
- }
- }
- d10 += d12;
- d11 += d13;
- }
- d1 += d5;
- d2 += d6;
- d3 += d7;
- d4 += d8;
- }
- }
- }
- }
- }
- public void replaceBiomeBlocks(int x, int z, ChunkPrimer primer, Biome[] biomesIn) {
- if (!net.minecraftforge.event.ForgeEventFactory.onReplaceBiomeBlocks(this, x, z, primer, this.world)) return;
- //double d0 = 0.03125D;
- this.depthBuffer = this.surfaceNoise.getRegion(this.depthBuffer, (double) (x * 16), (double) (z * 16), 16, 16, 0.0625D, 0.0625D, 1.0D);
- for (int i = 0; i < 16; ++i) {
- for (int j = 0; j < 16; ++j) {
- Biome biome = biomesIn[j + i * 16];
- biome.genTerrainBlocks(this.world, this.rand, primer, x * 16 + i, z * 16 + j, this.depthBuffer[j + i * 16]);
- }
- }
- }
- @Nonnull
- @Override
- public Chunk generateChunk(int x, int z) {
- this.rand.setSeed((long) x * 341873128712L + (long) z * 132897987541L);
- ChunkPrimer chunkprimer = new ChunkPrimer();
- this.setBlocksInChunk(x, z, chunkprimer);
- this.biomesForGeneration = this.world.getBiomeProvider().getBiomes(this.biomesForGeneration, x * 16, z * 16, 16, 16);
- this.replaceBiomeBlocks(x, z, chunkprimer, this.biomesForGeneration);
- Chunk chunk = new Chunk(this.world, chunkprimer, x, z);
- byte[] abyte = chunk.getBiomeArray();
- for (int i = 0; i < abyte.length; ++i) {
- abyte[i] = (byte) Biome.getIdForBiome(this.biomesForGeneration[i]);
- }
- chunk.generateSkylightMap();
- return chunk;
- }
- private void generateHeightmap(int x, int z) {
- this.depthRegion = this.depthNoise.generateNoiseOctaves(this.depthRegion, x, z, 5, 5, 200D, 200D, 0.5D);
- float f = 684.412F;
- float f1 = 684.412F;
- this.mainNoiseRegion = this.mainPerlinNoise.generateNoiseOctaves(this.mainNoiseRegion, x, 0, z, 5, 33, 5, f / 80D, f1 / 160D, f / 80D);
- this.minLimitRegion = this.minLimitPerlinNoise.generateNoiseOctaves(this.minLimitRegion, x, 0, z, 5, 33, 5, (double) f, (double) f1, (double) f);
- this.maxLimitRegion = this.maxLimitPerlinNoise.generateNoiseOctaves(this.maxLimitRegion, x, 0, z, 5, 33, 5, (double) f, (double) f1, (double) f);
- int i = 0;
- int j = 0;
- for (int k = 0; k < 5; ++k) {
- for (int l = 0; l < 5; ++l) {
- float f2 = 0.0F;
- float f3 = 0.0F;
- float f4 = 0.0F;
- //int i1 = 2;
- Biome biome = this.biomesForGeneration[k + 2 + (l + 2) * 10];
- for (int j1 = -2; j1 <= 2; ++j1) {
- for (int k1 = -2; k1 <= 2; ++k1) {
- Biome biome1 = this.biomesForGeneration[k + j1 + 2 + (l + k1 + 2) * 10];
- float f5 = biome1.getBaseHeight();
- float f6 = biome1.getHeightVariation();
- float f7 = this.biomeWeights[j1 + 2 + (k1 + 2) * 5] / (f5 + 2.0F);
- if (biome1.getBaseHeight() > biome.getBaseHeight()) {
- f7 /= 2.0F;
- }
- f2 += f6 * f7;
- f3 += f5 * f7;
- f4 += f7;
- }
- }
- f2 = f2 / f4;
- f3 = f3 / f4;
- f2 = f2 * 0.9F + 0.1F;
- f3 = (f3 * 4.0F - 1.0F) / 8.0F;
- double d7 = this.depthRegion[j] / 8000.0D;
- if (d7 < 0.0D) {
- d7 = -d7 * 0.3D;
- }
- d7 = d7 * 3.0D - 2.0D;
- if (d7 < 0.0D) {
- d7 = d7 / 2.0D;
- if (d7 < -1.0D) {
- d7 = -1.0D;
- }
- d7 = d7 / 1.4D;
- d7 = d7 / 2.0D;
- } else {
- if (d7 > 1.0D) {
- d7 = 1.0D;
- }
- d7 = d7 / 8.0D;
- }
- ++j;
- double d8 = (double) f3;
- double d9 = (double) f2;
- d8 = d8 + d7 * 0.2D;
- d8 = d8 * 8.5D / 8.0D;
- double d0 = 8.5D + d8 * 4.0D;
- for (int l1 = 0; l1 < 33; ++l1) {
- double d1 = ((double) l1 - d0) * 12D * 128.0D / 256.0D / d9;
- if (d1 < 0.0D) {
- d1 *= 4.0D;
- }
- double d2 = this.minLimitRegion[i] / 512D;
- double d3 = this.maxLimitRegion[i] / 512D;
- double d4 = (this.mainNoiseRegion[i] / 10.0D + 1.0D) / 2.0D;
- double d5 = MathHelper.clampedLerp(d2, d3, d4) - d1;
- if (l1 > 29) {
- double d6 = (double) ((float) (l1 - 29) / 3.0F);
- d5 = d5 * (1.0D - d6) + -10.0D * d6;
- }
- this.heightMap[i] = d5;
- ++i;
- }
- }
- }
- }
- @Override
- public void populate(int x, int z) {
- BlockFalling.fallInstantly = true;
- int i = x * 16;
- int j = z * 16;
- BlockPos blockpos = new BlockPos(i, 0, j);
- Biome biome = this.world.getBiome(blockpos.add(16, 0, 16));
- this.rand.setSeed(this.world.getSeed());
- long k = this.rand.nextLong() / 2L * 2L + 1L;
- long l = this.rand.nextLong() / 2L * 2L + 1L;
- this.rand.setSeed((long) x * k + (long) z * l ^ this.world.getSeed());
- ForgeEventFactory.onChunkPopulate(true, this, this.world, this.rand, x, z, false);
- if (net.minecraftforge.event.terraingen.TerrainGen.populate(this, this.world, this.rand, x, z, false, PopulateChunkEvent.Populate.EventType.CUSTOM))
- if (this.rand.nextInt(25) == 0) {
- int x0 = this.rand.nextInt(16) + 8;
- int y0 = this.rand.nextInt(256);
- int z0 = this.rand.nextInt(16) + 8;
- (new WorldGenLakes(OCEAN_BLOCK.getBlock())).generate(this.world, this.rand, blockpos.add(x0, y0, z0));
- }
- if (net.minecraftforge.event.terraingen.TerrainGen.populate(this, this.world, this.rand, x, z, false, PopulateChunkEvent.Populate.EventType.CUSTOM))
- if (this.rand.nextInt(8) == 0) {
- int x0 = this.rand.nextInt(16) + 8;
- int y0 = this.rand.nextInt(this.rand.nextInt(248) + 8);
- int z0 = this.rand.nextInt(16) + 8;
- if (y0 < this.world.getSeaLevel()) {
- (new WorldGenLakes(Blocks.WATER)).generate(this.world, this.rand, blockpos.add(x0, y0, z0));
- }
- }
- biome.decorate(this.world, this.rand, new BlockPos(i, 0, j));
- WorldEntitySpawner.performWorldGenSpawning(this.world, biome, i + 8, j + 8, 16, 16, this.rand);
- ForgeEventFactory.onChunkPopulate(false, this, this.world, this.rand, x, z, false);
- BlockFalling.fallInstantly = false;
- }
- @Override
- @ParametersAreNonnullByDefault
- public boolean generateStructures(Chunk chunkIn, int x, int z) {
- return false;
- }
- @Nonnull
- @Override
- @ParametersAreNonnullByDefault
- public List<Biome.SpawnListEntry> getPossibleCreatures(EnumCreatureType creatureType, BlockPos pos) {
- return this.world.getBiome(pos).getSpawnableList(creatureType);
- }
- @Override
- @ParametersAreNonnullByDefault
- public boolean isInsideStructure(World worldIn, String structureName, BlockPos pos) {
- return false;
- }
- @Override
- @Nullable
- @ParametersAreNonnullByDefault
- public BlockPos getNearestStructurePos(World worldIn, String structureName, BlockPos position, boolean findUnexplored) {
- return null;
- }
- /**
- * Recreates data about structures intersecting given chunk (used for example by getPossibleCreatures), without
- * placing any blocks. When called for the first time before any chunk is generated - also initializes the internal
- * state needed by getPossibleCreatures.
- */
- @Override
- @ParametersAreNonnullByDefault
- public void recreateStructures(Chunk chunkIn, int x, int z) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment