From b9dfbc00dc0dbf02cbc502bd82d58b5f4d937672 Mon Sep 17 00:00:00 2001 From: cheapie Date: Wed, 12 Apr 2017 02:33:09 -0500 Subject: Require a water supply if pipeworks is installed --- init.lua | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index 43d0c35..449b91f 100644 --- a/init.lua +++ b/init.lua @@ -1,10 +1,30 @@ -local function set_formspec(meta,enabled,full) +local pipeworks_installed = minetest.get_modpath("pipeworks") + +local function find_water_supply(pos) + if not pipeworks_installed then return true end + local minp = vector.add(pos,vector.new(-1,-1,-1)) + local maxp = vector.add(pos,vector.new(1,1,1)) + local nodes = minetest.find_nodes_in_area(minp,maxp,"group:pipe") + for _,pos in pairs(nodes) do + local node = minetest.get_node(pos) + if string.match(node.name,"^pipeworks:.*_loaded$") then + return true + end + end + return false +end + +local function set_formspec(meta,enabled,full,water) local status if enabled then - if full then - status = "Full Bin" + if water then + if full then + status = "Full Bin" + else + status = "Making Ice" + end else - status = "Making Ice" + status = "Water Error" end else status = "Off" @@ -23,17 +43,23 @@ local function update_status(pos,meta,ice) timer:stop() set_formspec(meta,false) else + local water = find_water_supply(pos) local binpos = vector.add(pos,vector.new(0,-1,0)) local binnode = minetest.get_node(binpos) local binmeta = minetest.get_meta(binpos) local bininv = binmeta:get_inventory() if binnode.name ~= "icemachine:bin" or not bininv:room_for_item("ice","icemachine:cube") then timer:stop() - set_formspec(meta,true,true) + set_formspec(meta,true,true,true) else - if not timer:is_started() then timer:start(30) end - if ice then bininv:add_item("ice","icemachine:cube 9") end - set_formspec(meta,true,false) + if water then + if not timer:is_started() then timer:start(30) end + if ice then bininv:add_item("ice","icemachine:cube 9") end + set_formspec(meta,true,false,true) + else + timer:stop() + set_formspec(meta,true,false,false) + end end end end -- cgit v1.2.3