Search in sources :

Example 11 with Material

use of org.bukkit.Material in project Glowstone by GlowstoneMC.

the class GenericTree method generate.

public boolean generate() {
    if (!canHeightFit() || !canPlaceOn() || !canPlace()) {
        return false;
    }
    // generate the leaves
    for (int y = loc.getBlockY() + height - 3; y <= loc.getBlockY() + height; y++) {
        int n = y - (loc.getBlockY() + height);
        int radius = 1 - n / 2;
        for (int x = loc.getBlockX() - radius; x <= loc.getBlockX() + radius; x++) {
            for (int z = loc.getBlockZ() - radius; z <= loc.getBlockZ() + radius; z++) {
                if (Math.abs(x - loc.getBlockX()) != radius || Math.abs(z - loc.getBlockZ()) != radius || random.nextBoolean() && n != 0) {
                    Material material = delegate.getBlockState(loc.getWorld(), x, y, z).getType();
                    if (material == Material.AIR || material == Material.LEAVES) {
                        delegate.setTypeAndRawData(loc.getWorld(), x, y, z, Material.LEAVES, leavesType);
                    }
                }
            }
        }
    }
    // generate the trunk
    for (int y = 0; y < height; y++) {
        Material material = delegate.getBlockState(loc.getWorld(), loc.getBlockX(), loc.getBlockY() + y, loc.getBlockZ()).getType();
        if (material == Material.AIR || material == Material.LEAVES) {
            delegate.setTypeAndRawData(loc.getWorld(), loc.getBlockX(), loc.getBlockY() + y, loc.getBlockZ(), Material.LOG, logType);
        }
    }
    // block below trunk is always dirt
    Dirt dirt = new Dirt(DirtType.NORMAL);
    delegate.setTypeAndData(loc.getWorld(), loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ(), Material.DIRT, dirt);
    return true;
}
Also used : Dirt(org.bukkit.material.Dirt) Material(org.bukkit.Material)

Example 12 with Material

use of org.bukkit.Material in project Glowstone by GlowstoneMC.

the class RedwoodTree method generate.

@Override
public boolean generate() {
    if (!canHeightFit() || !canPlaceOn() || !canPlace()) {
        return false;
    }
    // generate the leaves
    int radius = random.nextInt(2);
    int peakRadius = 1;
    int minRadius = 0;
    for (int y = loc.getBlockY() + height; y >= loc.getBlockY() + leavesHeight; y--) {
        // leaves are built from top to bottom
        for (int x = loc.getBlockX() - radius; x <= loc.getBlockX() + radius; x++) {
            for (int z = loc.getBlockZ() - radius; z <= loc.getBlockZ() + radius; z++) {
                if ((Math.abs(x - loc.getBlockX()) != radius || Math.abs(z - loc.getBlockZ()) != radius || radius <= 0) && delegate.getBlockState(loc.getWorld(), x, y, z).getType() == Material.AIR) {
                    delegate.setTypeAndRawData(loc.getWorld(), x, y, z, Material.LEAVES, leavesType);
                }
            }
        }
        if (radius >= peakRadius) {
            radius = minRadius;
            // after the peak radius is reached once, the min radius increases
            minRadius = 1;
            // the peak radius increases each time it's reached
            peakRadius++;
            if (peakRadius > maxRadius) {
                peakRadius = maxRadius;
            }
        } else {
            radius++;
        }
    }
    // generate the trunk
    for (int y = 0; y < height - random.nextInt(3); y++) {
        Material type = delegate.getBlockState(loc.getWorld(), loc.getBlockX(), loc.getBlockY() + y, loc.getBlockZ()).getType();
        if (overridables.contains(type)) {
            delegate.setTypeAndRawData(loc.getWorld(), loc.getBlockX(), loc.getBlockY() + y, loc.getBlockZ(), Material.LOG, logType);
        }
    }
    // block below trunk is always dirt
    Dirt dirt = new Dirt(DirtType.NORMAL);
    delegate.setTypeAndData(loc.getWorld(), loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ(), Material.DIRT, dirt);
    return true;
}
Also used : Dirt(org.bukkit.material.Dirt) Material(org.bukkit.Material)

Example 13 with Material

use of org.bukkit.Material in project Glowstone by GlowstoneMC.

the class SwampTree method generate.

@Override
public boolean generate() {
    while (loc.getBlock().getRelative(BlockFace.DOWN).getType() == Material.WATER || loc.getBlock().getRelative(BlockFace.DOWN).getType() == Material.STATIONARY_WATER) {
        loc.subtract(0, 1, 0);
    }
    if (!canHeightFit() || !canPlaceOn() || !canPlace()) {
        return false;
    }
    // generate the leaves
    for (int y = loc.getBlockY() + height - 3; y <= loc.getBlockY() + height; y++) {
        int n = y - (loc.getBlockY() + height);
        int radius = 2 - n / 2;
        for (int x = loc.getBlockX() - radius; x <= loc.getBlockX() + radius; x++) {
            for (int z = loc.getBlockZ() - radius; z <= loc.getBlockZ() + radius; z++) {
                if (Math.abs(x - loc.getBlockX()) != radius || Math.abs(z - loc.getBlockZ()) != radius || random.nextBoolean() && n != 0) {
                    Material material = delegate.getBlockState(loc.getWorld(), x, y, z).getType();
                    if (material == Material.AIR || material == Material.LEAVES) {
                        delegate.setTypeAndRawData(loc.getWorld(), x, y, z, Material.LEAVES, leavesType);
                    }
                }
            }
        }
    }
    // generate the trunk
    for (int y = 0; y < height; y++) {
        Material material = delegate.getBlockState(loc.getWorld(), loc.getBlockX(), loc.getBlockY() + y, loc.getBlockZ()).getType();
        if (material == Material.AIR || material == Material.LEAVES || material == Material.WATER || material == Material.STATIONARY_WATER) {
            delegate.setTypeAndRawData(loc.getWorld(), loc.getBlockX(), loc.getBlockY() + y, loc.getBlockZ(), Material.LOG, logType);
        }
    }
    // add some vines on the leaves
    addVinesOnLeaves();
    // block below trunk is always dirt
    Dirt dirt = new Dirt(DirtType.NORMAL);
    delegate.setTypeAndData(loc.getWorld(), loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ(), Material.DIRT, dirt);
    return true;
}
Also used : Dirt(org.bukkit.material.Dirt) Material(org.bukkit.Material)

Example 14 with Material

use of org.bukkit.Material in project Glowstone by GlowstoneMC.

the class ItemIdsTest method mappingExists.

@Test
public void mappingExists() {
    String nameid = ItemIds.getName(material);
    assertThat("Identifier missing for " + material, nameid, notNullValue());
    if (!nameid.startsWith("minecraft:")) {
        fail("Identifier '" + nameid + "' does not start with 'minecraft:'");
    }
    Material item = ItemIds.getItem(nameid);
    Material block = ItemIds.getBlock(nameid);
    String base = "Material " + material + "\t-> \"" + nameid + "\"\t-> ";
    if (material.isBlock()) {
        assertThat(base + "block, has no block entry", block, notNullValue());
        assertThat("wrong block material", block, is(material));
        if (item != material) {
            System.out.println(base + "item: " + item);
        }
    } else {
        assertThat(base + "item, has no item entry", item, notNullValue());
        assertThat("wrong item material", item, is(material));
        if (block == material) {
            fail(base + "not block, but maps to block: " + block);
        }
    }
}
Also used : Material(org.bukkit.Material) Test(org.junit.Test)

Example 15 with Material

use of org.bukkit.Material in project Glowstone by GlowstoneMC.

the class BlockTallGrass method canPlaceAt.

@Override
public boolean canPlaceAt(GlowBlock block, BlockFace against) {
    int typeIdBelow = block.getWorld().getBlockTypeIdAt(block.getX(), block.getY() - 1, block.getZ());
    Material typeBelow = Material.getMaterial(typeIdBelow);
    return typeBelow == Material.GRASS || typeBelow == Material.DIRT || typeBelow == Material.SOIL;
}
Also used : Material(org.bukkit.Material)

Aggregations

Material (org.bukkit.Material)427 ItemStack (org.bukkit.inventory.ItemStack)99 Block (org.bukkit.block.Block)87 EventHandler (org.bukkit.event.EventHandler)51 ArrayList (java.util.ArrayList)46 Player (org.bukkit.entity.Player)44 Location (org.bukkit.Location)42 Vector (org.bukkit.util.Vector)27 EntityType (org.bukkit.entity.EntityType)26 GlowBlock (net.glowstone.block.GlowBlock)24 Test (org.junit.Test)24 BlockFace (org.bukkit.block.BlockFace)23 Entity (org.bukkit.entity.Entity)22 MaterialData (org.bukkit.material.MaterialData)22 World (org.bukkit.World)20 HashMap (java.util.HashMap)19 IOException (java.io.IOException)17 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)16 File (java.io.File)15 HashSet (java.util.HashSet)13