From 4e58413fcf66952054102473f03216070e3625e0 Mon Sep 17 00:00:00 2001 From: AntumDeluge Date: Sat, 6 Aug 2016 21:36:09 -0700 Subject: [PATCH] Add "campfire" mod. --- README.md | 2 + mods/campfire/depends.txt | 1 + mods/campfire/init.lua | 180 ++++++++++++++++++++++++ mods/campfire/textures/CampFire.png | Bin 0 -> 992 bytes mods/campfire/textures/CampFire_off.png | Bin 0 -> 253 bytes 5 files changed, 183 insertions(+) create mode 100644 mods/campfire/depends.txt create mode 100644 mods/campfire/init.lua create mode 100644 mods/campfire/textures/CampFire.png create mode 100644 mods/campfire/textures/CampFire_off.png diff --git a/README.md b/README.md index 6d32a881..aa642d7d 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ The following mods are also included: * [moreblocks][] ([zlib](mods/buildings/moreblocks/LICENSE.md)) * plasmascreen ([homedecor_modpack][homedecor]) * [stairsplus][] ([zlib](mods/buildings/stairsplus/LICENSE.txt)) +* [campfire][] (WTFPL) * chat/ * [away][] ([GPL](mods/chat/away/COPYING)) * [chatlog][] ([CC0](mods/chat/chatlog/Readme.txt)) @@ -120,6 +121,7 @@ The following mods are also included: [away]: https://forum.minetest.net/viewtopic.php?t=1211 [bags]: http://cornernote.github.io/minetest-bags/ [biome_lib]: https://forum.minetest.net/viewtopic.php?f=11&t=12999 +[campfire]: https://forum.minetest.net/viewtopic.php?t=3794 [carts]: https://forum.minetest.net/viewtopic.php?t=2451 [character_creator]: https://forum.minetest.net/viewtopic.php?f=9&t=13138 [chatlog]: https://forum.minetest.net/viewtopic.php?id=6220 diff --git a/mods/campfire/depends.txt b/mods/campfire/depends.txt new file mode 100644 index 00000000..331d858c --- /dev/null +++ b/mods/campfire/depends.txt @@ -0,0 +1 @@ +default \ No newline at end of file diff --git a/mods/campfire/init.lua b/mods/campfire/init.lua new file mode 100644 index 00000000..0f7487f5 --- /dev/null +++ b/mods/campfire/init.lua @@ -0,0 +1,180 @@ +minetest.register_craft({ + output = "campfire:campfire", + recipe = {{'', 'default:stick', ''}, {'default:stick', '', 'default:stick'}} +}) + + +minetest.register_node("campfire:campfire", { + description = "Camp Fire", + drawtype = "plantlike", + tiles = {"CampFire_off.png"}, + walkable=false, + sunlight_propogates=true, + paramtype="light", + paramtype2 = "facedir", + groups = {oddly_breakable_by_hand=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("infotext", "Campfire") + local inv = meta:get_inventory() + inv:set_size("fuel", 1) + inv:set_size("src", 1) + inv:set_size("dst", 4) + 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("campfire:campfire_active", { + description = "Campfire Active", + drawtype = "plantlike", + tiles = {{name="CampFire.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=3.0}}}, + light_source = 8, + paramtype="light", + walkable=false, + drop = "campfire:campfire", + 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.furnace_inactive_formspec) + meta:set_string("infotext", "Furnace"); + local inv = meta:get_inventory() + inv:set_size("fuel", 1) + inv:set_size("src", 1) + inv:set_size("dst", 4) + 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, +}) + +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 = {"campfire:campfire","campfire:campfire_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") + 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 + -- 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("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 + local percent = math.floor(meta:get_float("fuel_time") / + meta:get_float("fuel_totaltime") * 100) + meta:set_string("infotext","Furnace active: "..percent.."%") + hacky_swap_node(pos,"campfire:campfire_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","Put more wood on the fire!") + hacky_swap_node(pos,"campfire:campfire") + meta:set_string("formspec", default.furnace_inactive_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, +}) diff --git a/mods/campfire/textures/CampFire.png b/mods/campfire/textures/CampFire.png new file mode 100644 index 0000000000000000000000000000000000000000..85f84510fa1f7787224ae43e6dcaf9bdcb51f045 GIT binary patch literal 992 zcmV<610Vc}P)8?>3;Xkd2`oSyx3W@_U?i% zK{1DYBtX-CYjtb^W2~|$oMu|0Rup3Vwq2*WUW2lI2F<3Ea;_tR2>n#O1@x>xL31gC z<~wRA(_uxh(7B5i2jVm}oRo7kuLE;X(`dXqLGxD)$_W5=#uzJ~Ol;w-g1qn2>2<44 z+4dU37^?yd5g}~syCQt91QPS*PEsauQh>m+!V!B104JHvc7`LD5&K7&yd~5h<$Ib+ z$OLo3?JBS{Uf_5vS`Ke3B4I8k+fhbT!7n%JxyM}2hxW@4_87!}cLWY1`GxGDvzHzO z0A;GygOzk$5ylfj=>f>&)`JpAcs;-Yf>omjHV9r`Ubg`7`}ua#R}U};&iJj+0~}ef z&QA|kA2rH3jy#0b19PlF5{|2}Ej>_6`CkwIq#gt^Er`x;!l++yEvPGD0H&}9&HeR& znTQIwqeEq?5)=2R3IQ0|pgGYiTuI zE0qa)z`cQ^KLGD>Y;o>E-IdWgD&DWB!mT}&Z;jIOmDr|lfAIK3M3QHEBq>?9+!v#z z%Q~3?psM}=tH8YUV7Aw&><>6WtOt{Ay5zrG557HUpf~4q)`PO3s3pTTJ~c!%y|wVkSLE#q;Q@RATX?qy)UO?@_zsb)B}Xc2L^J!&>l6BlhArl z@m*Ai_4oUOP&EE6Pp&CqdNmO0yP6+QO1mexdV-Adxepc;77%t)^+8$L7YY*ZB$6b*0yzDkWAdpeIeVtlV;m2LQS8I2J6AYqY+1ckP{6C z^Z)=*rNH|FBs_gMQtl60qPBCW`vNkY7gWyo#47Y4bbkQOL;wDv{@^Dyg6gJLP`HBt O0000*da literal 0 HcmV?d00001 diff --git a/mods/campfire/textures/CampFire_off.png b/mods/campfire/textures/CampFire_off.png new file mode 100644 index 0000000000000000000000000000000000000000..cc3f98058a4321935e572b035c6a3b82b4e35824 GIT binary patch literal 253 zcmV=6e(-I%rUM2ONM3Sz>uY;$uao}gH|MfY zF}lRxw!;GA;kxRT^Gp?v6ID*$8bPU;3BvCL2)H5P&L9qdCilBe)4DqBeEW6+Hl(0+ zT%3ooViX7rDw)JFtpd%ZvKy#mT?|O}qc1`ew0w}PrKk#-M{_qXi5AA2*z{}IwkFTQ z#ujp`@7m0o