Jump to content

How to make a crafting-recipe WITH Item, you won't loose


elterPro

Recommended Posts

Hey Guys,

first I want to say sorry, because my english maybe can be bad, it's school english...

So my question is, how can I define a crafting recipe, with some factors, wich won't be away after crafting and stay at there slot?

Maybe someone knows Equivalent Exchange, there are many crafting-recipes with the philosophers stone and the stone stays in the slot, even if I've crafted something...So I don't consume it...

My Code:

Relevant parts of the mod_***

//...
public static Block vaporizer;
public static BlockFlower aloeVera;
public static Item aloeVeraAloin;
//...
vaporizer = (new BlockVaporizer(539, 0)) .setBlockName("vaporizer");
	LanguageRegistry.addName(vaporizer, "Vaporizer");
	GameRegistry.registerBlock(vaporizer);
aloeVera = (BlockFlower) new BlockAloeVera(540,0).setBlockName("aloeVera");
	LanguageRegistry.addName(aloeVera, "Aloe Vera");
	GameRegistry.registerBlock(aloeVera);

aloeVeraAloin = (new ItemFoodAloeVeraAloin(904)).setIconIndex(4).setItemName("aloeVeraAloin");
	LanguageRegistry.addName(aloeVeraAloin, "Aloin");
	GameRegistry.addRecipe(new ItemStack(aloeVeraAloin,1), new Object[]{"A", "V", 'A', mod_eltersmiasmata.aloeVera, 'V', mod_eltersmiasmata.vaporizer});
//...

Ok I want, that you can craft aloeVeraAloin with AloeVera and a vaporizer, the AloeVeraPlant is consumed after crafting but the vaporizer is still there...

 

Hope you can help me!

Greetings!

Link to comment
Share on other sites

Its a container Item

 

look in the Item.java an search for the item bucketLava

 

there is setContainerItem(item) and there comes the item

 

public static Item test = new Item(111).setContainerItem(test).setItemName("test");

 

and now when you craft an item with this item look here:

 

ModLoader.addRecipe(new ItemStack(Item.diamond, 1), new Object[]{"XY", 'X', Item.test, 'Y', Block.dirt});

 

with this recipe the Dirt will consumed but the test item will be still there. I hope it help.

Link to comment
Share on other sites

I have a note on this.... ok here it is,

 

Now I haven't tested it myself but I found it here a while back.

 

You need a Crafting Handler class, and you need to register it in your main mod class with:

 

GameRegistry.registerCraftingHandler(new Your Crafting Handler());

 

 

And then inside the crafting handler, which implements ICraftingHandler, your onCrafting method should look a little something like this.

public void onCrafting(EntityPlayer player, ItemStack item, IInventory inv) 
{
    for(int i=0; i < inv.getSizeInventory(); i++)
    {
        if(inv.getStackInSlot(i) != null)
        {
            ItemStack j = inv.getStackInSlot(i);
            if(j.getItem() != null && j.getItem() == Your Item)
            {
                ItemStack k = new ItemStack(Your Item, 2, (j.getItemDamage() + 1));
                inv.setInventorySlotContents(i, k);
            }
        }
    }
}

 

Basically what this does, is run a check every time something is crafted. It looks in every slot and if it finds Your Item, it replaces that stack with a new stack of 2 of your item, one of which is used up in the crafting. It also adds one damage to the item.

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.



×
×
  • Create New...

Important Information

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