Java Code Examples for cn.nukkit.math.NukkitMath

The following examples show how to use cn.nukkit.math.NukkitMath. These examples are extracted from open source projects. 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
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 2
Source Project: Nukkit   Source File: PopulatorFlower.java    License: 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 3
Source Project: Jupiter   Source File: Entity.java    License: 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 4
Source Project: Nukkit   Source File: BlockUpdateScheduler.java    License: 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 5
Source Project: Nukkit   Source File: SwampTreePopulator.java    License: 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 Project: Jupiter   Source File: SavannaTreePopulator.java    License: 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 7
Source Project: Jupiter   Source File: JungleTreePopulator.java    License: 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 8
Source Project: Jupiter   Source File: SwampTreePopulator.java    License: 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 9
Source Project: Jupiter   Source File: DarkOakTreePopulator.java    License: 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 ObjectDarkOakTree().generate(level, random, v.setComponents(x, y, z));
    }
}
 
Example 10
@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 11
Source Project: Jupiter   Source File: MushroomPopulator.java    License: 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 Project: Nukkit   Source File: ContainerInventory.java    License: 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 13
Source Project: Jupiter   Source File: PopulatorFlower.java    License: 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 14
Source Project: Jupiter   Source File: Level.java    License: 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 15
Source Project: Jupiter   Source File: Level.java    License: 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 16
Source Project: Jupiter   Source File: Level.java    License: 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 17
Source Project: Jupiter   Source File: Level.java    License: 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 18
Source Project: Jupiter   Source File: ContainerInventory.java    License: 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 19
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;
    }
}
 
Example 20
Source Project: Nukkit   Source File: SavannaTreePopulator.java    License: 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 21
Source Project: Nukkit   Source File: SavannaTreePopulator.java    License: 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 22
Source Project: Nukkit   Source File: SwampTreePopulator.java    License: 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 23
Source Project: Nukkit   Source File: DarkOakTreePopulator.java    License: 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 24
Source Project: Nukkit   Source File: JungleTreePopulator.java    License: 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 25
@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 26
@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 27
Source Project: Nukkit   Source File: PopulatorOre.java    License: 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 28
Source Project: Nukkit   Source File: Server.java    License: 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 29
Source Project: Nukkit   Source File: ContainerInventory.java    License: 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 30
Source Project: Nukkit   Source File: BlockUpdateScheduler.java    License: 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;
    }
}