use of net.glowstone.entity.physics.BoundingBox in project Glowstone by GlowstoneMC.
the class GlowLightningStrike method getNearbyEntities.
@Override
public List<Entity> getNearbyEntities(double x, double y, double z) {
// This behavior is similar to CraftBukkit, where a call with args
// (0, 0, 0) finds any entities whose bounding boxes intersect that of
// this entity.
BoundingBox searchBox = BoundingBox.fromPositionAndSize(location.toVector(), new Vector(0, 0, 0));
Vector vec = new Vector(x, y, z);
Vector vec2 = new Vector(0, 0.5 * y, 0);
searchBox.minCorner.subtract(vec).add(vec2);
searchBox.maxCorner.add(vec).add(vec2);
return world.getEntityManager().getEntitiesInside(searchBox, this);
}
use of net.glowstone.entity.physics.BoundingBox in project Glowstone by GlowstoneMC.
the class GlowWorld method getNearbyEntities.
/**
* Returns a list of entities within a bounding box centered around a Location.
* <p>
* Some implementations may impose artificial restrictions on the size of the search bounding box.
*
* @param location The center of the bounding box
* @param x 1/2 the size of the box along x axis
* @param y 1/2 the size of the box along y axis
* @param z 1/2 the size of the box along z axis
* @return the collection of entities near location. This will always be a non-null collection.
*/
@Override
public Collection<Entity> getNearbyEntities(Location location, double x, double y, double z) {
Vector minCorner = new Vector(location.getX() - x, location.getY() - y, location.getZ() - z);
Vector maxCorner = new Vector(location.getX() + x, location.getY() + y, location.getZ() + z);
// TODO: test
BoundingBox searchBox = BoundingBox.fromCorners(minCorner, maxCorner);
GlowEntity except = null;
return entities.getEntitiesInside(searchBox, except);
}
use of net.glowstone.entity.physics.BoundingBox in project Glowstone by GlowstoneMC.
the class GlowWorld method strikeLightningInChunk.
private void strikeLightningInChunk(int cx, int cz) {
int n = random.nextInt();
// get lightning target block
int x = (cx << 4) + (n & 0xF);
int z = (cz << 4) + (n >> 8 & 0xF);
int y = getHighestBlockYAt(x, z);
// search for living entities in a 6×6×h (there's an error in the wiki!) region from 3 below the
// target block up to the world height
BoundingBox searchBox = BoundingBox.fromPositionAndSize(new Vector(x, y, z), new Vector(0, 0, 0));
Vector vec = new Vector(3, 3, 3);
Vector vec2 = new Vector(0, getMaxHeight(), 0);
searchBox.minCorner.subtract(vec);
searchBox.maxCorner.add(vec).add(vec2);
List<LivingEntity> livingEntities = new LinkedList<>();
// make sure entity can see sky
getEntityManager().getEntitiesInside(searchBox, null).stream().filter(entity -> entity instanceof LivingEntity && !entity.isDead()).forEach(entity -> {
Vector pos = entity.getLocation().toVector();
int minY = getHighestBlockYAt(pos.getBlockX(), pos.getBlockZ());
if (pos.getBlockY() >= minY) {
livingEntities.add((LivingEntity) entity);
}
});
// re-target lightning if required
if (!livingEntities.isEmpty()) {
// randomly choose an entity
LivingEntity entity = livingEntities.get(random.nextInt(livingEntities.size()));
// re-target lightning on this living entity
Vector newTarget = entity.getLocation().toVector();
x = newTarget.getBlockX();
z = newTarget.getBlockZ();
y = newTarget.getBlockY();
}
// lightning strike if the target block is under rain
if (GlowBiomeClimate.isRainy(getBiome(x, z), x, y, z)) {
strikeLightning(new Location(this, x, y, z));
}
}
use of net.glowstone.entity.physics.BoundingBox in project Glowstone by GlowstoneMC.
the class GlowEntity method pulsePhysics.
protected void pulsePhysics() {
if (velocity.lengthSquared() > 0.01) {
double dx = 0;
double dy = 0;
double dz = 0;
double ndx = 0;
double ndy = 0;
double ndz = 0;
double x = location.getX();
double y = location.getY();
double z = location.getZ();
Vector inc = velocity.clone().normalize();
BoundingBox test;
boolean bbRelevant = (boundingBox == null ? 0 : boundingBox.getSize().lengthSquared()) >= 1;
if (velocity.getY() < 0d) {
if (!location.clone().add(new Vector(0, -1, 0)).getBlock().getType().isSolid()) {
block: while (dy >= velocity.getY()) {
ndy += inc.getY();
if (Material.getMaterial(((GlowWorld) location.getWorld()).getBlockTypeIdAt((int) x, (int) (y + ndy), (int) z)).isSolid()) {
break;
}
if (bbRelevant) {
test = BoundingBox.fromPositionAndSize(new Vector((int) x, (int) (y + ndy), (int) z), boundingBox.getSize());
Vector min = test.minCorner, max = test.maxCorner;
for (int bbx = min.getBlockX(); bbx <= max.getBlockX(); ++bbx) {
for (int bby = min.getBlockY(); bby <= max.getBlockY(); ++bby) {
for (int bbz = min.getBlockZ(); bbz <= max.getBlockZ(); ++bbz) {
if (Material.getMaterial(world.getBlockTypeIdAt(bbx, bby, bbz)).isSolid()) {
break block;
}
}
}
}
}
dy = ndy;
}
}
} else if (velocity.getY() > 0d) {
block: while (dy <= velocity.getY()) {
ndy += inc.getY();
if (Material.getMaterial(((GlowWorld) location.getWorld()).getBlockTypeIdAt((int) x, (int) (y + ndy), (int) z)).isSolid()) {
break;
}
if (bbRelevant) {
test = BoundingBox.fromPositionAndSize(new Vector((int) x, (int) (y + ndy), (int) z), boundingBox.getSize());
Vector min = test.minCorner, max = test.maxCorner;
for (int bbx = min.getBlockX(); bbx <= max.getBlockX(); ++bbx) {
for (int bby = min.getBlockY(); bby <= max.getBlockY(); ++bby) {
for (int bbz = min.getBlockZ(); bbz <= max.getBlockZ(); ++bbz) {
if (Material.getMaterial(world.getBlockTypeIdAt(bbx, bby, bbz)).isSolid()) {
break block;
}
}
}
}
}
dy = ndy;
}
}
velocity.setY(dy);
if (velocity.getX() < 0d) {
block: while (dx >= velocity.getX()) {
ndx += inc.getX();
if (Material.getMaterial(((GlowWorld) location.getWorld()).getBlockTypeIdAt((int) (x + ndx), (int) (y + dy), (int) z)).isSolid()) {
break;
}
if (bbRelevant) {
test = BoundingBox.fromPositionAndSize(new Vector((int) (x + ndx), (int) (y + dy), (int) z), boundingBox.getSize());
Vector min = test.minCorner, max = test.maxCorner;
for (int bbx = min.getBlockX(); bbx <= max.getBlockX(); ++bbx) {
for (int bby = min.getBlockY(); bby <= max.getBlockY(); ++bby) {
for (int bbz = min.getBlockZ(); bbz <= max.getBlockZ(); ++bbz) {
if (Material.getMaterial(world.getBlockTypeIdAt(bbx, bby, bbz)).isSolid()) {
break block;
}
}
}
}
}
dx = ndx;
}
} else if (velocity.getX() > 0d) {
block: while (dx <= velocity.getX()) {
ndx += inc.getX();
if (Material.getMaterial(((GlowWorld) location.getWorld()).getBlockTypeIdAt((int) (x + ndx), (int) (y + dy), (int) z)).isSolid()) {
break;
}
if (bbRelevant) {
test = BoundingBox.fromPositionAndSize(new Vector((int) (x + ndx), (int) (y + dy), (int) z), boundingBox.getSize());
Vector min = test.minCorner, max = test.maxCorner;
for (int bbx = min.getBlockX(); bbx <= max.getBlockX(); ++bbx) {
for (int bby = min.getBlockY(); bby <= max.getBlockY(); ++bby) {
for (int bbz = min.getBlockZ(); bbz <= max.getBlockZ(); ++bbz) {
if (Material.getMaterial(world.getBlockTypeIdAt(bbx, bby, bbz)).isSolid()) {
break block;
}
}
}
}
}
dx = ndx;
}
}
velocity.setX(dx);
if (velocity.getZ() < 0d) {
block: while (dz >= velocity.getZ()) {
ndz += inc.getZ();
if (Material.getMaterial(((GlowWorld) location.getWorld()).getBlockTypeIdAt((int) (x + dx), (int) (y + dy), (int) (z + ndz))).isSolid()) {
break;
}
if (bbRelevant) {
test = BoundingBox.fromPositionAndSize(new Vector((int) (x + dx), (int) (y + dy), (int) (z + ndz)), boundingBox.getSize());
Vector min = test.minCorner, max = test.maxCorner;
for (int bbx = min.getBlockX(); bbx <= max.getBlockX(); ++bbx) {
for (int bby = min.getBlockY(); bby <= max.getBlockY(); ++bby) {
for (int bbz = min.getBlockZ(); bbz <= max.getBlockZ(); ++bbz) {
if (Material.getMaterial(world.getBlockTypeIdAt(bbx, bby, bbz)).isSolid()) {
break block;
}
}
}
}
}
dz = ndz;
}
} else if (velocity.getZ() > 0d) {
block: while (dz <= velocity.getZ()) {
ndz += inc.getZ();
if (Material.getMaterial(((GlowWorld) location.getWorld()).getBlockTypeIdAt((int) (x + dx), (int) (y + dy), (int) (z + ndz))).isSolid()) {
break;
}
if (bbRelevant) {
test = BoundingBox.fromPositionAndSize(new Vector((int) (x + dx), (int) (y + dy), (int) (z + ndz)), boundingBox.getSize());
Vector min = test.minCorner, max = test.maxCorner;
for (int bbx = min.getBlockX(); bbx <= max.getBlockX(); ++bbx) {
for (int bby = min.getBlockY(); bby <= max.getBlockY(); ++bby) {
for (int bbz = min.getBlockZ(); bbz <= max.getBlockZ(); ++bbz) {
if (Material.getMaterial(world.getBlockTypeIdAt(bbx, bby, bbz)).isSolid()) {
break block;
}
}
}
}
}
dz = ndz;
}
}
velocity.setZ(dz);
setRawLocation(location.clone().add(velocity));
}
// apply friction and gravity
if (location.getBlock().getType() == Material.WATER) {
velocity.multiply(liquidDrag);
velocity.setY(velocity.getY() + getGravityAccel().getY() / 4d);
} else if (location.getBlock().getType() == Material.LAVA) {
velocity.multiply(liquidDrag - 0.3);
velocity.setY(velocity.getY() + getGravityAccel().getY() / 4d);
} else {
velocity.setY(airDrag * (velocity.getY() + getGravityAccel().getY()));
if (isOnGround()) {
velocity.setX(velocity.getX() * slipMultiplier);
velocity.setZ(velocity.getZ() * slipMultiplier);
} else {
velocity.setX(velocity.getX() * 0.91);
velocity.setZ(velocity.getZ() * 0.91);
}
}
}
use of net.glowstone.entity.physics.BoundingBox in project Glowstone by GlowstoneMC.
the class GlowEntity method getNearbyEntities.
////////////////////////////////////////////////////////////////////////////
// Miscellaneous actions
@Override
public List<Entity> getNearbyEntities(double x, double y, double z) {
// This behavior is similar to CraftBukkit, where a call with args
// (0, 0, 0) finds any entities whose bounding boxes intersect that of
// this entity.
BoundingBox searchBox;
if (boundingBox == null) {
searchBox = BoundingBox.fromPositionAndSize(location.toVector(), new Vector(0, 0, 0));
} else {
searchBox = BoundingBox.copyOf(boundingBox);
}
Vector vec = new Vector(x, y, z);
searchBox.minCorner.subtract(vec);
searchBox.maxCorner.add(vec);
return world.getEntityManager().getEntitiesInside(searchBox, this);
}
Aggregations