cn.nukkit.math.AxisAlignedBB Java Examples
The following examples show how to use
cn.nukkit.math.AxisAlignedBB.
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: BlockEntityMobSpawner.java From Jupiter with GNU General Public License v3.0 | 6 votes |
public boolean canUpdate() { if (this.getNetworkId() == 0) { return false; } int count = 0; boolean hasPlayer = false; AxisAlignedBB boundingBox = new AxisAlignedBB(x - 8.5, y - 4.5, z - 8.5, x + 8.5, y + 4.5, z + 8.5); for (Entity entity : this.level.getNearbyEntities(boundingBox)) { if (entity.getNetworkId() == this.getNetworkId()) { ++count; } if (entity instanceof Player) { hasPlayer = true; } } if (hasPlayer && count < 6) { return true; } return false; }
Example #2
Source File: Level.java From Jupiter with GNU General Public License v3.0 | 6 votes |
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 #3
Source File: BlockFenceGate.java From Jupiter with GNU General Public License v3.0 | 6 votes |
@Override protected AxisAlignedBB recalculateBoundingBox() { if ((this.getDamage() & 0x04) > 0) { return null; } int i = this.getDamage() & 0x03; if (i == 2 || i == 0) { return new AxisAlignedBB( x, y, z + 0.375, x + 1, y + 1.5, z + 0.625 ); } else { return new AxisAlignedBB( x + 0.375, y, z, x + 0.625, y + 1.5, z + 1 ); } }
Example #4
Source File: Level.java From Jupiter with GNU General Public License v3.0 | 6 votes |
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 #5
Source File: Pig.java From Actaeon with MIT License | 6 votes |
@Override public boolean entityBaseTick(int tickDiff){ if(!this.hasTarget()){ Entity[] entities = this.level.getNearbyEntities(new AxisAlignedBB(this.x, this.y, this.z, this.x, this.y, this.z).expand(7, 7, 7)); Entity near = null; for(Entity entity : entities){ if(entity instanceof Player && (near == null || this.distance(near) < this.distance(entity))){ if(((Player) entity).getInventory().getItemInHand().getId() == Item.CARROT){ near = entity; } } } this.setTarget(near, "Pig"); } return super.entityBaseTick(tickDiff); }
Example #6
Source File: BlockFence.java From Jupiter with GNU General Public License v3.0 | 6 votes |
protected AxisAlignedBB recalculateBoundingBox() { boolean north = this.canConnect(this.north()); boolean south = this.canConnect(this.south()); boolean west = this.canConnect(this.west()); boolean east = this.canConnect(this.east()); double n = north ? 0 : 0.375; double s = south ? 1 : 0.625; double w = west ? 0 : 0.375; double e = east ? 1 : 0.625; return new AxisAlignedBB( this.x + w, this.y, this.z + n, this.x + e, this.y + 1.5, this.z + s ); }
Example #7
Source File: Level.java From Jupiter with GNU General Public License v3.0 | 6 votes |
public List<BlockUpdateEntry> getPendingBlockUpdates(AxisAlignedBB boundingBox) { List<BlockUpdateEntry> list = null; Iterator<BlockUpdateEntry> iterator; iterator = this.updateQueue.iterator(); while (iterator.hasNext()) { BlockUpdateEntry entry = iterator.next(); Vector3 pos = entry.pos; if (pos.getX() >= boundingBox.minX && pos.getX() < boundingBox.maxX && pos.getZ() >= boundingBox.minZ && pos.getZ() < boundingBox.maxZ) { if (list == null) { list = new ArrayList<>(); } list.add(entry); } } return list; }
Example #8
Source File: BlockFence.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override protected AxisAlignedBB recalculateBoundingBox() { boolean north = this.canConnect(this.north()); boolean south = this.canConnect(this.south()); boolean west = this.canConnect(this.west()); boolean east = this.canConnect(this.east()); double n = north ? 0 : 0.375; double s = south ? 1 : 0.625; double w = west ? 0 : 0.375; double e = east ? 1 : 0.625; return new SimpleAxisAlignedBB( this.x + w, this.y, this.z + n, this.x + e, this.y + 1.5, this.z + s ); }
Example #9
Source File: Level.java From Jupiter with GNU General Public License v3.0 | 6 votes |
public Vector3 adjustPosToNearbyEntity(Vector3 pos) { pos.y = this.getHighestBlockAt(pos.getFloorX(), pos.getFloorZ()); AxisAlignedBB axisalignedbb = new AxisAlignedBB(pos.x, pos.y, pos.z, pos.getX(), 255, pos.getZ()).expand(3, 3, 3); List<Entity> list = new ArrayList<>(); for (Entity entity : this.getCollidingEntities(axisalignedbb)) { if (entity.isAlive() && canBlockSeeSky(entity)) { list.add(entity); } } if (!list.isEmpty()) { return list.get(this.rand.nextInt(list.size())).getPosition(); } else { if (pos.getY() == -1) { pos = pos.up(2); } return pos; } }
Example #10
Source File: BlockStairs.java From Jupiter with GNU General Public License v3.0 | 6 votes |
@Override protected AxisAlignedBB recalculateBoundingBox() { if ((this.getDamage() & 0x04) > 0) { return new AxisAlignedBB( this.x, this.y + 0.5, this.z, this.x + 1, this.y + 1, this.z + 1 ); } else { return new AxisAlignedBB( this.x, this.y, this.z, this.x + 1, this.y + 0.5, this.z + 1 ); } }
Example #11
Source File: BlockSoulSand.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override protected AxisAlignedBB recalculateBoundingBox() { return new AxisAlignedBB( this.x, this.y, this.z, this.x + 1, this.y + 1 - 0.125, this.z + 1 ); }
Example #12
Source File: BlockBed.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override protected AxisAlignedBB recalculateBoundingBox() { return new AxisAlignedBB( this.x, this.y, this.z, this.x + 1, this.y + 0.5625, this.z + 1 ); }
Example #13
Source File: BlockFire.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override protected AxisAlignedBB recalculateCollisionBoundingBox() { return new AxisAlignedBB( this.x, this.y, this.z, this.x + 1, this.y + 1, this.z + 1 ); }
Example #14
Source File: BlockEnderChest.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public AxisAlignedBB recalculateBoundingBox() { return new AxisAlignedBB( this.x + 0.0625, this.y, this.z + 0.0625, this.x + 0.9375, this.y + 0.9475, this.z + 0.9375 ); }
Example #15
Source File: BlockWall.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override protected AxisAlignedBB recalculateBoundingBox() { boolean north = this.canConnect(this.getSide(BlockFace.NORTH)); boolean south = this.canConnect(this.getSide(BlockFace.SOUTH)); boolean west = this.canConnect(this.getSide(BlockFace.WEST)); boolean east = this.canConnect(this.getSide(BlockFace.EAST)); double n = north ? 0 : 0.25; double s = south ? 1 : 0.75; double w = west ? 0 : 0.25; double e = east ? 1 : 0.75; if (north && south && !west && !east) { w = 0.3125; e = 0.6875; } else if (!north && !south && west && east) { n = 0.3125; s = 0.6875; } return new AxisAlignedBB( this.x + w, this.y, this.z + n, this.x + e, this.y + 1.5, this.z + s ); }
Example #16
Source File: BlockPressurePlateBase.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override protected AxisAlignedBB recalculateBoundingBox() { if (isActivated()) { return new AxisAlignedBB(this.x + 0.0625, this.y, this.z + 0.0625, this.x + 0.9375, this.y + 0.03125, this.z + 0.9375); } else { return new AxisAlignedBB(this.x + 0.0625, this.y, this.z + 0.0625, this.x + 0.9375, this.y + 0.0625, this.z + 0.9375); } }
Example #17
Source File: BlockGrassPath.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override protected AxisAlignedBB recalculateBoundingBox() { return new AxisAlignedBB( this.x, this.y, this.z, this.x + 1, this.y + 0.9375, this.z + 1 ); }
Example #18
Source File: BlockRail.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public AxisAlignedBB recalculateBoundingBox() { return new AxisAlignedBB( this.x, this.y, this.z, this.x + 1, this.y + 0.125D, this.z + 1); }
Example #19
Source File: BlockPressurePlateWood.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override protected int computeRedstoneStrength() { AxisAlignedBB bb = getCollisionBoundingBox(); for (Entity entity : this.level.getCollidingEntities(bb)) { if (entity.doesTriggerPressurePlate()) { return 15; } } return 0; }
Example #20
Source File: BlockPressurePlateStone.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override protected int computeRedstoneStrength() { AxisAlignedBB bb = getCollisionBoundingBox(); for (Entity entity : this.level.getCollidingEntities(bb)) { if (entity instanceof EntityLiving && entity.doesTriggerPressurePlate()) { return 15; } } return 0; }
Example #21
Source File: BlockRailDetector.java From Jupiter with GNU General Public License v3.0 | 5 votes |
protected void updateState() { boolean wasPowered = isActive(); boolean isPowered = false; for (Entity entity : level.getNearbyEntities(new AxisAlignedBB( getFloorX() + 0.125D, getFloorY(), getFloorZ() + 0.125D, getFloorX() + 0.875D, getFloorY() + 0.525D, getFloorZ() + 0.875D))) { if (entity instanceof EntityMinecartAbstract) { isPowered = true; } } if (isPowered && !wasPowered) { setActive(true); level.scheduleUpdate(this, this, 0); level.scheduleUpdate(this, this.down(), 0); } if (!isPowered && wasPowered) { setActive(false); level.scheduleUpdate(this, this, 0); level.scheduleUpdate(this, this.down(), 0); } level.updateComparatorOutputLevel(this); }
Example #22
Source File: BlockPressurePlateWood.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override protected int computeRedstoneStrength() { AxisAlignedBB bb = getCollisionBoundingBox(); for (Entity entity : this.level.getCollidingEntities(bb)) { if (entity.doesTriggerPressurePlate()) { return 15; } } return 0; }
Example #23
Source File: BlockCocoa.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public AxisAlignedBB getBoundingBox() { if (boundingBox == null) { this.boundingBox = recalculateBoundingBox(); } return this.boundingBox; }
Example #24
Source File: BlockCocoa.java From Nukkit with GNU General Public License v3.0 | 5 votes |
private AxisAlignedBB getRelativeBoundingBox() { int damage = this.getDamage(); if (damage > 11) { this.setDamage(damage = 11); } AxisAlignedBB boundingBox = ALL[damage]; if (boundingBox != null) return boundingBox; AxisAlignedBB[] bbs; switch (getDamage()) { case 0: case 4: case 8: bbs = NORTH; break; case 1: case 5: case 9: bbs = EAST; break; case 2: case 6: case 10: bbs = SOUTH; break; case 3: case 7: case 11: bbs = WEST; break; default: bbs = NORTH; break; } return ALL[damage] = bbs[this.getDamage() >> 2]; }
Example #25
Source File: BlockEndPortalFrame.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override protected AxisAlignedBB recalculateBoundingBox() { return new AxisAlignedBB( x, y, z, x + 1, y + ((this.getDamage() & 0x04) > 0 ? 1 : 0.8125), z + 1 ); }
Example #26
Source File: BlockEntityPistonArm.java From Jupiter with GNU General Public License v3.0 | 5 votes |
private void pushEntities() { float lastProgress = this.getExtendedProgress(this.lastProgress); double x = (double) (lastProgress * (float) this.facing.getXOffset()); double y = (double) (lastProgress * (float) this.facing.getYOffset()); double z = (double) (lastProgress * (float) this.facing.getZOffset()); AxisAlignedBB bb = new AxisAlignedBB(x, y, z, x + 1.0D, y + 1.0D, z + 1.0D); Entity[] entities = this.level.getCollidingEntities(bb); if (entities.length != 0) { ; } }
Example #27
Source File: MovingEntity.java From Actaeon with MIT License | 5 votes |
private void checkGround(){ AxisAlignedBB[] list = this.level.getCollisionCubes(this, this.level.getTickRate() > 1 ? this.boundingBox.getOffsetBoundingBox(0, -1, 0) : this.boundingBox.addCoord(0, -1, 0), false); double maxY = 0; for(AxisAlignedBB bb : list){ if(bb.maxY > maxY){ maxY = bb.maxY; } } this.onGround = (maxY == this.boundingBox.minY); }
Example #28
Source File: BlockThin.java From Nukkit with GNU General Public License v3.0 | 5 votes |
protected AxisAlignedBB recalculateBoundingBox() { final double offNW = 7.0 / 16.0; final double offSE = 9.0 / 16.0; final double onNW = 0.0; final double onSE = 1.0; double w = offNW; double e = offSE; double n = offNW; double s = offSE; try { boolean north = this.canConnect(this.north()); boolean south = this.canConnect(this.south()); boolean west = this.canConnect(this.west()); boolean east = this.canConnect(this.east()); w = west ? onNW : offNW; e = east ? onSE : offSE; n = north ? onNW : offNW; s = south ? onSE : offSE; } catch (LevelException ignore) { //null sucks } return new SimpleAxisAlignedBB( this.x + w, this.y, this.z + n, this.x + e, this.y + 1, this.z + s ); }
Example #29
Source File: BlockWall.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override protected AxisAlignedBB recalculateBoundingBox() { boolean north = this.canConnect(this.getSide(BlockFace.NORTH)); boolean south = this.canConnect(this.getSide(BlockFace.SOUTH)); boolean west = this.canConnect(this.getSide(BlockFace.WEST)); boolean east = this.canConnect(this.getSide(BlockFace.EAST)); double n = north ? 0 : 0.25; double s = south ? 1 : 0.75; double w = west ? 0 : 0.25; double e = east ? 1 : 0.75; if (north && south && !west && !east) { w = 0.3125; e = 0.6875; } else if (!north && !south && west && east) { n = 0.3125; s = 0.6875; } return new SimpleAxisAlignedBB( this.x + w, this.y, this.z + n, this.x + e, this.y + 1.5, this.z + s ); }
Example #30
Source File: BlockCocoa.java From Nukkit with GNU General Public License v3.0 | 5 votes |
private AxisAlignedBB getRelativeBoundingBox() { int damage = this.getDamage(); if (damage > 11) { this.setDamage(damage = 11); } AxisAlignedBB boundingBox = ALL[damage]; if (boundingBox != null) return boundingBox; AxisAlignedBB[] bbs; switch (getDamage()) { case 0: case 4: case 8: bbs = NORTH; break; case 1: case 5: case 9: bbs = EAST; break; case 2: case 6: case 10: bbs = SOUTH; break; case 3: case 7: case 11: bbs = WEST; break; default: bbs = NORTH; break; } return ALL[damage] = bbs[this.getDamage() >> 2]; }