Require a water supply if pipeworks is installed

This commit is contained in:
cheapie 2017-04-12 02:33:09 -05:00
parent 24cbcff820
commit b9dfbc00dc
2 changed files with 35 additions and 9 deletions

2
README

@ -1,3 +1,3 @@
This mod adds an ice machine, ice bin, and ice cubes. 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.

@ -1,11 +1,31 @@
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 local status
if enabled then if enabled then
if water then
if full then if full then
status = "Full Bin" status = "Full Bin"
else else
status = "Making Ice" status = "Making Ice"
end end
else
status = "Water Error"
end
else else
status = "Off" status = "Off"
end end
@ -23,17 +43,23 @@ local function update_status(pos,meta,ice)
timer:stop() timer:stop()
set_formspec(meta,false) set_formspec(meta,false)
else else
local water = find_water_supply(pos)
local binpos = vector.add(pos,vector.new(0,-1,0)) local binpos = vector.add(pos,vector.new(0,-1,0))
local binnode = minetest.get_node(binpos) local binnode = minetest.get_node(binpos)
local binmeta = minetest.get_meta(binpos) local binmeta = minetest.get_meta(binpos)
local bininv = binmeta:get_inventory() local bininv = binmeta:get_inventory()
if binnode.name ~= "icemachine:bin" or not bininv:room_for_item("ice","icemachine:cube") then if binnode.name ~= "icemachine:bin" or not bininv:room_for_item("ice","icemachine:cube") then
timer:stop() timer:stop()
set_formspec(meta,true,true) set_formspec(meta,true,true,true)
else else
if water then
if not timer:is_started() then timer:start(30) end if not timer:is_started() then timer:start(30) end
if ice then bininv:add_item("ice","icemachine:cube 9") end if ice then bininv:add_item("ice","icemachine:cube 9") end
set_formspec(meta,true,false) set_formspec(meta,true,false,true)
else
timer:stop()
set_formspec(meta,true,false,false)
end
end end
end end
end end