Java Code Examples for cn.nukkit.math.NukkitMath#ceilDouble()

The following examples show how to use cn.nukkit.math.NukkitMath#ceilDouble() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Entity.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public List<Block> getBlocksAround() {
    if (this.blocksAround == null) {
        int minX = NukkitMath.floorDouble(this.boundingBox.minX);
        int minY = NukkitMath.floorDouble(this.boundingBox.minY);
        int minZ = NukkitMath.floorDouble(this.boundingBox.minZ);
        int maxX = NukkitMath.ceilDouble(this.boundingBox.maxX);
        int maxY = NukkitMath.ceilDouble(this.boundingBox.maxY);
        int maxZ = NukkitMath.ceilDouble(this.boundingBox.maxZ);

        this.blocksAround = new ArrayList<>();

        for (int z = minZ; z <= maxZ; ++z) {
            for (int x = minX; x <= maxX; ++x) {
                for (int y = minY; y <= maxY; ++y) {
                    Block block = this.level.getBlock(this.temporalVector.setComponents(x, y, z));
                    this.blocksAround.add(block);
                }
            }
        }
    }

    return this.blocksAround;
}
 
Example 2
Source File: Level.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public boolean hasCollision(Entity entity, AxisAlignedBB bb, boolean entities) {
    int minX = NukkitMath.floorDouble(bb.minX);
    int minY = NukkitMath.floorDouble(bb.minY);
    int minZ = NukkitMath.floorDouble(bb.minZ);
    int maxX = NukkitMath.ceilDouble(bb.maxX);
    int maxY = NukkitMath.ceilDouble(bb.maxY);
    int maxZ = NukkitMath.ceilDouble(bb.maxZ);

    for (int z = minZ; z <= maxZ; ++z) {
        for (int x = minX; x <= maxX; ++x) {
            for (int y = minY; y <= maxY; ++y) {
                Block block = this.getBlock(this.temporalVector.setComponents(x, y, z));
                if (!block.canPassThrough() && block.collidesWithBB(bb)) {
                    return true;
                }
            }
        }
    }

    if (entities) {
        return this.getCollidingEntities(bb.grow(0.25f, 0.25f, 0.25f), entity).length > 0;
    }
    return false;
}
 
Example 3
Source File: Level.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public Entity[] getCollidingEntities(AxisAlignedBB bb, Entity entity) {
    List<Entity> nearby = new ArrayList<>();

    if (entity == null || entity.canCollide()) {
        int minX = NukkitMath.floorDouble((bb.minX - 2) / 16);
        int maxX = NukkitMath.ceilDouble((bb.maxX + 2) / 16);
        int minZ = NukkitMath.floorDouble((bb.minZ - 2) / 16);
        int maxZ = NukkitMath.ceilDouble((bb.maxZ + 2) / 16);

        for (int x = minX; x <= maxX; ++x) {
            for (int z = minZ; z <= maxZ; ++z) {
                for (Entity ent : this.getChunkEntities(x, z).values()) {
                    if ((entity == null || (ent != entity && entity.canCollideWith(ent)))
                            && ent.boundingBox.intersectsWith(bb)) {
                        nearby.add(ent);
                    }
                }
            }
        }
    }

    return nearby.stream().toArray(Entity[]::new);
}
 
Example 4
Source File: Level.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public Entity[] getNearbyEntities(AxisAlignedBB bb, Entity entity) {
    List<Entity> nearby = new ArrayList<>();

    int minX = NukkitMath.floorDouble((bb.minX - 2) / 16);
    int maxX = NukkitMath.ceilDouble((bb.maxX + 2) / 16);
    int minZ = NukkitMath.floorDouble((bb.minZ - 2) / 16);
    int maxZ = NukkitMath.ceilDouble((bb.maxZ + 2) / 16);

    for (int x = minX; x <= maxX; ++x) {
        for (int z = minZ; z <= maxZ; ++z) {
            for (Entity ent : this.getChunkEntities(x, z).values()) {
                if (ent != entity && ent.boundingBox.intersectsWith(bb)) {
                    nearby.add(ent);
                }
            }
        }
    }

    return nearby.stream().toArray(Entity[]::new);
}
 
Example 5
Source File: Level.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public AxisAlignedBB[] getCollisionCubes(Entity entity, AxisAlignedBB bb, boolean entities) {
    int minX = NukkitMath.floorDouble(bb.minX);
    int minY = NukkitMath.floorDouble(bb.minY);
    int minZ = NukkitMath.floorDouble(bb.minZ);
    int maxX = NukkitMath.ceilDouble(bb.maxX);
    int maxY = NukkitMath.ceilDouble(bb.maxY);
    int maxZ = NukkitMath.ceilDouble(bb.maxZ);

    List<AxisAlignedBB> collides = new ArrayList<>();

    for (int z = minZ; z <= maxZ; ++z) {
        for (int x = minX; x <= maxX; ++x) {
            for (int y = minY; y <= maxY; ++y) {
                Block block = this.getBlock(this.temporalVector.setComponents(x, y, z));
                if (!block.canPassThrough() && block.collidesWithBB(bb)) {
                    collides.add(block.getBoundingBox());
                }
            }
        }
    }

    if (entities) {
        for (Entity ent : this.getCollidingEntities(bb.grow(0.25f, 0.25f, 0.25f), entity)) {
            collides.add(ent.boundingBox.clone());
        }
    }

    return collides.stream().toArray(AxisAlignedBB[]::new);
}
 
Example 6
Source File: EntityProjectile.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public int getResultDamage() {
    return NukkitMath.ceilDouble(Math.sqrt(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ) * getDamage());
}
 
Example 7
Source File: EntityProjectile.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public int getResultDamage() {
    return NukkitMath.ceilDouble(Math.sqrt(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ) * getDamage());
}
 
Example 8
Source File: EntityProjectile.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public int getResultDamage() {
    return NukkitMath.ceilDouble(Math.sqrt(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ) * getDamage());
}