Search in sources :

Example 1 with MaterialBrush

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

the class BrushSpell method processParameters.

@Override
public void processParameters(ConfigurationSection parameters) {
    super.processParameters(parameters);
    brushKey = parameters.getString("brush", null);
    brushIsErase = brushKey != null && (brushKey.equalsIgnoreCase("erase") || brushKey.equalsIgnoreCase("air"));
    hasBrush = brushKey != null && !brushKey.isEmpty();
    if (hasBrush) {
        brush = new MaterialBrush(mage, getLocation(), brushKey);
        if (parameters.getBoolean("preserve_data", false)) {
            brush.setData(null);
        }
        if (parameters.contains("brushmod")) {
            brush.update(parameters.getString("brushmod"));
            brush.update(brushKey);
        }
        Double dmxValue = ConfigurationUtils.getDouble(parameters, "obx", null);
        Double dmyValue = ConfigurationUtils.getDouble(parameters, "oby", null);
        Double dmzValue = ConfigurationUtils.getDouble(parameters, "obz", null);
        String targetWorldName = parameters.getString("obworld", null);
        if (dmxValue != null || dmyValue != null || dmzValue != null || targetWorldName != null) {
            Vector offset = new Vector(dmxValue == null ? 0 : dmxValue, dmyValue == null ? 0 : dmyValue, dmzValue == null ? 0 : dmzValue);
            brush.clearCloneTarget();
            brush.setTargetOffset(offset, targetWorldName);
        }
        if (parameters.getBoolean("brushtarget", false)) {
            brush.clearCloneLocation();
        }
        if (parameters.getBoolean("brushcolor", false)) {
            Color color = mage.getEffectColor();
            if (color != null) {
                DyeColor bestDyeColor = null;
                Double bestDistance = null;
                for (DyeColor testDyeColor : DyeColor.values()) {
                    Color testColor = testDyeColor.getColor();
                    double testDistance = ColorHD.getDistance(testColor, color);
                    if (bestDistance == null || testDistance < bestDistance) {
                        bestDistance = testDistance;
                        bestDyeColor = testDyeColor;
                        if (testDistance == 0)
                            break;
                    }
                }
                if (bestDyeColor != null) {
                    brush.setData((short) DeprecatedUtils.getWoolData(bestDyeColor));
                }
            }
        }
    } else {
        brush = null;
    }
}
Also used : MaterialBrush(com.elmakers.mine.bukkit.block.MaterialBrush) DyeColor(org.bukkit.DyeColor) Color(org.bukkit.Color) DyeColor(org.bukkit.DyeColor) Vector(org.bukkit.util.Vector)

Example 2 with MaterialBrush

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

the class BrushAction method step.

@Override
public SpellResult step(CastContext context) {
    if (brushes.size() == 0 && !sample) {
        return startActions();
    }
    if (sample) {
        Block targetBlock = context.getTargetBlock();
        if (targetBlock != null) {
            Mage mage = context.getMage();
            MaterialBrush brush = new MaterialBrush(mage, targetBlock);
            actionContext.setBrush(brush);
        }
    } else {
        String brushKey = brushes.get(context.getRandom().nextInt(brushes.size()));
        MaterialBrush brush = new MaterialBrush(context.getMage(), context.getLocation(), brushKey);
        actionContext.setBrush(brush);
    }
    return startActions();
}
Also used : MaterialBrush(com.elmakers.mine.bukkit.block.MaterialBrush) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Block(org.bukkit.block.Block)

Example 3 with MaterialBrush

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

the class Wand method createBrushItem.

@Nullable
public static ItemStack createBrushItem(String materialKey, com.elmakers.mine.bukkit.api.magic.MageController controller, Wand wand, boolean isItem) {
    MaterialBrush brushData = MaterialBrush.parseMaterialKey(materialKey);
    if (brushData == null)
        return null;
    ItemStack itemStack = brushData.getItem(controller, isItem);
    if (BrushGlow || (isItem && BrushItemGlow)) {
        CompatibilityUtils.addGlow(itemStack);
    }
    InventoryUtils.makeUnbreakable(itemStack);
    InventoryUtils.hideFlags(itemStack, (byte) 63);
    updateBrushItem(controller.getMessages(), itemStack, brushData, wand);
    return itemStack;
}
Also used : MaterialBrush(com.elmakers.mine.bukkit.block.MaterialBrush) ItemStack(org.bukkit.inventory.ItemStack) Nullable(javax.annotation.Nullable)

Aggregations

MaterialBrush (com.elmakers.mine.bukkit.block.MaterialBrush)3 Mage (com.elmakers.mine.bukkit.api.magic.Mage)1 Nullable (javax.annotation.Nullable)1 Color (org.bukkit.Color)1 DyeColor (org.bukkit.DyeColor)1 Block (org.bukkit.block.Block)1 ItemStack (org.bukkit.inventory.ItemStack)1 Vector (org.bukkit.util.Vector)1