Search in sources :

Example 6 with Material

use of org.bukkit.Material in project Denizen-For-Bukkit by DenizenScript.

the class StatisticCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    Element action = scriptEntry.getElement("action");
    dList players = scriptEntry.getdObject("players");
    Element statistic = scriptEntry.getElement("statistic");
    Element amount = scriptEntry.getElement("amount");
    dMaterial material = scriptEntry.getdObject("material");
    dEntity entity = scriptEntry.getdObject("entity");
    dB.report(scriptEntry, getName(), action.debug() + statistic.debug() + amount.debug() + players.debug() + (material != null ? material.debug() : entity != null ? entity.debug() : ""));
    Action act = Action.valueOf(action.asString().toUpperCase());
    Statistic stat = Statistic.valueOf(statistic.asString().toUpperCase());
    int amt = amount.asInt();
    switch(stat.getType()) {
        case BLOCK:
        case ITEM:
            Material mat = material.getMaterial();
            switch(act) {
                case ADD:
                    for (dPlayer player : players.filter(dPlayer.class)) {
                        player.incrementStatistic(stat, mat, amt);
                    }
                    break;
                case TAKE:
                    for (dPlayer player : players.filter(dPlayer.class)) {
                        player.decrementStatistic(stat, mat, amt);
                    }
                    break;
                case SET:
                    for (dPlayer player : players.filter(dPlayer.class)) {
                        player.setStatistic(stat, mat, amt);
                    }
                    break;
            }
            break;
        case ENTITY:
            EntityType ent = entity.getBukkitEntityType();
            switch(act) {
                case ADD:
                    for (dPlayer player : players.filter(dPlayer.class)) {
                        player.incrementStatistic(stat, ent, amt);
                    }
                    break;
                case TAKE:
                    for (dPlayer player : players.filter(dPlayer.class)) {
                        player.decrementStatistic(stat, ent, amt);
                    }
                    break;
                case SET:
                    for (dPlayer player : players.filter(dPlayer.class)) {
                        player.setStatistic(stat, ent, amt);
                    }
                    break;
            }
            break;
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) net.aufdemrand.denizen.objects.dMaterial(net.aufdemrand.denizen.objects.dMaterial) Statistic(org.bukkit.Statistic) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) net.aufdemrand.denizen.objects.dMaterial(net.aufdemrand.denizen.objects.dMaterial) Material(org.bukkit.Material)

Example 7 with Material

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

the class ItemType method setId.

/**
     * Assign an id number to this ItemType (for internal use only).
     *
     * @param id The internal item id for this item.
     */
public final void setId(int id) {
    if (this.id != -1) {
        throw new IllegalStateException("Id is already set in " + this);
    }
    this.id = id;
    // pull a few defaults from Material if possible
    Material mat = getMaterial();
    if (mat != null) {
        maxStackSize = mat.getMaxStackSize();
    }
}
Also used : Material(org.bukkit.Material)

Example 8 with Material

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

the class GlowBlock method applyPhysics.

/////////////////////////////////////////////////////////////////////////////
// Physics
/**
     * Notify this block and its surrounding blocks that this block has changed
     * type and data.
     *
     * @param oldType   the old block type
     * @param newTypeId the new block type
     * @param oldData   the old data
     * @param newData   the new data
     */
public void applyPhysics(Material oldType, int newTypeId, byte oldData, byte newData) {
    // notify the surrounding blocks that this block has changed
    ItemTable itemTable = ItemTable.instance();
    Material newType = Material.getMaterial(newTypeId);
    for (int y = -1; y <= 1; y++) {
        for (BlockFace face : LAYER) {
            if (y == 0 && face == BlockFace.SELF) {
                continue;
            }
            GlowBlock notify = getRelative(face.getModX(), face.getModY() + y, face.getModZ());
            BlockFace blockFace;
            if (y == 0) {
                blockFace = face.getOppositeFace();
            } else if (y == -1 && face == BlockFace.SELF) {
                blockFace = BlockFace.UP;
            } else if (y == 1 && face == BlockFace.SELF) {
                blockFace = BlockFace.DOWN;
            } else {
                blockFace = null;
            }
            BlockType notifyType = itemTable.getBlock(notify.getTypeId());
            if (notifyType != null) {
                notifyType.onNearBlockChanged(notify, blockFace, this, oldType, oldData, newType, newData);
            }
        }
    }
    BlockType type = itemTable.getBlock(oldType);
    if (type != null) {
        type.onBlockChanged(this, oldType, oldData, newType, newData);
    }
}
Also used : BlockType(net.glowstone.block.blocktype.BlockType) BlockFace(org.bukkit.block.BlockFace) Material(org.bukkit.Material)

Example 9 with Material

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

the class TallRedwoodTree method generate.

@Override
public boolean generate() {
    if (!canHeightFit() || !canPlaceOn() || !canPlace()) {
        return false;
    }
    // generate the leaves
    int radius = 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 >= 1 && y == loc.getBlockY() + leavesHeight + 1) {
            radius--;
        } else if (radius < maxRadius) {
            radius++;
        }
    }
    // generate the trunk
    for (int y = 0; y < height - 1; y++) {
        Material type = delegate.getBlockState(loc.getWorld(), loc.getBlockX(), loc.getBlockY() + y, loc.getBlockZ()).getType();
        if (type == Material.AIR || type == 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 10 with Material

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

the class DarkOakTree method generate.

@Override
public boolean generate() {
    if (!canHeightFit() || !canPlaceOn() || !canPlace()) {
        return false;
    }
    // random direction
    float d = (float) (random.nextFloat() * Math.PI * 2.0F);
    int dx = (int) (Math.cos(d) + 1.5F) - 1;
    int dz = (int) (Math.sin(d) + 1.5F) - 1;
    if (Math.abs(dx) > 0 && Math.abs(dz) > 0) {
        // reduce possible directions to NESW
        if (random.nextBoolean()) {
            dx = 0;
        } else {
            dz = 0;
        }
    }
    int twistHeight = height - random.nextInt(4);
    int twistCount = random.nextInt(3);
    int centerX = loc.getBlockX(), centerZ = loc.getBlockZ();
    int trunkTopY = 0;
    // generates the trunk
    for (int y = 0; y < height; y++) {
        // trunk twists
        if (twistCount > 0 && y >= twistHeight) {
            centerX += dx;
            centerZ += dz;
            twistCount--;
        }
        Material material = delegate.getBlockState(loc.getWorld(), centerX, loc.getBlockY() + y, centerZ).getType();
        if (material == Material.AIR || material == Material.LEAVES) {
            trunkTopY = loc.getBlockY() + y;
            // SELF, SOUTH, EAST, SOUTH EAST
            delegate.setTypeAndRawData(loc.getWorld(), centerX, loc.getBlockY() + y, centerZ, Material.LOG_2, 1);
            delegate.setTypeAndRawData(loc.getWorld(), centerX, loc.getBlockY() + y, centerZ + 1, Material.LOG_2, 1);
            delegate.setTypeAndRawData(loc.getWorld(), centerX + 1, loc.getBlockY() + y, centerZ, Material.LOG_2, 1);
            delegate.setTypeAndRawData(loc.getWorld(), centerX + 1, loc.getBlockY() + y, centerZ + 1, Material.LOG_2, 1);
        }
    }
    // generates leaves
    for (int x = -2; x <= 0; x++) {
        for (int z = -2; z <= 0; z++) {
            if ((x != -1 || z != -2) && (x > -2 || z > -1)) {
                setLeaves(centerX + x, trunkTopY + 1, centerZ + z);
                setLeaves(1 + centerX - x, trunkTopY + 1, centerZ + z);
                setLeaves(centerX + x, trunkTopY + 1, 1 + centerZ - z);
                setLeaves(1 + centerX - x, trunkTopY + 1, 1 + centerZ - z);
            }
            setLeaves(centerX + x, trunkTopY - 1, centerZ + z);
            setLeaves(1 + centerX - x, trunkTopY - 1, centerZ + z);
            setLeaves(centerX + x, trunkTopY - 1, 1 + centerZ - z);
            setLeaves(1 + centerX - x, trunkTopY - 1, 1 + centerZ - z);
        }
    }
    // finish leaves below the canopy
    for (int x = -3; x <= 4; x++) {
        for (int z = -3; z <= 4; z++) {
            if (Math.abs(x) < 3 || Math.abs(z) < 3) {
                setLeaves(centerX + x, trunkTopY, centerZ + z);
            }
        }
    }
    // generates some trunk excrescences
    for (int x = -1; x <= 2; x++) {
        for (int z = -1; z <= 2; z++) {
            if ((x == -1 || z == -1 || x == 2 || z == 2) && random.nextInt(3) == 0) {
                for (int y = 0; y < random.nextInt(3) + 2; y++) {
                    Material material = delegate.getBlockState(loc.getWorld(), loc.getBlockX() + x, trunkTopY - y - 1, loc.getBlockZ() + z).getType();
                    if (material == Material.AIR || material == Material.LEAVES) {
                        delegate.setTypeAndRawData(loc.getWorld(), loc.getBlockX() + x, trunkTopY - y - 1, loc.getBlockZ() + z, Material.LOG_2, 1);
                    }
                }
                // leaves below the canopy
                for (int i = -1; i <= 1; i++) {
                    for (int j = -1; j <= 1; j++) {
                        setLeaves(centerX + x + i, trunkTopY, centerZ + z + j);
                    }
                }
                for (int i = -2; i <= 2; i++) {
                    for (int j = -2; j <= 2; j++) {
                        if (Math.abs(i) < 2 || Math.abs(j) < 2) {
                            setLeaves(centerX + x + i, trunkTopY - 1, centerZ + z + j);
                        }
                    }
                }
            }
        }
    }
    // 50% chance to have a 4 leaves cap on the center of the canopy
    if (random.nextInt(2) == 0) {
        setLeaves(centerX, trunkTopY + 2, centerZ);
        setLeaves(centerX + 1, trunkTopY + 2, centerZ);
        setLeaves(centerX + 1, trunkTopY + 2, centerZ + 1);
        setLeaves(centerX, trunkTopY + 2, centerZ + 1);
    }
    // block below trunk is always dirt (SELF, SOUTH, EAST, SOUTH EAST)
    Dirt dirt = new Dirt(DirtType.NORMAL);
    delegate.setTypeAndData(loc.getWorld(), loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ(), Material.DIRT, dirt);
    delegate.setTypeAndData(loc.getWorld(), loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ() + 1, Material.DIRT, dirt);
    delegate.setTypeAndData(loc.getWorld(), loc.getBlockX() + 1, loc.getBlockY() - 1, loc.getBlockZ(), Material.DIRT, dirt);
    delegate.setTypeAndData(loc.getWorld(), loc.getBlockX() + 1, loc.getBlockY() - 1, loc.getBlockZ() + 1, Material.DIRT, dirt);
    return true;
}
Also used : Dirt(org.bukkit.material.Dirt) 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