Java Code Examples for cn.nukkit.item.Item#ANVIL

The following examples show how to use cn.nukkit.item.Item#ANVIL . 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: EntityFallingBlock.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onUpdate(int currentTick) {

    if (closed) {
        return false;
    }

    this.timing.startTiming();

    int tickDiff = currentTick - lastUpdate;
    if (tickDiff <= 0 && !justCreated) {
        return true;
    }

    lastUpdate = currentTick;

    boolean hasUpdate = entityBaseTick(tickDiff);

    if (isAlive()) {
        motionY -= getGravity();

        move(motionX, motionY, motionZ);

        float friction = 1 - getDrag();

        motionX *= friction;
        motionY *= 1 - getDrag();
        motionZ *= friction;

        Vector3 pos = (new Vector3(x - 0.5, y, z - 0.5)).round();

        if (onGround) {
            close();
            Block block = level.getBlock(pos);
            if (block.getId() > 0 && block.isTransparent() && !block.canBeReplaced()) {
                if (this.level.getGameRules().getBoolean(GameRule.DO_ENTITY_DROPS)) {
                    getLevel().dropItem(this, Item.get(this.getBlock(), this.getDamage(), 1));
                }
            } else {
                EntityBlockChangeEvent event = new EntityBlockChangeEvent(this, block, Block.get(getBlock(), getDamage()));
                server.getPluginManager().callEvent(event);
                if (!event.isCancelled()) {
                    getLevel().setBlock(pos, event.getTo(), true);

                    if (event.getTo().getId() == Item.ANVIL) {
                        getLevel().addSound(pos, Sound.RANDOM_ANVIL_LAND);
                    }
                }
            }
            hasUpdate = true;
        }

        updateMovement();
    }

    this.timing.stopTiming();

    return hasUpdate || !onGround || Math.abs(motionX) > 0.00001 || Math.abs(motionY) > 0.00001 || Math.abs(motionZ) > 0.00001;
}
 
Example 2
Source File: EntityFallingBlock.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onUpdate(int currentTick) {

    if (closed) {
        return false;
    }

    this.timing.startTiming();

    int tickDiff = currentTick - lastUpdate;
    if (tickDiff <= 0 && !justCreated) {
        return true;
    }

    lastUpdate = currentTick;

    boolean hasUpdate = entityBaseTick(tickDiff);

    if (isAlive()) {
        motionY -= getGravity();

        move(motionX, motionY, motionZ);

        float friction = 1 - getDrag();

        motionX *= friction;
        motionY *= 1 - getDrag();
        motionZ *= friction;

        Vector3 pos = (new Vector3(x - 0.5, y, z - 0.5)).round();

        if (onGround) {
            kill();
            Block block = level.getBlock(pos);
            if (block.getId() > 0 && block.isTransparent() && !block.canBeReplaced()) {
                if (this.level.getGameRules().getBoolean(GameRule.DO_ENTITY_DROPS)) {
                    getLevel().dropItem(this, Item.get(this.getBlock(), this.getDamage(), 1));
                }
            } else {
                EntityBlockChangeEvent event = new EntityBlockChangeEvent(this, block, Block.get(getBlock(), getDamage()));
                server.getPluginManager().callEvent(event);
                if (!event.isCancelled()) {
                    getLevel().setBlock(pos, event.getTo(), true);

                    if (event.getTo().getId() == Item.ANVIL) {
                        getLevel().addSound(pos, Sound.RANDOM_ANVIL_LAND);
                    }
                }
            }
            hasUpdate = true;
        }

        updateMovement();
    }

    this.timing.stopTiming();

    return hasUpdate || !onGround || Math.abs(motionX) > 0.00001 || Math.abs(motionY) > 0.00001 || Math.abs(motionZ) > 0.00001;
}