aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/bwcrossmod/galacticraft/planets/ross128ba/ChunkProviderRoss128ba.java
blob: 67b776f4736ab701e364137a89a97a6762d0a1af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
 * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in the Software without restriction,
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following
 * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial
 * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

package bwcrossmod.galacticraft.planets.ross128ba;

import java.util.Arrays;
import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.BlockFalling;
import net.minecraft.init.Blocks;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.IChunkProvider;

import bartworks.util.NoiseUtil.BartsNoise;
import bwcrossmod.galacticraft.planets.ross128b.ChunkProviderRoss128b;
import gregtech.api.objects.XSTR;
import micdoodle8.mods.galacticraft.api.prefab.world.gen.MapGenBaseMeta;
import micdoodle8.mods.galacticraft.core.blocks.GCBlocks;
import micdoodle8.mods.galacticraft.core.world.gen.BiomeGenBaseMoon;
import micdoodle8.mods.galacticraft.core.world.gen.ChunkProviderMoon;
import micdoodle8.mods.galacticraft.core.world.gen.MapGenCavesMoon;

public class ChunkProviderRoss128ba extends ChunkProviderMoon {

    private final XSTR rand = new XSTR();
    private final World worldObj;
    private BiomeGenBase[] biomesForGeneration;
    private final MapGenBaseMeta caveGenerator;

    public ChunkProviderRoss128ba(World world, long seed, boolean mapFeaturesEnabled) {
        super(world, seed, mapFeaturesEnabled);
        this.biomesForGeneration = new BiomeGenBase[] { BiomeGenBaseMoon.moonFlat };
        this.caveGenerator = new MapGenCavesMoon();
        this.worldObj = world;
    }

    @Override
    public Chunk provideChunk(int cx, int cz) {
        this.rand.setSeed(cx * 341873128712L + cz * 132897987541L);
        Block[] ids = new Block[65536];
        byte[] meta = new byte[65536];
        Arrays.fill(ids, Blocks.air);
        this.generateTerrain(cx, cz, ids, meta);
        this.biomesForGeneration = this.worldObj.getWorldChunkManager()
            .loadBlockGeneratorData(this.biomesForGeneration, cx * 16, cz * 16, 16, 16);
        this.createCraters(cx, cz, ids, meta);
        this.replaceBlocksForBiome(cx, cz, ids, meta, this.biomesForGeneration);
        this.caveGenerator.generate(this, this.worldObj, cx, cz, ids, meta);
        Chunk Chunk = new Chunk(this.worldObj, ids, meta, cx, cz);
        Chunk.generateSkylightMap();
        return Chunk;
    }

    @Override
    public void decoratePlanet(World par1World, Random par2Random, int par3, int par4) {}

    @Override
    public void populate(IChunkProvider par1IChunkProvider, int par2, int par3) {
        super.populate(par1IChunkProvider, par2, par3);
        BlockFalling.fallInstantly = true;
        ChunkProviderRoss128b.BWOreGen.generate(this.rand, par2, par3, this.worldObj, this, this);
        BlockFalling.fallInstantly = false;
    }

    private int getIndex(int x, int y, int z) {
        return (x * 16 + z) * 256 + y;
    }

    final Block lowerBlockID = GCBlocks.blockMoon;
    final BartsNoise noiseGen = new BartsNoise(2, 0.008F, 1D, System.nanoTime());
    final BartsNoise noiseGen2 = new BartsNoise(2, 0.01F, 1D, System.nanoTime());
    final BartsNoise noiseGen3 = new BartsNoise(2, 0.002F, 1D, System.nanoTime());

    @Override
    public void generateTerrain(int chunkX, int chunkZ, Block[] idArray, byte[] metaArray) {
        for (int x = 0; x < 16; ++x) {
            for (int z = 0; z < 16; ++z) {
                double d = this.noiseGen.getNoise(x + chunkX * 16, z + chunkZ * 16);
                double d2 = this.noiseGen2.getNoise(x + chunkX * 16, z + chunkZ * 16);
                double d3 = this.noiseGen3.getCosNoise(x + chunkX * 16, z + chunkZ * 16);

                double yDev = d * 4 + d2 * 2 + d3;

                for (int y = 0; y < 128; ++y) {
                    if (y < 60.0D + yDev) {
                        idArray[this.getIndex(x, y, z)] = this.lowerBlockID;
                        int var10001 = this.getIndex(x, y, z);
                        metaArray[var10001] = 4;
                    }
                }
            }
        }
    }
}