Search in sources :

Example 11 with Enchantment

use of cn.nukkit.item.enchantment.Enchantment in project Nukkit by Nukkit.

the class CraftingDataPacket method writeEnchantList.

private static int writeEnchantList(EnchantmentList list, BinaryStream stream) {
    stream.putByte((byte) list.getSize());
    for (int i = 0; i < list.getSize(); ++i) {
        EnchantmentEntry entry = list.getSlot(i);
        stream.putUnsignedVarInt(entry.getCost());
        stream.putUnsignedVarInt(entry.getEnchantments().length);
        for (Enchantment enchantment : entry.getEnchantments()) {
            stream.putUnsignedVarInt(enchantment.getId());
            stream.putUnsignedVarInt(enchantment.getLevel());
        }
        stream.putString(entry.getRandomName());
    }
    return CraftingDataPacket.ENTRY_ENCHANT_LIST;
}
Also used : EnchantmentEntry(cn.nukkit.item.enchantment.EnchantmentEntry) Enchantment(cn.nukkit.item.enchantment.Enchantment)

Example 12 with Enchantment

use of cn.nukkit.item.enchantment.Enchantment in project Nukkit by Nukkit.

the class BlockOreEmerald method getDrops.

@Override
public Item[] getDrops(Item item) {
    if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_IRON) {
        int count = 1;
        Enchantment fortune = item.getEnchantment(Enchantment.ID_FORTUNE_DIGGING);
        if (fortune != null && fortune.getLevel() >= 1) {
            int i = ThreadLocalRandom.current().nextInt(fortune.getLevel() + 2) - 1;
            if (i < 0) {
                i = 0;
            }
            count = i + 1;
        }
        return new Item[] { new ItemEmerald(0, count) };
    } else {
        return new Item[0];
    }
}
Also used : Item(cn.nukkit.item.Item) ItemEmerald(cn.nukkit.item.ItemEmerald) Enchantment(cn.nukkit.item.enchantment.Enchantment)

Example 13 with Enchantment

use of cn.nukkit.item.enchantment.Enchantment in project Nukkit by Nukkit.

the class BlockOreQuartz method getDrops.

@Override
public Item[] getDrops(Item item) {
    if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_WOODEN) {
        int count = 1;
        Enchantment fortune = item.getEnchantment(Enchantment.ID_FORTUNE_DIGGING);
        if (fortune != null && fortune.getLevel() >= 1) {
            int i = ThreadLocalRandom.current().nextInt(fortune.getLevel() + 2) - 1;
            if (i < 0) {
                i = 0;
            }
            count = i + 1;
        }
        return new Item[] { new ItemQuartz(0, count) };
    } else {
        return new Item[0];
    }
}
Also used : Item(cn.nukkit.item.Item) ItemQuartz(cn.nukkit.item.ItemQuartz) Enchantment(cn.nukkit.item.enchantment.Enchantment)

Example 14 with Enchantment

use of cn.nukkit.item.enchantment.Enchantment in project Nukkit by Nukkit.

the class BlockOreRedstone method getDrops.

@Override
public Item[] getDrops(Item item) {
    if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_IRON) {
        int count = new Random().nextInt(2) + 4;
        Enchantment fortune = item.getEnchantment(Enchantment.ID_FORTUNE_DIGGING);
        if (fortune != null && fortune.getLevel() >= 1) {
            count += new Random().nextInt(fortune.getLevel() + 1);
        }
        return new Item[] { new ItemRedstone(0, count) };
    } else {
        return new Item[0];
    }
}
Also used : Item(cn.nukkit.item.Item) NukkitRandom(cn.nukkit.math.NukkitRandom) Random(java.util.Random) Enchantment(cn.nukkit.item.enchantment.Enchantment) ItemRedstone(cn.nukkit.item.ItemRedstone)

Example 15 with Enchantment

use of cn.nukkit.item.enchantment.Enchantment in project Nukkit by Nukkit.

the class BlockOreDiamond method getDrops.

@Override
public Item[] getDrops(Item item) {
    if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_IRON) {
        int count = 1;
        Enchantment fortune = item.getEnchantment(Enchantment.ID_FORTUNE_DIGGING);
        if (fortune != null && fortune.getLevel() >= 1) {
            int i = ThreadLocalRandom.current().nextInt(fortune.getLevel() + 2) - 1;
            if (i < 0) {
                i = 0;
            }
            count = i + 1;
        }
        return new Item[] { new ItemDiamond(0, count) };
    } else {
        return new Item[0];
    }
}
Also used : Item(cn.nukkit.item.Item) Enchantment(cn.nukkit.item.enchantment.Enchantment) ItemDiamond(cn.nukkit.item.ItemDiamond)

Aggregations

Enchantment (cn.nukkit.item.enchantment.Enchantment)18 Item (cn.nukkit.item.Item)13 Random (java.util.Random)6 BlockAir (cn.nukkit.block.BlockAir)3 CompoundTag (cn.nukkit.nbt.tag.CompoundTag)3 Player (cn.nukkit.Player)2 BlockEntity (cn.nukkit.blockentity.BlockEntity)2 EntityArrow (cn.nukkit.entity.projectile.EntityArrow)2 EntityDamageByEntityEvent (cn.nukkit.event.entity.EntityDamageByEntityEvent)2 ItemBlock (cn.nukkit.item.ItemBlock)2 TranslationContainer (cn.nukkit.lang.TranslationContainer)2 Type (cn.nukkit.AdventureSettings.Type)1 cn.nukkit.block (cn.nukkit.block)1 Block (cn.nukkit.block.Block)1 BlockEntityChest (cn.nukkit.blockentity.BlockEntityChest)1 BlockEntityItemFrame (cn.nukkit.blockentity.BlockEntityItemFrame)1 BlockEntitySpawnable (cn.nukkit.blockentity.BlockEntitySpawnable)1 Command (cn.nukkit.command.Command)1 CommandSender (cn.nukkit.command.CommandSender)1 CommandDataVersions (cn.nukkit.command.data.CommandDataVersions)1