Search in sources :

Example 1 with Biome

use of org.bukkit.block.Biome in project Glowstone by GlowstoneMC.

the class BlockBed method blockInteract.

@Override
public boolean blockInteract(GlowPlayer player, GlowBlock block, BlockFace face, Vector clickedLoc) {
    GlowWorld world = player.getWorld();
    MaterialData data = block.getState().getData();
    if (!(data instanceof Bed)) {
        warnMaterialData(Bed.class, data);
        return false;
    }
    block = getHead(block);
    // Disallow sleeping in nether and end biomes
    Biome biome = block.getBiome();
    if (biome == Biome.HELL || biome == Biome.SKY) {
        // Set off an explosion at the bed slightly stronger than TNT
        world.createExplosion(block.getLocation(), 5F, true);
        return true;
    }
    // Tick values for day/night time taken from the minecraft wiki
    if (world.getTime() < 12541 || world.getTime() > 23458 || world.isThundering()) {
        player.sendMessage("You can only sleep at night");
        return true;
    }
    if (isOccupied(block)) {
        player.sendMessage("This bed is occupied.");
        return true;
    }
    if (!isWithinDistance(player, block, 3, 2, 3)) {
        // Distance between player and bed is too great, fail silently
        return true;
    }
    for (LivingEntity e : world.getLivingEntities()) {
        // Check for hostile mobs relative to the block below the head of the bed
        if (e instanceof Creature && isWithinDistance(e, block.getRelative(BlockFace.DOWN), 8, 5, 8)) {
            player.sendMessage("You may not rest now, there are monsters nearby");
            return true;
        }
    }
    player.enterBed(block);
    return true;
}
Also used : Bed(org.bukkit.material.Bed) LivingEntity(org.bukkit.entity.LivingEntity) Biome(org.bukkit.block.Biome) Creature(org.bukkit.entity.Creature) GlowWorld(net.glowstone.GlowWorld) MaterialData(org.bukkit.material.MaterialData)

Example 2 with Biome

use of org.bukkit.block.Biome in project Glowstone by GlowstoneMC.

the class GlowTemple method shouldGenerate.

@Override
public boolean shouldGenerate(Random random) {
    Biome biome = world.getBiome((chunkX << 4) + 8, (chunkZ << 4) + 8);
    if (types.containsKey(biome)) {
        int x = chunkX < 0 ? (chunkX - MAX_DISTANCE - 1) / MAX_DISTANCE : chunkX / MAX_DISTANCE;
        int z = chunkZ < 0 ? (chunkZ - MAX_DISTANCE - 1) / MAX_DISTANCE : chunkZ / MAX_DISTANCE;
        x = x * MAX_DISTANCE + random.nextInt(MAX_DISTANCE - MIN_DISTANCE);
        z = z * MAX_DISTANCE + random.nextInt(MAX_DISTANCE - MIN_DISTANCE);
        if (x == chunkX && z == chunkZ) {
            return true;
        }
    }
    return false;
}
Also used : Biome(org.bukkit.block.Biome)

Example 3 with Biome

use of org.bukkit.block.Biome in project Glowstone by GlowstoneMC.

the class Lake method generate.

public void generate(World world, Random random, int sourceX, int sourceY, int sourceZ) {
    sourceY -= (int) MAX_HEIGHT / 2;
    byte[] lakeMap = new byte[MAX_BLOCKS];
    for (int n = 0; n < random.nextInt(4) + 4; n++) {
        double sizeX = random.nextDouble() * 6.0D + 3;
        double sizeY = random.nextDouble() * 4.0D + 2;
        double sizeZ = random.nextDouble() * 6.0D + 3;
        double dX = random.nextDouble() * (MAX_DIAMETER - sizeX - 2) + 1 + sizeX / 2.0D;
        double dY = random.nextDouble() * (MAX_HEIGHT - sizeY - 4) + 2 + sizeY / 2.0D;
        double dZ = random.nextDouble() * (MAX_DIAMETER - sizeZ - 2) + 1 + sizeZ / 2.0D;
        for (int x = 1; x < (int) MAX_DIAMETER - 1; x++) {
            for (int z = 1; z < (int) MAX_DIAMETER - 1; z++) {
                for (int y = 1; y < (int) MAX_HEIGHT - 1; y++) {
                    double nX = (x - dX) / (sizeX / 2.0D);
                    nX *= nX;
                    double nY = (y - dY) / (sizeY / 2.0D);
                    nY *= nY;
                    double nZ = (z - dZ) / (sizeZ / 2.0D);
                    nZ *= nZ;
                    if (nX + nY + nZ < 1.0D) {
                        setLakeBlock(lakeMap, x, y, z);
                    }
                }
            }
        }
    }
    if (!canPlace(lakeMap, world, sourceX, sourceY, sourceZ)) {
        return;
    }
    Biome biome = world.getBiome(sourceX + 8 + (int) MAX_DIAMETER / 2, sourceZ + 8 + (int) MAX_DIAMETER / 2);
    boolean mycelBiome = Arrays.asList(MYCEL_BIOMES).contains(biome);
    for (int x = 0; x < (int) MAX_DIAMETER; x++) {
        for (int z = 0; z < (int) MAX_DIAMETER; z++) {
            for (int y = 0; y < (int) MAX_HEIGHT; y++) {
                if (isLakeBlock(lakeMap, x, y, z)) {
                    Material type = this.type;
                    Block block = world.getBlockAt(sourceX + x, sourceY + y, sourceZ + z);
                    Block blockAbove = block.getRelative(BlockFace.UP);
                    if (block.getType() == Material.DIRT && (blockAbove.getType() == Material.LOG || blockAbove.getType() == Material.LOG_2) || block.getType() == Material.LOG || block.getType() == Material.LOG_2) {
                        continue;
                    }
                    if (y >= (int) MAX_HEIGHT / 2) {
                        type = Material.AIR;
                        for (Material mat : PLANT_TYPES) {
                            if (blockAbove.getType() == mat) {
                                if (mat == Material.DOUBLE_PLANT) {
                                    Block blockAboveBlock = blockAbove.getRelative(BlockFace.UP);
                                    if (blockAboveBlock.getState().getData() instanceof DoublePlant && ((DoublePlant) blockAboveBlock.getState().getData()).getSpecies() == DoublePlantSpecies.PLANT_APEX) {
                                        blockAboveBlock.setType(Material.AIR);
                                    }
                                }
                                blockAbove.setType(Material.AIR);
                                break;
                            }
                        }
                        if (this.type == Material.STATIONARY_WATER && (block.getType() == Material.ICE || block.getType() == Material.PACKED_ICE)) {
                            type = block.getType();
                        }
                    } else if (y == MAX_HEIGHT / 2 - 1) {
                        if (type == Material.STATIONARY_WATER && GlowBiomeClimate.isCold(world.getBiome(sourceX + x, sourceZ + z), sourceX + x, y, sourceZ + z)) {
                            type = Material.ICE;
                        }
                    }
                    block.setType(type);
                }
            }
        }
    }
    for (int x = 0; x < (int) MAX_DIAMETER; x++) {
        for (int z = 0; z < (int) MAX_DIAMETER; z++) {
            for (int y = (int) MAX_HEIGHT / 2; y < (int) MAX_HEIGHT; y++) {
                if (isLakeBlock(lakeMap, x, y, z)) {
                    Block block = world.getBlockAt(sourceX + x, sourceY + y - 1, sourceZ + z);
                    if (block.getType() == Material.DIRT && !block.getRelative(BlockFace.UP).getType().isOccluding() && block.getRelative(BlockFace.UP).getLightLevel() > 0) {
                        block.setType(mycelBiome ? Material.MYCEL : Material.GRASS);
                    }
                }
            }
        }
    }
}
Also used : Biome(org.bukkit.block.Biome) Block(org.bukkit.block.Block) Material(org.bukkit.Material) DoublePlant(org.bukkit.material.DoublePlant)

Example 4 with Biome

use of org.bukkit.block.Biome in project Glowstone by GlowstoneMC.

the class OverworldGenerator method generateTerrainDensity.

private void generateTerrainDensity(World world, int x, int z) {
    WorldType type = world.getWorldType();
    // Scaling chunk x and z coordinates (4x, see below)
    x <<= 2;
    z <<= 2;
    // Get biome grid data at lower res (scaled 4x, at this scale a chunk is 4x4 columns of the biome grid),
    // we are loosing biome detail but saving huge amount of computation.
    // We need 1 chunk (4 columns) + 1 column for later needed outer edges (1 column) and at least 2 columns
    // on each side to be able to cover every value.
    // 4 + 1 + 2 + 2 = 9 columns but the biomegrid generator needs a multiple of 2 so we ask 10 columns wide
    // to the biomegrid generator.
    // This gives a total of 81 biome grid columns to work with, and this includes the chunk neighborhood.
    int[] biomeGrid = ((GlowWorld) world).getChunkManager().getBiomeGridAtLowerRes(x - 2, z - 2, 10, 10);
    Map<String, OctaveGenerator> octaves = getWorldOctaves(world);
    double[] heightNoise = ((PerlinOctaveGenerator) octaves.get("height")).fBm(x, z, 0.5D, 2.0D);
    double[] roughnessNoise = ((PerlinOctaveGenerator) octaves.get("roughness")).fBm(x, 0, z, 0.5D, 2.0D);
    double[] roughnessNoise2 = ((PerlinOctaveGenerator) octaves.get("roughness2")).fBm(x, 0, z, 0.5D, 2.0D);
    double[] detailNoise = ((PerlinOctaveGenerator) octaves.get("detail")).fBm(x, 0, z, 0.5D, 2.0D);
    int index = 0;
    int indexHeight = 0;
    // re-scale it and do linear interpolation before densities can be used to generate raw terrain.
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 5; j++) {
            double avgHeightScale = 0;
            double avgHeightBase = 0;
            double totalWeight = 0;
            Biome biome = GlowBiome.getBiome(biomeGrid[i + 2 + (j + 2) * 10]);
            BiomeHeight biomeHeight = HEIGHT_MAP.getOrDefault(biome, defaultHeight);
            // of the current biomegrid column.
            for (int m = 0; m < 5; m++) {
                for (int n = 0; n < 5; n++) {
                    Biome nearBiome = GlowBiome.getBiome(biomeGrid[i + m + (j + n) * 10]);
                    BiomeHeight nearBiomeHeight = HEIGHT_MAP.getOrDefault(nearBiome, defaultHeight);
                    double heightBase = biomeHeightOffset + nearBiomeHeight.getHeight() * biomeHeightWeight;
                    double heightScale = biomeScaleOffset + nearBiomeHeight.getScale() * biomeScaleWeight;
                    if (type == WorldType.AMPLIFIED && heightBase > 0) {
                        heightBase = 1.0D + heightBase * 2.0D;
                        heightScale = 1.0D + heightScale * 4.0D;
                    }
                    double weight = ELEVATION_WEIGHT[m][n] / (heightBase + 2.0D);
                    if (nearBiomeHeight.getHeight() > biomeHeight.getHeight()) {
                        weight *= 0.5D;
                    }
                    avgHeightScale += heightScale * weight;
                    avgHeightBase += heightBase * weight;
                    totalWeight += weight;
                }
            }
            avgHeightScale /= totalWeight;
            avgHeightBase /= totalWeight;
            avgHeightScale = avgHeightScale * 0.9D + 0.1D;
            avgHeightBase = (avgHeightBase * 4.0D - 1.0D) / 8.0D;
            double noiseH = heightNoise[indexHeight++] / 8000.0D;
            if (noiseH < 0) {
                noiseH = Math.abs(noiseH) * 0.3D;
            }
            noiseH = noiseH * 3.0D - 2.0D;
            if (noiseH < 0) {
                noiseH = Math.max(noiseH * 0.5D, -1) / 1.4D * 0.5D;
            } else {
                noiseH = Math.min(noiseH, 1) / 8.0D;
            }
            noiseH = (noiseH * 0.2D + avgHeightBase) * baseSize / 8.0D * 4.0D + baseSize;
            for (int k = 0; k < 33; k++) {
                // density should be lower and lower as we climb up, this gets a height value to
                // subtract from the noise.
                double nH = (k - noiseH) * stretchY * 128.0D / 256.0D / avgHeightScale;
                if (nH < 0.0D) {
                    nH *= 4.0D;
                }
                double noiseR = roughnessNoise[index] / 512.0D;
                double noiseR2 = roughnessNoise2[index] / 512.0D;
                double noiseD = (detailNoise[index] / 10.0D + 1.0D) / 2.0D;
                // linear interpolation
                double dens = noiseD < 0 ? noiseR : noiseD > 1 ? noiseR2 : noiseR + (noiseR2 - noiseR) * noiseD;
                dens -= nH;
                index++;
                if (k > 29) {
                    double lowering = (k - 29) / 3.0D;
                    // linear interpolation
                    dens = dens * (1.0D - lowering) + -10.0D * lowering;
                }
                density[i][j][k] = dens;
            }
        }
    }
}
Also used : WorldType(org.bukkit.WorldType) Biome(org.bukkit.block.Biome) GlowBiome(net.glowstone.constants.GlowBiome) PerlinOctaveGenerator(net.glowstone.util.noise.PerlinOctaveGenerator) SimplexOctaveGenerator(net.glowstone.util.noise.SimplexOctaveGenerator) OctaveGenerator(org.bukkit.util.noise.OctaveGenerator) PerlinOctaveGenerator(net.glowstone.util.noise.PerlinOctaveGenerator)

Aggregations

Biome (org.bukkit.block.Biome)4 GlowWorld (net.glowstone.GlowWorld)1 GlowBiome (net.glowstone.constants.GlowBiome)1 PerlinOctaveGenerator (net.glowstone.util.noise.PerlinOctaveGenerator)1 SimplexOctaveGenerator (net.glowstone.util.noise.SimplexOctaveGenerator)1 Material (org.bukkit.Material)1 WorldType (org.bukkit.WorldType)1 Block (org.bukkit.block.Block)1 Creature (org.bukkit.entity.Creature)1 LivingEntity (org.bukkit.entity.LivingEntity)1 Bed (org.bukkit.material.Bed)1 DoublePlant (org.bukkit.material.DoublePlant)1 MaterialData (org.bukkit.material.MaterialData)1 OctaveGenerator (org.bukkit.util.noise.OctaveGenerator)1