Search in sources :

Example 1 with BoneMealParticle

use of cn.nukkit.level.particle.BoneMealParticle in project Nukkit by Nukkit.

the class BlockCocoa method onActivate.

@Override
public boolean onActivate(Item item, Player player) {
    if (item.getId() == Item.DYE && item.getDamage() == 0x0f) {
        Block block = this.clone();
        if (this.getDamage() / 4 < 2) {
            block.setDamage(block.getDamage() + 4);
            BlockGrowEvent ev = new BlockGrowEvent(this, block);
            Server.getInstance().getPluginManager().callEvent(ev);
            if (ev.isCancelled()) {
                return false;
            }
            this.getLevel().setBlock(this, ev.getNewState(), true, true);
        }
        this.level.addParticle(new BoneMealParticle(this.add(0.5, 0.5, 0.5)));
        item.count--;
        return true;
    }
    return false;
}
Also used : BoneMealParticle(cn.nukkit.level.particle.BoneMealParticle) BlockGrowEvent(cn.nukkit.event.block.BlockGrowEvent)

Example 2 with BoneMealParticle

use of cn.nukkit.level.particle.BoneMealParticle in project Nukkit by Nukkit.

the class BlockSapling method onActivate.

public boolean onActivate(Item item, Player player) {
    if (item.getId() == Item.DYE && item.getDamage() == 0x0F) {
        // BoneMeal
        if ((player.gamemode & 0x01) == 0) {
            item.count--;
        }
        this.level.addParticle(new BoneMealParticle(this));
        if (ThreadLocalRandom.current().nextFloat() >= 0.45) {
            return true;
        }
        BasicGenerator generator = null;
        boolean bigTree = false;
        int x = 0;
        int z = 0;
        switch(this.getDamage()) {
            case JUNGLE:
                loop: for (x = 0; x >= -1; --x) {
                    for (z = 0; z >= -1; --z) {
                        if (this.findSaplings(x, z, JUNGLE)) {
                            generator = new ObjectJungleBigTree(10, 20, new BlockWood(BlockWood.JUNGLE), new BlockLeaves(BlockLeaves.JUNGLE));
                            bigTree = true;
                            break loop;
                        }
                    }
                }
                if (!bigTree) {
                    generator = new NewJungleTree(4 + ThreadLocalRandom.current().nextInt(7));
                }
                break;
            case ACACIA:
                generator = new ObjectSavannaTree();
                break;
            case DARK_OAK:
                bigTree = false;
                loop: for (x = 0; x >= -1; --x) {
                    for (z = 0; z >= -1; --z) {
                        if (this.findSaplings(x, z, DARK_OAK)) {
                            generator = new ObjectDarkOakTree();
                            bigTree = true;
                            break loop;
                        }
                    }
                }
                if (!bigTree) {
                    return false;
                }
                break;
            // TODO: big spruce
            default:
                ObjectTree.growTree(this.getLevel(), (int) this.x, (int) this.y, (int) this.z, new NukkitRandom(), this.getDamage() & 0x07);
                return true;
        }
        BlockAir air = new BlockAir();
        if (bigTree) {
            this.level.setBlock(this.add(x, 0, z), air, true, false);
            this.level.setBlock(this.add(x + 1, 0, z), air, true, false);
            this.level.setBlock(this.add(x, 0, z + 1), air, true, false);
            this.level.setBlock(this.add(x + 1, 0, z + 1), air, true, false);
        } else {
            this.level.setBlock(this, air, true, false);
        }
        if (!generator.generate(this.level, new NukkitRandom(), this.add(x, 0, z))) {
            if (bigTree) {
                this.level.setBlock(this.add(x, 0, z), this, true, false);
                this.level.setBlock(this.add(x + 1, 0, z), this, true, false);
                this.level.setBlock(this.add(x, 0, z + 1), this, true, false);
                this.level.setBlock(this.add(x + 1, 0, z + 1), this, true, false);
            } else {
                this.level.setBlock(this, this, true, false);
            }
        }
        return true;
    }
    return false;
}
Also used : BoneMealParticle(cn.nukkit.level.particle.BoneMealParticle) BasicGenerator(cn.nukkit.level.generator.object.BasicGenerator) NukkitRandom(cn.nukkit.math.NukkitRandom)

Example 3 with BoneMealParticle

use of cn.nukkit.level.particle.BoneMealParticle in project Nukkit by Nukkit.

the class BlockSugarcane method onActivate.

@Override
public boolean onActivate(Item item, Player player) {
    if (item.getId() == Item.DYE && item.getDamage() == 0x0F) {
        // Bonemeal
        int count = 1;
        for (int i = 1; i <= 2; i++) {
            int id = this.level.getBlockIdAt(this.getFloorX(), this.getFloorY() - i, this.getFloorZ());
            if (id == SUGARCANE_BLOCK) {
                count++;
            }
        }
        if (count < 3) {
            int toGrow = 3 - count;
            for (int i = 1; i <= toGrow; i++) {
                Block block = this.up(i);
                if (block.getId() == 0) {
                    BlockGrowEvent ev = new BlockGrowEvent(block, new BlockSugarcane());
                    Server.getInstance().getPluginManager().callEvent(ev);
                    if (!ev.isCancelled()) {
                        this.getLevel().setBlock(block, ev.getNewState(), true);
                    }
                } else if (block.getId() != SUGARCANE_BLOCK) {
                    break;
                }
            }
        }
        if ((player.gamemode & 0x01) == 0) {
            item.count--;
        }
        this.level.addParticle(new BoneMealParticle(this.add(0.5, 0.5, 0.5)));
        return true;
    }
    return false;
}
Also used : BoneMealParticle(cn.nukkit.level.particle.BoneMealParticle) BlockGrowEvent(cn.nukkit.event.block.BlockGrowEvent)

Example 4 with BoneMealParticle

use of cn.nukkit.level.particle.BoneMealParticle in project Nukkit by Nukkit.

the class BlockCrops method onActivate.

@Override
public boolean onActivate(Item item, Player player) {
    // Bone meal
    if (item.getId() == Item.DYE && item.getDamage() == 0x0f) {
        BlockCrops block = (BlockCrops) this.clone();
        if (this.getDamage() < 7) {
            block.setDamage(block.getDamage() + new Random().nextInt(3) + 2);
            if (block.getDamage() > 7) {
                block.setDamage(7);
            }
            BlockGrowEvent ev = new BlockGrowEvent(this, block);
            Server.getInstance().getPluginManager().callEvent(ev);
            if (ev.isCancelled()) {
                return false;
            }
            this.getLevel().setBlock(this, ev.getNewState(), false, true);
        }
        this.level.addParticle(new BoneMealParticle(this.add(0.5, 0.5, 0.5)));
        item.count--;
        return true;
    }
    return false;
}
Also used : BoneMealParticle(cn.nukkit.level.particle.BoneMealParticle) Random(java.util.Random) BlockGrowEvent(cn.nukkit.event.block.BlockGrowEvent)

Aggregations

BoneMealParticle (cn.nukkit.level.particle.BoneMealParticle)4 BlockGrowEvent (cn.nukkit.event.block.BlockGrowEvent)3 BasicGenerator (cn.nukkit.level.generator.object.BasicGenerator)1 NukkitRandom (cn.nukkit.math.NukkitRandom)1 Random (java.util.Random)1