diff options
author | cheapie <no-email-for-you@example.com> | 2017-04-12 02:33:09 -0500 |
---|---|---|
committer | cheapie <no-email-for-you@example.com> | 2017-04-12 02:33:09 -0500 |
commit | b9dfbc00dc0dbf02cbc502bd82d58b5f4d937672 (patch) | |
tree | 0c0c3f585d7d6a685dec2cb73ce491be6ba1f9bf /init.lua | |
parent | 24cbcff820b7b78297bcae8812821a1d523194d4 (diff) | |
download | icemachine-b9dfbc00dc0dbf02cbc502bd82d58b5f4d937672.tar icemachine-b9dfbc00dc0dbf02cbc502bd82d58b5f4d937672.tar.gz icemachine-b9dfbc00dc0dbf02cbc502bd82d58b5f4d937672.tar.bz2 icemachine-b9dfbc00dc0dbf02cbc502bd82d58b5f4d937672.tar.xz icemachine-b9dfbc00dc0dbf02cbc502bd82d58b5f4d937672.zip |
Require a water supply if pipeworks is installed
Diffstat (limited to 'init.lua')
-rw-r--r-- | init.lua | 42 |
1 files changed, 34 insertions, 8 deletions
@@ -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 |