Java Code Examples for net.minecraft.init.Items.BOOK

The following are Jave code examples for showing how to use BOOK of the net.minecraft.init.Items class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Adventurers-Toolbox   File: BookRecipe.java   View Source Code Vote up 6 votes
@Override
public boolean matches(InventoryCrafting inv, World worldIn) {
	boolean book = false;
	boolean head = false;
	
	List<ItemStack> items = new ArrayList<ItemStack>();
	for (int i = 0; i < inv.getSizeInventory(); i++) {
		if (!inv.getStackInSlot(i).isEmpty()) {
			if (inv.getStackInSlot(i).getItem() instanceof ItemToolHead) {
				head = true;
			} else if (inv.getStackInSlot(i).getItem() == Items.BOOK) {
				book = true;
			}
			items.add(inv.getStackInSlot(i));
		}
	}
	
	if (items.size() != 2) {
		return false;
	}
	
	return book && head;

}
 
Example 2
Project: Backmemed   File: EnchantmentHelper.java   View Source Code Vote up 6 votes
public static List<EnchantmentData> getEnchantmentDatas(int p_185291_0_, ItemStack p_185291_1_, boolean allowTreasure)
{
    List<EnchantmentData> list = Lists.<EnchantmentData>newArrayList();
    Item item = p_185291_1_.getItem();
    boolean flag = p_185291_1_.getItem() == Items.BOOK;

    for (Enchantment enchantment : Enchantment.REGISTRY)
    {
        if ((!enchantment.isTreasureEnchantment() || allowTreasure) && (enchantment.type.canEnchantItem(item) || flag))
        {
            for (int i = enchantment.getMaxLevel(); i > enchantment.getMinLevel() - 1; --i)
            {
                if (p_185291_0_ >= enchantment.getMinEnchantability(i) && p_185291_0_ <= enchantment.getMaxEnchantability(i))
                {
                    list.add(new EnchantmentData(enchantment, i));
                    break;
                }
            }
        }
    }

    return list;
}
 
Example 3
Project: BetterBeginningsReborn   File: TileEntityInfusionRepair.java   View Source Code Vote up 6 votes
private boolean canDiffuse()
   {
boolean foundBook = false;
boolean foundEnchItem = false;
for(int s = 0; s < mainHandler.getSlots(); s++)
{
    ItemStack stack = mainHandler.getStackInSlot(s);
    if(Prep1_11.isValid(stack))
    {
	if(stack.getItem() == Items.BOOK)
	    foundBook = true;
	else if(stack.isItemEnchanted())
	    foundEnchItem = true;
    }
}
return foundBook && foundEnchItem;
   }
 
Example 4
Project: CustomWorldGen   File: EnchantmentHelper.java   View Source Code Vote up 6 votes
/**
 * Applys a random enchantment to the specified item.
 */
public static ItemStack addRandomEnchantment(Random random, ItemStack p_77504_1_, int p_77504_2_, boolean allowTreasure)
{
    boolean flag = p_77504_1_.getItem() == Items.BOOK;
    List<EnchantmentData> list = buildEnchantmentList(random, p_77504_1_, p_77504_2_, allowTreasure);

    if (flag)
    {
        p_77504_1_.setItem(Items.ENCHANTED_BOOK);
    }

    for (EnchantmentData enchantmentdata : list)
    {
        if (flag)
        {
            Items.ENCHANTED_BOOK.addEnchantment(p_77504_1_, enchantmentdata);
        }
        else
        {
            p_77504_1_.addEnchantment(enchantmentdata.enchantmentobj, enchantmentdata.enchantmentLevel);
        }
    }

    return p_77504_1_;
}
 
Example 5
Project: CustomWorldGen   File: EnchantmentHelper.java   View Source Code Vote up 6 votes
public static List<EnchantmentData> getEnchantmentDatas(int p_185291_0_, ItemStack p_185291_1_, boolean allowTreasure)
{
    List<EnchantmentData> list = Lists.<EnchantmentData>newArrayList();
    Item item = p_185291_1_.getItem();
    boolean flag = p_185291_1_.getItem() == Items.BOOK;

    for (Enchantment enchantment : Enchantment.REGISTRY)
    {
        if ((!enchantment.isTreasureEnchantment() || allowTreasure) && (enchantment.canApplyAtEnchantingTable(p_185291_1_) || (flag && enchantment.isAllowedOnBooks())))
        {
            for (int i = enchantment.getMaxLevel(); i > enchantment.getMinLevel() - 1; --i)
            {
                if (p_185291_0_ >= enchantment.getMinEnchantability(i) && p_185291_0_ <= enchantment.getMaxEnchantability(i))
                {
                    list.add(new EnchantmentData(enchantment, i));
                    break;
                }
            }
        }
    }

    return list;
}
 
Example 6
Project: VirtualTool   File: VirtualEnchantingTable.java   View Source Code Vote up 5 votes
private List<EnchantmentData> getEnchantmentList(net.minecraft.item.ItemStack stack, int p_178148_2_, int p_178148_3_) {
    this.rand.setSeed((long) (this.xpSeed + p_178148_2_));
    List<EnchantmentData> list = EnchantmentHelper.buildEnchantmentList(this.rand, stack, p_178148_3_, false);

    if (stack.getItem() == Items.BOOK && list.size() > 1) {
        list.remove(this.rand.nextInt(list.size()));
    }

    return list;
}
 
Example 7
Project: Backmemed   File: ContainerEnchantment.java   View Source Code Vote up 5 votes
private List<EnchantmentData> getEnchantmentList(ItemStack stack, int p_178148_2_, int p_178148_3_)
{
    this.rand.setSeed((long)(this.xpSeed + p_178148_2_));
    List<EnchantmentData> list = EnchantmentHelper.buildEnchantmentList(this.rand, stack, p_178148_3_, false);

    if (stack.getItem() == Items.BOOK && list.size() > 1)
    {
        list.remove(this.rand.nextInt(list.size()));
    }

    return list;
}
 
Example 8
Project: CustomWorldGen   File: ContainerEnchantment.java   View Source Code Vote up 5 votes
private List<EnchantmentData> getEnchantmentList(ItemStack stack, int p_178148_2_, int p_178148_3_)
{
    this.rand.setSeed((long)(this.xpSeed + p_178148_2_));
    List<EnchantmentData> list = EnchantmentHelper.buildEnchantmentList(this.rand, stack, p_178148_3_, false);

    if (stack.getItem() == Items.BOOK && list.size() > 1)
    {
        list.remove(this.rand.nextInt(list.size()));
    }

    return list;
}
 
Example 9
Project: Backmemed   File: BlockBookshelf.java   View Source Code Vote up 4 votes
/**
 * Get the Item that this Block should drop when harvested.
 */
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
    return Items.BOOK;
}
 
Example 10
Project: BetterBeginningsReborn   File: TileEntityInfusionRepair.java   View Source Code Vote up 4 votes
private boolean tryAbsorbDroppedItem(EntityItem item, IBlockState state)
   {
ItemStack newStack = Prep1_11.getEmptyStack();
ItemStack stack = item.getItem();
switch(mode)
{
case DIFFUSION:
    if(isIngredientPresent(stack)) return false;
    if(stack.getItem() == Items.BOOK || stack.isItemEnchanted())
    {
	newStack = stack.copy();
	newStack.setCount(1);
	if(!world.isRemote) stack.shrink(1);
    }
    break;
case REPAIR:
    if(pendingIngredients.isEmpty()) return false;
    RecipeElement currentIngredient = pendingIngredients.peek();
    if(currentIngredient.matches(stack))
    {
	newStack = stack.copy();
	newStack.setCount(Math.min(currentIngredient.getStackSize(), stack.getCount()));
	currentIngredient.setStackSize(currentIngredient.getStackSize() - Math.min(currentIngredient.getStackSize(), stack.getCount()));

	if(currentIngredient.getStackSize() <= 0)
	{
	    pendingIngredients.pop();
	}
	if(!world.isRemote) stack.shrink(newStack.getCount());
	markDirty();
    }
    break;
default:
    break;
}	
if(newStack == null) return false;
boolean slotFound = false;
if(newStack.isItemEnchanted())
{
    mainHandler.setStackInSlot(SLOT_ENCH_ITEM, newStack);
    slotFound = true;
}
else
{
    //attempt to insert stacks into inv
    for(int s = SLOT_ENCH_ITEM + 1; s < mainHandler.getSlots(); s++)
    {
	ItemStack slotStack = mainHandler.getStackInSlot(s);
	if (ItemHandlerHelper.canItemStacksStack(newStack, slotStack))
	{
	    CapUtils.incrementStack(mainHandler, s, newStack.getCount());
	    slotFound = true;
	    break;
	}
	if(Prep1_11.isEmpty(slotStack))
	{
	    mainHandler.setStackInSlot(s, newStack);
	    slotFound = true;
	    break;
	}
    }
}
return slotFound;
   }
 
Example 11
Project: CustomWorldGen   File: BlockBookshelf.java   View Source Code Vote up 4 votes
/**
 * Get the Item that this Block should drop when harvested.
 */
@Nullable
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
    return Items.BOOK;
}
 
Example 12
Project: CustomWorldGen   File: ContainerEnchantment.java   View Source Code Vote up 4 votes
/**
 * Handles the given Button-click on the server, currently only used by enchanting. Name is for legacy.
 */
public boolean enchantItem(EntityPlayer playerIn, int id)
{
    ItemStack itemstack = this.tableInventory.getStackInSlot(0);
    ItemStack itemstack1 = this.tableInventory.getStackInSlot(1);
    int i = id + 1;

    if ((itemstack1 == null || itemstack1.stackSize < i) && !playerIn.capabilities.isCreativeMode)
    {
        return false;
    }
    else if (this.enchantLevels[id] > 0 && itemstack != null && (playerIn.experienceLevel >= i && playerIn.experienceLevel >= this.enchantLevels[id] || playerIn.capabilities.isCreativeMode))
    {
        if (!this.worldPointer.isRemote)
        {
            List<EnchantmentData> list = this.getEnchantmentList(itemstack, id, this.enchantLevels[id]);
            boolean flag = itemstack.getItem() == Items.BOOK;

            if (list != null)
            {
                playerIn.removeExperienceLevel(i);

                if (flag)
                {
                    itemstack.setItem(Items.ENCHANTED_BOOK);
                }

                for (int j = 0; j < list.size(); ++j)
                {
                    EnchantmentData enchantmentdata = (EnchantmentData)list.get(j);

                    if (flag)
                    {
                        Items.ENCHANTED_BOOK.addEnchantment(itemstack, enchantmentdata);
                    }
                    else
                    {
                        itemstack.addEnchantment(enchantmentdata.enchantmentobj, enchantmentdata.enchantmentLevel);
                    }
                }

                if (!playerIn.capabilities.isCreativeMode)
                {
                    itemstack1.stackSize -= i;

                    if (itemstack1.stackSize <= 0)
                    {
                        this.tableInventory.setInventorySlotContents(1, (ItemStack)null);
                    }
                }

                playerIn.addStat(StatList.ITEM_ENCHANTED);
                this.tableInventory.markDirty();
                this.xpSeed = playerIn.getXPSeed();
                this.onCraftMatrixChanged(this.tableInventory);
                this.worldPointer.playSound((EntityPlayer)null, this.position, SoundEvents.BLOCK_ENCHANTMENT_TABLE_USE, SoundCategory.BLOCKS, 1.0F, this.worldPointer.rand.nextFloat() * 0.1F + 0.9F);
            }
        }

        return true;
    }
    else
    {
        return false;
    }
}