Search in sources :

Example 1 with BoundingBox

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

the class CuboidTag method getEntitiesPossiblyWithinForTag.

public Collection<Entity> getEntitiesPossiblyWithinForTag() {
    WorldTag world = getWorld();
    if (pairs.size() != 1) {
        return world.getEntitiesForTag();
    }
    BoundingBox box = BoundingBox.of(getLow(0).toVector(), getHigh(0).toVector().add(new Vector(1, 1, 1)));
    return world.getPossibleEntitiesForBoundary(box);
}
Also used : BoundingBox(org.bukkit.util.BoundingBox) Vector(org.bukkit.util.Vector)

Example 2 with BoundingBox

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

the class PushCommand method execute.

@Override
public void execute(final ScriptEntry scriptEntry) {
    EntityTag originEntity = scriptEntry.getObjectTag("origin_entity");
    LocationTag originLocation = scriptEntry.hasObject("origin_location") ? (LocationTag) scriptEntry.getObject("origin_location") : new LocationTag(originEntity.getEyeLocation().add(originEntity.getEyeLocation().getDirection()).subtract(0, 0.4, 0));
    boolean no_rotate = scriptEntry.hasObject("no_rotate") && scriptEntry.getElement("no_rotate").asBoolean();
    final boolean no_damage = scriptEntry.hasObject("no_damage") && scriptEntry.getElement("no_damage").asBoolean();
    // If there is no destination set, but there is a shooter, get a point in front of the shooter and set it as the destination
    final LocationTag destination = scriptEntry.hasObject("destination") ? (LocationTag) scriptEntry.getObject("destination") : (originEntity != null ? new LocationTag(originEntity.getEyeLocation().add(originEntity.getEyeLocation().getDirection().multiply(30))) : null);
    // TODO: Should this be checked in argument parsing?
    if (destination == null) {
        Debug.echoError("No destination specified!");
        scriptEntry.setFinished(true);
        return;
    }
    List<EntityTag> entities = (List<EntityTag>) scriptEntry.getObject("entities");
    final ScriptTag script = scriptEntry.getObjectTag("script");
    final ListTag definitions = scriptEntry.getObjectTag("definitions");
    ElementTag speedElement = scriptEntry.getElement("speed");
    DurationTag duration = (DurationTag) scriptEntry.getObject("duration");
    ElementTag force_along = scriptEntry.getElement("force_along");
    ElementTag precision = scriptEntry.getElement("precision");
    ElementTag ignore_collision = scriptEntry.getElement("ignore_collision");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), db("origin", originEntity != null ? originEntity : originLocation), db("entities", entities), destination, speedElement, duration, script, force_along, precision, (no_rotate ? db("no_rotate", "true") : ""), (no_damage ? db("no_damage", "true") : ""), ignore_collision, definitions);
    }
    final boolean ignoreCollision = ignore_collision != null && ignore_collision.asBoolean();
    final double speed = speedElement.asDouble();
    final int maxTicks = duration.getTicksAsInt();
    final boolean forceAlong = force_along.asBoolean();
    // Keep a ListTag of entities that can be called using <entry[name].pushed_entities> later in the script queue
    final ListTag entityList = new ListTag();
    for (EntityTag entity : entities) {
        entity.spawnAt(originLocation);
        entityList.addObject(entity);
        if (!no_rotate) {
            NMSHandler.getEntityHelper().faceLocation(entity.getBukkitEntity(), destination);
        }
        if (entity.isProjectile() && originEntity != null) {
            entity.setShooter(originEntity);
        }
    }
    scriptEntry.addObject("pushed_entities", entityList);
    Position.mount(Conversion.convertEntities(entities));
    final EntityTag lastEntity = entities.get(entities.size() - 1);
    final Vector v2 = destination.toVector();
    final Vector Origin = originLocation.toVector();
    final int prec = precision.asInt();
    BukkitRunnable task = new BukkitRunnable() {

        int runs = 0;

        LocationTag lastLocation;

        @Override
        public void run() {
            if (runs < maxTicks && lastEntity.isValid()) {
                Vector v1 = lastEntity.getLocation().toVector();
                Vector v3 = v2.clone().subtract(v1).normalize();
                if (forceAlong) {
                    Vector newDest = v2.clone().subtract(Origin).normalize().multiply(runs * speed).add(Origin);
                    lastEntity.teleport(new Location(lastEntity.getLocation().getWorld(), newDest.getX(), newDest.getY(), newDest.getZ(), lastEntity.getLocation().getYaw(), lastEntity.getLocation().getPitch()));
                }
                runs += prec;
                // Check if the entity is close to its destination
                if (Math.abs(v2.getX() - v1.getX()) < 1.5f && Math.abs(v2.getY() - v1.getY()) < 1.5f && Math.abs(v2.getZ() - v1.getZ()) < 1.5f) {
                    runs = maxTicks;
                    return;
                }
                Vector newVel = v3.multiply(speed);
                lastEntity.setVelocity(newVel);
                if (!ignoreCollision && lastEntity.isValid()) {
                    BoundingBox box = lastEntity.getBukkitEntity().getBoundingBox().expand(newVel);
                    Location ref = lastEntity.getLocation().clone();
                    for (int x = (int) Math.floor(box.getMinX()); x < Math.ceil(box.getMaxX()); x++) {
                        ref.setX(x);
                        for (int y = (int) Math.floor(box.getMinY()); y < Math.ceil(box.getMaxY()); y++) {
                            ref.setY(y);
                            for (int z = (int) Math.floor(box.getMinZ()); z < Math.ceil(box.getMaxZ()); z++) {
                                ref.setZ(z);
                                if (!isSafeBlock(ref)) {
                                    runs = maxTicks;
                                }
                            }
                        }
                    }
                }
                if (no_damage && lastEntity.isLivingEntity()) {
                    lastEntity.getLivingEntity().setFallDistance(0);
                }
                // Record the location in case the entity gets lost (EG, if a pushed arrow hits a mob)
                lastLocation = lastEntity.getLocation();
            } else {
                this.cancel();
                if (script != null) {
                    Consumer<ScriptQueue> configure = (queue) -> {
                        if (lastEntity.getLocation() != null) {
                            queue.addDefinition("location", lastEntity.getLocation());
                        } else {
                            queue.addDefinition("location", lastLocation);
                        }
                        queue.addDefinition("pushed_entities", entityList);
                        queue.addDefinition("last_entity", lastEntity);
                    };
                    ScriptUtilities.createAndStartQueue(script.getContainer(), null, scriptEntry.entryData, null, configure, null, null, definitions, scriptEntry);
                }
                scriptEntry.setFinished(true);
            }
        }
    };
    task.runTaskTimer(Denizen.getInstance(), 0, prec);
}
Also used : Utilities(com.denizenscript.denizen.utilities.Utilities) BoundingBox(org.bukkit.util.BoundingBox) LocationTag(com.denizenscript.denizen.objects.LocationTag) NMSHandler(com.denizenscript.denizen.nms.NMSHandler) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException) Holdable(com.denizenscript.denizencore.scripts.commands.Holdable) ScriptQueue(com.denizenscript.denizencore.scripts.queues.ScriptQueue) Location(org.bukkit.Location) ScriptEntry(com.denizenscript.denizencore.scripts.ScriptEntry) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Position(com.denizenscript.denizen.utilities.entity.Position) Denizen(com.denizenscript.denizen.Denizen) Vector(org.bukkit.util.Vector) Consumer(java.util.function.Consumer) List(java.util.List) ScriptUtilities(com.denizenscript.denizencore.utilities.ScriptUtilities) EntityTag(com.denizenscript.denizen.objects.EntityTag) com.denizenscript.denizencore.objects(com.denizenscript.denizencore.objects) Debug(com.denizenscript.denizen.utilities.debugging.Debug) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) AbstractCommand(com.denizenscript.denizencore.scripts.commands.AbstractCommand) Conversion(com.denizenscript.denizen.utilities.Conversion) TaskScriptContainer(com.denizenscript.denizencore.scripts.containers.core.TaskScriptContainer) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) LocationTag(com.denizenscript.denizen.objects.LocationTag) BoundingBox(org.bukkit.util.BoundingBox) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) EntityTag(com.denizenscript.denizen.objects.EntityTag) List(java.util.List) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location) ScriptQueue(com.denizenscript.denizencore.scripts.queues.ScriptQueue)

Example 3 with BoundingBox

use of org.bukkit.util.BoundingBox in project EliteMobs by MagmaGuy.

the class Explosion method fullBlockRestore.

private void fullBlockRestore(BlockState blockState, boolean isShutdown) {
    for (Entity entity : blockState.getWorld().getNearbyEntities(new BoundingBox(blockState.getX(), blockState.getY(), blockState.getZ(), blockState.getX() + 1, blockState.getY() + 1, blockState.getZ() + 1))) entity.teleport(entity.getLocation().clone().add(new Vector(0, 1, 0)));
    blockState.setBlockData(blockState.getBlockData());
    if (blockState instanceof Container) {
        Inventory container = null;
        switch(blockState.getType()) {
            case LECTERN:
                container = ((Lectern) blockState).getInventory();
                break;
            case JUKEBOX:
                // ((Jukebox) blockState).setRecord(this.items.get(0));
                blockState.update(true, false);
                break;
            default:
                container = ((Container) blockState).getInventory();
        }
        if (container != null)
            container.setContents(((Container) blockState).getInventory().getContents());
    }
    blockState.update(true);
    if (!isShutdown)
        detonatedBlocks.remove(blockState);
}
Also used : EliteEntity(com.magmaguy.elitemobs.mobconstructor.EliteEntity) Entity(org.bukkit.entity.Entity) BoundingBox(org.bukkit.util.BoundingBox) Vector(org.bukkit.util.Vector) Inventory(org.bukkit.inventory.Inventory)

Example 4 with BoundingBox

use of org.bukkit.util.BoundingBox in project EliteMobs by MagmaGuy.

the class EnderDragonShockwave method doDamagePhase.

private void doDamagePhase(EliteEntity eliteEntity) {
    List<Block> blockList = new ArrayList<>();
    Iterator<PieBlock> pieBlockIterator = realBlocks.iterator();
    while (pieBlockIterator.hasNext()) {
        PieBlock pieBlock = pieBlockIterator.next();
        if (pieBlock.distance < damagePhaseCounter) {
            Location rawPieBlock = eliteEntity.getLivingEntity().getLocation().clone().add(pieBlock.vector);
            if (rawPieBlock.getBlock().isPassable())
                continue;
            for (Entity entity : rawPieBlock.getWorld().getNearbyEntities(new BoundingBox(rawPieBlock.getX(), rawPieBlock.getY(), rawPieBlock.getZ(), rawPieBlock.getX() + 1, rawPieBlock.getY() + 3, rawPieBlock.getZ() + 1))) {
                if (entity.getType().equals(EntityType.FALLING_BLOCK))
                    continue;
                entity.setVelocity(entity.getLocation().clone().subtract(eliteEntity.getLivingEntity().getLocation()).toVector().setY(1).normalize().multiply(3));
                if (entity.getType().equals(EntityType.PLAYER))
                    BossCustomAttackDamage.dealCustomDamage(eliteEntity.getLivingEntity(), (LivingEntity) entity, 20);
            }
            if (rawPieBlock.getBlock().getType().getBlastResistance() >= 7)
                continue;
            blockList.add(rawPieBlock.getBlock());
            pieBlockIterator.remove();
        }
    }
    damagePhaseCounter++;
    Explosion.generateFakeExplosion(blockList, eliteEntity.getLivingEntity());
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) EliteEntity(com.magmaguy.elitemobs.mobconstructor.EliteEntity) LivingEntity(org.bukkit.entity.LivingEntity) BoundingBox(org.bukkit.util.BoundingBox) ArrayList(java.util.ArrayList) Block(org.bukkit.block.Block) Location(org.bukkit.Location)

Aggregations

BoundingBox (org.bukkit.util.BoundingBox)4 Vector (org.bukkit.util.Vector)3 EliteEntity (com.magmaguy.elitemobs.mobconstructor.EliteEntity)2 Location (org.bukkit.Location)2 Entity (org.bukkit.entity.Entity)2 Denizen (com.denizenscript.denizen.Denizen)1 NMSHandler (com.denizenscript.denizen.nms.NMSHandler)1 EntityTag (com.denizenscript.denizen.objects.EntityTag)1 LocationTag (com.denizenscript.denizen.objects.LocationTag)1 Conversion (com.denizenscript.denizen.utilities.Conversion)1 Utilities (com.denizenscript.denizen.utilities.Utilities)1 Debug (com.denizenscript.denizen.utilities.debugging.Debug)1 Position (com.denizenscript.denizen.utilities.entity.Position)1 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)1 com.denizenscript.denizencore.objects (com.denizenscript.denizencore.objects)1 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)1 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)1 ListTag (com.denizenscript.denizencore.objects.core.ListTag)1 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)1 ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)1