cn.nukkit.block.BlockMycelium Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of powernukkit Show documentation
Show all versions of powernukkit Show documentation
A Minecraft Bedrock Edition server software implementation made in Java from scratch which supports all new features.
package cn.nukkit.block;
import cn.nukkit.Server;
import cn.nukkit.event.block.BlockSpreadEvent;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemBlock;
import cn.nukkit.item.ItemTool;
import cn.nukkit.level.Level;
import cn.nukkit.math.NukkitRandom;
import cn.nukkit.math.Vector3;
import cn.nukkit.utils.BlockColor;
/**
* @author Pub4Game
* @since 03.01.2016
*/
public class BlockMycelium extends BlockSolid {
public BlockMycelium() {
}
@Override
public String getName() {
return "Mycelium";
}
@Override
public int getId() {
return MYCELIUM;
}
@Override
public int getToolType() {
return ItemTool.TYPE_SHOVEL;
}
@Override
public double getHardness() {
return 0.6;
}
@Override
public double getResistance() {
return 2.5;
}
@Override
public Item[] getDrops(Item item) {
return new Item[]{
new ItemBlock(Block.get(BlockID.DIRT))
};
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_RANDOM) {
if (getLevel().getFullLight(add(0, 1, 0)) >= BlockCrops.MINIMUM_LIGHT_LEVEL) {
//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 && block.getDamage() == 0) {
if (block.up().isTransparent()) {
BlockSpreadEvent ev = new BlockSpreadEvent(block, this, Block.get(BlockID.MYCELIUM));
Server.getInstance().getPluginManager().callEvent(ev);
if (!ev.isCancelled()) {
this.getLevel().setBlock(block, ev.getNewState());
}
}
}
}
}
return 0;
}
@Override
public BlockColor getColor() {
return BlockColor.PURPLE_BLOCK_COLOR;
}
@Override
public boolean canSilkTouch() {
return true;
}
}