Java Code Examples for cn.nukkit.math.NukkitMath#floorDouble()
The following examples show how to use
cn.nukkit.math.NukkitMath#floorDouble() .
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 |
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 |
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 |
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 |
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 | 6 votes |
private boolean isAreaLoaded(AxisAlignedBB bb) { if (bb.maxY < 0 || bb.minY >= 256) { return false; } int minX = NukkitMath.floorDouble(bb.minX) >> 4; int minZ = NukkitMath.floorDouble(bb.minZ) >> 4; int maxX = NukkitMath.floorDouble(bb.maxX) >> 4; int maxZ = NukkitMath.floorDouble(bb.maxZ) >> 4; for (int x = minX; x <= maxX; ++x) { for (int z = minZ; z <= maxZ; ++z) { if (!this.isChunkLoaded(x, z)) { return false; } } } return true; }
Example 6
Source File: Level.java From Jupiter with GNU General Public License v3.0 | 5 votes |
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 7
Source File: CraftingTransaction.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public void setInput(int index, Item item) { int y = NukkitMath.floorDouble((double) index / this.gridSize); int x = index % this.gridSize; if (this.inputs[y][x].isNull()) { inputs[y][x] = item.clone(); } else if (!inputs[y][x].equals(item)) { throw new RuntimeException("Input " + index + " has already been set and does not match the current item (expected " + inputs[y][x] + ", got " + item + ")"); } }
Example 8
Source File: Entity.java From Jupiter with GNU General Public License v3.0 | 4 votes |
protected boolean checkObstruction(double x, double y, double z) { if (this.level.getCollisionCubes(this, this.getBoundingBox(), false).length == 0) { return false; } int i = NukkitMath.floorDouble(x); int j = NukkitMath.floorDouble(y); int k = NukkitMath.floorDouble(z); double diffX = x - i; double diffY = y - j; double diffZ = z - k; if (!Block.transparent[this.level.getBlockIdAt(i, j, k)]) { boolean flag = Block.transparent[this.level.getBlockIdAt(i - 1, j, k)]; boolean flag1 = Block.transparent[this.level.getBlockIdAt(i + 1, j, k)]; boolean flag2 = Block.transparent[this.level.getBlockIdAt(i, j - 1, k)]; boolean flag3 = Block.transparent[this.level.getBlockIdAt(i, j + 1, k)]; boolean flag4 = Block.transparent[this.level.getBlockIdAt(i, j, k - 1)]; boolean flag5 = Block.transparent[this.level.getBlockIdAt(i, j, k + 1)]; int direction = -1; double limit = 9999; if (flag) { limit = diffX; direction = 0; } if (flag1 && 1 - diffX < limit) { limit = 1 - diffX; direction = 1; } if (flag2 && diffY < limit) { limit = diffY; direction = 2; } if (flag3 && 1 - diffY < limit) { limit = 1 - diffY; direction = 3; } if (flag4 && diffZ < limit) { limit = diffZ; direction = 4; } if (flag5 && 1 - diffZ < limit) { direction = 5; } double force = new Random().nextDouble() * 0.2 + 0.1; if (direction == 0) { this.motionX = -force; return true; } if (direction == 1) { this.motionX = force; return true; } if (direction == 2) { this.motionY = -force; return true; } if (direction == 3) { this.motionY = force; return true; } if (direction == 4) { this.motionZ = -force; return true; } if (direction == 5) { this.motionZ = force; return true; } } return false; }
Example 9
Source File: StatusCommand.java From Jupiter with GNU General Public License v3.0 | 4 votes |
@Override public boolean execute(CommandSender sender, String commandLabel, String[] args) { if (!this.testPermission(sender)) { return true; } Server server = sender.getServer(); sender.sendMessage(TextFormat.GREEN + "---- " + TextFormat.WHITE + "Server status" + TextFormat.GREEN + " ----"); long time = (System.currentTimeMillis() - Nukkit.START_TIME) / 1000; int seconds = NukkitMath.floorDouble(time % 60); int minutes = NukkitMath.floorDouble((time % 3600) / 60); int hours = NukkitMath.floorDouble(time % (3600 * 24) / 3600); int days = NukkitMath.floorDouble(time / (3600 * 24)); String upTimeString = TextFormat.RED + "" + days + TextFormat.GOLD + " days " + TextFormat.RED + hours + TextFormat.GOLD + " hours " + TextFormat.RED + minutes + TextFormat.GOLD + " minutes " + TextFormat.RED + seconds + TextFormat.GOLD + " seconds"; sender.sendMessage(TextFormat.GOLD + "Uptime: " + upTimeString); TextFormat tpsColor = TextFormat.GREEN; float tps = server.getTicksPerSecond(); if (tps < 17) { tpsColor = TextFormat.GOLD; } else if (tps < 12) { tpsColor = TextFormat.RED; } sender.sendMessage(TextFormat.GOLD + "Current TPS: " + tpsColor + NukkitMath.round(tps, 2)); sender.sendMessage(TextFormat.GOLD + "Load: " + tpsColor + server.getTickUsage() + "%"); sender.sendMessage(TextFormat.GOLD + "Network upload: " + TextFormat.GREEN + NukkitMath.round((server.getNetwork().getUpload() / 1024 * 1000), 2) + " kB/s"); sender.sendMessage(TextFormat.GOLD + "Network download: " + TextFormat.GREEN + NukkitMath.round((server.getNetwork().getDownload() / 1024 * 1000), 2) + " kB/s"); sender.sendMessage(TextFormat.GOLD + "Thread count: " + TextFormat.GREEN + Thread.getAllStackTraces().size()); Runtime runtime = Runtime.getRuntime(); double totalMB = NukkitMath.round(((double) runtime.totalMemory()) / 1024 / 1024, 2); double usedMB = NukkitMath.round((double) (runtime.totalMemory() - runtime.freeMemory()) / 1024 / 1024, 2); double maxMB = NukkitMath.round(((double) runtime.maxMemory()) / 1024 / 1024, 2); double usage = usedMB / maxMB * 100; TextFormat usageColor = TextFormat.GREEN; if (usage > 85) { usageColor = TextFormat.GOLD; } sender.sendMessage(TextFormat.GOLD + "Used memory: " + usageColor + usedMB + " MB. (" + NukkitMath.round(usage, 2) + "%)"); sender.sendMessage(TextFormat.GOLD + "Total memory: " + TextFormat.RED + totalMB + " MB."); sender.sendMessage(TextFormat.GOLD + "Maximum VM memory: " + TextFormat.RED + maxMB + " MB."); sender.sendMessage(TextFormat.GOLD + "Available processors: " + TextFormat.GREEN + runtime.availableProcessors()); TextFormat playerColor = TextFormat.GREEN; if (((float) server.getOnlinePlayers().size() / (float) server.getMaxPlayers()) > 0.85) { playerColor = TextFormat.GOLD; } sender.sendMessage(TextFormat.GOLD + "Players: " + playerColor + server.getOnlinePlayers().size() + TextFormat.GREEN + " online, " + TextFormat.RED + server.getMaxPlayers() + TextFormat.GREEN + " max. "); for (Level level : server.getLevels().values()) { sender.sendMessage( TextFormat.GOLD + "World \"" + level.getFolderName() + "\"" + (!Objects.equals(level.getFolderName(), level.getName()) ? " (" + level.getName() + ")" : "") + ": " + TextFormat.RED + level.getChunks().size() + TextFormat.GREEN + " chunks, " + TextFormat.RED + level.getEntities().length + TextFormat.GREEN + " entities, " + TextFormat.RED + level.getBlockEntities().size() + TextFormat.GREEN + " blockEntities." + " Time " + ((level.getTickRate() > 1 || level.getTickRateTime() > 40) ? TextFormat.RED : TextFormat.YELLOW) + NukkitMath.round(level.getTickRateTime(), 2) + "ms" + (level.getTickRate() > 1 ? " (tick rate " + level.getTickRate() + ")" : "") ); } return true; }
Example 10
Source File: StatusCommand.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public boolean execute(CommandSender sender, String commandLabel, String[] args) { if (!this.testPermission(sender)) { return true; } Server server = sender.getServer(); sender.sendMessage(TextFormat.GREEN + "---- " + TextFormat.WHITE + "Server status" + TextFormat.GREEN + " ----"); long time = (System.currentTimeMillis() - Nukkit.START_TIME) / 1000; int seconds = NukkitMath.floorDouble(time % 60); int minutes = NukkitMath.floorDouble((time % 3600) / 60); int hours = NukkitMath.floorDouble(time % (3600 * 24) / 3600); int days = NukkitMath.floorDouble(time / (3600 * 24)); String upTimeString = TextFormat.RED + "" + days + TextFormat.GOLD + " days " + TextFormat.RED + hours + TextFormat.GOLD + " hours " + TextFormat.RED + minutes + TextFormat.GOLD + " minutes " + TextFormat.RED + seconds + TextFormat.GOLD + " seconds"; sender.sendMessage(TextFormat.GOLD + "Uptime: " + upTimeString); TextFormat tpsColor = TextFormat.GREEN; float tps = server.getTicksPerSecond(); if (tps < 17) { tpsColor = TextFormat.GOLD; } else if (tps < 12) { tpsColor = TextFormat.RED; } sender.sendMessage(TextFormat.GOLD + "Current TPS: " + tpsColor + NukkitMath.round(tps, 2)); sender.sendMessage(TextFormat.GOLD + "Load: " + tpsColor + server.getTickUsage() + "%"); sender.sendMessage(TextFormat.GOLD + "Network upload: " + TextFormat.GREEN + NukkitMath.round((server.getNetwork().getUpload() / 1024 * 1000), 2) + " kB/s"); sender.sendMessage(TextFormat.GOLD + "Network download: " + TextFormat.GREEN + NukkitMath.round((server.getNetwork().getDownload() / 1024 * 1000), 2) + " kB/s"); sender.sendMessage(TextFormat.GOLD + "Thread count: " + TextFormat.GREEN + Thread.getAllStackTraces().size()); Runtime runtime = Runtime.getRuntime(); double totalMB = NukkitMath.round(((double) runtime.totalMemory()) / 1024 / 1024, 2); double usedMB = NukkitMath.round((double) (runtime.totalMemory() - runtime.freeMemory()) / 1024 / 1024, 2); double maxMB = NukkitMath.round(((double) runtime.maxMemory()) / 1024 / 1024, 2); double usage = usedMB / maxMB * 100; TextFormat usageColor = TextFormat.GREEN; if (usage > 85) { usageColor = TextFormat.GOLD; } sender.sendMessage(TextFormat.GOLD + "Used memory: " + usageColor + usedMB + " MB. (" + NukkitMath.round(usage, 2) + "%)"); sender.sendMessage(TextFormat.GOLD + "Total memory: " + TextFormat.RED + totalMB + " MB."); sender.sendMessage(TextFormat.GOLD + "Maximum VM memory: " + TextFormat.RED + maxMB + " MB."); sender.sendMessage(TextFormat.GOLD + "Available processors: " + TextFormat.GREEN + runtime.availableProcessors()); TextFormat playerColor = TextFormat.GREEN; if (((float) server.getOnlinePlayers().size() / (float) server.getMaxPlayers()) > 0.85) { playerColor = TextFormat.GOLD; } sender.sendMessage(TextFormat.GOLD + "Players: " + playerColor + server.getOnlinePlayers().size() + TextFormat.GREEN + " online, " + TextFormat.RED + server.getMaxPlayers() + TextFormat.GREEN + " max. "); for (Level level : server.getLevels().values()) { sender.sendMessage( TextFormat.GOLD + "World \"" + level.getFolderName() + "\"" + (!Objects.equals(level.getFolderName(), level.getName()) ? " (" + level.getName() + ")" : "") + ": " + TextFormat.RED + level.getChunks().size() + TextFormat.GREEN + " chunks, " + TextFormat.RED + level.getEntities().length + TextFormat.GREEN + " entities, " + TextFormat.RED + level.getBlockEntities().size() + TextFormat.GREEN + " blockEntities." + " Time " + ((level.getTickRate() > 1 || level.getTickRateTime() > 40) ? TextFormat.RED : TextFormat.YELLOW) + NukkitMath.round(level.getTickRateTime(), 2) + "ms" + (level.getTickRate() > 1 ? " (tick rate " + level.getTickRate() + ")" : "") ); } return true; }