Search in sources :

Example 1 with Block

use of cn.nukkit.block.Block in project Nukkit by Nukkit.

the class BlockEntityBrewingStand method updateBlock.

public void updateBlock() {
    Block block = this.getLevelBlock();
    if (!(block instanceof BlockBrewingStand)) {
        return;
    }
    int meta = 0;
    for (int i = 1; i <= 3; ++i) {
        Item potion = this.inventory.getItem(i);
        if (potion.getId() == Item.POTION && potion.getCount() > 0) {
            meta |= 1 << i;
        }
    }
    block.setDamage(meta);
    this.level.setBlock(block, block, false, false);
}
Also used : Item(cn.nukkit.item.Item) BlockBrewingStand(cn.nukkit.block.BlockBrewingStand) ItemBlock(cn.nukkit.item.ItemBlock) Block(cn.nukkit.block.Block)

Example 2 with Block

use of cn.nukkit.block.Block in project Nukkit by Nukkit.

the class EntityFallingBlock method onUpdate.

@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;
}
Also used : EntityBlockChangeEvent(cn.nukkit.event.entity.EntityBlockChangeEvent) Block(cn.nukkit.block.Block) Vector3(cn.nukkit.math.Vector3)

Example 3 with Block

use of cn.nukkit.block.Block in project Nukkit by Nukkit.

the class EntityMinecartAbstract method onUpdate.

@Override
public boolean onUpdate(int currentTick) {
    if (this.closed) {
        return false;
    }
    if (!this.isAlive()) {
        ++this.deadTicks;
        if (this.deadTicks >= 10) {
            this.despawnFromAll();
            this.close();
        }
        return this.deadTicks < 10;
    }
    int tickDiff = currentTick - this.lastUpdate;
    if (tickDiff <= 0) {
        return false;
    }
    this.lastUpdate = currentTick;
    if (isAlive()) {
        super.onUpdate(currentTick);
        // Entity variables
        lastX = x;
        lastY = y;
        lastZ = z;
        motionY -= 0.03999999910593033D;
        int dx = MathHelper.floor(x);
        int dy = MathHelper.floor(y);
        int dz = MathHelper.floor(z);
        // Some hack to check rails
        if (Rail.isRailBlock(level.getBlockIdAt(dx, dy - 1, dz))) {
            --dy;
        }
        Block block = level.getBlock(new Vector3(dx, dy, dz));
        // Ensure that the block is a rail
        if (Rail.isRailBlock(block)) {
            processMovement(dx, dy, dz, (BlockRail) block);
            if (block instanceof BlockRailActivator) {
                // Activate the minecart/TNT
                activate(dx, dy, dz, (block.getDamage() & 0x8) != 0);
            }
        } else {
            setFalling();
        }
        checkBlockCollision();
        // Minecart head
        pitch = 0;
        double diffX = this.lastX - this.x;
        double diffZ = this.lastZ - this.z;
        double yawToChange = yaw;
        if (diffX * diffX + diffZ * diffZ > 0.001D) {
            yawToChange = (Math.atan2(diffZ, diffX) * 180 / 3.141592653589793D);
        }
        // Reverse yaw if yaw is below 0
        if (yawToChange < 0) {
            // -90-(-90)-(-90) = 90
            yawToChange -= yawToChange - yawToChange;
        }
        setRotation(yawToChange, pitch);
        Location from = new Location(lastX, lastY, lastZ, lastYaw, lastPitch, level);
        Location to = new Location(this.x, this.y, this.z, this.yaw, this.pitch, level);
        this.getServer().getPluginManager().callEvent(new VehicleUpdateEvent(this));
        if (!from.equals(to)) {
            this.getServer().getPluginManager().callEvent(new VehicleMoveEvent(this, from, to));
        }
        // Collisions
        for (Entity entity : level.getNearbyEntities(boundingBox.grow(0.2D, 0, 0.2D), this)) {
            if (entity != linkedEntity && entity instanceof EntityMinecartAbstract) {
                entity.applyEntityCollision(this);
            }
        }
        // Easier
        if ((linkedEntity != null) && (!linkedEntity.isAlive())) {
            if (linkedEntity.riding == this) {
                linkedEntity.riding = null;
            }
            linkedEntity = null;
        }
        // No need to onGround or Motion diff! This always have an update
        return true;
    }
    return false;
}
Also used : Entity(cn.nukkit.entity.Entity) BlockRailActivator(cn.nukkit.block.BlockRailActivator) VehicleUpdateEvent(cn.nukkit.event.vehicle.VehicleUpdateEvent) VehicleMoveEvent(cn.nukkit.event.vehicle.VehicleMoveEvent) Block(cn.nukkit.block.Block) Vector3(cn.nukkit.math.Vector3) Location(cn.nukkit.level.Location)

Example 4 with Block

use of cn.nukkit.block.Block in project Nukkit by Nukkit.

the class Entity method isInsideOfSolid.

public boolean isInsideOfSolid() {
    double y = this.y + this.getEyeHeight();
    Block block = this.level.getBlock(this.temporalVector.setComponents(NukkitMath.floorDouble(this.x), NukkitMath.floorDouble(y), NukkitMath.floorDouble(this.z)));
    AxisAlignedBB bb = block.getBoundingBox();
    return bb != null && block.isSolid() && !block.isTransparent() && bb.intersectsWith(this.getBoundingBox());
}
Also used : Block(cn.nukkit.block.Block)

Example 5 with Block

use of cn.nukkit.block.Block in project Nukkit by Nukkit.

the class Entity method checkBlockCollision.

protected void checkBlockCollision() {
    Vector3 vector = new Vector3(0, 0, 0);
    boolean portal = false;
    for (Block block : this.getCollisionBlocks()) {
        if (block.getId() == Block.NETHER_PORTAL) {
            portal = true;
            continue;
        }
        block.onEntityCollide(this);
        block.addVelocityToEntity(this, vector);
    }
    if (portal) {
        inPortalTicks++;
    } else {
        this.inPortalTicks = 0;
    }
    if (vector.lengthSquared() > 0) {
        vector = vector.normalize();
        double d = 0.014d;
        this.motionX += vector.x * d;
        this.motionY += vector.y * d;
        this.motionZ += vector.z * d;
    }
}
Also used : Block(cn.nukkit.block.Block)

Aggregations

Block (cn.nukkit.block.Block)29 ItemBlock (cn.nukkit.item.ItemBlock)13 Entity (cn.nukkit.entity.Entity)7 BlockEntity (cn.nukkit.blockentity.BlockEntity)5 Vector3 (cn.nukkit.math.Vector3)5 Player (cn.nukkit.Player)4 BlockAir (cn.nukkit.block.BlockAir)4 Item (cn.nukkit.item.Item)4 BaseFullChunk (cn.nukkit.level.format.generic.BaseFullChunk)4 FullChunk (cn.nukkit.level.format.FullChunk)3 BlockFire (cn.nukkit.block.BlockFire)2 BlockWater (cn.nukkit.block.BlockWater)2 EntityItem (cn.nukkit.entity.item.EntityItem)2 BlockIgniteEvent (cn.nukkit.event.block.BlockIgniteEvent)2 BlockUpdateEvent (cn.nukkit.event.block.BlockUpdateEvent)2 PlayerInteractEvent (cn.nukkit.event.player.PlayerInteractEvent)2 ArrayList (java.util.ArrayList)2 BlockBrewingStand (cn.nukkit.block.BlockBrewingStand)1 BlockDirt (cn.nukkit.block.BlockDirt)1 BlockHugeMushroomBrown (cn.nukkit.block.BlockHugeMushroomBrown)1