Search in sources :

Example 1 with EndChunkGenerator

use of net.minecraft.world.gen.EndChunkGenerator 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)

Aggregations

BlockPos (net.minecraft.util.math.BlockPos)1 ChunkGenerator (net.minecraft.world.gen.ChunkGenerator)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 Structure (net.minecraft.world.gen.feature.structure.Structure)1