use of cn.nukkit.event.block.BlockGrowEvent 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;
}
use of cn.nukkit.event.block.BlockGrowEvent in project Nukkit by Nukkit.
the class BlockCocoa method onUpdate.
@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;
}
use of cn.nukkit.event.block.BlockGrowEvent 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;
}
use of cn.nukkit.event.block.BlockGrowEvent 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;
}
Aggregations