From 38f3ee8ac740ac876318762aff900fdb8ccec62a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Mart=C3=ADnez?= Date: Fri, 5 Apr 2013 07:00:34 -0300 Subject: [PATCH] Added Microwave Oven --- init.lua | 1 + microwave_oven.lua | 221 ++++++++++++++++++ textures/homedecor_microwave_back.png | Bin 0 -> 113 bytes textures/homedecor_microwave_bottom.png | Bin 0 -> 112 bytes textures/homedecor_microwave_front.png | Bin 0 -> 224 bytes textures/homedecor_microwave_front_active.png | Bin 0 -> 250 bytes textures/homedecor_microwave_left.png | Bin 0 -> 118 bytes textures/homedecor_microwave_right.png | Bin 0 -> 114 bytes textures/homedecor_microwave_top.png | Bin 0 -> 110 bytes 9 files changed, 222 insertions(+) create mode 100644 microwave_oven.lua create mode 100644 textures/homedecor_microwave_back.png create mode 100644 textures/homedecor_microwave_bottom.png create mode 100644 textures/homedecor_microwave_front.png create mode 100644 textures/homedecor_microwave_front_active.png create mode 100644 textures/homedecor_microwave_left.png create mode 100644 textures/homedecor_microwave_right.png create mode 100644 textures/homedecor_microwave_top.png diff --git a/init.lua b/init.lua index 47d12ef..12d8893 100644 --- a/init.lua +++ b/init.lua @@ -75,6 +75,7 @@ dofile(minetest.get_modpath("homedecor").."/lighting.lua") dofile(minetest.get_modpath("homedecor").."/kitchen_cabinet.lua") dofile(minetest.get_modpath("homedecor").."/refrigerator.lua") dofile(minetest.get_modpath("homedecor").."/oven.lua") +dofile(minetest.get_modpath("homedecor").."/microwave_oven.lua") dofile(minetest.get_modpath("homedecor").."/nightstands.lua") dofile(minetest.get_modpath("homedecor").."/crafts.lua") diff --git a/microwave_oven.lua b/microwave_oven.lua new file mode 100644 index 0000000..8cfdefe --- /dev/null +++ b/microwave_oven.lua @@ -0,0 +1,221 @@ +-- This code supplies an oven/stove. Basically it's just a copy of the default furnace with different textures. + +-- Boilerplate to support localized strings if intllib mod is installed. +local S +if (minetest.get_modpath("intllib")) then + dofile(minetest.get_modpath("intllib").."/intllib.lua") + S = intllib.Getter(minetest.get_current_modname()) +else + S = function ( s ) return s end +end + +local mw_oven_inactive_formspec = + "size[8,9]".. + "image[2,2;1,1;default_furnace_fire_bg.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;]" + +minetest.register_node("homedecor:microwave_oven", { + description = S("Microwave Oven"), + tiles = { + "homedecor_microwave_top.png", + "homedecor_microwave_bottom.png", + "homedecor_microwave_right.png", + "homedecor_microwave_left.png", + "homedecor_microwave_back.png", + "homedecor_microwave_front.png" + }, + drawtype = "nodebox", + paramtype = "light", + paramtype2 = "facedir", + node_box = { + type = "fixed", + fixed = { { -0.5, -0.5, -0.125, 0.5, 0.125, 0.5 } }, + }, + groups = {cracky=2}, + legacy_facedir_simple = true, + sounds = default.node_sound_wood_defaults(), + on_construct = function(pos) + local meta = minetest.env:get_meta(pos) + 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) + inv:set_size("dst", 1) + end, + can_dig = function(pos,player) + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + 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 + end, +}) + +minetest.register_node("homedecor:microwave_oven_active", { + description = S("Microwave Oven"), + tiles = { + "homedecor_microwave_top.png", + "homedecor_microwave_bottom.png", + "homedecor_microwave_right.png", + "homedecor_microwave_left.png", + "homedecor_microwave_back.png", + "homedecor_microwave_front_active.png" + }, + drawtype = "nodebox", + paramtype = "light", + paramtype2 = "facedir", + node_box = { + type = "fixed", + fixed = { { -0.5, -0.5, -0.125, 0.5, 0.125, 0.5 } }, + }, + light_source = 8, + drop = "homedecor:microwave_oven", + groups = {cracky=2, not_in_creative_inventory=1}, + legacy_facedir_simple = true, + 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")) + local inv = meta:get_inventory() + inv:set_size("fuel", 1) + inv:set_size("src", 1) + inv:set_size("dst", 2) + end, + can_dig = function(pos,player) + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + 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 + end, +}) + +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() + if node.name == name then + return + end + node.name = name + local meta0 = meta:to_table() + minetest.env:set_node(pos,node) + meta = minetest.env:get_meta(pos) + meta:from_table(meta0) +end + +minetest.register_abm({ + nodenames = {"homedecor:microwave_oven","homedecor:microwave_oven_active"}, + 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.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) + 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("Oven active: %d%%"):format(percent)) + hacky_swap_node(pos,"homedecor:microwave_oven_active") + 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("Oven out of fuel")) + hacky_swap_node(pos,"homedecor:microwave_oven") + meta:set_string("formspec", mw_oven_inactive_formspec) + return + end + + if cooked.item:is_empty() then + if was_active then + meta:set_string("infotext",S("Oven is empty")) + hacky_swap_node(pos,"homedecor:microwave_oven") + meta:set_string("formspec", mw_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) + end, +}) diff --git a/textures/homedecor_microwave_back.png b/textures/homedecor_microwave_back.png new file mode 100644 index 0000000000000000000000000000000000000000..9a77dce28fd2849b9f97e3d14b18fe74a4a54e35 GIT binary patch literal 113 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`7M?DSAr`&K2@G3UEz3U%l$eO{6zU3j@H`Uf?2NtPl6mQgY5aoS_49>4Jpb;qcI(&MX@U>=9_*DD zlTPk1lzX@3nm=>HluJt+i~A&$w}vrH31Y}^HhxxlEb6v;UX&N(12dxy*S@Jw3tF+Y z?61bbd9_WwiA?WpkIlHu;@mt%==7#9C%sm#`|yih>5_P9YlqA^%k*Uehh`Pana%&m Y5U|dxU9P2WG0@2jp00i_>zopr0F*Xb2LJ#7 literal 0 HcmV?d00001 diff --git a/textures/homedecor_microwave_front_active.png b/textures/homedecor_microwave_front_active.png new file mode 100644 index 0000000000000000000000000000000000000000..553da110d6f6ada56dbdf1654bfce9029929a6d3 GIT binary patch literal 250 zcmV{V2gb_X)0K!QpUv+SKGg!1vTDl|dbN~PV07*qoM6N<$f}fpc AD*ylh literal 0 HcmV?d00001 diff --git a/textures/homedecor_microwave_left.png b/textures/homedecor_microwave_left.png new file mode 100644 index 0000000000000000000000000000000000000000..69d77866145d87972a0aa4a4ad4467c7bb6b598a GIT binary patch literal 118 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`ww^AIAr`&K2@2zHvomrD4+KE~|)z4*}Q$iB}aR(+1 literal 0 HcmV?d00001 diff --git a/textures/homedecor_microwave_right.png b/textures/homedecor_microwave_right.png new file mode 100644 index 0000000000000000000000000000000000000000..d4ed854b5610ceb336c6dba7bacc97a6aa9369f3 GIT binary patch literal 114 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`mYyz-Ar`&K2@gTe~DWM4fGeRC~ literal 0 HcmV?d00001 diff --git a/textures/homedecor_microwave_top.png b/textures/homedecor_microwave_top.png new file mode 100644 index 0000000000000000000000000000000000000000..22d3c0af2b69110467c367c94eb93145cdae22a2 GIT binary patch literal 110 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`rk*a2Ar`%F&n^^XFyL_tymk8D z>BK@w716yq4bL>MJTLivz(r{5VMWgCweg%P6Apx{D4yiA3HcxpFCJEV0B8V%r>mdK II;Vst0Ep=#>i_@% literal 0 HcmV?d00001