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

The following are Jave code examples for showing how to use written_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: EntityPlayerMP.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.written_book)
    {
        this.playerNetServerHandler.sendPacket(new S3FPacketCustomPayload("MC|BOpen", new PacketBuffer(Unpooled.buffer())));
    }
}
 
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: EntityPlayerMP.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.written_book)
    {
        this.playerNetServerHandler.sendPacket(new S3FPacketCustomPayload("MC|BOpen", new PacketBuffer(Unpooled.buffer())));
    }
}
 
Example 4
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 5
Project: BaseClient   File: EntityPlayerMP.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.written_book)
    {
        this.playerNetServerHandler.sendPacket(new S3FPacketCustomPayload("MC|BOpen", new PacketBuffer(Unpooled.buffer())));
    }
}
 
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: EntityPlayerMP.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.written_book)
    {
        this.playerNetServerHandler.sendPacket(new S3FPacketCustomPayload("MC|BOpen", new PacketBuffer(Unpooled.buffer())));
    }
}
 
Example 8
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 9
Project: BaseClient   File: NetHandlerPlayClient.java   View Source Code Vote up 5 votes
/**
 * Handles packets that have room for a channel specification. Vanilla
 * implemented channels are "MC|TrList" to acquire a MerchantRecipeList trades
 * for a villager merchant, "MC|Brand" which sets the server brand? on the
 * player instance and finally "MC|RPack" which the server uses to communicate
 * the identifier of the default server resourcepack for the client to load.
 */
public void handleCustomPayload(S3FPacketCustomPayload packetIn) {
	PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController);

	if ("MC|TrList".equals(packetIn.getChannelName())) {
		PacketBuffer packetbuffer = packetIn.getBufferData();

		try {
			int i = packetbuffer.readInt();
			GuiScreen guiscreen = this.gameController.currentScreen;

			if (guiscreen != null && guiscreen instanceof GuiMerchant
					&& i == this.gameController.thePlayer.openContainer.windowId) {
				IMerchant imerchant = ((GuiMerchant) guiscreen).getMerchant();
				MerchantRecipeList merchantrecipelist = MerchantRecipeList.readFromBuf(packetbuffer);
				imerchant.setRecipes(merchantrecipelist);
			}
		} catch (IOException ioexception) {
			logger.error((String) "Couldn\'t load trade info", (Throwable) ioexception);
		} finally {
			packetbuffer.release();
		}
	} else if ("MC|Brand".equals(packetIn.getChannelName())) {
		this.gameController.thePlayer.setClientBrand(packetIn.getBufferData().readStringFromBuffer(32767));
	} else if ("MC|BOpen".equals(packetIn.getChannelName())) {
		ItemStack itemstack = this.gameController.thePlayer.getCurrentEquippedItem();

		if (itemstack != null && itemstack.getItem() == Items.written_book) {
			this.gameController
					.displayGuiScreen(new GuiScreenBook(this.gameController.thePlayer, itemstack, false));
		}
	}
}
 
Example 10
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 11
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 12
Project: DecompiledMinecraft   File: NetHandlerPlayClient.java   View Source Code Vote up 4 votes
/**
 * Handles packets that have room for a channel specification. Vanilla implemented channels are "MC|TrList" to
 * acquire a MerchantRecipeList trades for a villager merchant, "MC|Brand" which sets the server brand? on the
 * player instance and finally "MC|RPack" which the server uses to communicate the identifier of the default server
 * resourcepack for the client to load.
 */
public void handleCustomPayload(S3FPacketCustomPayload packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController);

    if ("MC|TrList".equals(packetIn.getChannelName()))
    {
        PacketBuffer packetbuffer = packetIn.getBufferData();

        try
        {
            int i = packetbuffer.readInt();
            GuiScreen guiscreen = this.gameController.currentScreen;

            if (guiscreen != null && guiscreen instanceof GuiMerchant && i == this.gameController.thePlayer.openContainer.windowId)
            {
                IMerchant imerchant = ((GuiMerchant)guiscreen).getMerchant();
                MerchantRecipeList merchantrecipelist = MerchantRecipeList.readFromBuf(packetbuffer);
                imerchant.setRecipes(merchantrecipelist);
            }
        }
        catch (IOException ioexception)
        {
            logger.error((String)"Couldn\'t load trade info", (Throwable)ioexception);
        }
        finally
        {
            packetbuffer.release();
        }
    }
    else if ("MC|Brand".equals(packetIn.getChannelName()))
    {
        this.gameController.thePlayer.setClientBrand(packetIn.getBufferData().readStringFromBuffer(32767));
    }
    else if ("MC|BOpen".equals(packetIn.getChannelName()))
    {
        ItemStack itemstack = this.gameController.thePlayer.getCurrentEquippedItem();

        if (itemstack != null && itemstack.getItem() == Items.written_book)
        {
            this.gameController.displayGuiScreen(new GuiScreenBook(this.gameController.thePlayer, itemstack, false));
        }
    }
}
 
Example 13
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 14
Project: BaseClient   File: NetHandlerPlayClient.java   View Source Code Vote up 4 votes
/**
 * Handles packets that have room for a channel specification. Vanilla implemented channels are "MC|TrList" to
 * acquire a MerchantRecipeList trades for a villager merchant, "MC|Brand" which sets the server brand? on the
 * player instance and finally "MC|RPack" which the server uses to communicate the identifier of the default server
 * resourcepack for the client to load.
 */
public void handleCustomPayload(S3FPacketCustomPayload packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController);

    if ("MC|TrList".equals(packetIn.getChannelName()))
    {
        PacketBuffer packetbuffer = packetIn.getBufferData();

        try
        {
            int i = packetbuffer.readInt();
            GuiScreen guiscreen = this.gameController.currentScreen;

            if (guiscreen != null && guiscreen instanceof GuiMerchant && i == this.gameController.thePlayer.openContainer.windowId)
            {
                IMerchant imerchant = ((GuiMerchant)guiscreen).getMerchant();
                MerchantRecipeList merchantrecipelist = MerchantRecipeList.readFromBuf(packetbuffer);
                imerchant.setRecipes(merchantrecipelist);
            }
        }
        catch (IOException ioexception)
        {
            logger.error((String)"Couldn\'t load trade info", (Throwable)ioexception);
        }
        finally
        {
            packetbuffer.release();
        }
    }
    else if ("MC|Brand".equals(packetIn.getChannelName()))
    {
        this.gameController.thePlayer.setClientBrand(packetIn.getBufferData().readStringFromBuffer(32767));
    }
    else if ("MC|BOpen".equals(packetIn.getChannelName()))
    {
        ItemStack itemstack = this.gameController.thePlayer.getCurrentEquippedItem();

        if (itemstack != null && itemstack.getItem() == Items.written_book)
        {
            this.gameController.displayGuiScreen(new GuiScreenBook(this.gameController.thePlayer, itemstack, false));
        }
    }
}
 
Example 15
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 16
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
}