Search in sources :

Example 6 with Block

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

the class Entity method fall.

public void fall(float fallDistance) {
    float damage = (float) Math.floor(fallDistance - 3 - (this.hasEffect(Effect.JUMP) ? this.getEffect(Effect.JUMP).getAmplifier() + 1 : 0));
    if (damage > 0) {
        this.attack(new EntityDamageEvent(this, DamageCause.FALL, damage));
    }
    if (fallDistance > 0.75) {
        Block down = this.level.getBlock(this.floor().down());
        if (down.getId() == Item.FARMLAND) {
            Event ev;
            if (this instanceof Player) {
                ev = new PlayerInteractEvent((Player) this, null, down, null, Action.PHYSICAL);
            } else {
                ev = new EntityInteractEvent(this, down);
            }
            this.server.getPluginManager().callEvent(ev);
            if (ev.isCancelled()) {
                return;
            }
            this.level.setBlock(down, new BlockDirt(), false, true);
        }
    }
}
Also used : Player(cn.nukkit.Player) PlayerInteractEvent(cn.nukkit.event.player.PlayerInteractEvent) Block(cn.nukkit.block.Block) PlayerInteractEvent(cn.nukkit.event.player.PlayerInteractEvent) Event(cn.nukkit.event.Event) PlayerTeleportEvent(cn.nukkit.event.player.PlayerTeleportEvent) BlockDirt(cn.nukkit.block.BlockDirt)

Example 7 with Block

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

the class Entity method getBlocksAround.

public List<Block> getBlocksAround() {
    if (this.blocksAround == null) {
        int minX = NukkitMath.floorDouble(this.boundingBox.getMinX());
        int minY = NukkitMath.floorDouble(this.boundingBox.getMinY());
        int minZ = NukkitMath.floorDouble(this.boundingBox.getMinZ());
        int maxX = NukkitMath.ceilDouble(this.boundingBox.getMaxX());
        int maxY = NukkitMath.ceilDouble(this.boundingBox.getMaxY());
        int maxZ = NukkitMath.ceilDouble(this.boundingBox.getMaxZ());
        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;
}
Also used : Block(cn.nukkit.block.Block)

Example 8 with Block

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

the class EntityLiving method getLineOfSight.

public Block[] getLineOfSight(int maxDistance, int maxLength, Integer[] transparent) {
    if (maxDistance > 120) {
        maxDistance = 120;
    }
    if (transparent != null && transparent.length == 0) {
        transparent = null;
    }
    List<Block> blocks = new ArrayList<>();
    BlockIterator itr = new BlockIterator(this.level, this.getPosition(), this.getDirectionVector(), this.getEyeHeight(), maxDistance);
    while (itr.hasNext()) {
        Block block = itr.next();
        blocks.add(block);
        if (maxLength != 0 && blocks.size() > maxLength) {
            blocks.remove(0);
        }
        int id = block.getId();
        if (transparent == null) {
            if (id != 0) {
                break;
            }
        } else {
            if (Arrays.binarySearch(transparent, id) < 0) {
                break;
            }
        }
    }
    return blocks.stream().toArray(Block[]::new);
}
Also used : BlockIterator(cn.nukkit.utils.BlockIterator) ArrayList(java.util.ArrayList) Block(cn.nukkit.block.Block)

Example 9 with Block

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

the class EntityLiving method getTargetBlock.

public Block getTargetBlock(int maxDistance, Integer[] transparent) {
    try {
        Block[] blocks = this.getLineOfSight(maxDistance, 1, transparent);
        Block block = blocks[0];
        if (block != null) {
            if (transparent != null && transparent.length != 0) {
                if (Arrays.binarySearch(transparent, block.getId()) < 0) {
                    return block;
                }
            } else {
                return block;
            }
        }
    } catch (Exception ignored) {
    }
    return null;
}
Also used : Block(cn.nukkit.block.Block)

Example 10 with Block

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

the class EntityLightning method onUpdate.

@Override
public boolean onUpdate(int currentTick) {
    if (this.closed) {
        return false;
    }
    int tickDiff = currentTick - this.lastUpdate;
    if (tickDiff <= 0 && !this.justCreated) {
        return true;
    }
    this.lastUpdate = currentTick;
    this.entityBaseTick(tickDiff);
    if (this.state == 2) {
        this.level.addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_THUNDER, 93, -1);
        this.level.addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_EXPLODE, 93, -1);
    }
    this.state--;
    if (this.state < 0) {
        if (this.liveTime == 0) {
            this.close();
            return false;
        } else if (this.state < -ThreadLocalRandom.current().nextInt(10)) {
            this.liveTime--;
            this.state = 1;
            if (this.isEffect && this.level.gameRules.getBoolean(GameRule.DO_FIRE_TICK)) {
                Block block = this.getLevelBlock();
                if (block.getId() == Block.AIR || block.getId() == Block.TALL_GRASS) {
                    BlockIgniteEvent e = new BlockIgniteEvent(block, null, this, BlockIgniteEvent.BlockIgniteCause.LIGHTNING);
                    getServer().getPluginManager().callEvent(e);
                    if (!e.isCancelled()) {
                        Block fire = new BlockFire();
                        this.level.setBlock(block, fire);
                        this.getLevel().scheduleUpdate(fire, fire.tickRate());
                    }
                }
            }
        }
    }
    if (this.state >= 0) {
        if (this.isEffect) {
            AxisAlignedBB bb = getBoundingBox().grow(3, 3, 3);
            bb.setMaxX(bb.getMaxX() + 6);
            for (Entity entity : this.level.getCollidingEntities(bb, this)) {
                entity.onStruckByLightning(this);
            }
        }
    }
    return true;
}
Also used : AxisAlignedBB(cn.nukkit.math.AxisAlignedBB) Entity(cn.nukkit.entity.Entity) Block(cn.nukkit.block.Block) BlockIgniteEvent(cn.nukkit.event.block.BlockIgniteEvent) BlockFire(cn.nukkit.block.BlockFire)

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