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 --- README | 2 +- init.lua | 42 ++++++++++++++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/README b/README index c3814a4..0acf6bf 100644 --- a/README +++ b/README @@ -1,3 +1,3 @@ This mod adds an ice machine, ice bin, and ice cubes. -To make the machine work, place it on top of an ice bin and turn it on. It will slowly produce ice cubes and eject them into the bin. The cubes can then be crafted (9 at a time) into ice blocks. If technic is installed, these ice blocks can then be ground into snow if desired. +To make the machine work, place it on top of an ice bin and turn it on. If pipeworks is installed, a pipe carrying water must be within 1m of the machine. After right-clicking and turning the machine on, it will slowly produce ice cubes and eject them into the bin. The cubes can then be crafted (9 at a time) into ice blocks. If technic is installed, these ice blocks can then be ground into snow if desired. 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