Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --theinsekt/craftstuff
- --experiment, untested
- --need to be able to specify positions in a crafting table
- recipes={
- awkward={"craft",3,{"water bottle",1},{"nether wart",1}}
- }
- materials={
- awkward=1,
- }
- function craftHelp(recipes,materials,want,amount,crafting)
- --get how much of material already have
- local haveAmount=materials[want]
- if haveAmount==nil then haveAmount=0 end
- if haveAmount<want then
- if haveAmount>0 then
- --add have this amount of material
- crafting[#crafting+1]={want,haveAmount,"have"}
- amount=amount-haveAmount
- haveAmount=0
- materials[want]=haveAmount
- end
- --need to craft the rest
- --check if have materials in crafting recipe
- if recipes[want]==nil then
- --no crafting recipe, so need this material
- crafting[#crafting+1]={want,amount,"need"}
- else
- --have crafting recipe, so add need to craft
- crafting[#crafting+1]={want,amount,"craft"}
- --check all the components in the crafting recipe
- for k,v in pairs(recipes[want]) do
- local how,amountOut,want2,amount2=unpack(v)
- --todo take amountOut into account
- --put as many craftings as as neccesary but
- --put extra materials in the materials table
- craftHelp(recipes,materials,want2,amount2*amount,crafting)
- end
- end
- else--haveAmount>=want
- crafting[#crafting+1]={want,amount,"have"}
- haveAmount=haveAmount-amount
- materials[want]=haveAmount
- amount=0
- end
- --if there are no need entries,
- --it's then possible to go from bottom up in the
- --crafting, and perform the crafting actions, if
- end
- function craft(recipes,materials,want,amount)
- local res={}
- craftHelp(recipes,materials,want,amount,res)
- return res
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement