Java Code Examples for cn.nukkit.block.Block#canPassThrough()

The following examples show how to use cn.nukkit.block.Block#canPassThrough() . 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: 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 2
Source File: Level.java    From Nukkit 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.getMinX());
    int minY = NukkitMath.floorDouble(bb.getMinY());
    int minZ = NukkitMath.floorDouble(bb.getMinZ());
    int maxX = NukkitMath.ceilDouble(bb.getMaxX());
    int maxY = NukkitMath.ceilDouble(bb.getMaxY());
    int maxZ = NukkitMath.ceilDouble(bb.getMaxZ());

    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 Nukkit 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.getMinX());
    int minY = NukkitMath.floorDouble(bb.getMinY());
    int minZ = NukkitMath.floorDouble(bb.getMinZ());
    int maxX = NukkitMath.ceilDouble(bb.getMaxX());
    int maxY = NukkitMath.ceilDouble(bb.getMaxY());
    int maxZ = NukkitMath.ceilDouble(bb.getMaxZ());

    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 4
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 5
Source File: ItemFirework.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
    if (block.canPassThrough()) {
        this.spawnFirework(level, block);

        if (!player.isCreative()) {
            player.getInventory().decreaseCount(player.getInventory().getHeldItemIndex());
        }

        return true;
    }

    return false;
}
 
Example 6
Source File: Level.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public AxisAlignedBB[] getCollisionCubes(Entity entity, AxisAlignedBB bb, boolean entities, boolean solidEntities) {
    int minX = NukkitMath.floorDouble(bb.getMinX());
    int minY = NukkitMath.floorDouble(bb.getMinY());
    int minZ = NukkitMath.floorDouble(bb.getMinZ());
    int maxX = NukkitMath.ceilDouble(bb.getMaxX());
    int maxY = NukkitMath.ceilDouble(bb.getMaxY());
    int maxZ = NukkitMath.ceilDouble(bb.getMaxZ());

    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), false);
                if (!block.canPassThrough() && block.collidesWithBB(bb)) {
                    collides.add(block.getBoundingBox());
                }
            }
        }
    }

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

    return collides.toArray(new AxisAlignedBB[0]);
}
 
Example 7
Source File: AdvancedRouteFinder.java    From Actaeon with MIT License 5 votes vote down vote up
private Block getHighestUnder(double x, double dy, double z){
	for(int y=(int)dy;y >= 0; y--){
		Block block = level.getBlock(new Vector3(x, y, z));

		if(!canWalkOn(block)) return block;
		if(!block.canPassThrough()) return block;
	}
	return null;
}
 
Example 8
Source File: Level.java    From Nukkit 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.getMinX());
    int minY = NukkitMath.floorDouble(bb.getMinY());
    int minZ = NukkitMath.floorDouble(bb.getMinZ());
    int maxX = NukkitMath.ceilDouble(bb.getMaxX());
    int maxY = NukkitMath.ceilDouble(bb.getMaxY());
    int maxZ = NukkitMath.ceilDouble(bb.getMaxZ());

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