mirror of
https://github.com/luanti-org/minetest_game.git
synced 2025-08-27 11:17:46 -04:00
Merge 4979632ded
into c526be36ff
This commit is contained in:
commit
65858f2366
1 changed files with 51 additions and 34 deletions
|
@ -53,19 +53,19 @@ end
|
||||||
--
|
--
|
||||||
|
|
||||||
local function can_dig(pos, player)
|
local function can_dig(pos, player)
|
||||||
local meta = minetest.get_meta(pos);
|
local meta = core.get_meta(pos)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
return inv:is_empty("fuel") and inv:is_empty("dst") and inv:is_empty("src")
|
return inv:is_empty("fuel") and inv:is_empty("dst") and inv:is_empty("src")
|
||||||
end
|
end
|
||||||
|
|
||||||
local function allow_metadata_inventory_put(pos, listname, index, stack, player)
|
local function allow_metadata_inventory_put(pos, listname, index, stack, player)
|
||||||
if minetest.is_protected(pos, player:get_player_name()) then
|
if core.is_protected(pos, player:get_player_name()) then
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = core.get_meta(pos)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
if listname == "fuel" then
|
if listname == "fuel" then
|
||||||
if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then
|
if core.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then
|
||||||
if inv:is_empty("src") then
|
if inv:is_empty("src") then
|
||||||
meta:set_string("infotext", S("Furnace is empty"))
|
meta:set_string("infotext", S("Furnace is empty"))
|
||||||
end
|
end
|
||||||
|
@ -81,44 +81,53 @@ local function allow_metadata_inventory_put(pos, listname, index, stack, player)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
|
local function allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = core.get_meta(pos)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
local stack = inv:get_stack(from_list, from_index)
|
local stack = inv:get_stack(from_list, from_index)
|
||||||
return allow_metadata_inventory_put(pos, to_list, to_index, stack, player)
|
return allow_metadata_inventory_put(pos, to_list, to_index, stack, player)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function allow_metadata_inventory_take(pos, listname, index, stack, player)
|
local function allow_metadata_inventory_take(pos, listname, index, stack, player)
|
||||||
if minetest.is_protected(pos, player:get_player_name()) then
|
if core.is_protected(pos, player:get_player_name()) then
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
return stack:get_count()
|
return stack:get_count()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function stop_furnace_sound(pos, fadeout_step)
|
local function stop_furnace_sound(pos, fadeout_step)
|
||||||
local hash = minetest.hash_node_position(pos)
|
local hash = core.hash_node_position(pos)
|
||||||
local sound_ids = furnace_fire_sounds[hash]
|
local sound_ids = furnace_fire_sounds[hash]
|
||||||
if sound_ids then
|
if sound_ids then
|
||||||
for _, sound_id in ipairs(sound_ids) do
|
for _, sound_id in ipairs(sound_ids) do
|
||||||
minetest.sound_fade(sound_id, -1, 0)
|
core.sound_fade(sound_id, -1, 0)
|
||||||
end
|
end
|
||||||
furnace_fire_sounds[hash] = nil
|
furnace_fire_sounds[hash] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function swap_node(pos, name)
|
local function swap_node(pos, name)
|
||||||
local node = minetest.get_node(pos)
|
local node = core.get_node(pos)
|
||||||
if node.name == name then
|
if node.name == name then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
node.name = name
|
node.name = name
|
||||||
minetest.swap_node(pos, node)
|
core.swap_node(pos, node)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function add_item_or_drop(inv, pos, item)
|
||||||
|
local leftover = inv:add_item("dst", item)
|
||||||
|
if not leftover:is_empty() then
|
||||||
|
local above = vector.offset(pos, 0, 1, 0)
|
||||||
|
local drop_pos = core.find_node_near(pos, 1, {"air"}) or above
|
||||||
|
core.item_drop(leftover, nil, drop_pos)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function furnace_node_timer(pos, elapsed)
|
local function furnace_node_timer(pos, elapsed)
|
||||||
--
|
--
|
||||||
-- Initialize metadata
|
-- Initialize metadata
|
||||||
--
|
--
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = core.get_meta(pos)
|
||||||
local fuel_time = meta:get_float("fuel_time") or 0
|
local fuel_time = meta:get_float("fuel_time") or 0
|
||||||
local src_time = meta:get_float("src_time") or 0
|
local src_time = meta:get_float("src_time") or 0
|
||||||
local fuel_totaltime = meta:get_float("fuel_totaltime") or 0
|
local fuel_totaltime = meta:get_float("fuel_totaltime") or 0
|
||||||
|
@ -132,7 +141,6 @@ local function furnace_node_timer(pos, elapsed)
|
||||||
|
|
||||||
local cookable, cooked
|
local cookable, cooked
|
||||||
local fuel
|
local fuel
|
||||||
|
|
||||||
local update = true
|
local update = true
|
||||||
local items_smelt = 0
|
local items_smelt = 0
|
||||||
while elapsed > 0 and update do
|
while elapsed > 0 and update do
|
||||||
|
@ -147,7 +155,7 @@ local function furnace_node_timer(pos, elapsed)
|
||||||
|
|
||||||
-- Check if we have cookable content
|
-- Check if we have cookable content
|
||||||
local aftercooked
|
local aftercooked
|
||||||
cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
|
cooked, aftercooked = core.get_craft_result({method = "cooking", width = 1, items = srclist})
|
||||||
cookable = cooked.time ~= 0
|
cookable = cooked.time ~= 0
|
||||||
|
|
||||||
local el = math.min(elapsed, fuel_totaltime - fuel_time)
|
local el = math.min(elapsed, fuel_totaltime - fuel_time)
|
||||||
|
@ -167,8 +175,22 @@ local function furnace_node_timer(pos, elapsed)
|
||||||
if inv:room_for_item("dst", cooked.item) then
|
if inv:room_for_item("dst", cooked.item) then
|
||||||
inv:add_item("dst", cooked.item)
|
inv:add_item("dst", cooked.item)
|
||||||
inv:set_stack("src", 1, aftercooked.items[1])
|
inv:set_stack("src", 1, aftercooked.items[1])
|
||||||
|
-- stop any final replacement from clogging "src"
|
||||||
|
local can_cook = core.get_craft_result({
|
||||||
|
method = "cooking", width = 1,
|
||||||
|
items = {aftercooked.items[1]:to_string()}})
|
||||||
|
|
||||||
|
if can_cook.time == 0 and can_cook.item:to_string() == ""
|
||||||
|
and aftercooked.items[1]:to_string() ~= "" then
|
||||||
|
inv:set_stack("src", 1, "")
|
||||||
|
add_item_or_drop(inv, pos, aftercooked.items[1])
|
||||||
|
end
|
||||||
src_time = src_time - cooked.time
|
src_time = src_time - cooked.time
|
||||||
update = true
|
update = true
|
||||||
|
-- add replacement item to dst so they arent lost
|
||||||
|
if cooked.replacements[1] then
|
||||||
|
add_item_or_drop(inv, pos, cooked.replacements[1])
|
||||||
|
end
|
||||||
else
|
else
|
||||||
dst_full = true
|
dst_full = true
|
||||||
end
|
end
|
||||||
|
@ -183,7 +205,7 @@ local function furnace_node_timer(pos, elapsed)
|
||||||
if cookable then
|
if cookable then
|
||||||
-- We need to get new fuel
|
-- We need to get new fuel
|
||||||
local afterfuel
|
local afterfuel
|
||||||
fuel, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
|
fuel, afterfuel = core.get_craft_result({method = "fuel", width = 1, items = fuellist})
|
||||||
|
|
||||||
if fuel.time == 0 then
|
if fuel.time == 0 then
|
||||||
-- No valid fuel in fuel list
|
-- No valid fuel in fuel list
|
||||||
|
@ -191,7 +213,7 @@ local function furnace_node_timer(pos, elapsed)
|
||||||
src_time = 0
|
src_time = 0
|
||||||
else
|
else
|
||||||
-- prevent blocking of fuel inventory (for automatization mods)
|
-- prevent blocking of fuel inventory (for automatization mods)
|
||||||
local is_fuel = minetest.get_craft_result({method = "fuel", width = 1, items = {afterfuel.items[1]:to_string()}})
|
local is_fuel = core.get_craft_result({method = "fuel", width = 1, items = {afterfuel.items[1]:to_string()}})
|
||||||
if is_fuel.time == 0 then
|
if is_fuel.time == 0 then
|
||||||
table.insert(fuel.replacements, afterfuel.items[1])
|
table.insert(fuel.replacements, afterfuel.items[1])
|
||||||
inv:set_stack("fuel", 1, "")
|
inv:set_stack("fuel", 1, "")
|
||||||
|
@ -202,12 +224,7 @@ local function furnace_node_timer(pos, elapsed)
|
||||||
-- Put replacements in dst list or drop them on the furnace.
|
-- Put replacements in dst list or drop them on the furnace.
|
||||||
local replacements = fuel.replacements
|
local replacements = fuel.replacements
|
||||||
if replacements[1] then
|
if replacements[1] then
|
||||||
local leftover = inv:add_item("dst", replacements[1])
|
add_item_or_drop(inv, pos, replacements[1])
|
||||||
if not leftover:is_empty() then
|
|
||||||
local above = vector.new(pos.x, pos.y + 1, pos.z)
|
|
||||||
local drop_pos = minetest.find_node_near(above, 1, {"air"}) or above
|
|
||||||
minetest.item_drop(replacements[1], nil, drop_pos)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
update = true
|
update = true
|
||||||
fuel_totaltime = fuel.time + (fuel_totaltime - fuel_time)
|
fuel_totaltime = fuel.time + (fuel_totaltime - fuel_time)
|
||||||
|
@ -225,7 +242,7 @@ local function furnace_node_timer(pos, elapsed)
|
||||||
|
|
||||||
if items_smelt > 0 then
|
if items_smelt > 0 then
|
||||||
-- Play cooling sound
|
-- Play cooling sound
|
||||||
minetest.sound_play("default_cool_lava",
|
core.sound_play("default_cool_lava",
|
||||||
{ pos = pos, max_hear_distance = 16, gain = 0.07 * math.min(items_smelt, 7) }, true)
|
{ pos = pos, max_hear_distance = 16, gain = 0.07 * math.min(items_smelt, 7) }, true)
|
||||||
end
|
end
|
||||||
if fuel and fuel_totaltime > fuel.time then
|
if fuel and fuel_totaltime > fuel.time then
|
||||||
|
@ -271,9 +288,9 @@ local function furnace_node_timer(pos, elapsed)
|
||||||
|
|
||||||
-- Play sound every 5 seconds while the furnace is active
|
-- Play sound every 5 seconds while the furnace is active
|
||||||
if timer_elapsed == 0 or (timer_elapsed + 1) % 5 == 0 then
|
if timer_elapsed == 0 or (timer_elapsed + 1) % 5 == 0 then
|
||||||
local sound_id = minetest.sound_play("default_furnace_active",
|
local sound_id = core.sound_play("default_furnace_active",
|
||||||
{pos = pos, max_hear_distance = 16, gain = 0.25})
|
{pos = pos, max_hear_distance = 16, gain = 0.25})
|
||||||
local hash = minetest.hash_node_position(pos)
|
local hash = core.hash_node_position(pos)
|
||||||
furnace_fire_sounds[hash] = furnace_fire_sounds[hash] or {}
|
furnace_fire_sounds[hash] = furnace_fire_sounds[hash] or {}
|
||||||
table.insert(furnace_fire_sounds[hash], sound_id)
|
table.insert(furnace_fire_sounds[hash], sound_id)
|
||||||
-- Only remember the 3 last sound handles
|
-- Only remember the 3 last sound handles
|
||||||
|
@ -281,7 +298,7 @@ local function furnace_node_timer(pos, elapsed)
|
||||||
table.remove(furnace_fire_sounds[hash], 1)
|
table.remove(furnace_fire_sounds[hash], 1)
|
||||||
end
|
end
|
||||||
-- Remove the sound ID automatically from table after 11 seconds
|
-- Remove the sound ID automatically from table after 11 seconds
|
||||||
minetest.after(11, function()
|
core.after(11, function()
|
||||||
if not furnace_fire_sounds[hash] then
|
if not furnace_fire_sounds[hash] then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -302,7 +319,7 @@ local function furnace_node_timer(pos, elapsed)
|
||||||
formspec = default.get_furnace_inactive_formspec()
|
formspec = default.get_furnace_inactive_formspec()
|
||||||
swap_node(pos, "default:furnace")
|
swap_node(pos, "default:furnace")
|
||||||
-- stop timer on the inactive furnace
|
-- stop timer on the inactive furnace
|
||||||
minetest.get_node_timer(pos):stop()
|
core.get_node_timer(pos):stop()
|
||||||
meta:set_int("timer_elapsed", 0)
|
meta:set_int("timer_elapsed", 0)
|
||||||
|
|
||||||
stop_furnace_sound(pos)
|
stop_furnace_sound(pos)
|
||||||
|
@ -338,7 +355,7 @@ local function apply_logger(def)
|
||||||
return def
|
return def
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_node("default:furnace", apply_logger({
|
core.register_node("default:furnace", apply_logger({
|
||||||
description = S("Furnace"),
|
description = S("Furnace"),
|
||||||
tiles = {
|
tiles = {
|
||||||
"default_furnace_top.png", "default_furnace_bottom.png",
|
"default_furnace_top.png", "default_furnace_bottom.png",
|
||||||
|
@ -356,7 +373,7 @@ minetest.register_node("default:furnace", apply_logger({
|
||||||
on_timer = furnace_node_timer,
|
on_timer = furnace_node_timer,
|
||||||
|
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = core.get_meta(pos)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
inv:set_size('src', 1)
|
inv:set_size('src', 1)
|
||||||
inv:set_size('fuel', 1)
|
inv:set_size('fuel', 1)
|
||||||
|
@ -365,15 +382,15 @@ minetest.register_node("default:furnace", apply_logger({
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_metadata_inventory_move = function(pos)
|
on_metadata_inventory_move = function(pos)
|
||||||
minetest.get_node_timer(pos):start(1.0)
|
core.get_node_timer(pos):start(1.0)
|
||||||
end,
|
end,
|
||||||
on_metadata_inventory_put = function(pos)
|
on_metadata_inventory_put = function(pos)
|
||||||
-- start timer function, it will sort out whether furnace can burn or not.
|
-- start timer function, it will sort out whether furnace can burn or not.
|
||||||
minetest.get_node_timer(pos):start(1.0)
|
core.get_node_timer(pos):start(1.0)
|
||||||
end,
|
end,
|
||||||
on_metadata_inventory_take = function(pos)
|
on_metadata_inventory_take = function(pos)
|
||||||
-- check whether the furnace is empty or not.
|
-- check whether the furnace is empty or not.
|
||||||
minetest.get_node_timer(pos):start(1.0)
|
core.get_node_timer(pos):start(1.0)
|
||||||
end,
|
end,
|
||||||
on_blast = function(pos)
|
on_blast = function(pos)
|
||||||
local drops = {}
|
local drops = {}
|
||||||
|
@ -381,7 +398,7 @@ minetest.register_node("default:furnace", apply_logger({
|
||||||
default.get_inventory_drops(pos, "fuel", drops)
|
default.get_inventory_drops(pos, "fuel", drops)
|
||||||
default.get_inventory_drops(pos, "dst", drops)
|
default.get_inventory_drops(pos, "dst", drops)
|
||||||
drops[#drops+1] = "default:furnace"
|
drops[#drops+1] = "default:furnace"
|
||||||
minetest.remove_node(pos)
|
core.remove_node(pos)
|
||||||
return drops
|
return drops
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
@ -390,7 +407,7 @@ minetest.register_node("default:furnace", apply_logger({
|
||||||
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
minetest.register_node("default:furnace_active", apply_logger({
|
core.register_node("default:furnace_active", apply_logger({
|
||||||
description = S("Furnace"),
|
description = S("Furnace"),
|
||||||
tiles = {
|
tiles = {
|
||||||
"default_furnace_top.png", "default_furnace_bottom.png",
|
"default_furnace_top.png", "default_furnace_bottom.png",
|
||||||
|
@ -426,7 +443,7 @@ minetest.register_node("default:furnace_active", apply_logger({
|
||||||
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
minetest.register_craft({
|
core.register_craft({
|
||||||
output = "default:furnace",
|
output = "default:furnace",
|
||||||
recipe = {
|
recipe = {
|
||||||
{"group:stone", "group:stone", "group:stone"},
|
{"group:stone", "group:stone", "group:stone"},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue