cn.nukkit.event.block.BlockGrowEvent Java Examples

The following examples show how to use cn.nukkit.event.block.BlockGrowEvent. 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: BlockCocoa.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example #2
Source File: BlockCocoa.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onActivate(Item item, Player player) {
    if (item.getId() == Item.DYE && item.getDamage() == 0x0f) {
        Block block = this.clone();
        if (this.meta / 4 < 2) {
            block.meta += 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;
}
 
Example #3
Source File: BlockCocoa.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@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));

            if (player != null && (player.gamemode & 0x01) == 0) {
                item.count--;
            }
        }

        return true;
    }

    return false;
}
 
Example #4
Source File: BlockNetherWart.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_NORMAL) {
        if (this.down().getId() != SOUL_SAND) {
            this.getLevel().useBreakOn(this);
            return Level.BLOCK_UPDATE_NORMAL;
        }
    } else if (type == Level.BLOCK_UPDATE_RANDOM) {
        if (new Random().nextInt(10) == 1) {
            if (this.getDamage() < 0x03) {
                BlockNetherWart block = (BlockNetherWart) this.clone();
                block.setDamage(block.getDamage() + 1);
                BlockGrowEvent ev = new BlockGrowEvent(this, block);
                Server.getInstance().getPluginManager().callEvent(ev);

                if (!ev.isCancelled()) {
                    this.getLevel().setBlock(this, ev.getNewState(), true, true);
                } else {
                    return Level.BLOCK_UPDATE_RANDOM;
                }
            }
        } else {
            return Level.BLOCK_UPDATE_RANDOM;
        }
    }

    return 0;
}
 
Example #5
Source File: BlockCocoa.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_NORMAL) {
        int[] faces = new int[]{
                3, 4, 2, 5, 3, 4, 2, 5, 3, 4, 2, 5
        };

        Block side = this.getSide(BlockFace.fromIndex(faces[this.getDamage()]));

        if (side.getId() != Block.WOOD && side.getDamage() != BlockWood.JUNGLE) {
            this.getLevel().useBreakOn(this);
            return Level.BLOCK_UPDATE_NORMAL;
        }
    } else if (type == Level.BLOCK_UPDATE_RANDOM) {
        if (new Random().nextInt(2) == 1) {
            if (this.getDamage() / 4 < 2) {
                BlockCocoa block = (BlockCocoa) this.clone();
                block.setDamage(block.getDamage() + 4);
                BlockGrowEvent ev = new BlockGrowEvent(this, block);
                Server.getInstance().getPluginManager().callEvent(ev);

                if (!ev.isCancelled()) {
                    this.getLevel().setBlock(this, ev.getNewState(), true, true);
                } else {
                    return Level.BLOCK_UPDATE_RANDOM;
                }
            }
        } else {
            return Level.BLOCK_UPDATE_RANDOM;
        }
    }

    return 0;
}
 
Example #6
Source File: BlockCactus.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_NORMAL) {
        Block down = down();
        if (down.getId() != SAND && down.getId() != CACTUS) {
            this.getLevel().useBreakOn(this);
        } else {
            for (int side = 2; side <= 5; ++side) {
                Block block = getSide(BlockFace.fromIndex(side));
                if (!block.canBeFlowedInto()) {
                    this.getLevel().useBreakOn(this);
                }
            }
        }
    } else if (type == Level.BLOCK_UPDATE_RANDOM) {
        if (down().getId() != CACTUS) {
            if (this.getDamage() == 0x0F) {
                for (int y = 1; y < 3; ++y) {
                    Block b = this.getLevel().getBlock(new Vector3(this.x, this.y + y, this.z));
                    if (b.getId() == AIR) {
                        BlockGrowEvent event = new BlockGrowEvent(b, new BlockCactus());
                        Server.getInstance().getPluginManager().callEvent(event);
                        if (!event.isCancelled()) {
                            this.getLevel().setBlock(b, event.getNewState(), true);
                        }
                    }
                }
                this.setDamage(0);
                this.getLevel().setBlock(this, this);
            } else {
                this.setDamage(this.getDamage() + 1);
                this.getLevel().setBlock(this, this);
            }
        }
    }

    return 0;
}
 
Example #7
Source File: BlockNetherWart.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_NORMAL) {
        if (this.down().getId() != SOUL_SAND) {
            this.getLevel().useBreakOn(this);
            return Level.BLOCK_UPDATE_NORMAL;
        }
    } else if (type == Level.BLOCK_UPDATE_RANDOM) {
        if (new Random().nextInt(10) == 1) {
            if (this.getDamage() < 0x03) {
                BlockNetherWart block = (BlockNetherWart) this.clone();
                block.setDamage(block.getDamage() + 1);
                BlockGrowEvent ev = new BlockGrowEvent(this, block);
                Server.getInstance().getPluginManager().callEvent(ev);

                if (!ev.isCancelled()) {
                    this.getLevel().setBlock(this, ev.getNewState(), true, true);
                } else {
                    return Level.BLOCK_UPDATE_RANDOM;
                }
            }
        } else {
            return Level.BLOCK_UPDATE_RANDOM;
        }
    }

    return 0;
}
 
Example #8
Source File: BlockCrops.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_NORMAL) {
        if (this.down().getId() != FARMLAND) {
            this.getLevel().useBreakOn(this);
            return Level.BLOCK_UPDATE_NORMAL;
        }
    } else if (type == Level.BLOCK_UPDATE_RANDOM) {
        if (new Random().nextInt(2) == 1) {
            if (this.getDamage() < 0x07) {
                BlockCrops block = (BlockCrops) this.clone();
                block.setDamage(block.getDamage() + 1);
                BlockGrowEvent ev = new BlockGrowEvent(this, block);
                Server.getInstance().getPluginManager().callEvent(ev);

                if (!ev.isCancelled()) {
                    this.getLevel().setBlock(this, ev.getNewState(), false, true);
                } else {
                    return Level.BLOCK_UPDATE_RANDOM;
                }
            }
        } else {
            return Level.BLOCK_UPDATE_RANDOM;
        }
    }

    return 0;
}
 
Example #9
Source File: BlockCrops.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example #10
Source File: BlockSugarcane.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example #11
Source File: BlockCocoa.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_NORMAL) {
        int[] faces = new int[]{
                3, 4, 2, 5, 3, 4, 2, 5, 3, 4, 2, 5
        };

        Block side = this.getSide(BlockFace.fromIndex(faces[this.getDamage()]));

        if (side.getId() != Block.WOOD && side.getDamage() != BlockWood.JUNGLE) {
            this.getLevel().useBreakOn(this);
            return Level.BLOCK_UPDATE_NORMAL;
        }
    } else if (type == Level.BLOCK_UPDATE_RANDOM) {
        if (ThreadLocalRandom.current().nextInt(2) == 1) {
            if (this.getDamage() / 4 < 2) {
                BlockCocoa block = (BlockCocoa) this.clone();
                block.setDamage(block.getDamage() + 4);
                BlockGrowEvent ev = new BlockGrowEvent(this, block);
                Server.getInstance().getPluginManager().callEvent(ev);

                if (!ev.isCancelled()) {
                    this.getLevel().setBlock(this, ev.getNewState(), true, true);
                } else {
                    return Level.BLOCK_UPDATE_RANDOM;
                }
            }
        } else {
            return Level.BLOCK_UPDATE_RANDOM;
        }
    }

    return 0;
}
 
Example #12
Source File: BlockCactus.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_NORMAL) {
        Block down = down();
        if (down.getId() != SAND && down.getId() != CACTUS) {
            this.getLevel().useBreakOn(this);
        } else {
            for (int side = 2; side <= 5; ++side) {
                Block block = getSide(BlockFace.fromIndex(side));
                if (!block.canBeFlowedInto()) {
                    this.getLevel().useBreakOn(this);
                }
            }
        }
    } else if (type == Level.BLOCK_UPDATE_RANDOM) {
        if (down().getId() != CACTUS) {
            if (this.getDamage() == 0x0F) {
                for (int y = 1; y < 3; ++y) {
                    Block b = this.getLevel().getBlock(new Vector3(this.x, this.y + y, this.z));
                    if (b.getId() == AIR) {
                        BlockGrowEvent event = new BlockGrowEvent(b, Block.get(BlockID.CACTUS));
                        Server.getInstance().getPluginManager().callEvent(event);
                        if (!event.isCancelled()) {
                            this.getLevel().setBlock(b, event.getNewState(), true);
                        }
                    }
                }
                this.setDamage(0);
                this.getLevel().setBlock(this, this);
            } else {
                this.setDamage(this.getDamage() + 1);
                this.getLevel().setBlock(this, this);
            }
        }
    }

    return 0;
}
 
Example #13
Source File: BlockSugarcane.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example #14
Source File: BlockCrops.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_NORMAL) {
        if (this.down().getId() != FARMLAND) {
            this.getLevel().useBreakOn(this);
            return Level.BLOCK_UPDATE_NORMAL;
        }
    } else if (type == Level.BLOCK_UPDATE_RANDOM) {
        if (ThreadLocalRandom.current().nextInt(2) == 1) {
            if (this.getDamage() < 0x07) {
                BlockCrops block = (BlockCrops) this.clone();
                block.setDamage(block.getDamage() + 1);
                BlockGrowEvent ev = new BlockGrowEvent(this, block);
                Server.getInstance().getPluginManager().callEvent(ev);

                if (!ev.isCancelled()) {
                    this.getLevel().setBlock(this, ev.getNewState(), false, true);
                } else {
                    return Level.BLOCK_UPDATE_RANDOM;
                }
            }
        } else {
            return Level.BLOCK_UPDATE_RANDOM;
        }
    }

    return 0;
}
 
Example #15
Source File: BlockCrops.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onActivate(Item item, Player player) {
    //Bone meal
    if (item.getId() == Item.DYE && item.getDamage() == 0x0f) {
        if (this.getDamage() < 7) {
            BlockCrops block = (BlockCrops) this.clone();
            block.setDamage(block.getDamage() + ThreadLocalRandom.current().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));

            if (player != null && (player.gamemode & 0x01) == 0) {
                item.count--;
            }
        }

        return true;
    }

    return false;
}
 
Example #16
Source File: BlockSugarcane.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_NORMAL) {
        Block down = this.down();
        if (down.isTransparent() && down.getId() != SUGARCANE_BLOCK) {
            this.getLevel().useBreakOn(this);
            return Level.BLOCK_UPDATE_NORMAL;
        }
    } else if (type == Level.BLOCK_UPDATE_RANDOM) {
        if (this.down().getId() != SUGARCANE_BLOCK) {
            if (this.getDamage() == 0x0F) {
                for (int y = 1; y < 3; ++y) {
                    Block b = this.getLevel().getBlock(new Vector3(this.x, this.y + y, this.z));
                    if (b.getId() == AIR) {
                        BlockGrowEvent ev = new BlockGrowEvent(b, Block.get(BlockID.SUGARCANE_BLOCK));
                        Server.getInstance().getPluginManager().callEvent(ev);
                        
                        if (!ev.isCancelled()) {
                            this.getLevel().setBlock(b, Block.get(BlockID.SUGARCANE_BLOCK), false);
                        }
                        break;
                    }
                }
                this.setDamage(0);
                this.getLevel().setBlock(this, this, false);
            } else {
                this.setDamage(this.getDamage() + 1);
                this.getLevel().setBlock(this, this, false);
            }
            return Level.BLOCK_UPDATE_RANDOM;
        }
    }
    return 0;
}
 
Example #17
Source File: BlockCocoa.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_NORMAL) {
        int[] faces = new int[]{
                3, 4, 2, 5, 3, 4, 2, 5, 3, 4, 2, 5
        };

        Block side = this.getSide(BlockFace.fromIndex(faces[this.meta]));

        if (side.getId() != Block.WOOD && side.getDamage() != BlockWood.JUNGLE) {
            this.getLevel().useBreakOn(this);
            return Level.BLOCK_UPDATE_NORMAL;
        }
    } else if (type == Level.BLOCK_UPDATE_RANDOM) {
        if (new Random().nextInt(2) == 1) {
            if (this.meta / 4 < 2) {
                BlockCocoa block = (BlockCocoa) this.clone();
                block.meta += 4;
                BlockGrowEvent ev = new BlockGrowEvent(this, block);
                Server.getInstance().getPluginManager().callEvent(ev);

                if (!ev.isCancelled()) {
                    this.getLevel().setBlock(this, ev.getNewState(), true, true);
                } else {
                    return Level.BLOCK_UPDATE_RANDOM;
                }
            }
        } else {
            return Level.BLOCK_UPDATE_RANDOM;
        }
    }

    return 0;
}
 
Example #18
Source File: BlockCactus.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_NORMAL) {
        Block down = down();
        if (down.getId() != SAND && down.getId() != CACTUS) {
            this.getLevel().useBreakOn(this);
        } else {
            for (int side = 2; side <= 5; ++side) {
                Block block = getSide(BlockFace.fromIndex(side));
                if (!block.canBeFlowedInto()) {
                    this.getLevel().useBreakOn(this);
                }
            }
        }
    } else if (type == Level.BLOCK_UPDATE_RANDOM) {
        if (down().getId() != CACTUS) {
            if (this.meta == 0x0F) {
                for (int y = 1; y < 3; ++y) {
                    Block b = this.getLevel().getBlock(new Vector3(this.x, this.y + y, this.z));
                    if (b.getId() == AIR) {
                        BlockGrowEvent event = new BlockGrowEvent(b, new BlockCactus());
                        Server.getInstance().getPluginManager().callEvent(event);
                        if (!event.isCancelled()) {
                            this.getLevel().setBlock(b, event.getNewState(), true);
                        }
                    }
                }
                this.meta = 0;
                this.getLevel().setBlock(this, this);
            } else {
                ++this.meta;
                this.getLevel().setBlock(this, this);
            }
        }
    }

    return 0;
}
 
Example #19
Source File: BlockNetherWart.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_NORMAL) {
        if (this.down().getId() != SOUL_SAND) {
            this.getLevel().useBreakOn(this);
            return Level.BLOCK_UPDATE_NORMAL;
        }
    } else if (type == Level.BLOCK_UPDATE_RANDOM) {
        if (new Random().nextInt(10) == 1) {
            if (this.meta < 0x03) {
                BlockNetherWart block = (BlockNetherWart) this.clone();
                ++block.meta;
                BlockGrowEvent ev = new BlockGrowEvent(this, block);
                Server.getInstance().getPluginManager().callEvent(ev);

                if (!ev.isCancelled()) {
                    this.getLevel().setBlock(this, ev.getNewState(), true, true);
                } else {
                    return Level.BLOCK_UPDATE_RANDOM;
                }
            }
        } else {
            return Level.BLOCK_UPDATE_RANDOM;
        }
    }

    return 0;
}
 
Example #20
Source File: BlockCrops.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_NORMAL) {
        if (this.down().getId() != FARMLAND) {
            this.getLevel().useBreakOn(this);
            return Level.BLOCK_UPDATE_NORMAL;
        }
    } else if (type == Level.BLOCK_UPDATE_RANDOM) {
        if (new Random().nextInt(2) == 1) {
            if (this.meta < 0x07) {
                BlockCrops block = (BlockCrops) this.clone();
                ++block.meta;
                BlockGrowEvent ev = new BlockGrowEvent(this, block);
                Server.getInstance().getPluginManager().callEvent(ev);

                if (!ev.isCancelled()) {
                    this.getLevel().setBlock(this, ev.getNewState(), true, true);
                } else {
                    return Level.BLOCK_UPDATE_RANDOM;
                }
            }
        } else {
            return Level.BLOCK_UPDATE_RANDOM;
        }
    }

    return 0;
}
 
Example #21
Source File: BlockCrops.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@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.meta < 7) {
            block.meta += new Random().nextInt(3) + 2;
            if (block.meta > 7) {
                block.meta = 7;
            }
            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;
}
 
Example #22
Source File: BlockSugarcane.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@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) {
            boolean success = false;
            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, Block.get(BlockID.SUGARCANE_BLOCK));
                    Server.getInstance().getPluginManager().callEvent(ev);

                    if (!ev.isCancelled()) {
                        this.getLevel().setBlock(block, ev.getNewState(), true);
                        success = true;
                    }
                } else if (block.getId() != SUGARCANE_BLOCK) {
                    break;
                }
            }

            if (success) {
                if (player != null && (player.gamemode & 0x01) == 0) {
                    item.count--;
                }

                this.level.addParticle(new BoneMealParticle(this));
            }
        }

        return true;
    }
    return false;
}