Jump to content

Getting multiple items from a recipe


Rubixdoed

Recommended Posts

     What I am looking to do is to process an item into several simpler components. Specifically, I would like to be able to process a TreeBranch into Twigs, stick, and leaves, where TreeBranch and Twigs are part of the Base, and stick and leaves are custom items.

 

This works fine:

recipe Process Branch{	TreeBranch,		Result:stick,	Time:20.0,}

     I understand how to return a single item, but what is the best way to return multiple, different items.

     I could return several more generic items, like a stick, that can further be processed into twigs, or leaves, but I would much prefer to return several items, if it is possible.

 

Example of generic to specific items:

recipe Process Branch{     TreeBranch,          Result:stick=3,     Time:20.0,}recipe Process stick to twigs{     stick,          Result:Twigs,     Time:20.0,}recipe Process stick to leaves{     stick,     Result:leaves,     Time:20.0,}
Link to comment
Share on other sites

you'll need to hop onto lua code to get a recipe to spit out more than one type of item. You basically hook onto the onCreate parameter of a recipe and link it to a lua function. Once in the function you get the player's inventory and add the item.

 

I do this in my canning mod (WIP in the items mods subforum). Feel free to take a look there to get a grasp of what I'm talking about.

Link to comment
Share on other sites

     Okay, so I was having problems getting OnCreate to work. Then I realized that my function was local. So I have that bit working now.

     Now, I can guess what the parameters player, and result are. I would assume that player is the player crafting the item ( you ), and result is the item crafted.

     So, a few things. If I change what the result is, does it change the result of the crafting. Lets say that I change something about it, say its age, does it carry over the the result, without any further coding?

     Also, what is the parameter items. What data does that contain?

 

Thanks for your help.

Link to comment
Share on other sites

you'll need to hop onto lua code to get a recipe to spit out more than one type of item. You basically hook onto the onCreate parameter of a recipe and link it to a lua function. Once in the function you get the player's inventory and add the item.

 

I do this in my canning mod (WIP in the items mods subforum). Feel free to take a look there to get a grasp of what I'm talking about.

 

All I needed to do is use the parameter OnCreate in the recipe. Then, create a lua function, which will be called when the item is created. There, you can add what you want to change about the recipe, and add more outputs.

 

Recipe:

recipe Process Branch{	TreeBranch,		Result:stick,	Time:20.0,	OnCreate:recipe_Process_Branch,} 

 

Lua:

function recipe_Process_Branch(items, result, player)	local inv = player:getInventory();	inv:AddItem("Rubixdoeds.plantFiber");	inv:AddItem("Rubixdoeds.plantFiber");	inv:AddItem("Rubixdoeds.leaves");	inv:AddItem("Rubixdoeds.leaves");	inv:AddItem("Rubixdoeds.leaves");	inv:AddItem("Base.Twigs");	inv:AddItem("Base.Twigs");	inv:AddItem("Base.Twigs");end 

 

Thanks Deadend.

Link to comment
Share on other sites

  • 2 years later...
  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...