cn.nukkit.block.BlockCarrot 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.item.Item;
import cn.nukkit.item.ItemID;
import cn.nukkit.item.enchantment.Enchantment;
import java.util.concurrent.ThreadLocalRandom;
/**
* @author Nukkit Project Team
*/
public class BlockCarrot extends BlockCrops {
public BlockCarrot(int meta) {
super(meta);
}
public BlockCarrot() {
this(0);
}
@Override
public String getName() {
return "Carrot Block";
}
@Override
public int getId() {
return CARROT_BLOCK;
}
@Override
public Item[] getDrops(Item item) {
if (!isFullyGrown()) {
return new Item[]{
Item.get(ItemID.CARROT)
};
}
int drops = 2;
int attempts = 3 + Math.min(0, item.getEnchantmentLevel(Enchantment.ID_FORTUNE_DIGGING));
ThreadLocalRandom random = ThreadLocalRandom.current();
for (int i = 0; i < attempts; i++) {
if (random.nextInt(7) < 4) { // 4/7, 0.57142857142857142857142857142857
drops++;
}
}
return new Item[]{
Item.get(ItemID.CARROT, 0, drops)
};
}
@Override
public Item toItem() {
return Item.get(ItemID.CARROT);
}
}