cn.nukkit.math.NukkitMath Java Examples

The following examples show how to use cn.nukkit.math.NukkitMath. 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: SpruceBigTreePopulator.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random, FullChunk chunk) {
    this.level = level;
    int amount = random.nextBoundedInt(this.randomAmount + 1) + this.baseAmount;
    Vector3 v = new Vector3();

    for (int i = 0; i < amount; ++i) {
        int x = NukkitMath.randomRange(random, chunkX << 4, (chunkX << 4) + 15);
        int z = NukkitMath.randomRange(random, chunkZ << 4, (chunkZ << 4) + 15);
        int y = this.getHighestWorkableBlock(x, z);
        if (y == -1) {
            continue;
        }
        new ObjectBigSpruceTree(3 / 4f, 4).placeObject(this.level, (int) (v.x = x), (int) (v.y = y), (int) (v.z = z), random);
    }
}
 
Example #2
Source File: SwampTreePopulator.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random) {
    this.level = level;
    int amount = random.nextBoundedInt(this.randomAmount + 1) + this.baseAmount;
    Vector3 v = new Vector3();

    for (int i = 0; i < amount; ++i) {
        int x = NukkitMath.randomRange(random, chunkX << 4, (chunkX << 4) + 15);
        int z = NukkitMath.randomRange(random, chunkZ << 4, (chunkZ << 4) + 15);
        int y = this.getHighestWorkableBlock(x, z);
        if (y == -1) {
            continue;
        }
        new ObjectSwampTree().generate(level, random, v.setComponents(x, y, z));
    }
}
 
Example #3
Source File: MushroomPopulator.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random) {
    this.level = level;
    int amount = random.nextBoundedInt(this.randomAmount + 1) + this.baseAmount;
    Vector3 v = new Vector3();

    for (int i = 0; i < amount; ++i) {
        int x = NukkitMath.randomRange(random, chunkX << 4, (chunkX << 4) + 15);
        int z = NukkitMath.randomRange(random, chunkZ << 4, (chunkZ << 4) + 15);
        int y = this.getHighestWorkableBlock(x, z);
        if (y == -1) {
            continue;
        }
        new BigMushroom(type).generate(level, random, v.setComponents(x, y, z));
    }
}
 
Example #4
Source File: JungleBigTreePopulator.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random) {
    this.level = level;
    int amount = random.nextBoundedInt(this.randomAmount + 1) + this.baseAmount;
    Vector3 v = new Vector3();

    for (int i = 0; i < amount; ++i) {
        int x = NukkitMath.randomRange(random, chunkX << 4, (chunkX << 4) + 15);
        int z = NukkitMath.randomRange(random, chunkZ << 4, (chunkZ << 4) + 15);
        int y = this.getHighestWorkableBlock(x, z);
        if (y == -1) {
            continue;
        }
        new ObjectJungleBigTree(10, 20, new BlockWood(BlockWood.JUNGLE), new BlockLeaves(BlockLeaves.JUNGLE)).generate(this.level, random, v.setComponents(x, y, z));
    }
}
 
Example #5
Source File: SwampTreePopulator.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random) {
    this.level = level;
    int amount = random.nextBoundedInt(this.randomAmount + 1) + this.baseAmount;
    Vector3 v = new Vector3();

    for (int i = 0; i < amount; ++i) {
        int x = NukkitMath.randomRange(random, chunkX << 4, (chunkX << 4) + 15);
        int z = NukkitMath.randomRange(random, chunkZ << 4, (chunkZ << 4) + 15);
        int y = this.getHighestWorkableBlock(x, z);
        if (y == -1) {
            continue;
        }
        new ObjectSwampTree().generate(level, random, v.setComponents(x, y, z));
    }
}
 
Example #6
Source File: BlockUpdateScheduler.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
private void perform(long tick) {
    try {
        lastTick = tick;
        Set<BlockUpdateEntry> updates = pendingUpdates = queuedUpdates.remove(tick);
        if (updates != null) {
            for (BlockUpdateEntry entry : updates) {
                Vector3 pos = entry.pos;
                if (level.isChunkLoaded(NukkitMath.floorDouble(pos.x) >> 4, NukkitMath.floorDouble(pos.z) >> 4)) {
                    Block block = level.getBlock(entry.pos);

                    if (Block.equals(block, entry.block, false)) {
                        block.onUpdate(level.BLOCK_UPDATE_SCHEDULED);
                    }
                } else {
                    level.scheduleUpdate(entry.block, entry.pos, 0);
                }
            }
        }
    } finally {
        pendingUpdates = null;
    }
}
 
Example #7
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 #8
Source File: PopulatorFlower.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random) {
    this.level = level;
    int amount = random.nextBoundedInt(this.randomAmount + 1) + this.baseAmount;

    if (flowerTypes.size() == 0) {
        this.addType(Block.RED_FLOWER, BlockFlower.TYPE_POPPY);
        this.addType(Block.DANDELION, 0);
    }

    int endNum = this.flowerTypes.size();

    for (int i = 0; i < amount; ++i) {
        int x = NukkitMath.randomRange(random, chunkX * 16, chunkX * 16 + 15);
        int z = NukkitMath.randomRange(random, chunkZ * 16, chunkZ * 16 + 15);
        int y = this.getHighestWorkableBlock(x, z);


        if (y != -1 && this.canFlowerStay(x, y, z)) {
            int[] type = this.flowerTypes.get(random.nextRange(0, endNum - 1));
            this.level.setBlockIdAt(x, y, z, type[0]);
            this.level.setBlockDataAt(x, y, z, type[1]);
        }
    }
}
 
Example #9
Source File: ContainerInventory.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public static int calculateRedstone(Inventory inv) {
    if (inv == null) {
        return 0;
    } else {
        int itemCount = 0;
        float averageCount = 0;

        for (int slot = 0; slot < inv.getSize(); ++slot) {
            Item item = inv.getItem(slot);

            if (item.getId() != 0) {
                averageCount += (float) item.getCount() / (float) Math.min(inv.getMaxStackSize(), item.getMaxStackSize());
                ++itemCount;
            }
        }

        averageCount = averageCount / (float) inv.getSize();
        return NukkitMath.floorFloat(averageCount * 14) + (itemCount > 0 ? 1 : 0);
    }
}
 
Example #10
Source File: Server.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public void titleTick() {
    if (!Nukkit.ANSI || !Nukkit.TITLE) {
        return;
    }

    Runtime runtime = Runtime.getRuntime();
    double used = NukkitMath.round((double) (runtime.totalMemory() - runtime.freeMemory()) / 1024 / 1024, 2);
    double max = NukkitMath.round(((double) runtime.maxMemory()) / 1024 / 1024, 2);
    String usage = Math.round(used / max * 100) + "%";
    String title = (char) 0x1b + "]0;" + this.getName() + " "
            + this.getNukkitVersion()
            + " | Online " + this.players.size() + "/" + this.getMaxPlayers()
            + " | Memory " + usage;
    if (!Nukkit.shortTitle) {
        title += " | U " + NukkitMath.round((this.network.getUpload() / 1024 * 1000), 2)
                + " D " + NukkitMath.round((this.network.getDownload() / 1024 * 1000), 2) + " kB/s";
    }
    title += " | TPS " + this.getTicksPerSecond()
            + " | Load " + this.getTickUsage() + "%" + (char) 0x07;

    System.out.print(title);
}
 
Example #11
Source File: MushroomPopulator.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random) {
    this.level = level;
    int amount = random.nextBoundedInt(this.randomAmount + 1) + this.baseAmount;
    Vector3 v = new Vector3();

    for (int i = 0; i < amount; ++i) {
        int x = NukkitMath.randomRange(random, chunkX << 4, (chunkX << 4) + 15);
        int z = NukkitMath.randomRange(random, chunkZ << 4, (chunkZ << 4) + 15);
        int y = this.getHighestWorkableBlock(x, z);
        if (y == -1) {
            continue;
        }
        new BigMushroom(type).generate(level, random, v.setComponents(x, y, z));
    }
}
 
Example #12
Source File: PopulatorOre.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random, FullChunk chunk) {
    int sx = chunkX << 4;
    int ex = sx + 15;
    int sz = chunkZ << 4;
    int ez = sz + 15;
    for (OreType type : this.oreTypes) {
        for (int i = 0; i < type.clusterCount; i++) {
            int x = NukkitMath.randomRange(random, sx, ex);
            int z = NukkitMath.randomRange(random, sz, ez);
            int y = NukkitMath.randomRange(random, type.minHeight, type.maxHeight);
            if (level.getBlockIdAt(x, y, z) != replaceId) {
                continue;
            }
            type.spawn(level, random, replaceId, x, y, z);
        }
    }
}
 
Example #13
Source File: ContainerInventory.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public static int calculateRedstone(Inventory inv) {
    if (inv == null) {
        return 0;
    } else {
        int itemCount = 0;
        float averageCount = 0;

        for (int slot = 0; slot < inv.getSize(); ++slot) {
            Item item = inv.getItem(slot);

            if (item.getId() != 0) {
                averageCount += (float) item.getCount() / (float) Math.min(inv.getMaxStackSize(), item.getMaxStackSize());
                ++itemCount;
            }
        }

        averageCount = averageCount / (float) inv.getSize();
        return NukkitMath.floorFloat(averageCount * 14) + (itemCount > 0 ? 1 : 0);
    }
}
 
Example #14
Source File: PopulatorFlower.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random) {
    this.level = level;
    int amount = random.nextBoundedInt(this.randomAmount + 1) + this.baseAmount;

    if (flowerTypes.size() == 0) {
        this.addType(Block.RED_FLOWER, BlockFlower.TYPE_POPPY);
        this.addType(Block.DANDELION, 0);
    }

    int endNum = this.flowerTypes.size();

    for (int i = 0; i < amount; ++i) {
        int x = NukkitMath.randomRange(random, chunkX * 16, chunkX * 16 + 15);
        int z = NukkitMath.randomRange(random, chunkZ * 16, chunkZ * 16 + 15);
        int y = this.getHighestWorkableBlock(x, z);


        if (y != -1 && this.canFlowerStay(x, y, z)) {
            int[] type = this.flowerTypes.get(random.nextRange(0, endNum - 1));
            this.level.setBlockIdAt(x, y, z, type[0]);
            this.level.setBlockDataAt(x, y, z, type[1]);
        }
    }
}
 
Example #15
Source File: SpruceMegaTreePopulator.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random, FullChunk chunk) {
    this.level = level;
    int amount = random.nextBoundedInt(this.randomAmount + 1) + this.baseAmount;
    Vector3 v = new Vector3();

    for (int i = 0; i < amount; ++i) {
        int x = NukkitMath.randomRange(random, chunkX << 4, (chunkX << 4) + 15);
        int z = NukkitMath.randomRange(random, chunkZ << 4, (chunkZ << 4) + 15);
        int y = this.getHighestWorkableBlock(x, z);
        if (y == -1) {
            continue;
        }
        new ObjectBigSpruceTree(1 / 4f, 5).placeObject(this.level, (int) (v.x = x), (int) (v.y = y), (int) (v.z = z), random);
    }
}
 
Example #16
Source File: BlockUpdateScheduler.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
private void perform(long tick) {
    try {
        lastTick = tick;
        Set<BlockUpdateEntry> updates = pendingUpdates = queuedUpdates.remove(tick);
        if (updates != null) {
            for (BlockUpdateEntry entry : updates) {
                Vector3 pos = entry.pos;
                if (level.isChunkLoaded(NukkitMath.floorDouble(pos.x) >> 4, NukkitMath.floorDouble(pos.z) >> 4)) {
                    Block block = level.getBlock(entry.pos);

                    if (Block.equals(block, entry.block, false)) {
                        block.onUpdate(Level.BLOCK_UPDATE_SCHEDULED);
                    }
                } else {
                    level.scheduleUpdate(entry.block, entry.pos, 0);
                }
            }
        }
    } finally {
        pendingUpdates = null;
    }
}
 
Example #17
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 #18
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 #19
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 #20
Source File: Level.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
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 #21
Source File: JungleTreePopulator.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random) {
    this.level = level;
    int amount = random.nextBoundedInt(this.randomAmount + 1) + this.baseAmount;
    Vector3 v = new Vector3();

    for (int i = 0; i < amount; ++i) {
        int x = NukkitMath.randomRange(random, chunkX << 4, (chunkX << 4) + 15);
        int z = NukkitMath.randomRange(random, chunkZ << 4, (chunkZ << 4) + 15);
        int y = this.getHighestWorkableBlock(x, z);
        if (y == -1) {
            continue;
        }
        new NewJungleTree(4 + random.nextBoundedInt(7)).generate(level, random, v.setComponents(x, y, z));
    }
}
 
Example #22
Source File: DarkOakTreePopulator.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random, FullChunk chunk) {
    this.level = level;
    int amount = random.nextBoundedInt(this.randomAmount + 1) + this.baseAmount;
    Vector3 v = new Vector3();

    for (int i = 0; i < amount; ++i) {
        int x = NukkitMath.randomRange(random, chunkX << 4, (chunkX << 4) + 15);
        int z = NukkitMath.randomRange(random, chunkZ << 4, (chunkZ << 4) + 15);
        int y = this.getHighestWorkableBlock(x, z);
        if (y == -1) {
            continue;
        }

        new ObjectDarkOakTree().generate(level, random, v.setComponents(x, y, z));
    }
}
 
Example #23
Source File: EntityEnderPearl.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onUpdate(int currentTick) {
    if (this.closed) {
        return false;
    }

    this.timing.startTiming();

    boolean hasUpdate = super.onUpdate(currentTick);

    if (this.isCollided && this.shootingEntity instanceof Player) {
        this.shootingEntity.teleport(new Vector3(NukkitMath.floorDouble(this.x) + 0.5, this.y, NukkitMath.floorDouble(this.z) + 0.5), TeleportCause.ENDER_PEARL);
        if ((((Player) this.shootingEntity).getGamemode() & 0x01) == 0) this.shootingEntity.attack(5);
        this.level.addSound(this, Sound.MOB_ENDERMEN_PORTAL);
    }

    if (this.age > 1200 || this.isCollided) {
        this.kill();
        hasUpdate = true;
    }

    this.timing.stopTiming();

    return hasUpdate;
}
 
Example #24
Source File: SwampTreePopulator.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random, FullChunk chunk) {
    this.level = level;
    int amount = random.nextBoundedInt(this.randomAmount + 1) + this.baseAmount;
    Vector3 v = new Vector3();

    for (int i = 0; i < amount; ++i) {
        int x = NukkitMath.randomRange(random, chunkX << 4, (chunkX << 4) + 15);
        int z = NukkitMath.randomRange(random, chunkZ << 4, (chunkZ << 4) + 15);
        int y = this.getHighestWorkableBlock(x, z);
        if (y == -1) {
            continue;
        }
        new ObjectSwampTree().generate(level, random, v.setComponents(x, y, z));
    }
}
 
Example #25
Source File: SavannaTreePopulator.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random, FullChunk chunk) {
    this.level = level;
    int amount = random.nextBoundedInt(this.randomAmount + 1) + this.baseAmount;
    Vector3 v = new Vector3();

    for (int i = 0; i < amount; ++i) {
        int x = NukkitMath.randomRange(random, chunkX << 4, (chunkX << 4) + 15);
        int z = NukkitMath.randomRange(random, chunkZ << 4, (chunkZ << 4) + 15);
        int y = this.getHighestWorkableBlock(x, z);
        if (y == -1) {
            continue;
        }
        new ObjectSavannaTree().generate(level, random, v.setComponents(x, y, z));
    }
}
 
Example #26
Source File: SavannaTreePopulator.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random) {
    this.level = level;
    int amount = random.nextBoundedInt(this.randomAmount + 1) + this.baseAmount;
    Vector3 v = new Vector3();

    for (int i = 0; i < amount; ++i) {
        int x = NukkitMath.randomRange(random, chunkX << 4, (chunkX << 4) + 15);
        int z = NukkitMath.randomRange(random, chunkZ << 4, (chunkZ << 4) + 15);
        int y = this.getHighestWorkableBlock(x, z);
        if (y == -1) {
            continue;
        }
        new ObjectSavannaTree().generate(level, random, v.setComponents(x, y, z));
    }
}
 
Example #27
Source File: ContainerInventory.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public static int calculateRedstone(Inventory inv) {
    if (inv == null) {
        return 0;
    } else {
        int itemCount = 0;
        float averageCount = 0;

        for (int slot = 0; slot < inv.getSize(); ++slot) {
            Item item = inv.getItem(slot);

            if (item.getId() != 0) {
                averageCount += (float) item.getCount() / (float) Math.min(inv.getMaxStackSize(), item.getMaxStackSize());
                ++itemCount;
            }
        }

        averageCount = averageCount / (float) inv.getSize();
        return NukkitMath.floorFloat(averageCount * 14) + (itemCount > 0 ? 1 : 0);
    }
}
 
Example #28
Source File: EntityMinecartAbstract.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
private void setFalling() {
    motionX = NukkitMath.clamp(motionX, -getMaxSpeed(), getMaxSpeed());
    motionZ = NukkitMath.clamp(motionZ, -getMaxSpeed(), getMaxSpeed());
    
    if(linkedEntity != null && !hasUpdated){
        updateRiderPosition(getMountedYOffset() + 0.35F);
        hasUpdated = true;
    } else {
        hasUpdated = false;
    }
    
    if (onGround) {
        motionX *= derailedX;
        motionY *= derailedY;
        motionZ *= derailedZ;
    }

    move(motionX, motionY, motionZ);
    if (!onGround) {
        motionX *= flyingX;
        motionY *= flyingY;
        motionZ *= flyingZ;
    }
}
 
Example #29
Source File: Server.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public void titleTick() {
    if (!Nukkit.ANSI) {
        return;
    }

    Runtime runtime = Runtime.getRuntime();
    double used = NukkitMath.round((double) (runtime.totalMemory() - runtime.freeMemory()) / 1024 / 1024, 2);
    double max = NukkitMath.round(((double) runtime.maxMemory()) / 1024 / 1024, 2);
    String usage = Math.round(used / max * 100) + "%";
    String title = (char) 0x1b + "]0;" + this.getName() + " "
            + this.getNukkitVersion()
            + " | Online " + this.players.size() + "/" + this.getMaxPlayers()
            + " | Memory " + usage;
    if (!Nukkit.shortTitle) {
        title += " | U " + NukkitMath.round((this.network.getUpload() / 1024 * 1000), 2)
                + " D " + NukkitMath.round((this.network.getDownload() / 1024 * 1000), 2) + " kB/s";
    }
    title += " | TPS " + this.getTicksPerSecond()
            + " | Load " + this.getTickUsage() + "%" + (char) 0x07;

    System.out.print(title);
}
 
Example #30
Source File: EntityMinecartAbstract.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
private void setFalling() {
    motionX = NukkitMath.clamp(motionX, -getMaxSpeed(), getMaxSpeed());
    motionZ = NukkitMath.clamp(motionZ, -getMaxSpeed(), getMaxSpeed());

    if (!hasUpdated) {
        for (cn.nukkit.entity.Entity linked : passengers) {
            linked.setSeatPosition(getMountedOffset(linked).add(0, 0.35f));
            updatePassengerPosition(linked);
        }

        hasUpdated = true;
    }

    if (onGround) {
        motionX *= derailedX;
        motionY *= derailedY;
        motionZ *= derailedZ;
    }

    move(motionX, motionY, motionZ);
    if (!onGround) {
        motionX *= flyingX;
        motionY *= flyingY;
        motionZ *= flyingZ;
    }
}