Jump to content

[1.7.2] IRecipe changing ItemStack's ntbtags


Casual Dutchman

Recommended Posts

I created a Item that will use custom itemstack's nbt tag lists. (same as Dyeable Leather armor)

The only thing is, I will not use it to change color.

I want it so that is you place in item A, the main item, All Items B increase the tier.

 

The only problem is, it does not even create a new item in the crafting table;

Just nothing.

 

This is the register code:

GameRegistry.addRecipe(new RecipeIncreaseTier());

 

Here is my Item Code:

public boolean hasTier(ItemStack par1ItemStack)
    {
        return (!par1ItemStack.hasTagCompound() ? false : (!par1ItemStack.getTagCompound().hasKey("display", 10) ? false : par1ItemStack.getTagCompound().getCompoundTag("display").hasKey("tier", 3)));
    }

public int getTier(ItemStack par1ItemStack)
{
	NBTTagCompound nbttagcompound = par1ItemStack.getTagCompound();

        if (nbttagcompound == null)
        {
            return 1;
        }
        else
        {
            NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("display");
            return nbttagcompound1 == null ? 1 : (nbttagcompound1.hasKey("tier", 3) ? nbttagcompound1.getInteger("tier") : 1);
        }
}

public void setTier(ItemStack par1ItemStack, int par2)
{
	NBTTagCompound nbttagcompound = par1ItemStack.getTagCompound();

        if (nbttagcompound == null)
        {
            nbttagcompound = new NBTTagCompound();
            par1ItemStack.setTagCompound(nbttagcompound);
        }

        NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("display");

        if (!nbttagcompound.hasKey("display", 10))
        {
            nbttagcompound.setTag("display", nbttagcompound1);
        }

        nbttagcompound1.setInteger("tier", par2);
}

public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
{
  String info = "";

  NBTTagCompound nbttagcompound = par1ItemStack.getTagCompound();
  NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("display");
  
  info = "Tier " + (nbttagcompound1 == null ? 1 : (nbttagcompound1.hasKey("tier", 3) ? nbttagcompound1.getInteger("tier") : 1));
		  
    
  par3List.add(info);
    	
}
}

 

Here is the IRecipe Code:

@Override
public boolean matches(InventoryCrafting par1InventoryCrafting, World var2) {

	ItemStack itemstack = null;
        ArrayList arraylist = new ArrayList();

        for (int i = 0; i < par1InventoryCrafting.getSizeInventory(); ++i)
        {
            ItemStack itemstack1 = par1InventoryCrafting.getStackInSlot(i);

            if (itemstack1 != null)
            {
                if (itemstack1.getItem() instanceof ItemBackpack)
                {
                    if (itemstack1.getItem() != Core.BackPack || itemstack != null)
                    {
                        return false;
                    }

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

                    arraylist.add(itemstack1);
                }
            }
        }
        return itemstack != null && !arraylist.isEmpty();
}

@Override
public ItemStack getCraftingResult(InventoryCrafting par1InventoryCrafting) 
{
	ItemStack itemstack = null;

	int Int = 0;

        int[] aint = new int[3];
        int i = 0;
        int j = 0;
        ItemBackpack backpack = null;
        int k;
        int l;
        float f;
        float f1;
        int l1;

        for (k = 0; k < par1InventoryCrafting.getSizeInventory(); ++k)
        {
            ItemStack itemstack1 = par1InventoryCrafting.getStackInSlot(k);

            if (itemstack1 != null)
            {
                if (itemstack1.getItem() instanceof ItemBackpack)
                {
                    backpack = (ItemBackpack)itemstack1.getItem();

                    if (itemstack1.getItem() != Core.BackPack || itemstack != null)
                    {
                        return null;
                    }

                    itemstack = itemstack1.copy();
                    itemstack.stackSize = 1;

                    if (backpack.hasTier(itemstack1))
                    {
                        l = backpack.getTier(itemstack);
                        Int = l;
                        ++j;
                    }
                }
                else
                {
                    if (itemstack1.getItem() != Items.diamond)
                    {
                        return null;
                    }

                    Int = Int + 1;
                    ++j;
                }
            }
        }

        if (backpack == null)
        {
            return null;
        }
        else
        {
            l1 = Int + j;
            backpack.setTier(itemstack, l1);
            return itemstack;
        }
}

@Override
public int getRecipeSize() {
	return 10;
}

@Override
public ItemStack getRecipeOutput() {
	return null;
}

}

Coding, Testing, Smiling, Publishing!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.