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

项目:Backmemed    文件:RecipeBookCloning.java   
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
{
    NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>func_191197_a(inv.getSizeInventory(), ItemStack.field_190927_a);

    for (int i = 0; i < nonnulllist.size(); ++i)
    {
        ItemStack itemstack = inv.getStackInSlot(i);

        if (itemstack.getItem() instanceof ItemWrittenBook)
        {
            ItemStack itemstack1 = itemstack.copy();
            itemstack1.func_190920_e(1);
            nonnulllist.set(i, itemstack1);
            break;
        }
    }

    return nonnulllist;
}
项目:CustomWorldGen    文件:RecipeBookCloning.java   
public ItemStack[] getRemainingItems(InventoryCrafting inv)
{
    ItemStack[] aitemstack = new ItemStack[inv.getSizeInventory()];

    for (int i = 0; i < aitemstack.length; ++i)
    {
        ItemStack itemstack = inv.getStackInSlot(i);

        if (itemstack != null && itemstack.getItem() instanceof ItemWrittenBook)
        {
            aitemstack[i] = itemstack.copy();
            aitemstack[i].stackSize = 1;
            break;
        }
    }

    return aitemstack;
}
项目:ExpandedRailsMod    文件:RecipeBookCloning.java   
public ItemStack[] getRemainingItems(InventoryCrafting inv)
{
    ItemStack[] aitemstack = new ItemStack[inv.getSizeInventory()];

    for (int i = 0; i < aitemstack.length; ++i)
    {
        ItemStack itemstack = inv.getStackInSlot(i);

        if (itemstack != null && itemstack.getItem() instanceof ItemWrittenBook)
        {
            aitemstack[i] = itemstack.copy();
            aitemstack[i].stackSize = 1;
            break;
        }
    }

    return aitemstack;
}
项目:uniquecrops    文件:Knowledge.java   
@Override
   public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {

    if (this.getAge(state) >= getMaxAge() || world.isRemote)
        return;

    Iterable<BlockPos> getBox = BlockPos.getAllInBox(pos.add(-4, -2, -4), pos.add(4, 2, 4));
    Iterator it = getBox.iterator();
    while (it.hasNext()) {
        BlockPos fromIt = (BlockPos)it.next();
        IBlockState loopstate = world.getBlockState(fromIt);
        if (loopstate.getBlock() == Blocks.BOOKSHELF) {
            TileEntity te = world.getTileEntity(fromIt.add(0, 1, 0));
            if (te != null && te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN)) {
                IItemHandler cap = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN);
                boolean found = false;
                for (int i = 0; i < cap.getSlots(); i++) {
                    if (found)
                        return;
                    ItemStack book = cap.getStackInSlot(i);
                    if (book != null && book.getItem() == Items.WRITTEN_BOOK) {
                        NBTTagCompound tag = book.getTagCompound();
                        if (ItemWrittenBook.validBookTagContents(tag) && !NBTUtils.getBoolean(book, "UC_tagRead", false) && ItemWrittenBook.getGeneration(book) == 0)
                        {
                            NBTTagList taglist = tag.getTagList("pages", 8);
                            for (int j = 0; j < taglist.tagCount(); ++j)
                            {
                                String str = taglist.getStringTagAt(j);
                                ITextComponent text = ITextComponent.Serializer.fromJsonLenient(str);
                                try
                                {
                                    if (str.length() >= 100 && str.length() <= 512)
                                        found = true;
                                } 
                                catch (Exception e) 
                                {
                                    System.out.println("whoopsy doopsy");
                                }
                                if (found) {
                                    ITextComponent newStr = eatSomeLetters(text);
                                    taglist.set(j, new NBTTagString(newStr.getUnformattedText()));
                                    break;
                                }
                            }
                            tag.setTag("pages", taglist);
                            tag.setBoolean("UC_tagRead", true);

                            if (found) {
                                int addAge = taglist.tagCount();
                                if (getAge(state) + addAge >= ((BlockCrops)state.getBlock()).getMaxAge())
                                    world.setBlockState(pos, ((BlockCrops)state.getBlock()).withAge(((BlockCrops)state.getBlock()).getMaxAge()), 2);
                                else
                                    world.setBlockState(pos, ((BlockCrops)state.getBlock()).withAge(getAge(state) + addAge), 2);
                            }
                            return;
                        }
                    }
                }
            }
        }
    }
}
项目:Backmemed    文件:RecipeBookCloning.java   
/**
 * Returns an Item that is the result of this recipe
 */
public ItemStack getCraftingResult(InventoryCrafting inv)
{
    int i = 0;
    ItemStack itemstack = ItemStack.field_190927_a;

    for (int j = 0; j < inv.getSizeInventory(); ++j)
    {
        ItemStack itemstack1 = inv.getStackInSlot(j);

        if (!itemstack1.func_190926_b())
        {
            if (itemstack1.getItem() == Items.WRITTEN_BOOK)
            {
                if (!itemstack.func_190926_b())
                {
                    return ItemStack.field_190927_a;
                }

                itemstack = itemstack1;
            }
            else
            {
                if (itemstack1.getItem() != Items.WRITABLE_BOOK)
                {
                    return ItemStack.field_190927_a;
                }

                ++i;
            }
        }
    }

    if (!itemstack.func_190926_b() && itemstack.hasTagCompound() && i >= 1 && ItemWrittenBook.getGeneration(itemstack) < 2)
    {
        ItemStack itemstack2 = new ItemStack(Items.WRITTEN_BOOK, i);
        itemstack2.setTagCompound(itemstack.getTagCompound().copy());
        itemstack2.getTagCompound().setInteger("generation", ItemWrittenBook.getGeneration(itemstack) + 1);

        if (itemstack.hasDisplayName())
        {
            itemstack2.setStackDisplayName(itemstack.getDisplayName());
        }

        return itemstack2;
    }
    else
    {
        return ItemStack.field_190927_a;
    }
}
项目:CustomWorldGen    文件:RecipeBookCloning.java   
/**
 * Returns an Item that is the result of this recipe
 */
@Nullable
public ItemStack getCraftingResult(InventoryCrafting inv)
{
    int i = 0;
    ItemStack itemstack = null;

    for (int j = 0; j < inv.getSizeInventory(); ++j)
    {
        ItemStack itemstack1 = inv.getStackInSlot(j);

        if (itemstack1 != null)
        {
            if (itemstack1.getItem() == Items.WRITTEN_BOOK)
            {
                if (itemstack != null)
                {
                    return null;
                }

                itemstack = itemstack1;
            }
            else
            {
                if (itemstack1.getItem() != Items.WRITABLE_BOOK)
                {
                    return null;
                }

                ++i;
            }
        }
    }

    if (itemstack != null && i >= 1 && ItemWrittenBook.getGeneration(itemstack) < 2)
    {
        ItemStack itemstack2 = new ItemStack(Items.WRITTEN_BOOK, i);
        itemstack2.setTagCompound(itemstack.getTagCompound().copy());
        itemstack2.getTagCompound().setInteger("generation", ItemWrittenBook.getGeneration(itemstack) + 1);

        if (itemstack.hasDisplayName())
        {
            itemstack2.setStackDisplayName(itemstack.getDisplayName());
        }

        return itemstack2;
    }
    else
    {
        return null;
    }
}
项目:ExpandedRailsMod    文件:RecipeBookCloning.java   
/**
 * Returns an Item that is the result of this recipe
 */
@Nullable
public ItemStack getCraftingResult(InventoryCrafting inv)
{
    int i = 0;
    ItemStack itemstack = null;

    for (int j = 0; j < inv.getSizeInventory(); ++j)
    {
        ItemStack itemstack1 = inv.getStackInSlot(j);

        if (itemstack1 != null)
        {
            if (itemstack1.getItem() == Items.WRITTEN_BOOK)
            {
                if (itemstack != null)
                {
                    return null;
                }

                itemstack = itemstack1;
            }
            else
            {
                if (itemstack1.getItem() != Items.WRITABLE_BOOK)
                {
                    return null;
                }

                ++i;
            }
        }
    }

    if (itemstack != null && i >= 1 && ItemWrittenBook.getGeneration(itemstack) < 2)
    {
        ItemStack itemstack2 = new ItemStack(Items.WRITTEN_BOOK, i);
        itemstack2.setTagCompound(itemstack.getTagCompound().copy());
        itemstack2.getTagCompound().setInteger("generation", ItemWrittenBook.getGeneration(itemstack) + 1);

        if (itemstack.hasDisplayName())
        {
            itemstack2.setStackDisplayName(itemstack.getDisplayName());
        }

        return itemstack2;
    }
    else
    {
        return null;
    }
}