Search in sources :

Example 1 with ChunkPrimer

use of net.minecraft.world.chunk.ChunkPrimer in project Realistic-Terrain-Generation by Team-RTG.

the class OrganicBiomeGenerator method organicTerrain.

public int[] organicTerrain(int cx, int cz) {
    ChunkPrimer primer = new ChunkPrimer();
    organicProvider.setBlocksInChunk(cx, cz, primer);
    int[] heights = new int[256];
    for (int x = 0; x < 16; x++) {
        for (int z = 0; z < 16; z++) {
            for (int y = 255; y >= 0; --y) {
                IBlockState iblockstate = primer.getBlockState(x, y, z);
                if (iblockstate != null && iblockstate != Blocks.AIR.getDefaultState()) {
                    heights[x * 16 + z] = y;
                    break;
                }
            }
        }
    }
    chunkHeights.put(new PlaneLocation.Invariant(cx, cz), heights);
    return heights;
}
Also used : PlaneLocation(rtg.api.util.PlaneLocation) IBlockState(net.minecraft.block.state.IBlockState) ChunkPrimer(net.minecraft.world.chunk.ChunkPrimer)

Example 2 with ChunkPrimer

use of net.minecraft.world.chunk.ChunkPrimer in project RFToolsDimensions by McJty.

the class LostCitiesTerrainGenerator method generateStreet.

private int generateStreet(ChunkPrimerHelper helper, BuildingInfo info, Random rand, int chunkX, int chunkZ, int index, int x, int z, int height) {
    ChunkPrimer primer = helper.getPrimer();
    DamageArea damageArea = info.getDamageArea();
    Style style = info.getStyle();
    int cx = chunkX * 16;
    int cz = chunkZ * 16;
    boolean xRail = info.hasXCorridor();
    boolean zRail = info.hasZCorridor();
    boolean doOceanBorder = isDoOceanBorder(info, chunkX, chunkZ, x, z);
    while (height < groundLevel) {
        IBlockState railx = Blocks.RAIL.getDefaultState().withProperty(BlockRail.SHAPE, BlockRailBase.EnumRailDirection.EAST_WEST);
        IBlockState railz = Blocks.RAIL.getDefaultState();
        IBlockState b = baseBlock;
        if (doOceanBorder) {
            b = Blocks.STONEBRICK.getDefaultState();
        } else if (height >= groundLevel - 5 && height <= groundLevel - 1) {
            if (height <= groundLevel - 2 && ((xRail && z >= 7 && z <= 10) || (zRail && x >= 7 && x <= 10))) {
                b = air;
                if (height == groundLevel - 5 && xRail && z == 10) {
                    b = railx;
                }
                if (height == groundLevel - 5 && zRail && x == 10) {
                    b = railz;
                }
                if (height == groundLevel - 2) {
                    if ((xRail && x == 7 && (z == 8 || z == 9)) || (zRail && z == 7 && (x == 8 || x == 9))) {
                        b = Blocks.GLASS.getDefaultState();
                    } else {
                        b = Blocks.STONEBRICK.getDefaultState();
                    }
                }
            } else if (height == groundLevel - 1 && ((xRail && x == 7 && (z == 8 || z == 9)) || (zRail && z == 7 && (x == 8 || x == 9)))) {
                b = Blocks.GLOWSTONE.getDefaultState();
            }
        }
        // BaseTerrainGenerator.setBlockState(primer, index++, height < waterLevel ? baseLiquid : damageArea.damageBlock(b, height < waterLevel ? baseLiquid : air, rand, cx + x, height, cz + z, index, style));
        BaseTerrainGenerator.setBlockState(primer, index++, damageArea.damageBlock(b, height < waterLevel ? baseLiquid : air, rand, cx + x, height, cz + z, index, style));
        height++;
    }
    IBlockState b;
    BuildingInfo.StreetType streetType = info.streetType;
    boolean elevated = info.isElevatedParkSection();
    if (elevated) {
        streetType = BuildingInfo.StreetType.PARK;
        BaseTerrainGenerator.setBlockState(primer, index++, damageArea.damageBlock(Blocks.STONEBRICK.getDefaultState(), air, rand, cx + x, height, cz + z, index, style));
        height++;
    }
    b = baseBlock;
    switch(streetType) {
        case NORMAL:
            if (isStreetBorder(x, z)) {
                if (x <= STREETBORDER && z > STREETBORDER && z < (15 - STREETBORDER) && (info.getXmin().doesRoadExtendTo() || (info.getXmin().hasXBridge(provider) >= 0))) {
                    b = style.street;
                } else if (x >= (15 - STREETBORDER) && z > STREETBORDER && z < (15 - STREETBORDER) && (info.getXmax().doesRoadExtendTo() || (info.getXmax().hasXBridge(provider) >= 0))) {
                    b = style.street;
                } else if (z <= STREETBORDER && x > STREETBORDER && x < (15 - STREETBORDER) && (info.getZmin().doesRoadExtendTo() || (info.getZmin().hasZBridge(provider) >= 0))) {
                    b = style.street;
                } else if (z >= (15 - STREETBORDER) && x > STREETBORDER && x < (15 - STREETBORDER) && (info.getZmax().doesRoadExtendTo() || (info.getZmax().hasZBridge(provider) >= 0))) {
                    b = style.street;
                }
            } else {
                b = style.street;
            }
            break;
        case FULL:
            if (isSide(x, z)) {
                b = style.street;
            } else {
                b = style.street2;
            }
            break;
        case PARK:
            if (x == 0 || x == 15 || z == 0 || z == 15) {
                b = style.street;
                if (elevated) {
                    boolean el00 = info.getXmin().getZmin().isElevatedParkSection();
                    boolean el10 = info.getZmin().isElevatedParkSection();
                    boolean el20 = info.getXmax().getZmin().isElevatedParkSection();
                    boolean el01 = info.getXmin().isElevatedParkSection();
                    boolean el21 = info.getXmax().isElevatedParkSection();
                    boolean el02 = info.getXmin().getZmax().isElevatedParkSection();
                    boolean el12 = info.getZmax().isElevatedParkSection();
                    boolean el22 = info.getXmax().getZmax().isElevatedParkSection();
                    if (x == 0 && z == 0) {
                        if (el01 && el00 && el10) {
                            b = Blocks.GRASS.getDefaultState();
                        }
                    } else if (x == 15 && z == 0) {
                        if (el21 && el20 && el10) {
                            b = Blocks.GRASS.getDefaultState();
                        }
                    } else if (x == 0 && z == 15) {
                        if (el01 && el02 && el12) {
                            b = Blocks.GRASS.getDefaultState();
                        }
                    } else if (x == 15 && z == 15) {
                        if (el12 && el22 && el21) {
                            b = Blocks.GRASS.getDefaultState();
                        }
                    } else if (x == 0) {
                        if (el01) {
                            b = Blocks.GRASS.getDefaultState();
                        }
                    } else if (x == 15) {
                        if (el21) {
                            b = Blocks.GRASS.getDefaultState();
                        }
                    } else if (z == 0) {
                        if (el10) {
                            b = Blocks.GRASS.getDefaultState();
                        }
                    } else if (z == 15) {
                        if (el12) {
                            b = Blocks.GRASS.getDefaultState();
                        }
                    }
                }
            } else {
                b = Blocks.GRASS.getDefaultState();
            }
            break;
    }
    if (doOceanBorder) {
        b = Blocks.STONEBRICK.getDefaultState();
    }
    BaseTerrainGenerator.setBlockState(primer, index++, damageArea.damageBlock(b, air, rand, cx + x, height, cz + z, index, style));
    height++;
    if (streetType == BuildingInfo.StreetType.PARK || info.fountainType >= 0) {
        int l = 0;
        Level level = streetType == BuildingInfo.StreetType.PARK ? ParkData.PARKS[info.parkType] : FountainData.FOUNTAINS[info.fountainType];
        while (l < level.getFloor().length) {
            if (l == 0 && doOceanBorder) {
                b = Blocks.COBBLESTONE_WALL.getDefaultState();
            } else {
                b = level.get(info, x, l, z);
            }
            b = damageArea.damageBlock(b, air, rand, cx + x, height, cz + z, index, style);
            BaseTerrainGenerator.setBlockState(primer, index++, b);
            height++;
            l++;
        }
    } else if (doOceanBorder) {
        b = Blocks.COBBLESTONE_WALL.getDefaultState();
        b = damageArea.damageBlock(b, air, rand, cx + x, height, cz + z, index, style);
        BaseTerrainGenerator.setBlockState(primer, index++, b);
        height++;
    }
    int blocks = 256 - height;
    helper.setDataRange(index, index + blocks, Block.BLOCK_STATE_IDS.get(air));
    index += blocks;
    return index;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ChunkPrimer(net.minecraft.world.chunk.ChunkPrimer)

Example 3 with ChunkPrimer

use of net.minecraft.world.chunk.ChunkPrimer in project RFToolsDimensions by McJty.

the class LostCitiesTerrainGenerator method generateBuilding.

private int generateBuilding(ChunkPrimerHelper helper, BuildingInfo info, Random rand, int chunkX, int chunkZ, int index, int x, int z, int height) {
    ChunkPrimer primer = helper.getPrimer();
    DamageArea damageArea = info.getDamageArea();
    Style style = info.getStyle();
    int cx = chunkX * 16;
    int cz = chunkZ * 16;
    int lowestLevel = groundLevel - info.floorsBelowGround * 6;
    int buildingtop = 69 + info.floors * 6;
    boolean corridor;
    if (isSide(x, z)) {
        BuildingInfo adjacent = info.getAdjacent(x, z);
        corridor = (adjacent.hasXCorridor() || adjacent.hasZCorridor()) && isRailDoorway(x, z);
    } else {
        corridor = false;
    }
    while (height < lowestLevel) {
        // BaseTerrainGenerator.setBlockState(primer, index++, height < waterLevel ? baseLiquid : damageArea.damageBlock(baseBlock, air, rand, cx + x, height, cz + z, index, style));
        BaseTerrainGenerator.setBlockState(primer, index++, damageArea.damageBlock(baseBlock, height < waterLevel ? baseLiquid : air, rand, cx + x, height, cz + z, index, style));
        height++;
    }
    while (height < buildingtop) {
        IBlockState b;
        // Make a connection to a corridor if needed
        if (corridor && height >= groundLevel - 5 && height <= groundLevel - 3) {
            b = air;
        } else {
            b = getBlockForLevel(info, x, z, height);
            b = damageArea.damageBlock(b, height < waterLevel ? baseLiquid : air, rand, cx + x, height, cz + z, index, style);
        }
        BaseTerrainGenerator.setBlockState(primer, index++, b);
        height++;
    }
    while (height < buildingtop + 6) {
        int f = getFloor(height);
        int floortype = info.topType;
        Level level = info.getTopData(floortype);
        if (f >= level.getFloor().length) {
            break;
        }
        IBlockState b = level.get(info, x, f, z);
        b = damageArea.damageBlock(b, air, rand, cx + x, height, cz + z, index, style);
        BaseTerrainGenerator.setBlockState(primer, index++, b);
        height++;
    }
    int blocks = 256 - height;
    helper.setDataRange(index, index + blocks, Block.BLOCK_STATE_IDS.get(air));
    index += blocks;
    return index;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ChunkPrimer(net.minecraft.world.chunk.ChunkPrimer)

Example 4 with ChunkPrimer

use of net.minecraft.world.chunk.ChunkPrimer in project RFToolsDimensions by McJty.

the class LostCitiesTerrainGenerator method generateDebrisFromChunk.

private void generateDebrisFromChunk(ChunkPrimerHelper helper, Random rand, BuildingInfo adjacentInfo, BiFunction<Integer, Integer, Float> locationFactor) {
    if (adjacentInfo.hasBuilding) {
        int air = Block.BLOCK_STATE_IDS.get(LostCitiesTerrainGenerator.air);
        int liquid = Block.BLOCK_STATE_IDS.get(provider.dimensionInformation.getFluidForTerrain().getDefaultState());
        float damageFactor = adjacentInfo.getDamageArea().getDamageFactor();
        if (damageFactor > .5f) {
            // An estimate of the amount of blocks
            int blocks = (1 + adjacentInfo.floors) * 1000;
            float damage = Math.max(1.0f, damageFactor * DamageArea.BLOCK_DAMAGE_CHANCE);
            int destroyedBlocks = (int) (blocks * damage);
            // How many go this direction (approx, based on cardinal directions from building as well as number that simply fall down)
            destroyedBlocks /= LostCityConfiguration.DEBRIS_TO_NEARBYCHUNK_FACTOR;
            ChunkPrimer primer = helper.getPrimer();
            for (int i = 0; i < destroyedBlocks; i++) {
                int x = rand.nextInt(16);
                int z = rand.nextInt(16);
                if (rand.nextFloat() < locationFactor.apply(x, z)) {
                    int index = (x << 12) | (z << 8) + 255;
                    while (helper.getData(index) == air || helper.getData(index) == liquid) {
                        index--;
                    }
                    index++;
                    IBlockState b;
                    switch(rand.nextInt(5)) {
                        case 0:
                            b = Blocks.IRON_BARS.getDefaultState();
                            break;
                        case 1:
                            b = adjacentInfo.getStyle().bricks;
                            break;
                        default:
                            b = adjacentInfo.getStyle().bricks_cracked;
                            break;
                    }
                    BaseTerrainGenerator.setBlockState(primer, index, b);
                }
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ChunkPrimer(net.minecraft.world.chunk.ChunkPrimer)

Example 5 with ChunkPrimer

use of net.minecraft.world.chunk.ChunkPrimer in project MorePlanets by SteveKunG.

the class ChunkProviderDiona method generateChunk.

@Override
public Chunk generateChunk(int chunkX, int chunkZ) {
    ChunkPrimer primer = new ChunkPrimer();
    this.rand.setSeed(chunkX * 341873128712L + chunkZ * 132897987541L);
    this.generateTerrain(chunkX, chunkZ, primer);
    this.biomesForGeneration = this.worldObj.getBiomeProvider().getBiomes(this.biomesForGeneration, chunkX * 16, chunkZ * 16, 16, 16);
    this.createCraters(chunkX, chunkZ, primer);
    this.replaceBiomeBlocks(chunkX, chunkZ, primer, this.biomesForGeneration);
    this.caveGenerator.generate(this.worldObj, chunkX, chunkZ, primer);
    this.mineshaftGenerator.generate(this.worldObj, chunkX, chunkZ, primer);
    this.dungeonGenerator.generate(this.worldObj, chunkX, chunkZ, primer);
    Chunk chunk = new Chunk(this.worldObj, primer, chunkX, chunkZ);
    chunk.generateSkylightMap();
    return chunk;
}
Also used : Chunk(net.minecraft.world.chunk.Chunk) ChunkPrimer(net.minecraft.world.chunk.ChunkPrimer)

Aggregations

ChunkPrimer (net.minecraft.world.chunk.ChunkPrimer)50 Chunk (net.minecraft.world.chunk.Chunk)39 IBlockState (net.minecraft.block.state.IBlockState)8 BlockPos (net.minecraft.util.math.BlockPos)3 Biome (net.minecraft.world.biome.Biome)3 ChunkBufferPrimer (org.spongepowered.common.util.gen.ChunkBufferPrimer)3 Nonnull (javax.annotation.Nonnull)2 ChunkPos (net.minecraft.util.math.ChunkPos)2 BOPOverworldBiome (biomesoplenty.common.biome.overworld.BOPOverworldBiome)1 Vector3i (com.flowpowered.math.vector.Vector3i)1 MapGenStructureHook (ivorius.reccomplex.world.gen.feature.structure.MapGenStructureHook)1 Random (java.util.Random)1 Nullable (javax.annotation.Nullable)1 Pair (kotlin.Pair)1 WorldProviderAsteroids (micdoodle8.mods.galacticraft.planets.asteroids.dimension.WorldProviderAsteroids)1 MutableBlockPos (net.minecraft.util.math.BlockPos.MutableBlockPos)1 ChunkCoordIntPair (net.minecraft.world.ChunkCoordIntPair)1 World (net.minecraft.world.World)1 BiomeProvider (net.minecraft.world.biome.BiomeProvider)1 ChunkGeneratorOverworld (net.minecraft.world.gen.ChunkGeneratorOverworld)1