diff --git a/abms.lua b/abms.lua index e8cc47f..5b4a8c5 100644 --- a/abms.lua +++ b/abms.lua @@ -3,61 +3,82 @@ minetest.register_abm({ -- Controls non-contained fire interval = 1.0, chance = 1, action = function(pos, node, active_object_count, active_object_count_wider) - local meta = minetest.env:get_meta(pos) - for i, name in ipairs({ - 'fuel_totaltime', - 'fuel_time', - }) do - if meta:get_string(name) == '' then - meta:set_float(name, 5.0) - end - end local meta = minetest.get_meta(pos) + local fuel_time = meta:get_float("fuel_time") or 0 + local src_time = meta:get_float("src_time") or 0 + local fuel_totaltime = meta:get_float("fuel_totaltime") or 0 local inv = meta:get_inventory() + local srclist = inv:get_list("src") + local cooked = nil + if srclist then + cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist}) + end local was_active = false - if meta:get_float('fuel_time') < meta:get_float('fuel_totaltime') then + if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then was_active = true - meta:set_float('fuel_time', meta:get_float('fuel_time') + 0.25) - end - if meta:get_float('fuel_time') < meta:get_float('fuel_totaltime') then - minetest.sound_play({name='fire_small'},{gain=0.07}, - {loop=true}) - local percent = math.floor(meta:get_float('fuel_time') / - meta:get_float('fuel_totaltime') * 100) - meta:set_string('infotext','Campfire active: '..percent..'%') - minetest.swap_node(pos, {name = 'more_fire:campfire'}) - meta:set_string('formspec', - 'size[8,6.75]'.. - default.gui_bg.. - default.gui_slots.. - 'background[5,5;1,1;more_fire_campfire_active.png;true]'.. - 'list[current_name;fuel;1,1.5;1,1;]'.. - 'list[current_player;main;0,2.75;8,1;]'.. - 'list[current_player;main;0,4;8,3;8]') - return - end - local fuel = nil - local fuellist = inv:get_list('fuel') - if fuellist then - fuel = minetest.get_craft_result({method = 'fuel', width = 1, items = fuellist}) - end - if fuel.time <= 0 then - local node = minetest.get_node(pos) - if node.name == 'more_fire:campfire' then - meta:set_string('infotext','Put more wood on the fire!') - minetest.swap_node(pos, {name = 'more_fire:embers'}) - local timer = minetest.get_node_timer(pos) - meta:set_string('formspec', more_fire.embers_formspec) - timer:start(180) + meta:set_float("fuel_time", meta:get_float("fuel_time") + 0.25) + meta:set_float("src_time", meta:get_float("src_time") + 0.25) + if cooked and cooked.item and meta:get_float("src_time") >= cooked.time then + if inv:room_for_item("dst",cooked.item) then + inv:add_item("dst", cooked.item) + local srcstack = inv:get_stack("src", 1) + srcstack:take_item() + inv:set_stack("src", 1, srcstack) + else + print("Could not insert '"..cooked.item:to_string().."'") end + meta:set_string("src_time", 0) + end + end + + if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then + minetest.sound_play({name="campfire_small"},{pos=pos}, {max_hear_distance = 1},{loop=true},{gain=0.009}) + local percent = math.floor(meta:get_float("fuel_time") / + meta:get_float("fuel_totaltime") * 100) + meta:set_string("infotext","Campfire active: "..percent.."%") + minetest.swap_node(pos, {name = 'more_fire:campfire'}) return end - meta:set_string('fuel_totaltime', fuel.time) - meta:set_string('fuel_time', 0) - local stack = inv:get_stack('fuel', 1) + + local cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist}) + local cookable = true + if cooked.time == 0 then + cookable = false + end + + local item_state = '' + local item_percent = 0 + if cookable then + item_percent = math.floor(src_time / cooked.time * 100) + item_state = item_percent .. "%" + end + + meta:set_string("formspec", more_fire.fire_formspec(item_percent)) + + local fuel = nil + local cooked = nil + local fuellist = inv:get_list("fuel") + local srclist = inv:get_list("src") + if srclist then + cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist}) + end + + if fuellist then + fuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist}) + end + + if fuel.time <= 0 then + meta:set_string("infotext","The campfire is out.") + minetest.swap_node(pos, {name = 'more_fire:embers'}) + meta:set_string("formspec", more_fire.fire_formspec(item_percent)) + return + end + meta:set_string("fuel_totaltime", fuel.time) + meta:set_string("fuel_time", 0) + local stack = inv:get_stack("fuel", 1) stack:take_item() - inv:set_stack('fuel', 1, stack) -end, + inv:set_stack("fuel", 1, stack) + end, }) minetest.register_abm({ -- Controls the contained fires. @@ -65,63 +86,86 @@ minetest.register_abm({ -- Controls the contained fires. interval = 1.0, chance = 1, action = function(pos, node, active_object_count, active_object_count_wider) - local meta = minetest.env:get_meta(pos) - for i, name in ipairs({ - 'fuel_totaltime', - 'fuel_time', - }) do - if meta:get_string(name) == '' then - meta:set_float(name, 0.0) - end - end local meta = minetest.get_meta(pos) + local meta = minetest.get_meta(pos) + local fuel_time = meta:get_float("fuel_time") or 0 + local src_time = meta:get_float("src_time") or 0 + local fuel_totaltime = meta:get_float("fuel_totaltime") or 0 local inv = meta:get_inventory() + local srclist = inv:get_list("src") + local cooked = nil + if srclist then + cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist}) + end local was_active = false - if meta:get_float('fuel_time') < meta:get_float('fuel_totaltime') then + if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then was_active = true - meta:set_float('fuel_time', meta:get_float('fuel_time') + 0.25) - end - if meta:get_float('fuel_time') < meta:get_float('fuel_totaltime') then - minetest.sound_play({name='fire_small'},{gain=0.07}, - {loop=true}) - local percent = math.floor(meta:get_float('fuel_time') / - meta:get_float('fuel_totaltime') * 100) - meta:set_string('infotext','Campfire active: '..percent..'%') - minetest.swap_node(pos, {name = 'more_fire:campfire_contained'}) - meta:set_string('formspec', - 'size[8,6.75]'.. - default.gui_bg.. - default.gui_slots.. - 'background[5,5;1,1;more_fire_campfire_active.png;true]'.. - 'list[current_name;fuel;1,1.5;1,1;]'.. - 'list[current_player;main;0,2.75;8,1;]'.. - 'list[current_player;main;0,4;8,3;8]') - return - end - local fuel = nil - local fuellist = inv:get_list('fuel') - if fuellist then - fuel = minetest.get_craft_result({method = 'fuel', width = 1, items = fuellist}) - end - if fuel.time <= 0 then - local node = minetest.get_node(pos) - if node.name == 'more_fire:campfire_contained' then - meta:set_string('infotext','Put more wood on the fire!') - minetest.swap_node(pos, {name = 'more_fire:embers_contained'}) - meta:set_string('formspec', more_fire.embers_formspec) - local timer = minetest.get_node_timer(pos) - timer:start(190) + meta:set_float("fuel_time", meta:get_float("fuel_time") + 0.25) + meta:set_float("src_time", meta:get_float("src_time") + 0.25) + if cooked and cooked.item and meta:get_float("src_time") >= cooked.time then + if inv:room_for_item("dst",cooked.item) then + inv:add_item("dst", cooked.item) + local srcstack = inv:get_stack("src", 1) + srcstack:take_item() + inv:set_stack("src", 1, srcstack) + else + print("Could not insert '"..cooked.item:to_string().."'") end + meta:set_string("src_time", 0) + end + end + + if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then + minetest.sound_play({name="campfire_small"},{pos=pos}, {max_hear_distance = 1},{loop=true},{gain=0.009}) + local percent = math.floor(meta:get_float("fuel_time") / + meta:get_float("fuel_totaltime") * 100) + meta:set_string("infotext","Campfire active: "..percent.."%") + minetest.swap_node(pos, {name = 'more_fire:campfire_contained'}) return end - meta:set_string('fuel_totaltime', fuel.time) - meta:set_string('fuel_time', 0) - local stack = inv:get_stack('fuel', 1) + + local cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist}) + local cookable = true + if cooked.time == 0 then + cookable = false + end + + local item_state = '' + local item_percent = 0 + if cookable then + item_percent = math.floor(src_time / cooked.time * 100) + item_state = item_percent .. "%" + end + + meta:set_string("formspec", more_fire.fire_formspec(item_percent)) + + local fuel = nil + local cooked = nil + local fuellist = inv:get_list("fuel") + local srclist = inv:get_list("src") + if srclist then + cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist}) + end + + if fuellist then + fuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist}) + end + + if fuel.time <= 0 then + meta:set_string("infotext","The campfire is out.") + minetest.swap_node(pos, {name = 'more_fire:embers_contained'}) + meta:set_string("formspec", more_fire.embers_formspec) + return + end + meta:set_string("fuel_totaltime", fuel.time) + meta:set_string("fuel_time", 0) + local stack = inv:get_stack("fuel", 1) stack:take_item() - inv:set_stack('fuel', 1, stack) -end, + inv:set_stack("fuel", 1, stack) + end, }) + minetest.register_abm({ --smoke for embers nodenames = {'more_fire:embers', 'more_fire:embers_contained'}, interval = 1, diff --git a/changelog.txt b/changelog.txt index 6a98e1f..560691c 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,6 @@ +8-26-15: +You can finally cook in the fires, there seems to be a little bug yet in the arrow showing the progress of the cooking, but mechanics all seem to work alright. + 6-3-15: Campfires and embers now have particles, smoke for the embers, and little sparks for the fires. Also lava now spawns little lava particles, the particles do nothing other than add a little visual effect. diff --git a/craftitems.lua b/craftitems.lua index 36ebaff..ada5cd2 100644 --- a/craftitems.lua +++ b/craftitems.lua @@ -18,3 +18,15 @@ minetest.register_craftitem('more_fire:oil', { description = 'lantern oil', inventory_image = 'more_fire_oil.png', }) + +minetest.register_craftitem('more_fire:dried_grass', { + description = 'dried grass', + inventory_image = 'more_fire_grass_dried.png', + groups = {kindling=1} +}) + +minetest.register_craftitem('more_fire:kindle', { + description = 'Kindling', + inventory_image = 'more_fire_kindle.png', + groups = {flammable=1, kindling=1, stick=1} +}) diff --git a/crafts.lua b/crafts.lua index 42b98b9..8914c45 100644 --- a/crafts.lua +++ b/crafts.lua @@ -25,8 +25,7 @@ minetest.register_craft({ minetest.register_craft({ output = 'more_fire:embers 1', recipe = { - {'', '', ''}, - {'default:stick', 'default:torch', 'default:stick'}, + {'group:kindling', 'default:torch', 'group:kindling'}, {'group:wood', 'group:wood', 'group:wood'}, } }) @@ -48,17 +47,24 @@ minetest.register_craft({ }) minetest.register_craft({ - output = 'default:torch 4', + output = 'more_fire:torch_weak 4', recipe = { - {'more_fire:charcoal'}, - {'group:stick'}, + {'group:kindling', 'group:kindling', 'group:kindling'}, + {'group:kindling', 'group:stick', 'group:kindling'}, + {'', 'group:stick', ''} } }) +minetest.register_craft({ + type = 'shapeless', + output = 'default:torch', + recipe = {'more_fire:torch_weak', 'group:coal'}, +}) + minetest.register_craft({ type = 'shapeless', output = 'more_fire:kindling 1', - recipe = {'group:stick', 'group:wood', 'group:flammable', 'group:flammable'}, + recipe = {'group:kindling', 'group:wood', 'group:kindling', 'group:kindling', 'group:kindling'}, }) minetest.register_craft({ @@ -107,14 +113,6 @@ minetest.register_craft({ } }) -minetest.register_craft({ - output = 'more_fire:marker 1', - recipe = { - {'more_fire:torch_stub', 'more_fire:torch_stub', 'more_fire:torch_stub'} - - } -}) - -- cooking recipes minetest.register_craft({ type = 'cooking', @@ -124,8 +122,9 @@ minetest.register_craft({ minetest.register_craft({ type = 'cooking', - recipe = 'default:stick', - output = 'more_fire:marker' + recipe = 'default:grass_1', + output = 'more_fire:dried_grass', + cooktime = 1, }) -- fuel recipes diff --git a/functions.lua b/functions.lua index e06d8d5..b8c3cc1 100644 --- a/functions.lua +++ b/functions.lua @@ -6,28 +6,25 @@ function default.get_hotbar_bg(x,y) return out end -function more_fire.campfire(pos, percent, item_percent) +function more_fire.fire_formspec(item_percent) local formspec = - 'size[8,6.75]'.. - default.gui_bg.. - default.gui_bg_img.. - default.gui_slots.. - 'background[5,5;1,1;more_fire_campfire_active.png;true]'.. - 'list[current_name;fuel;1,1.5;1,1;]'.. - 'list[current_player;main;0,2.75;8,1;]'.. - 'list[current_player;main;0,4;8,3;8]'.. - default.get_hotbar_bg(0,2.75) + 'size[8,6.75]'.. + default.gui_slots.. + 'listcolors[#00000069;#5A5A5A;#141318;#30434C;#FFF]'.. + 'background[8,6.75;0,0;more_fire_campfire_bg.png;true]'.. + 'label[2,.75;< Add More Wood]'.. + 'label[1.25,2; Cook Something >]'.. + 'list[current_name;fuel;1,.5;1,1;]'.. + 'list[current_name;src;4,1.75;1,1;]'.. + 'image[5,1.75;1,1;gui_furnace_arrow_bg.png^[lowpart:'.. + (item_percent)..':gui_furnace_arrow_fg.png^[transformR270]'.. + 'list[current_name;dst;6,1.75;2,1;]'.. + 'list[current_player;main;0,2.75;8,1;]'.. + 'list[current_player;main;0,4;8,3;8]'.. + default.get_hotbar_bg(0,2.75) return formspec end -function more_fire.get_campfire_formspec(pos, percent) - local meta = minetest.get_meta(pos)local inv = meta:get_inventory() - local fuellist = inv:get_list('fuel') - if fuellist then - end - return more_fire.campfire(pos, percent, item_percent) -end - function burn(pointed_thing) --kindling doesn't always start from the first spark local ignite_chance = math.random(5) if ignite_chance == 1 diff --git a/init.lua b/init.lua index 554e328..9cd049f 100644 --- a/init.lua +++ b/init.lua @@ -10,12 +10,15 @@ more_fire = {} -- formspecs more_fire.embers_formspec = 'size[8,6.75]'.. -default.gui_bg.. -default.gui_bg_img.. default.gui_slots.. 'listcolors[#00000069;#5A5A5A;#141318;#30434C;#FFF]'.. -'background[5,5;1,1;more_fire_campfire_inactive.png;true]'.. -'list[current_name;fuel;1,1.5;1,1;]'.. +'background[8,6.75;0,0;more_fire_campfire_bg.png;true]'.. +'label[2,.75;< Add More Wood]'.. +'label[1.25,2; Cook Something >]'.. +'list[current_name;fuel;1,.5;1,1;]'.. +'list[current_name;src;4,1.75;1,1;]'.. +'image[5,1.75;1,1;gui_furnace_arrow_bg.png^[transformR270]'.. +'list[current_name;dst;6,1.75;2,1;]'.. 'list[current_player;main;0,2.75;8,1;]'.. 'list[current_player;main;0,4;8,3;8]'.. default.get_hotbar_bg(0,2.75) diff --git a/nodes.lua b/nodes.lua index 7ddbbe4..b0345bc 100644 --- a/nodes.lua +++ b/nodes.lua @@ -41,7 +41,7 @@ minetest.register_node(':default:torch', { wall_bottom = {-0.1, -0.5 , -0.1, 0.1, 0.0625, 0.1}, wall_side = {-0.35, -0.5 , -0.1, -0.5, 0.0625, 0.1}, }, - groups = {choppy = 2, dig_immediate = 3, flammable = 1, attached_node = 1, hot = 2}, + groups = {choppy = 2, dig_immediate = 3, flammable = 1, attached_node = 1, hot = 2, kindling=1}, sounds = default.node_sound_wood_defaults(), on_construct = function(pos) if finite_torches == true then @@ -57,6 +57,50 @@ minetest.register_node(':default:torch', { end, }) +minetest.register_node('more_fire:torch_weak', { + description = 'Weak Torch', + drawtype = 'nodebox', + tiles = { + {name = 'more_fire_torch_top.png'}, + {name = 'more_fire_torch_bottom.png'}, + {name = 'more_fire_torch_side.png'}, + }, + inventory_image = 'more_fire_torch_inv.png', + wield_image = 'more_fire_torch_inv.png', + paramtype = 'light', + paramtype2 = 'wallmounted', + sunlight_propagates = true, + is_ground_content = false, + walkable = false, + light_source = LIGHT_MAX - 6, + node_box = { + type = 'wallmounted', + wall_top = {-0.0625, -0.0625, -0.0625, 0.0625, 0.5 , 0.0625}, + wall_bottom = {-0.0625, -0.5 , -0.0625, 0.0625, 0.0625, 0.0625}, + wall_side = {-0.5 , -0.5 , -0.0625, -0.375, 0.0625, 0.0625}, + }, + selection_box = { + type = 'wallmounted', + wall_top = {-0.1, -0.05, -0.1, 0.1, 0.5 , 0.1}, + wall_bottom = {-0.1, -0.5 , -0.1, 0.1, 0.0625, 0.1}, + wall_side = {-0.35, -0.5 , -0.1, -0.5, 0.0625, 0.1}, + }, + groups = {choppy = 2, dig_immediate = 3, flammable = 1, attached_node = 1, hot = 2, kindling=1}, + sounds = default.node_sound_wood_defaults(), + on_construct = function(pos) + if finite_torches == true then + local timer = minetest.get_node_timer(pos) + timer:start(480) + end + end, + on_timer = function(pos, elapsed) + local timer = minetest.get_node_timer(pos) + local node = minetest.get_node(pos) + minetest.swap_node(pos, {name = 'more_fire:torch_stub', param2 = node.param2}) + timer:stop() + end, +}) + minetest.register_node('more_fire:torch_stub', { description = 'burnt out torch', drawtype = 'nodebox', @@ -84,7 +128,7 @@ minetest.register_node('more_fire:torch_stub', { wall_bottom = {-0.1, -0.5 , -0.1, 0.1, -0.2, 0.1}, wall_side = {-0.35, -0.5 , -0.1, -0.5, -0.2, 0.1}, }, - groups = {choppy = 2, dig_immediate = 3, flammable = 1, attached_node = 1, not_in_creative_inventory =1}, + groups = {choppy = 2, dig_immediate = 3, flammable = 1, attached_node = 1, not_in_creative_inventory = 1, kindling=1}, sounds = default.node_sound_wood_defaults(), }) @@ -113,7 +157,9 @@ minetest.register_node('more_fire:kindling', { on_construct = function(pos) local meta = minetest.env:get_meta(pos) local inv = meta:get_inventory() - inv:set_size('fuel', 4) + inv:set_size('fuel', 1) + inv:set_size("src", 1) + inv:set_size("dst", 2) end, }) @@ -141,12 +187,18 @@ minetest.register_node('more_fire:embers', { meta:set_string('infotext', 'Campfire'); local inv = meta:get_inventory() inv:set_size('fuel', 1) + inv:set_size("src", 1) + inv:set_size("dst", 2) timer:start(180) end, can_dig = function(pos, player) local meta = minetest.get_meta(pos); local inv = meta:get_inventory() - if not inv:is_empty('fuel') then + if not inv:is_empty("fuel") then + return false + elseif not inv:is_empty("dst") then + return false + elseif not inv:is_empty("src") then return false end return true @@ -186,19 +238,24 @@ minetest.register_node('more_fire:campfire', { damage_per_second = 1, light_source = 14, is_ground_content = true, + drop = 'more_fire:charcoal', groups = {cracky=2,hot=2,attached_node=1,igniter=1,not_in_creative_inventory=1}, selection_box = { type = 'fixed', fixed = { -0.48, -0.5, -0.48, 0.48, 0.0, 0.48 }, }, - can_dig = function(pos,player) - local meta = minetest.env:get_meta(pos); + can_dig = function(pos, player) + local meta = minetest.get_meta(pos); local inv = meta:get_inventory() - if not inv:is_empty('fuel') then + if not inv:is_empty("fuel") then return false - end + elseif not inv:is_empty("dst") then + return false + elseif not inv:is_empty("src") then + return false + end return true - end, + end, get_staticdata = function(self) end, }) @@ -222,11 +279,17 @@ minetest.register_node('more_fire:kindling_contained', { local meta = minetest.env:get_meta(pos) local inv = meta:get_inventory() inv:set_size('fuel', 4) + inv:set_size("src", 1) + inv:set_size("dst", 2) end, can_dig = function(pos, player) local meta = minetest.get_meta(pos); local inv = meta:get_inventory() - if not inv:is_empty('fuel') then + if not inv:is_empty("fuel") then + return false + elseif not inv:is_empty("dst") then + return false + elseif not inv:is_empty("src") then return false end return true @@ -257,13 +320,18 @@ minetest.register_node('more_fire:embers_contained', { meta:set_string('infotext', 'Campfire'); local inv = meta:get_inventory() inv:set_size('fuel', 4) + inv:set_size("src", 1) + inv:set_size("dst", 2) timer:start(190) - print 'called the on_construct function.' end, can_dig = function(pos, player) local meta = minetest.get_meta(pos); local inv = meta:get_inventory() - if not inv:is_empty('fuel') then + if not inv:is_empty("fuel") then + return false + elseif not inv:is_empty("dst") then + return false + elseif not inv:is_empty("src") then return false end return true @@ -309,14 +377,18 @@ minetest.register_node('more_fire:campfire_contained', { type = 'fixed', fixed = { -0.48, -0.5, -0.48, 0.48, 0.0, 0.48 }, }, - can_dig = function(pos,player) - local meta = minetest.env:get_meta(pos); + can_dig = function(pos, player) + local meta = minetest.get_meta(pos); local inv = meta:get_inventory() - if not inv:is_empty('fuel') then + if not inv:is_empty("fuel") then return false - end + elseif not inv:is_empty("dst") then + return false + elseif not inv:is_empty("src") then + return false + end return true - end, + end, get_staticdata = function(self) end, }) @@ -509,18 +581,3 @@ minetest.register_node('more_fire:oil_lamp_table_off', { end, }) -minetest.register_node('more_fire:marking', { - description = 'Nathan is really cool ;)', - paramtype = 'light', - paramtype2 = 'facedir', - tiles = {'more_fire_mark.png'}, - drawtype = 'mesh', - mesh = 'more_fire_mark.obj', - selection_box = { - type = 'fixed', - fixed = {-0.5, -0.5, -0.5, 0.5, -0.4, 0.5}, -- Right, Bottom, Back, Left, Top, Front - }, - walkable = false, - groups = {choppy = 2, dig_immediate = 3, attached_node = 1, not_in_creative_inventory=1}, - drop = '', -}) diff --git a/textures/more_fire_campfire_active.png b/textures/more_fire_campfire_active.png deleted file mode 100644 index 5af9e76..0000000 Binary files a/textures/more_fire_campfire_active.png and /dev/null differ diff --git a/textures/more_fire_campfire_bg.png b/textures/more_fire_campfire_bg.png new file mode 100644 index 0000000..522dd5c Binary files /dev/null and b/textures/more_fire_campfire_bg.png differ diff --git a/textures/more_fire_campfire_inactive.png b/textures/more_fire_campfire_inactive.png deleted file mode 100644 index 74b2cbd..0000000 Binary files a/textures/more_fire_campfire_inactive.png and /dev/null differ