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);
}
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);
}
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);
}
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());
}
Aggregations