Java 类net.minecraft.item.ItemBook 实例源码

项目:LittleThings-old    文件:BlockUnenchantingTable.java   
public static void runUnenchant(EntityPlayerMP playerEntity, BlockPos pos)
{
    System.out.println("Run");
    System.out.println("Pos: " + pos);
    World world = playerEntity.worldObj;

    IInventory te = (IInventory) world.getTileEntity(pos);
    if (te instanceof TileEntityUnenchantingTable) {
        ItemStack stack = te.getStackInSlot(0);

        if (stack != null && stack.getEnchantmentTagList() != null) {
            NBTTagList enchantmentList = stack.getEnchantmentTagList();
            Enchantment enchantment = Enchantment.getEnchantmentByID(enchantmentList.getCompoundTagAt(0).getShort("id"));
            int xp = (int) Math.floor(enchantment.getMinEnchantability(enchantmentList.getCompoundTagAt(0).getShort("lvl")) / 2);

            if (playerEntity.experienceLevel < xp && !playerEntity.isCreative())
                return;

            ItemStack books = te.getStackInSlot(1);
            if ((books != null && books.getItem() instanceof ItemBook) && te.getStackInSlot(2) == null) {
                NBTTagList list = stack.getEnchantmentTagList();
                NBTTagCompound enchTag = list.getCompoundTagAt(0);
                ItemStack book = new ItemStack(Items.enchanted_book);

                NBTTagCompound baseTag = new NBTTagCompound();
                NBTTagList enchList = new NBTTagList();
                enchList.appendTag(enchTag);
                baseTag.setTag("StoredEnchantments", enchList);
                book.setTagCompound(baseTag);

                te.setInventorySlotContents(2, book);
                --books.stackSize;

                list.removeTag(0);
                if (list.tagCount() == 0) {
                    stack.getTagCompound().removeTag("ench");
                    if (stack.getTagCompound().hasNoTags()) {
                        stack.setTagCompound(null);
                    }
                }

                if (stack.isItemStackDamageable()) {
                    int damage = world.rand.nextInt(1 + (stack.getMaxDamage() / 4));
                    int m = stack.getMaxDamage();
                    damage = Math.min(m, damage + 1 + (m / 10)) + (m == 1 ? 1 : 0);
                    if (stack.attemptDamageItem(damage, world.rand)) {
                        te.setInventorySlotContents(0, null);
                        stack = null;
                    }
                }
                if (stack != null)
                    te.setInventorySlotContents(0, stack);

                if (!playerEntity.isCreative()) {
                    playerEntity.removeExperienceLevel(xp);
                }
            }
        }
    }
}
项目:LittleThings-old    文件:ContainerUnenchantingTable.java   
@Override
public boolean isItemValid(ItemStack stack)
{
    return stack.getItem() instanceof ItemBook;
}
项目:Gravestone-mod-Extended    文件:EnchantmentBoneRain.java   
@Override
public boolean canApply(ItemStack stack) {
    return stack.getItem() instanceof IBoneHoe || stack.getItem() instanceof ItemBook;
}
项目:Gravestone-mod-Extended    文件:EnchantmentPainMirror.java   
@Override
public boolean canApply(ItemStack stack) {
    return stack.getItem() instanceof IBoneShiled || stack.getItem() instanceof ItemBook;
}
项目:IceAndShadow2    文件:NyxDeathSystem.java   
public static InventoryPlayer determineRespawnInventory(InventoryPlayer plai_inv, boolean do_drop) {
    boolean drop_main = true;
    for (int i = 0; i < plai_inv.mainInventory.length; ++i)
        if (plai_inv.mainInventory[i] != null) {
            final ItemStack is = plai_inv.mainInventory[i];
            if (is.getItem() instanceof NyxItemBoneSanctified && is.isItemDamaged()) {
                drop_main = false;
            }
        }
    for (int i = 0; i < plai_inv.mainInventory.length; ++i)
        if (plai_inv.mainInventory[i] != null) {
            final Item it = plai_inv.mainInventory[i].getItem();
            if (it instanceof IIaSOnDeathRuin) {
                plai_inv.mainInventory[i] = null;
                continue;
            }
            final EnumRarity rarity = it.getRarity(plai_inv.mainInventory[i]);
            if (rarity == EnumRarity.uncommon || rarity == EnumRarity.epic) {
                plai_inv.player.dropPlayerItemWithRandomChoice(plai_inv.mainInventory[i], true);
                plai_inv.mainInventory[i] = null;
                continue;
            }
            if (rarity == EnumRarity.rare || it instanceof ItemBook) {
                if (i < 9) {
                    continue;
                }
                plai_inv.player.dropPlayerItemWithRandomChoice(plai_inv.mainInventory[i], true);
                plai_inv.mainInventory[i] = null;
            }
            if (!drop_main) {
                continue;
            }
            if (i < 9)
                if (it == Items.arrow || it instanceof ItemSword || it instanceof ItemBow || it instanceof ItemTool) {
                    continue;
                }
            plai_inv.player.dropPlayerItemWithRandomChoice(plai_inv.mainInventory[i], true);
            plai_inv.mainInventory[i] = null;
        }
    return plai_inv;
}
项目:EnhancedBooks    文件:Utils.java   
public static boolean isBook(Item item) {
    return bookshelfAllowedItems.contains(item.getUnlocalizedName().substring(5, item.getUnlocalizedName().length())) || bookshelfAllowedItems.contains(String.valueOf(item.itemID)) || (item instanceof ItemBook);
}