Search in sources :

Example 1 with BlockSpreadEvent

use of cn.nukkit.event.block.BlockSpreadEvent in project Nukkit by Nukkit.

the class BlockMycelium method onUpdate.

@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_RANDOM) {
        // TODO: light levels
        NukkitRandom random = new NukkitRandom();
        x = random.nextRange((int) x - 1, (int) x + 1);
        y = random.nextRange((int) y - 1, (int) y + 1);
        z = random.nextRange((int) z - 1, (int) z + 1);
        Block block = this.getLevel().getBlock(new Vector3(x, y, z));
        if (block.getId() == Block.DIRT) {
            if (block.up().isTransparent()) {
                BlockSpreadEvent ev = new BlockSpreadEvent(block, this, new BlockMycelium());
                Server.getInstance().getPluginManager().callEvent(ev);
                if (!ev.isCancelled()) {
                    this.getLevel().setBlock(block, ev.getNewState());
                }
            }
        }
    }
    return 0;
}
Also used : BlockSpreadEvent(cn.nukkit.event.block.BlockSpreadEvent) ItemBlock(cn.nukkit.item.ItemBlock) Vector3(cn.nukkit.math.Vector3) NukkitRandom(cn.nukkit.math.NukkitRandom)

Example 2 with BlockSpreadEvent

use of cn.nukkit.event.block.BlockSpreadEvent in project Nukkit by Nukkit.

the class BlockGrass method onUpdate.

@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_RANDOM) {
        Block block = this.getLevel().getBlock(new Vector3(this.x, this.y, this.z));
        if (block.up().getLightLevel() < 4) {
            BlockSpreadEvent ev = new BlockSpreadEvent(block, this, new BlockDirt());
            Server.getInstance().getPluginManager().callEvent(ev);
        } else if (block.up().getLightLevel() >= 9) {
            for (int l = 0; l < 4; ++l) {
                NukkitRandom random = new NukkitRandom();
                int x = random.nextRange((int) this.x - 1, (int) this.x + 1);
                int y = random.nextRange((int) this.y - 2, (int) this.y + 2);
                int z = random.nextRange((int) this.z - 1, (int) this.z + 1);
                Block blocks = this.getLevel().getBlock(new Vector3(x, y, z));
                if (blocks.getId() == Block.DIRT && blocks.getDamage() == 0x0F && blocks.up().getLightLevel() >= 4 && blocks.z <= 2) {
                    BlockSpreadEvent ev = new BlockSpreadEvent(blocks, this, new BlockGrass());
                    Server.getInstance().getPluginManager().callEvent(ev);
                    if (!ev.isCancelled()) {
                        this.getLevel().setBlock(blocks, ev.getNewState());
                    }
                }
            }
        }
    }
    return 0;
}
Also used : BlockSpreadEvent(cn.nukkit.event.block.BlockSpreadEvent) Vector3(cn.nukkit.math.Vector3) NukkitRandom(cn.nukkit.math.NukkitRandom)

Aggregations

BlockSpreadEvent (cn.nukkit.event.block.BlockSpreadEvent)2 NukkitRandom (cn.nukkit.math.NukkitRandom)2 Vector3 (cn.nukkit.math.Vector3)2 ItemBlock (cn.nukkit.item.ItemBlock)1