use of com.elmakers.mine.bukkit.api.block.MaterialBrush in project MagicPlugin by elBukkit.
the class ThrowBlockAction method start.
@Override
public SpellResult start(CastContext context) {
Location location = context.getLocation();
if (!context.hasBuildPermission(location.getBlock())) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
location.setY(location.getY() - 1);
MaterialBrush buildWith = context.getBrush();
buildWith.setTarget(location);
if (buildWith.isErase() || buildWith.getMaterial() == Material.AIR) {
return SpellResult.NO_TARGET;
}
if (consumeBlocks && !context.isConsumeFree()) {
Mage mage = context.getMage();
UndoList undoList = context.getUndoList();
if (undoList != null) {
undoList.setConsumed(true);
}
ItemStack requires = buildWith.getItemStack(1);
if (!mage.hasItem(requires, consumeVariants)) {
String requiresMessage = context.getMessage("insufficient_resources");
context.sendMessage(requiresMessage.replace("$cost", buildWith.getName()));
return SpellResult.STOP;
}
mage.removeItem(requires, consumeVariants);
}
Material material = buildWith.getMaterial();
byte data = buildWith.getBlockData();
location = sourceLocation.getLocation(context);
Vector direction = location.getDirection();
double speed = context.getRandom().nextDouble() * (speedMax - speedMin) + speedMin;
direction.normalize().multiply(speed);
Vector up = new Vector(0, 1, 0);
Vector perp = new Vector();
perp.copy(direction);
perp.crossProduct(up);
FallingBlock falling = DeprecatedUtils.spawnFallingBlock(location, material, data);
if (falling == null) {
return SpellResult.FAIL;
}
track(context, falling);
if (!consumeBlocks) {
falling.setDropItem(false);
}
SafetyUtils.setVelocity(falling, direction);
if (maxDamage > 0 && fallDamage > 0) {
CompatibilityUtils.setFallingBlockDamage(falling, fallDamage, maxDamage);
} else {
falling.setHurtEntities(hurts);
}
return checkTracking(context);
}
use of com.elmakers.mine.bukkit.api.block.MaterialBrush in project MagicPlugin by elBukkit.
the class VolumeAction method calculateSize.
protected boolean calculateSize(CastContext context) {
if (useBrushSize) {
MaterialBrush brush = context.getBrush();
if (!brush.isReady()) {
return false;
}
Vector bounds = brush.getSize();
xSize = (int) Math.ceil(bounds.getX() / 2) + 1;
ySize = (int) Math.ceil(bounds.getY() / 2) + 1;
zSize = (int) Math.ceil(bounds.getZ() / 2) + 1;
if (volumeType == VolumeType.SPIRAL) {
xSize = Math.max(xSize, zSize);
zSize = Math.max(xSize, zSize);
}
centerY = false;
context.getMage().sendDebugMessage(ChatColor.GREEN + "Brush Size: " + ChatColor.GRAY + xSize + "," + ySize + "," + zSize, 2);
} else if (!appliedMultiplier) {
xSize = context.getMage().getRadiusMultiplier() * this.xSize;
ySize = context.getMage().getRadiusMultiplier() * this.ySize;
zSize = context.getMage().getRadiusMultiplier() * this.zSize;
appliedMultiplier = true;
}
if (volumeType == VolumeType.SPIRAL && xSize != zSize) {
volumeType = VolumeType.YZX;
}
xSizeCeil = (int) Math.ceil(xSize);
ySizeCeil = (int) Math.ceil(ySize);
zSizeCeil = (int) Math.ceil(zSize);
if (centerY) {
yStart = -ySizeCeil;
yEnd = ySizeCeil;
} else {
yStart = 0;
yEnd = ySizeCeil * 2;
}
if (!centerX) {
xOffset = xSizeCeil;
} else {
xOffset = 0;
}
if (!centerZ) {
zOffset = zSizeCeil;
} else {
zOffset = 0;
}
if (volumeType != VolumeType.SPIRAL) {
min = new Vector(-xSizeCeil, yStart, -zSizeCeil);
max = new Vector(xSizeCeil, yEnd, zSizeCeil);
}
radius = Math.max(xSize, zSize);
spiralRadius = (int) Math.ceil(radius);
radius = Math.max(radius, ySize);
radiusSquared = (radius + radiusPadding) * (radius + radiusPadding);
startRadius = getStartRadius();
return true;
}
use of com.elmakers.mine.bukkit.api.block.MaterialBrush in project MagicPlugin by elBukkit.
the class BrushBatch method finish.
@Override
public void finish() {
if (!finished) {
MaterialBrush brush = spell.getBrush();
if (brush != null && brush.hasEntities()) {
// Copy over new entities
Collection<EntityData> entities = brush.getEntities();
// Delete any entities already in the area, add them to the undo list.
Collection<Entity> targetEntities = brush.getTargetEntities();
if (targetEntities != null) {
for (Entity entity : targetEntities) {
if (contains(entity.getLocation())) {
undoList.modify(entity);
entity.remove();
}
}
}
if (entities != null) {
for (EntityData entity : entities) {
if (contains(entity.getLocation())) {
undoList.add(entity.spawn());
}
}
}
}
super.finish();
}
}
use of com.elmakers.mine.bukkit.api.block.MaterialBrush in project MagicPlugin by elBukkit.
the class BridgeSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
Block playerBlock = getPlayerBlock();
if (playerBlock == null) {
// no spot found to bridge
return SpellResult.NO_TARGET;
}
if (!hasBuildPermission(playerBlock)) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
BlockFace direction = getPlayerFacing();
Block attachBlock = playerBlock;
Block targetBlock = attachBlock;
int distance = 0;
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();
buildWith.setTarget(attachBlock.getLocation(), targetBlock.getLocation());
buildWith.update(mage, targetBlock.getLocation());
registerForUndo(targetBlock);
buildWith.modify(targetBlock);
registerForUndo();
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.api.block.MaterialBrush in project MagicPlugin by elBukkit.
the class FillSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
boolean singleBlock = getTargetType() != TargetType.SELECT;
Block targetBlock = getTargetBlock();
if (!singleBlock && parameters.getBoolean("select_self", true) && isLookingDown()) {
targetBlock = mage.getLocation().getBlock().getRelative(BlockFace.DOWN);
}
if (targetBlock == null) {
return SpellResult.NO_TARGET;
}
MaterialBrush buildWith = getBrush();
boolean hasPermission = buildWith != null && buildWith.isErase() ? hasBreakPermission(targetBlock) : hasBuildPermission(targetBlock);
if (!hasPermission) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
if (singleBlock) {
deactivate();
if (isIndestructible(targetBlock)) {
return SpellResult.NO_TARGET;
}
registerForUndo(targetBlock);
buildWith.setTarget(targetBlock.getLocation());
buildWith.update(mage, targetBlock.getLocation());
buildWith.modify(targetBlock);
controller.updateBlock(targetBlock);
registerForUndo();
return SpellResult.CAST;
}
if (targetLocation2 != null) {
this.targetBlock = targetLocation2.getBlock();
}
if (this.targetBlock != null) {
// Update the brush using the center of the fill volume.
// This is kind of a hack to make map-building easier
Location centerLocation = this.targetBlock.getLocation();
Location secondLocation = this.targetBlock.getLocation();
if (buildWith.getMode() == BrushMode.MAP) {
centerLocation = targetBlock.getLocation();
centerLocation.setX(Math.floor((centerLocation.getX() + secondLocation.getX()) / 2));
centerLocation.setY(Math.floor((centerLocation.getY() + secondLocation.getY()) / 2));
centerLocation.setZ(Math.floor((centerLocation.getZ() + secondLocation.getZ()) / 2));
}
buildWith.setTarget(this.targetBlock.getLocation(), centerLocation);
FillBatch batch = new FillBatch(this, secondLocation, targetBlock.getLocation(), buildWith);
boolean consumeBlocks = parameters.getBoolean("consume", false);
batch.setConsume(consumeBlocks);
UndoList undoList = getUndoList();
if (undoList != null && !currentCast.isConsumeFree()) {
undoList.setConsumed(consumeBlocks);
}
int maxDimension = parameters.getInt("max_dimension", DEFAULT_MAX_DIMENSION);
maxDimension = parameters.getInt("md", maxDimension);
maxDimension = (int) (mage.getConstructionMultiplier() * maxDimension);
if (!batch.checkDimension(maxDimension)) {
return SpellResult.FAIL;
}
boolean success = mage.addBatch(batch);
deactivate();
return success ? SpellResult.CAST : SpellResult.FAIL;
} else {
this.targetBlock = targetBlock;
activate();
return SpellResult.TARGET_SELECTED;
}
}
Aggregations