Search in sources :

Example 6 with MaterialBrush

use of com.elmakers.mine.bukkit.api.block.MaterialBrush in project MagicPlugin by elBukkit.

the class PillarSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    Block attachBlock = getTargetBlock();
    if (attachBlock == null) {
        return SpellResult.NO_TARGET;
    }
    BlockFace direction = BlockFace.UP;
    String typeString = parameters.getString("type", "");
    if (typeString.equals("down")) {
        direction = BlockFace.DOWN;
    }
    Block targetBlock = attachBlock.getRelative(direction);
    int distance = 0;
    if (!hasBuildPermission(targetBlock)) {
        return SpellResult.INSUFFICIENT_PERMISSION;
    }
    while (isTargetable(targetBlock) && distance <= MAX_SEARCH_DISTANCE) {
        distance++;
        attachBlock = targetBlock;
        targetBlock = attachBlock.getRelative(direction);
    }
    if (isTargetable(targetBlock)) {
        return SpellResult.NO_TARGET;
    }
    if (!hasBuildPermission(targetBlock)) {
        return SpellResult.INSUFFICIENT_PERMISSION;
    }
    MaterialBrush buildWith = getBrush();
    Block pillar = targetBlock;
    buildWith.setTarget(attachBlock.getLocation(), pillar.getLocation());
    buildWith.update(mage, pillar.getLocation());
    registerForUndo(pillar);
    buildWith.modify(pillar);
    registerForUndo();
    return SpellResult.CAST;
}
Also used : MaterialBrush(com.elmakers.mine.bukkit.api.block.MaterialBrush) BlockFace(org.bukkit.block.BlockFace) Block(org.bukkit.block.Block)

Example 7 with MaterialBrush

use of com.elmakers.mine.bukkit.api.block.MaterialBrush in project MagicPlugin by elBukkit.

the class PlaceSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    Target attachToBlock = getTarget();
    if (!attachToBlock.isValid())
        return SpellResult.NO_TARGET;
    Block placeBlock = getPreviousBlock();
    if (placeBlock == null)
        return SpellResult.NO_TARGET;
    if (!hasBuildPermission(placeBlock)) {
        return SpellResult.INSUFFICIENT_PERMISSION;
    }
    MaterialBrush buildWith = getBrush();
    buildWith.setTarget(attachToBlock.getLocation(), placeBlock.getLocation());
    buildWith.update(mage, placeBlock.getLocation());
    registerForUndo(placeBlock);
    buildWith.modify(placeBlock);
    registerForUndo();
    return SpellResult.CAST;
}
Also used : Target(com.elmakers.mine.bukkit.utility.Target) MaterialBrush(com.elmakers.mine.bukkit.api.block.MaterialBrush) Block(org.bukkit.block.Block)

Example 8 with MaterialBrush

use of com.elmakers.mine.bukkit.api.block.MaterialBrush in project MagicPlugin by elBukkit.

the class TossSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    Location location = getLocation();
    if (!hasBuildPermission(location.getBlock())) {
        return SpellResult.INSUFFICIENT_PERMISSION;
    }
    location.setY(location.getY() - 1);
    MaterialBrush buildWith = getBrush();
    buildWith.setTarget(location);
    Material material = buildWith.getMaterial();
    byte data = buildWith.getBlockData();
    int tossCount = 1;
    tossCount = parameters.getInt("count", tossCount);
    tossCount = (int) (mage.getRadiusMultiplier() * tossCount);
    float speed = 0.6f;
    speed = (float) parameters.getDouble("speed", speed);
    Vector direction = getDirection();
    direction.normalize().multiply(speed);
    Vector up = new Vector(0, 1, 0);
    Vector perp = new Vector();
    perp.copy(direction);
    perp.crossProduct(up);
    for (int i = 0; i < tossCount; i++) {
        FallingBlock block = null;
        location = getEyeLocation();
        location.setX(location.getX() + perp.getX() * (Math.random() * tossCount / 4 - tossCount / 8));
        location.setY(location.getY());
        location.setZ(location.getZ() + perp.getZ() * (Math.random() * tossCount / 4 - tossCount / 8));
        block = getWorld().spawnFallingBlock(location, material, data);
        if (block == null) {
            registerForUndo();
            return SpellResult.FAIL;
        }
        registerForUndo(block);
        block.setDropItem(false);
        SafetyUtils.setVelocity(block, direction);
    }
    registerForUndo();
    return SpellResult.CAST;
}
Also used : FallingBlock(org.bukkit.entity.FallingBlock) MaterialBrush(com.elmakers.mine.bukkit.api.block.MaterialBrush) Material(org.bukkit.Material) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 9 with MaterialBrush

use of com.elmakers.mine.bukkit.api.block.MaterialBrush in project MagicPlugin by elBukkit.

the class BreakBlockAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Block block = context.getTargetBlock();
    if (block.getType() == Material.AIR || !context.isDestructible(block)) {
        return SpellResult.NO_TARGET;
    }
    context.registerForUndo(block);
    double scaledAmount = durabilityAmount;
    if (maxDistanceSquared > 0) {
        double distanceSquared = context.getTargetCenterLocation().distanceSquared(block.getLocation());
        if (distanceSquared > maxDistanceSquared) {
            return SpellResult.NO_TARGET;
        }
        if (distanceSquared > 0) {
            scaledAmount = scaledAmount * (1 - distanceSquared / maxDistanceSquared);
        }
    }
    double breakAmount = 1;
    double durability = CompatibilityUtils.getDurability(block.getType());
    if (durability > 0) {
        double breakPercentage = scaledAmount / durability;
        breakAmount = context.registerBreaking(block, breakPercentage);
    }
    if (breakAmount > 1) {
        if (context.hasBreakPermission(block)) {
            CompatibilityUtils.clearBreaking(block);
            BlockState blockState = block.getState();
            if (blockState != null && (blockState instanceof InventoryHolder || blockState.getType() == Material.FLOWER_POT)) {
                NMSUtils.clearItems(blockState.getLocation());
            }
            MaterialBrush brush = context.getBrush();
            if (brush == null) {
                brush = new com.elmakers.mine.bukkit.block.MaterialBrush(context.getMage(), Material.AIR, (byte) 0);
                context.setBrush(brush);
            } else {
                brush.setMaterial(Material.AIR);
            }
            super.perform(context);
            context.unregisterBreaking(block);
            context.playEffects("break");
        }
    } else {
        CompatibilityUtils.setBreaking(block, breakAmount);
    }
    return SpellResult.CAST;
}
Also used : BlockState(org.bukkit.block.BlockState) MaterialBrush(com.elmakers.mine.bukkit.api.block.MaterialBrush) Block(org.bukkit.block.Block) InventoryHolder(org.bukkit.inventory.InventoryHolder)

Example 10 with MaterialBrush

use of com.elmakers.mine.bukkit.api.block.MaterialBrush in project MagicPlugin by elBukkit.

the class ShapeSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    Target t = getTarget();
    Block target = t.getBlock();
    if (target == null) {
        return SpellResult.NO_TARGET;
    }
    int radius = parameters.getInt("radius", DEFAULT_RADIUS);
    radius = parameters.getInt("r", radius);
    Location orientTo = null;
    if (getTargetType() == TargetType.SELECT) {
        if (targetLocation2 != null) {
            this.targetBlock = targetLocation2.getBlock();
        }
        if (targetBlock == null) {
            targetBlock = target;
            activate();
            return SpellResult.TARGET_SELECTED;
        } else {
            radius = (int) targetBlock.getLocation().distance(target.getLocation());
            orientTo = target.getLocation();
            target = targetBlock;
        }
    }
    int maxDimension = parameters.getInt("max_dimension", DEFAULT_MAX_DIMENSION);
    maxDimension = parameters.getInt("md", maxDimension);
    maxDimension = (int) (mage.getConstructionMultiplier() * maxDimension);
    int diameter = radius * 2;
    if (diameter > maxDimension) {
        return SpellResult.FAIL;
    }
    if (!hasBuildPermission(target)) {
        return SpellResult.INSUFFICIENT_PERMISSION;
    }
    MaterialBrush buildWith = getBrush();
    buildWith.setTarget(target.getLocation());
    ConstructionType conType = DEFAULT_CONSTRUCTION_TYPE;
    String typeString = parameters.getString("type", "");
    ConstructionType testType = ConstructionType.parseString(typeString, ConstructionType.UNKNOWN);
    if (testType != ConstructionType.UNKNOWN) {
        conType = testType;
    }
    int thickness = parameters.getInt("thickness", 1);
    ShapeBatch batch = new ShapeBatch(this, target.getLocation(), conType, radius, thickness, orientTo);
    if (parameters.contains("orient_dimension_max")) {
        batch.setOrientDimensionMax(parameters.getInt("orient_dimension_max"));
    } else if (parameters.contains("odmax")) {
        batch.setOrientDimensionMax(parameters.getInt("odmax"));
    }
    if (parameters.contains("orient_dimension_min")) {
        batch.setOrientDimensionMin(parameters.getInt("orient_dimension_min"));
    } else if (parameters.contains("odmin")) {
        batch.setOrientDimensionMin(parameters.getInt("odmin"));
    }
    boolean success = mage.addBatch(batch);
    deactivate();
    return success ? SpellResult.CAST : SpellResult.FAIL;
}
Also used : Target(com.elmakers.mine.bukkit.utility.Target) MaterialBrush(com.elmakers.mine.bukkit.api.block.MaterialBrush) ConstructionType(com.elmakers.mine.bukkit.block.ConstructionType) Block(org.bukkit.block.Block) ShapeBatch(com.elmakers.mine.bukkit.batch.ShapeBatch) Location(org.bukkit.Location)

Aggregations

MaterialBrush (com.elmakers.mine.bukkit.api.block.MaterialBrush)20 Block (org.bukkit.block.Block)14 Location (org.bukkit.Location)8 Vector (org.bukkit.util.Vector)7 Material (org.bukkit.Material)6 FallingBlock (org.bukkit.entity.FallingBlock)4 Target (com.elmakers.mine.bukkit.utility.Target)3 UndoList (com.elmakers.mine.bukkit.api.block.UndoList)2 Mage (com.elmakers.mine.bukkit.api.magic.Mage)2 ConstructionType (com.elmakers.mine.bukkit.block.ConstructionType)2 UndoList (com.elmakers.mine.bukkit.block.UndoList)2 BlockFace (org.bukkit.block.BlockFace)2 BlockState (org.bukkit.block.BlockState)2 ItemStack (org.bukkit.inventory.ItemStack)2 BlockData (com.elmakers.mine.bukkit.api.block.BlockData)1 BlockList (com.elmakers.mine.bukkit.api.block.BlockList)1 MaterialAndData (com.elmakers.mine.bukkit.api.block.MaterialAndData)1 UndoQueue (com.elmakers.mine.bukkit.api.block.UndoQueue)1 EntityData (com.elmakers.mine.bukkit.api.entity.EntityData)1 ConstructBatch (com.elmakers.mine.bukkit.batch.ConstructBatch)1