forked from nalc/homedecor_modpack
commit
e6757700dc
|
@ -1117,6 +1117,15 @@ minetest.register_craft({
|
|||
}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "homedecor:microwave_oven 2",
|
||||
recipe = {
|
||||
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot", },
|
||||
{"default:steel_ingot", "moreblocks:ironglass", "mesecons_materials:silicon", },
|
||||
{"default:steel_ingot", "moreores:copper_ingot", "default:mese_crystal", },
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "homedecor:refrigerator",
|
||||
recipe = {
|
||||
|
|
|
@ -44,7 +44,7 @@ minetest.register_node("homedecor:microwave_oven", {
|
|||
local inv = meta:get_inventory()
|
||||
inv:set_size("fuel", 1)
|
||||
inv:set_size("src", 1)
|
||||
inv:set_size("dst", 1)
|
||||
inv:set_size("dst", 2)
|
||||
end,
|
||||
can_dig = function(pos,player)
|
||||
local meta = minetest.env:get_meta(pos);
|
||||
|
@ -58,6 +58,43 @@ minetest.register_node("homedecor:microwave_oven", {
|
|||
end
|
||||
return true
|
||||
end,
|
||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
if listname == "fuel" then
|
||||
if minetest.get_craft_result({method="fuel",width=1,items={stack}}).time ~= 0 then
|
||||
if inv:is_empty("src") then
|
||||
meta:set_string("infotext",S("Furnace is empty"))
|
||||
end
|
||||
return stack:get_count()
|
||||
else
|
||||
return 0
|
||||
end
|
||||
elseif listname == "src" then
|
||||
return stack:get_count()
|
||||
elseif listname == "dst" then
|
||||
return 0
|
||||
end
|
||||
end,
|
||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local stack = inv:get_stack(from_list, from_index)
|
||||
if to_list == "fuel" then
|
||||
if minetest.get_craft_result({method="fuel",width=1,items={stack}}).time ~= 0 then
|
||||
if inv:is_empty("src") then
|
||||
meta:set_string("infotext",S("Furnace is empty"))
|
||||
end
|
||||
return count
|
||||
else
|
||||
return 0
|
||||
end
|
||||
elseif to_list == "src" then
|
||||
return count
|
||||
elseif to_list == "dst" then
|
||||
return 0
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_node("homedecor:microwave_oven_active", {
|
||||
|
@ -84,8 +121,8 @@ minetest.register_node("homedecor:microwave_oven_active", {
|
|||
sounds = default.node_sound_stone_defaults(),
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_string("formspec", default.oven_inactive_formspec)
|
||||
meta:set_string("infotext", S("Oven"))
|
||||
meta:set_string("formspec", mw_oven_inactive_formspec)
|
||||
meta:set_string("infotext", S("Microwave Oven"))
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("fuel", 1)
|
||||
inv:set_size("src", 1)
|
||||
|
@ -103,6 +140,43 @@ minetest.register_node("homedecor:microwave_oven_active", {
|
|||
end
|
||||
return true
|
||||
end,
|
||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
if listname == "fuel" then
|
||||
if minetest.get_craft_result({method="fuel",width=1,items={stack}}).time ~= 0 then
|
||||
if inv:is_empty("src") then
|
||||
meta:set_string("infotext",S("Oven is empty"))
|
||||
end
|
||||
return stack:get_count()
|
||||
else
|
||||
return 0
|
||||
end
|
||||
elseif listname == "src" then
|
||||
return stack:get_count()
|
||||
elseif listname == "dst" then
|
||||
return 0
|
||||
end
|
||||
end,
|
||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local stack = inv:get_stack(from_list, from_index)
|
||||
if to_list == "fuel" then
|
||||
if minetest.get_craft_result({method="fuel",width=1,items={stack}}).time ~= 0 then
|
||||
if inv:is_empty("src") then
|
||||
meta:set_string("infotext",S("Oven is empty"))
|
||||
end
|
||||
return count
|
||||
else
|
||||
return 0
|
||||
end
|
||||
elseif to_list == "src" then
|
||||
return count
|
||||
elseif to_list == "dst" then
|
||||
return 0
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
local function hacky_swap_node(pos,name)
|
||||
|
@ -140,9 +214,10 @@ minetest.register_abm({
|
|||
|
||||
local srclist = inv:get_list("src")
|
||||
local cooked = nil
|
||||
local aftercooked
|
||||
|
||||
if srclist then
|
||||
cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
|
||||
cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
|
||||
end
|
||||
|
||||
local was_active = false
|
||||
|
@ -157,9 +232,7 @@ minetest.register_abm({
|
|||
-- Put result in "dst" list
|
||||
inv:add_item("dst", cooked.item)
|
||||
-- take stuff from "src" list
|
||||
srcstack = inv:get_stack("src", 1)
|
||||
srcstack:take_item()
|
||||
inv:set_stack("src", 1, srcstack)
|
||||
inv:set_stack("src", 1, aftercooked.items[1])
|
||||
else
|
||||
print(S("Could not insert '%s'"):format(cooked.item:to_string()))
|
||||
end
|
||||
|
@ -184,6 +257,7 @@ minetest.register_abm({
|
|||
end
|
||||
|
||||
local fuel = nil
|
||||
local afterfuel
|
||||
local cooked = nil
|
||||
local fuellist = inv:get_list("fuel")
|
||||
local srclist = inv:get_list("src")
|
||||
|
@ -192,7 +266,7 @@ minetest.register_abm({
|
|||
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})
|
||||
fuel, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
|
||||
end
|
||||
|
||||
if fuel.time <= 0 then
|
||||
|
@ -214,8 +288,6 @@ minetest.register_abm({
|
|||
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)
|
||||
inv:set_stack("fuel", 1, afterfuel.items[1])
|
||||
end,
|
||||
})
|
||||
|
|
209
oven.lua
209
oven.lua
|
@ -9,7 +9,7 @@ else
|
|||
S = function ( s ) return s end
|
||||
end
|
||||
|
||||
default.oven_inactive_formspec =
|
||||
local oven_inactive_formspec =
|
||||
"size[8,9]"..
|
||||
"image[2,2;1,1;default_furnace_fire_bg.png]"..
|
||||
"list[current_name;fuel;2,3;1,1;]"..
|
||||
|
@ -27,12 +27,12 @@ minetest.register_node("homedecor:oven", {
|
|||
sounds = default.node_sound_wood_defaults(),
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_string("formspec", default.oven_inactive_formspec)
|
||||
meta:set_string("infotext", "Oven")
|
||||
meta:set_string("formspec", oven_inactive_formspec)
|
||||
meta:set_string("infotext", S("Oven"))
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("fuel", 1)
|
||||
inv:set_size("src", 1)
|
||||
inv:set_size("dst", 4)
|
||||
inv:set_size("dst", 2)
|
||||
end,
|
||||
can_dig = function(pos,player)
|
||||
local meta = minetest.env:get_meta(pos);
|
||||
|
@ -46,6 +46,43 @@ minetest.register_node("homedecor:oven", {
|
|||
end
|
||||
return true
|
||||
end,
|
||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
if listname == "fuel" then
|
||||
if minetest.get_craft_result({method="fuel",width=1,items={stack}}).time ~= 0 then
|
||||
if inv:is_empty("src") then
|
||||
meta:set_string("infotext",S("Oven is empty"))
|
||||
end
|
||||
return stack:get_count()
|
||||
else
|
||||
return 0
|
||||
end
|
||||
elseif listname == "src" then
|
||||
return stack:get_count()
|
||||
elseif listname == "dst" then
|
||||
return 0
|
||||
end
|
||||
end,
|
||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local stack = inv:get_stack(from_list, from_index)
|
||||
if to_list == "fuel" then
|
||||
if minetest.get_craft_result({method="fuel",width=1,items={stack}}).time ~= 0 then
|
||||
if inv:is_empty("src") then
|
||||
meta:set_string("infotext",S("Oven is empty"))
|
||||
end
|
||||
return count
|
||||
else
|
||||
return 0
|
||||
end
|
||||
elseif to_list == "src" then
|
||||
return count
|
||||
elseif to_list == "dst" then
|
||||
return 0
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_node("homedecor:oven_active", {
|
||||
|
@ -60,12 +97,12 @@ minetest.register_node("homedecor:oven_active", {
|
|||
sounds = default.node_sound_stone_defaults(),
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_string("formspec", default.oven_inactive_formspec)
|
||||
meta:set_string("formspec", mw_oven_inactive_formspec)
|
||||
meta:set_string("infotext", S("Oven"))
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("fuel", 1)
|
||||
inv:set_size("src", 1)
|
||||
inv:set_size("dst", 4)
|
||||
inv:set_size("dst", 2)
|
||||
end,
|
||||
can_dig = function(pos,player)
|
||||
local meta = minetest.env:get_meta(pos);
|
||||
|
@ -79,9 +116,46 @@ minetest.register_node("homedecor:oven_active", {
|
|||
end
|
||||
return true
|
||||
end,
|
||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
if listname == "fuel" then
|
||||
if minetest.get_craft_result({method="fuel",width=1,items={stack}}).time ~= 0 then
|
||||
if inv:is_empty("src") then
|
||||
meta:set_string("infotext",S("Oven is empty"))
|
||||
end
|
||||
return stack:get_count()
|
||||
else
|
||||
return 0
|
||||
end
|
||||
elseif listname == "src" then
|
||||
return stack:get_count()
|
||||
elseif listname == "dst" then
|
||||
return 0
|
||||
end
|
||||
end,
|
||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local stack = inv:get_stack(from_list, from_index)
|
||||
if to_list == "fuel" then
|
||||
if minetest.get_craft_result({method="fuel",width=1,items={stack}}).time ~= 0 then
|
||||
if inv:is_empty("src") then
|
||||
meta:set_string("infotext",S("Oven is empty"))
|
||||
end
|
||||
return count
|
||||
else
|
||||
return 0
|
||||
end
|
||||
elseif to_list == "src" then
|
||||
return count
|
||||
elseif to_list == "dst" then
|
||||
return 0
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
function hacky_swap_node(pos,name)
|
||||
local function hacky_swap_node(pos,name)
|
||||
local node = minetest.env:get_node(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local meta0 = meta:to_table()
|
||||
|
@ -116,9 +190,10 @@ minetest.register_abm({
|
|||
|
||||
local srclist = inv:get_list("src")
|
||||
local cooked = nil
|
||||
local aftercooked
|
||||
|
||||
if srclist then
|
||||
cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
|
||||
cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
|
||||
end
|
||||
|
||||
local was_active = false
|
||||
|
@ -126,16 +201,14 @@ minetest.register_abm({
|
|||
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") + 1)
|
||||
meta:set_float("src_time", meta:get_float("src_time") + 1)
|
||||
meta:set_float("src_time", meta:get_float("src_time") + 1.25)
|
||||
if cooked and cooked.item and meta:get_float("src_time") >= cooked.time then
|
||||
-- check if there's room for output in "dst" list
|
||||
if inv:room_for_item("dst",cooked.item) then
|
||||
-- Put result in "dst" list
|
||||
inv:add_item("dst", cooked.item)
|
||||
-- take stuff from "src" list
|
||||
srcstack = inv:get_stack("src", 1)
|
||||
srcstack:take_item()
|
||||
inv:set_stack("src", 1, srcstack)
|
||||
inv:set_stack("src", 1, aftercooked.items[1])
|
||||
else
|
||||
print(S("Could not insert '%s'"):format(cooked.item:to_string()))
|
||||
end
|
||||
|
@ -160,6 +233,7 @@ minetest.register_abm({
|
|||
end
|
||||
|
||||
local fuel = nil
|
||||
local afterfuel
|
||||
local cooked = nil
|
||||
local fuellist = inv:get_list("fuel")
|
||||
local srclist = inv:get_list("src")
|
||||
|
@ -168,13 +242,13 @@ minetest.register_abm({
|
|||
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})
|
||||
fuel, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
|
||||
end
|
||||
|
||||
if fuel.time <= 0 then
|
||||
meta:set_string("infotext",S("Oven out of fuel"))
|
||||
hacky_swap_node(pos,"homedecor:oven")
|
||||
meta:set_string("formspec", default.oven_inactive_formspec)
|
||||
meta:set_string("formspec", oven_inactive_formspec)
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -182,7 +256,7 @@ minetest.register_abm({
|
|||
if was_active then
|
||||
meta:set_string("infotext",S("Oven is empty"))
|
||||
hacky_swap_node(pos,"homedecor:oven")
|
||||
meta:set_string("formspec", default.oven_inactive_formspec)
|
||||
meta:set_string("formspec", oven_inactive_formspec)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
@ -190,109 +264,6 @@ minetest.register_abm({
|
|||
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,
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"homedecor:oven_locked","homedecor:oven_active_locked"},
|
||||
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",
|
||||
"src_totaltime",
|
||||
"src_time"
|
||||
}) do
|
||||
if meta:get_string(name) == "" then
|
||||
meta:set_float(name, 0.0)
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
was_active = true
|
||||
meta:set_float("fuel_time", meta:get_float("fuel_time") + 1)
|
||||
meta:set_float("src_time", meta:get_float("src_time") + 1)
|
||||
if cooked and cooked.item and meta:get_float("src_time") >= cooked.time then
|
||||
-- check if there's room for output in "dst" list
|
||||
if inv:room_for_item("dst",cooked.item) then
|
||||
-- Put result in "dst" list
|
||||
inv:add_item("dst", cooked.item)
|
||||
-- take stuff from "src" list
|
||||
srcstack = inv:get_stack("src", 1)
|
||||
srcstack:take_item()
|
||||
inv:set_stack("src", 1, srcstack)
|
||||
else
|
||||
print(S("Could not insert '%s'"):format(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
|
||||
local percent = math.floor(meta:get_float("fuel_time") /
|
||||
meta:get_float("fuel_totaltime") * 100)
|
||||
meta:set_string("infotext",S("Locked oven active: %d%%"):format(percent))
|
||||
hacky_swap_node(pos,"homedecor:oven_active_locked")
|
||||
meta:set_string("formspec",
|
||||
"size[8,9]"..
|
||||
"image[2,2;1,1;default_furnace_fire_bg.png^[lowpart:"..
|
||||
(100-percent)..":default_furnace_fire_fg.png]"..
|
||||
"list[current_name;fuel;2,3;1,1;]"..
|
||||
"list[current_name;src;2,1;1,1;]"..
|
||||
"list[current_name;dst;5,1;2,2;]"..
|
||||
"list[current_player;main;0,5;8,4;]")
|
||||
return
|
||||
end
|
||||
|
||||
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",S("Locked oven out of fuel"))
|
||||
hacky_swap_node(pos,"homedecor:oven_locked")
|
||||
meta:set_string("formspec", default.oven_inactive_formspec)
|
||||
return
|
||||
end
|
||||
|
||||
if cooked.item:is_empty() then
|
||||
if was_active then
|
||||
meta:set_string("infotext",S("Locked oven is empty"))
|
||||
hacky_swap_node(pos,"homedecor:oven_locked")
|
||||
meta:set_string("formspec", default.oven_inactive_formspec)
|
||||
end
|
||||
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)
|
||||
inv:set_stack("fuel", 1, afterfuel.items[1])
|
||||
end,
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue
Block a user