Search in sources :

Example 51 with Item

use of cn.nukkit.item.Item 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)

Example 52 with Item

use of cn.nukkit.item.Item in project Nukkit by Nukkit.

the class CraftingManager method getMultiItemHash.

private String getMultiItemHash(Collection<Item> items) {
    BinaryStream stream = new BinaryStream();
    for (Item item : items) {
        stream.putUnsignedVarInt(item.getId());
        stream.putVarInt(item.getDamage());
    }
    return new String(stream.getByteArray());
}
Also used : Item(cn.nukkit.item.Item) BinaryStream(cn.nukkit.utils.BinaryStream)

Example 53 with Item

use of cn.nukkit.item.Item in project Nukkit by Nukkit.

the class CraftingManager method cloneItemMap.

private Item[][] cloneItemMap(Item[][] map) {
    Item[][] newMap = new Item[map.length][];
    for (int i = 0; i < newMap.length; i++) {
        Item[] old = map[i];
        Item[] n = new Item[old.length];
        System.arraycopy(old, 0, n, 0, n.length);
        newMap[i] = n;
    }
    for (int y = 0; y < newMap.length; y++) {
        Item[] row = newMap[y];
        for (int x = 0; x < row.length; x++) {
            Item item = newMap[y][x];
            newMap[y][x] = item.clone();
        }
    }
    return newMap;
}
Also used : Item(cn.nukkit.item.Item)

Example 54 with Item

use of cn.nukkit.item.Item in project Nukkit by Nukkit.

the class CraftingManager method registerFurnaceRecipe.

public void registerFurnaceRecipe(FurnaceRecipe recipe) {
    Item input = recipe.getInput();
    this.furnaceRecipes.put(getItemHash(input), recipe);
}
Also used : Item(cn.nukkit.item.Item)

Example 55 with Item

use of cn.nukkit.item.Item in project Nukkit by Nukkit.

the class CraftingManager method registerBrewingRecipe.

public void registerBrewingRecipe(BrewingRecipe recipe) {
    Item input = recipe.getInput();
    Item potion = recipe.getPotion();
    this.brewingRecipes.put(getItemHash(input.getId(), (!potion.hasMeta() ? 0 : potion.getDamage())), recipe);
}
Also used : Item(cn.nukkit.item.Item)

Aggregations

Item (cn.nukkit.item.Item)64 Enchantment (cn.nukkit.item.enchantment.Enchantment)13 Player (cn.nukkit.Player)10 ItemBlock (cn.nukkit.item.ItemBlock)10 BlockAir (cn.nukkit.block.BlockAir)8 Random (java.util.Random)7 BlockEntity (cn.nukkit.blockentity.BlockEntity)6 Entity (cn.nukkit.entity.Entity)5 Block (cn.nukkit.block.Block)4 EntityItem (cn.nukkit.entity.item.EntityItem)4 EntityInventoryChangeEvent (cn.nukkit.event.entity.EntityInventoryChangeEvent)4 Inventory (cn.nukkit.inventory.Inventory)3 InventoryHolder (cn.nukkit.inventory.InventoryHolder)3 BlockEntityItemFrame (cn.nukkit.blockentity.BlockEntityItemFrame)2 EntityArmorChangeEvent (cn.nukkit.event.entity.EntityArmorChangeEvent)2 EntityDamageByEntityEvent (cn.nukkit.event.entity.EntityDamageByEntityEvent)2 EntityDamageEvent (cn.nukkit.event.entity.EntityDamageEvent)2 HopperInventory (cn.nukkit.inventory.HopperInventory)2 InventoryAction (cn.nukkit.inventory.transaction.action.InventoryAction)2 TranslationContainer (cn.nukkit.lang.TranslationContainer)2