From dd180e1bfbb3bb02a643cbeb00499b8982f58cd6 Mon Sep 17 00:00:00 2001 From: FaceDeer Date: Sun, 30 Jun 2019 10:15:53 -0600 Subject: [PATCH] adding crafting recipes --- crafting.lua | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++ execute.lua | 11 +++++-- init.lua | 5 +-- nodes.lua | 3 +- 4 files changed, 106 insertions(+), 5 deletions(-) create mode 100644 crafting.lua diff --git a/crafting.lua b/crafting.lua new file mode 100644 index 0000000..2271c94 --- /dev/null +++ b/crafting.lua @@ -0,0 +1,92 @@ +--"waterworks:pipe" +if minetest.get_modpath("pipeworks") then +minetest.register_craft( { + output = "waterworks:pipe 12", + recipe = { + { "default:steel_ingot", "", "default:steel_ingot" }, + { "default:steel_ingot", "", "default:steel_ingot" }, + { "default:steel_ingot", "", "default:steel_ingot" } + }, +}) +else +minetest.register_craft( { + output = "waterworks:pipe 12", + recipe = { + { "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" }, + { "", "", "" }, + { "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" } + }, +}) +end + +--"waterworks:valve_on" +minetest.register_craft( { + output = "waterworks:valve_on", + recipe = { + { "default:steel_ingot", "", "default:steel_ingot" }, + { "", "waterworks:pipe", "" }, + { "default:steel_ingot", "", "default:steel_ingot" } + }, +}) + +--"waterworks:inlet" +minetest.register_craft( { + output = "waterworks:inlet", + recipe = { + { "default:steel_ingot", "", "" }, + { "", "waterworks:pipe", "" }, + { "default:steel_ingot", "", "" } + }, +}) +--"waterworks:pumped_inlet" +minetest.register_craft( { + output = "waterworks:pumped_inlet", + recipe = { + { "default:steel_ingot", "", "" }, + { "default:mese_crystal_fragment", "waterworks:pipe", "" }, + { "default:steel_ingot", "", "" } + }, +}) +minetest.register_craft( { + output = "waterworks:pumped_inlet", + recipe = { + { "default:mese_crystal_fragment", "waterworks:inlet"}, + }, +}) + +--"waterworks:outlet" +minetest.register_craft( { + output = "waterworks:outlet", + recipe = { + { "", "", "default:steel_ingot" }, + { "", "waterworks:pipe", "" }, + { "", "", "default:steel_ingot" } + }, +}) + +--"waterworks:grate" +minetest.register_craft( { + output = "waterworks:grate", + recipe = { + { "", "default:steel_ingot", "" }, + { "", "waterworks:pipe", "" }, + { "", "default:steel_ingot", "" } + }, +}) + +-- Allow the basic connectors to be cycled through +minetest.register_craft( { + output = "waterworks:inlet", + type = "shapeless", + recipe = { "waterworks:outlet"}, +}) +minetest.register_craft( { + output = "waterworks:outlet", + type = "shapeless", + recipe = {"waterworks:grate"}, +}) +minetest.register_craft( { + output = "waterworks:grate", + type = "shapeless", + recipe = {"waterworks:inlet"}, +}) \ No newline at end of file diff --git a/execute.lua b/execute.lua index 76b6c6f..72d7835 100644 --- a/execute.lua +++ b/execute.lua @@ -1,3 +1,5 @@ +local pressure_margin = 20 + local pipe_cache = {} local cardinal_dirs = { @@ -124,10 +126,12 @@ waterworks.execute_pipes = function(net_index, net_capacity) local inlets local outlets - if net.cache_valid then + if net.cache_valid then + -- We don't need to recalculate, nothing about the pipe network has changed since last time inlets = pipe_cache[net_index].inlets outlets = pipe_cache[net_index].outlets else + -- Find all the inlets and outlets and sort them by pressure inlets = {} if net.connected.inlet ~= nil then for _, inlet_set in pairs(net.connected.inlet) do @@ -148,6 +152,7 @@ waterworks.execute_pipes = function(net_index, net_capacity) end table.sort(outlets, sort_by_pressure) + -- Cache the results pipe_cache[net_index] = {} pipe_cache[net_index].inlets = inlets pipe_cache[net_index].outlets = outlets @@ -171,7 +176,9 @@ waterworks.execute_pipes = function(net_index, net_capacity) --minetest.debug("source: " .. dump(source)) --minetest.debug("sink: " .. dump(sink)) - if source.pressure >= sink.pressure then + -- pressure_margin allows us to check sources that are a little bit below sinks, + -- in case the extra pressure from their water depth is sufficient to force water through + if source.pressure + pressure_margin >= sink.pressure then local source_pos = find_source(source.target) local sink_pos if source_pos ~= nil then diff --git a/init.lua b/init.lua index 034bd68..ab2b149 100644 --- a/init.lua +++ b/init.lua @@ -6,6 +6,7 @@ dofile(modpath .. "/globalstep.lua") dofile(modpath .. "/network.lua") dofile(modpath .. "/execute.lua") dofile(modpath .. "/nodes.lua") +dofile(modpath .. "/crafting.lua") if minetest.settings:get_bool("waterworks_make_default_water_non_renewable") then local override_def = {liquid_renewable = false} @@ -14,8 +15,8 @@ if minetest.settings:get_bool("waterworks_make_default_water_non_renewable") the end --- For test purposes, this rebuilds pipe networks without needing to persist them. --- May be useful later for fixing broken stuff. +-- This rebuilds pipe networks whenever the map block is loaded. +-- May be useful for fixing broken stuff. -- Note that this doesn't *remove* pipes that are inappropriately listed in the network, -- that may be tricky. --minetest.register_lbm({ diff --git a/nodes.lua b/nodes.lua index 47f5e1b..15a9a16 100644 --- a/nodes.lua +++ b/nodes.lua @@ -88,9 +88,10 @@ minetest.register_node("waterworks:valve_off", { connect_left = {-0.5, -0.375, -0.375, -0.4375, 0.375, 0.375}, }, paramtype = "light", + drops = "waterworks:valve_on", is_ground_content = false, - groups = {oddly_breakable_by_hand = 1, waterworks_inert = 1}, + groups = {oddly_breakable_by_hand = 1, waterworks_inert = 1, not_in_creative_inventory = 1}, sounds = default.node_sound_metal_defaults(), on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) node.name = "waterworks:valve_on"