Java Code Examples for net.minecraft.init.Items.writable_book()

The following are Jave code examples for showing how to use writable_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: DecompiledMinecraft   File: RecipeBookCloning.java   View Source Code Vote up 5 votes
/**
 * Used to check if a recipe matches current crafting inventory
 */
public boolean matches(InventoryCrafting inv, World worldIn)
{
    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 false;
                }

                itemstack = itemstack1;
            }
            else
            {
                if (itemstack1.getItem() != Items.writable_book)
                {
                    return false;
                }

                ++i;
            }
        }
    }

    return itemstack != null && i > 0;
}
 
Example 2
Project: DecompiledMinecraft   File: RecipeBookCloning.java   View Source Code Vote up 5 votes
/**
 * Used to check if a recipe matches current crafting inventory
 */
public boolean matches(InventoryCrafting inv, World worldIn)
{
    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 false;
                }

                itemstack = itemstack1;
            }
            else
            {
                if (itemstack1.getItem() != Items.writable_book)
                {
                    return false;
                }

                ++i;
            }
        }
    }

    return itemstack != null && i > 0;
}
 
Example 3
Project: DecompiledMinecraft   File: EntityPlayerSP.java   View Source Code Vote up 5 votes
/**
 * Displays the GUI for interacting with a book.
 */
public void displayGUIBook(ItemStack bookStack)
{
    Item item = bookStack.getItem();

    if (item == Items.writable_book)
    {
        this.mc.displayGuiScreen(new GuiScreenBook(this, bookStack, true));
    }
}
 
Example 4
Project: BaseClient   File: RecipeBookCloning.java   View Source Code Vote up 5 votes
/**
 * Used to check if a recipe matches current crafting inventory
 */
public boolean matches(InventoryCrafting inv, World worldIn)
{
    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 false;
                }

                itemstack = itemstack1;
            }
            else
            {
                if (itemstack1.getItem() != Items.writable_book)
                {
                    return false;
                }

                ++i;
            }
        }
    }

    return itemstack != null && i > 0;
}
 
Example 5
Project: BaseClient   File: EntityPlayerSP.java   View Source Code Vote up 5 votes
/**
 * Displays the GUI for interacting with a book.
 */
public void displayGUIBook(ItemStack bookStack)
{
    Item item = bookStack.getItem();

    if (item == Items.writable_book)
    {
        this.mc.displayGuiScreen(new GuiScreenBook(this, bookStack, true));
    }
}
 
Example 6
Project: BaseClient   File: RecipeBookCloning.java   View Source Code Vote up 5 votes
/**
 * Used to check if a recipe matches current crafting inventory
 */
public boolean matches(InventoryCrafting inv, World worldIn)
{
    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 false;
                }

                itemstack = itemstack1;
            }
            else
            {
                if (itemstack1.getItem() != Items.writable_book)
                {
                    return false;
                }

                ++i;
            }
        }
    }

    return itemstack != null && i > 0;
}
 
Example 7
Project: BaseClient   File: EntityPlayerSP.java   View Source Code Vote up 5 votes
/**
 * Displays the GUI for interacting with a book.
 */
public void displayGUIBook(ItemStack bookStack) {
	Item item = bookStack.getItem();

	if (item == Items.writable_book) {
		this.mc.displayGuiScreen(new GuiScreenBook(this, bookStack, true));
	}
}
 
Example 8
Project: DecompiledMinecraft   File: RecipeBookCloning.java   View Source Code Vote up 4 votes
/**
 * Returns an Item that is the result of this recipe
 */
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 && ItemEditableBook.getGeneration(itemstack) < 2)
    {
        ItemStack itemstack2 = new ItemStack(Items.written_book, i);
        itemstack2.setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
        itemstack2.getTagCompound().setInteger("generation", ItemEditableBook.getGeneration(itemstack) + 1);

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

        return itemstack2;
    }
    else
    {
        return null;
    }
}
 
Example 9
Project: DecompiledMinecraft   File: RecipeBookCloning.java   View Source Code Vote up 4 votes
/**
 * Returns an Item that is the result of this recipe
 */
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 && ItemEditableBook.getGeneration(itemstack) < 2)
    {
        ItemStack itemstack2 = new ItemStack(Items.written_book, i);
        itemstack2.setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
        itemstack2.getTagCompound().setInteger("generation", ItemEditableBook.getGeneration(itemstack) + 1);

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

        return itemstack2;
    }
    else
    {
        return null;
    }
}
 
Example 10
Project: BaseClient   File: RecipeBookCloning.java   View Source Code Vote up 4 votes
/**
 * Returns an Item that is the result of this recipe
 */
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 && ItemEditableBook.getGeneration(itemstack) < 2)
    {
        ItemStack itemstack2 = new ItemStack(Items.written_book, i);
        itemstack2.setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
        itemstack2.getTagCompound().setInteger("generation", ItemEditableBook.getGeneration(itemstack) + 1);

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

        return itemstack2;
    }
    else
    {
        return null;
    }
}
 
Example 11
Project: BaseClient   File: RecipeBookCloning.java   View Source Code Vote up 4 votes
/**
 * Returns an Item that is the result of this recipe
 */
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 && ItemEditableBook.getGeneration(itemstack) < 2)
    {
        ItemStack itemstack2 = new ItemStack(Items.written_book, i);
        itemstack2.setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
        itemstack2.getTagCompound().setInteger("generation", ItemEditableBook.getGeneration(itemstack) + 1);

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

        return itemstack2;
    }
    else
    {
        return null;
    }
}
 
Example 12
Project: minecraft-quiverbow   File: AI_Storage.java   View Source Code Vote up 4 votes
public static void addItem(EntityPlayer player, Entity_AA turret, ItemStack playerStack)
{
	int slot = 0;
	
	while (slot < turret.storage.length)
	{
		if (turret.storage[slot] == null)	// That spot is free
		{
			turret.storage[slot] = playerStack.copy();	// Stored
			if (!player.capabilities.isCreativeMode) { player.setCurrentItemOrArmor(0, null); }	// Empty
			
			if (playerStack.getItem() == Items.writable_book && AI_Targeting.isNameOnWhitelist(turret, Commands.cmdStayStationary))
			{
				//System.out.println("[ARMS ASSISTANT] Received a book with STAY command. Setting target position");
				turret.stationaryX = turret.posX;
				turret.stationaryY = turret.posY;
				turret.stationaryZ = turret.posZ;
			}
			
			// Informing the client about this change
			NetHelper.sendTurretInventoryMessageToPlayersInRange(turret.worldObj, turret, 
					Item.getIdFromItem(turret.storage[slot].getItem()), slot, turret.storage[slot].getItemDamage());
			
			return;	// We're done here
		}
		// else, there's something in there
		
		slot += 1;
	}
	
	// No free spot found. What about existing ones?
	slot = 0;
	
	while (slot < turret.storage.length)
	{
		if (turret.storage[slot] != null)
		{				
			boolean skip = false;
			
			if (!(turret.storage[slot].getItem() instanceof _AmmoBase)) { skip = true; }	// Not ammunition, hm?
			
			if (turret.storage[slot].getItemDamage() < turret.storage[slot].getMaxDamage()) { skip = true; }	// Not empty
			
			if (!skip)
			{					
				// Has an empty magazine in there, so replacing that now
				dropSingleItem(turret, turret.storage[slot].copy());
				turret.storage[slot] = playerStack.copy();	// Stored
				
				if (!player.capabilities.isCreativeMode) { player.setCurrentItemOrArmor(0, null); }	// Empty
				
				// Informing the client about this change
				NetHelper.sendTurretInventoryMessageToPlayersInRange(turret.worldObj, turret, 
						Item.getIdFromItem(turret.storage[slot].getItem()), slot, turret.storage[slot].getItemDamage());
				return;
			}
			// else, not a magazine
		}
		// else, no free spot found but this is null? Da fuq?
		
		slot += 1;
	}
}
 
Example 13
Project: minecraft-quiverbow   File: AI_Targeting.java   View Source Code Vote up 4 votes
public static boolean isNameOnWhitelist(Entity_AA turret, String nameOrCmd)
{
	if (turret.storage == null) { return false; }	// Has no space to store anything in
	int counter = 0;
	
	// Step 1, find a book in our inventory
	
	while (counter < turret.storage.length)
	{
		if (turret.storage[counter] != null)
		{
			if (turret.storage[counter].getItem() == Items.writable_book || turret.storage[counter].getItem() == Items.written_book)
			{
				//System.out.println("[TURRET] Checking writable book for whitelist against " + playerName);
				
				if (turret.storage[counter].hasTagCompound())
				{
					NBTTagList pageList = turret.storage[counter].getTagCompound().getTagList("pages", 8);
					
					int pageCount = 0;
					
					String currentPage = pageList.getStringTagAt(pageCount);
					
					while (currentPage != null && !currentPage.isEmpty())
					{
						String[] lines = currentPage.split("\n");
						
						int lineCount = 0;
						
						while (lineCount < lines.length)
						{
							//System.out.println("[TURRET] Book page " + pageCount + " - line " + lineCount + ": " + lines[lineCount]);
							
							if (lines[lineCount].equals(nameOrCmd)) { return true;	} // Found it!
							// else, not on this line
							
							lineCount += 1;
						}
						
						pageCount += 1;
						currentPage = pageList.getStringTagAt(pageCount);	// Next!
					}
					// Done with all known pages (will stop when there's empty pages inbetween)
				}
				// else, no tag, so can't have anything in it
			}
			// else, not a book
		}
		// else, nothing in that slot
		
		
		counter += 1;
	}
	
	return false;	// Fallback. Didn't find a book with this name
}