Search in sources :

Example 1 with ChunkGenerator

use of net.minecraft.world.gen.ChunkGenerator in project ChocolateQuestRepoured by TeamChocoQuest.

the class StructureHelper method isStructureInRange.

public static boolean isStructureInRange(World world, BlockPos pos, int radius, String name) {
    if (!world.getWorldInfo().isMapFeaturesEnabled()) {
        return false;
    }
    if (name.equals("AW2")) {
        // check for aw2 structures
        if (!CQRMain.isAW2Installed) {
            return false;
        }
        return AW2Integration.isAW2StructureInRange(world, pos, radius);
    }
    ChunkGenerator chunkGenerator = ((ServerWorld) world).getChunkProvider().chunkGenerator;
    if (chunkGenerator instanceof OverworldChunkGenerator || chunkGenerator instanceof NetherChunkGenerator || chunkGenerator instanceof EndChunkGenerator || chunkGenerator instanceof FlatChunkGenerator || chunkGenerator instanceof DebugChunkGenerator) {
        // vanilla chunk generator
        Structure structureGenerator = getStructureGenerator(world, name);
        if (structureGenerator != null) {
            return isStructureInRange(world, structureGenerator, pos, radius);
        }
        return false;
    }
    // modded chunk generator
    BlockPos structurePos;
    try {
        structurePos = chunkGenerator.getNearestStructurePos(world, name, pos, false);
        if (structurePos != null && (Math.abs(structurePos.getX() - pos.getX()) <= radius || Math.abs(structurePos.getZ() - pos.getZ()) <= radius)) {
            return true;
        }
    } catch (NullPointerException e) {
    // ignore
    }
    try {
        structurePos = chunkGenerator.getNearestStructurePos(world, name, pos, true);
        if (structurePos != null && (Math.abs(structurePos.getX() - pos.getX()) <= radius || Math.abs(structurePos.getZ() - pos.getZ()) <= radius)) {
            return true;
        }
    } catch (NullPointerException e) {
    // ignore
    }
    return false;
}
Also used : FlatChunkGenerator(net.minecraft.world.gen.FlatChunkGenerator) EndChunkGenerator(net.minecraft.world.gen.EndChunkGenerator) BlockPos(net.minecraft.util.math.BlockPos) OverworldChunkGenerator(net.minecraft.world.gen.OverworldChunkGenerator) ChunkGenerator(net.minecraft.world.gen.ChunkGenerator) EndChunkGenerator(net.minecraft.world.gen.EndChunkGenerator) FlatChunkGenerator(net.minecraft.world.gen.FlatChunkGenerator) NetherChunkGenerator(net.minecraft.world.gen.NetherChunkGenerator) OverworldChunkGenerator(net.minecraft.world.gen.OverworldChunkGenerator) Structure(net.minecraft.world.gen.feature.structure.Structure) NetherChunkGenerator(net.minecraft.world.gen.NetherChunkGenerator)

Example 2 with ChunkGenerator

use of net.minecraft.world.gen.ChunkGenerator in project Mekanism by mekanism.

the class GenHandler method generate.

/**
 * @return True if some retro-generation happened, false otherwise
 */
public static boolean generate(ServerWorld world, Random random, int chunkX, int chunkZ) {
    BlockPos blockPos = new BlockPos(chunkX * 16, 0, chunkZ * 16);
    Biome biome = world.getBiome(blockPos);
    boolean generated = false;
    if (isValidBiome(biome.getBiomeCategory()) && world.hasChunk(chunkX, chunkZ)) {
        ChunkGenerator chunkGenerator = world.getChunkSource().getGenerator();
        for (ConfiguredFeature<?, ?> feature : ORE_RETROGENS.values()) {
            generated |= feature.place(world, chunkGenerator, random, blockPos);
        }
        generated |= SALT_RETROGEN_FEATURE.place(world, chunkGenerator, random, blockPos);
    }
    return generated;
}
Also used : Biome(net.minecraft.world.biome.Biome) BlockPos(net.minecraft.util.math.BlockPos) ChunkGenerator(net.minecraft.world.gen.ChunkGenerator)

Example 3 with ChunkGenerator

use of net.minecraft.world.gen.ChunkGenerator in project MCMOD-Industria by M-Marvin.

the class LakeFeature method place.

@SuppressWarnings("deprecation")
@Override
public boolean place(ISeedReader reader, ChunkGenerator generator, Random rand, BlockPos pos, LakeFeatureConfig config) {
    Random random = new Random(rand.nextLong());
    // Make Lake Shape
    int count = random.nextInt(config.maxIterationCount) + 1;
    BlockPos genPos = new BlockPos(0, -1, 0);
    List<BlockPos> positionList = new ArrayList<BlockPos>();
    for (int x1 = 0; x1 < count; x1++) {
        int maxWidth1 = config.minWidth + random.nextInt(config.maxWidth - config.minWidth);
        int maxWidth2 = config.minWidth + random.nextInt(config.maxWidth - config.minWidth);
        int r1 = random.nextInt((int) (maxWidth1 / 2F));
        int r3 = random.nextInt((int) (maxWidth2 / 2F));
        genPos = genPos.offset(r1, 0, r3);
        int depth = random.nextInt(config.maxDepth) + 2;
        for (int i0 = 0; i0 < depth; i0++) {
            float f0 = i0 / (float) (depth);
            int width1 = (int) (Math.cos(f0 * (Math.PI / 2)) * maxWidth1);
            int width2 = (int) (Math.cos(f0 * (Math.PI / 2)) * maxWidth2);
            BlockPos placePos0 = new BlockPos(0, -i0, 0);
            for (int i1 = 0; i1 < width1; i1++) {
                float f1 = i1 / (float) (width1);
                int rowWidth = (int) (Math.sin(f1 * Math.PI) * width2);
                BlockPos placePos1 = placePos0.offset(i1 - width2 / 2, 0, 0);
                for (int i4 = 0; i4 < rowWidth; i4++) {
                    BlockPos placePos2 = placePos1.offset(0, 0, i4 - rowWidth / 2);
                    positionList.add(genPos.offset(placePos2));
                }
            }
        }
    }
    // Make Border Shape
    List<BlockPos> borderPositions = new ArrayList<BlockPos>();
    for (BlockPos position : positionList) {
        for (Direction d : Direction.values()) {
            BlockPos checkPos = position.relative(d);
            if (!positionList.contains(checkPos))
                borderPositions.add(checkPos);
        }
    }
    // Check Valid Generation
    if (positionList.size() == 0)
        return false;
    for (BlockPos position : positionList) {
        BlockState replaceState = reader.getBlockState(position.offset(pos));
        if (!replaceState.getFluidState().isEmpty() || replaceState.isAir() || replaceState.getBlock() == Blocks.BEDROCK)
            return false;
    }
    // Place Blocks
    for (BlockPos position : positionList) {
        BlockState genState = Blocks.CAVE_AIR.defaultBlockState();
        if (position.getY() != -1) {
            genState = config.fillerBlock;
        }
        reader.setBlock(position.offset(pos), genState, 2);
    }
    Predicate<Block> borderReplacePredicate = (block) -> block != config.crustBlock.getBlock() && block != config.fillerBlock.getBlock() && block.getBlock() != Blocks.CAVE_AIR;
    for (BlockPos position : borderPositions) {
        if (position.getY() == -2) {
            reader.setBlock(position.offset(pos), config.crustBlock, 2);
        } else if (random.nextInt(5) == 0 && position.getY() != 0) {
            reader.setBlock(position.offset(pos), config.crustBlock, 2);
        } else if (position.getY() != -1 && position.getY() != 0) {
            reader.setBlock(position.offset(pos), config.borderBlock, 2);
        } else if (position.getY() == -1) {
            for (int i = 0; i < 10; i++) {
                BlockPos replacePos = position.offset(random.nextInt(6) - 3, random.nextInt(6) - 3, random.nextInt(6) - 3);
                BlockState replaceState = reader.getBlockState(replacePos.offset(pos));
                if (borderReplacePredicate.apply(replaceState.getBlock())) {
                    reader.setBlock(replacePos.offset(pos), Blocks.CAVE_AIR.defaultBlockState(), 2);
                }
            }
        }
    }
    return true;
}
Also used : ChunkGenerator(net.minecraft.world.gen.ChunkGenerator) Random(java.util.Random) BlockPos(net.minecraft.util.math.BlockPos) Direction(net.minecraft.util.Direction) Feature(net.minecraft.world.gen.feature.Feature) Blocks(net.minecraft.block.Blocks) ArrayList(java.util.ArrayList) List(java.util.List) Codec(com.mojang.serialization.Codec) Block(net.minecraft.block.Block) Predicate(com.google.common.base.Predicate) BlockState(net.minecraft.block.BlockState) ISeedReader(net.minecraft.world.ISeedReader) BlockState(net.minecraft.block.BlockState) Random(java.util.Random) ArrayList(java.util.ArrayList) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) Direction(net.minecraft.util.Direction)

Aggregations

BlockPos (net.minecraft.util.math.BlockPos)3 ChunkGenerator (net.minecraft.world.gen.ChunkGenerator)3 Predicate (com.google.common.base.Predicate)1 Codec (com.mojang.serialization.Codec)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Random (java.util.Random)1 Block (net.minecraft.block.Block)1 BlockState (net.minecraft.block.BlockState)1 Blocks (net.minecraft.block.Blocks)1 Direction (net.minecraft.util.Direction)1 ISeedReader (net.minecraft.world.ISeedReader)1 Biome (net.minecraft.world.biome.Biome)1 EndChunkGenerator (net.minecraft.world.gen.EndChunkGenerator)1 FlatChunkGenerator (net.minecraft.world.gen.FlatChunkGenerator)1 NetherChunkGenerator (net.minecraft.world.gen.NetherChunkGenerator)1 OverworldChunkGenerator (net.minecraft.world.gen.OverworldChunkGenerator)1 Feature (net.minecraft.world.gen.feature.Feature)1 Structure (net.minecraft.world.gen.feature.structure.Structure)1