@@ -1,21 +1,45 @@ +local disassembler_formspec = function(pos) + local m = minetest.get_meta(pos) + local i = m:get_inventory() + local form = [[ + formspec_version[3] + size[10.25,7] real_coordinates[true] + list[current_player;main;0.25,2;8,4] + ]] + local slot = function(name,x,y,ghost) + local s = string.format('list[context;%s;%f,%f;1,1;]', name, x, y) + if ghost and i:is_empty(name) then + s = string.format('image[%f,%f;1,1;sorcery_ui_ghost_%s.png]',x,y,ghost) .. s + end + form = form .. s + end + slot('item',0.25,0.5) + slot('paper',2.25,0.5,'paper') + slot('ink',3.50,0.5,'ink_bottle') + slot('pen',4.75,0.5,'pen') + slot('output',9,0.5) + form = form .. [[ + listring[context;output] + listring[current_player;main] listring[context;paper] + listring[current_player;main] listring[context;ink] + listring[current_player;main] listring[context;item] + listring[current_player;main] + ]] + m:set_string('formspec',form) +end local update_disassembler = function(pos) local m = minetest.get_meta(pos) local i = m:get_inventory() local paper = i:get_stack('paper',1) local item = i:get_stack('item',1) + local ink = i:get_stack('ink',1) + local pen = i:get_stack('pen',1) - local ink_count - for j=1,i:get_size('ink') do - local ink = i:get_stack('ink',j) - local c = ink:get_count() - if ink_count then - if c < ink_count then ink_count = c end - else ink_count = c end - end + local ink_count = ink:get_count() - ink_count = ink_count or 0 local maxrecs = math.min(ink_count, paper:get_count(), item:get_count()) + if pen:is_empty() then maxrecs = 0 end if maxrecs > 0 and sorcery.cookbook.classes.craft.find(item:get_name()) then local rec = ItemStack{name = 'sorcery:recipe', count = maxrecs} sorcery.cookbook.setrecipe(rec, 'craft', item:get_name()) @@ -22,8 +46,9 @@ i:set_stack('output',1,rec) else i:set_stack('output',1,ItemStack()) end + disassembler_formspec(pos) end local dsbox = { type = 'fixed'; fixed = { @@ -58,27 +83,13 @@ local m = minetest.get_meta(pos) local i = m:get_inventory() i:set_size('item',1) i:set_size('paper',1) - i:set_size('ink',3) + i:set_size('ink',1) + i:set_size('pen',1) i:set_size('output',1) m:set_string('infotext','Disassembly Kit') - m:set_string('formspec', [[ - formspec_version[3] - size[10.25,7] real_coordinates[true] - list[current_player;main;0.25,2;8,4] - - list[context;item;0.25,0.5;1,1;] - list[context;paper;2.25,0.5;1,1;] - list[context;ink;4.25,0.5;3,1;] - list[context;output;9,0.5;1,1;] - - listring[context;output] - listring[current_player;main] listring[context;paper] - listring[current_player;main] listring[context;ink] - listring[current_player;main] listring[context;item] - listring[current_player;main] - ]]) + disassembler_formspec(pos) end; on_metadata_inventory_put = update_disassembler; on_metadata_inventory_take = function(pos,list,idx,stack,user) local m = minetest.get_meta(pos) @@ -87,14 +98,14 @@ local item = i:get_stack('item',1) if list == 'output' then local count = stack:get_count() - local leftover = sorcery.data.infusion_leftovers[item:get_name()] + local leftover = sorcery.register.residue.db[item:get_name()] local lstack if leftover then lstack = ItemStack(leftover) lstack:set_count(lstack:get_count() * count) -- this slightly idiosyncratic code is used to ensure that - -- itemstrings can be used in the infusion leftovers table + -- itemstrings can be used in the residue table end item:take_item(count) if item:get_count() > 0 then if leftover then @@ -108,13 +119,20 @@ else i:set_stack('item',1,ItemStack()) end end - for j=1,i:get_size('ink') do - local ink = i:get_stack('ink',j) - ink:take_item(count) - i:set_stack('ink',j,ink) - end + local ink = i:get_stack('ink',1) + local paper = i:get_stack('paper',1) + ink:take_item(count) paper:take_item(count) + i:set_stack('ink',1,ink) i:set_stack('paper',1,paper) + local penstack = i:get_stack('pen',1) + local pen = penstack:get_definition()._sorcery + local uses = pen.material.data.durability * 0.10 + local dmg = 65535 / math.random(math.floor(uses*0.5),uses) + print('adding damage',dmg,penstack:get_wear()) + penstack:add_wear(dmg) + print('wear now',penstack:get_wear()) + i:set_stack('pen',1,penstack) end update_disassembler(pos) end; @@ -122,9 +140,11 @@ local name = stack:get_name() if list == 'paper' then if name == 'default:paper' then return stack:get_count() end elseif list == 'ink' then - if minetest.get_item_group(name,'dye') > 0 then return stack:get_count() end + if minetest.get_item_group(name,'ink') > 0 then return stack:get_count() end + elseif list == 'pen' then + if minetest.get_item_group(name,'sorcery_pen') > 0 then return stack:get_count() end elseif list == 'item' then return stack:get_count() elseif list == 'output' then return 0