biogasmachines: get rid of public is_member_of() function.
biogasmachines.is_member_of() function replaced with sparse arrays. Signed-off-by: Michal Cieslakiewicz <michal.cieslakiewicz@wp.pl>
This commit is contained in:
parent
1c89cb59f0
commit
300ef43afa
@ -69,7 +69,8 @@ local SOURCE_EMPTY = 0
|
||||
local SOURCE_BUCKET = 1
|
||||
local SOURCE_PIPE = 2
|
||||
-- water sources
|
||||
local water_buckets = { "bucket:bucket_water", "bucket:bucket_river_water" }
|
||||
local water_bucket = { ["bucket:bucket_water"] = true,
|
||||
["bucket:bucket_river_water"] = true }
|
||||
|
||||
--[[
|
||||
--------
|
||||
@ -148,16 +149,10 @@ end
|
||||
-------
|
||||
]]--
|
||||
|
||||
-- check if item is bucket with water (bool)
|
||||
local function is_water_bucket(stack)
|
||||
local stackname = stack:get_name()
|
||||
return biogasmachines.is_member_of(stackname, water_buckets)
|
||||
end
|
||||
|
||||
-- get bucket with water (itemstack)
|
||||
local function get_water_bucket(inv, listname)
|
||||
local stack = ItemStack({})
|
||||
for _, i in ipairs(water_buckets) do
|
||||
for i, _ in pairs(water_bucket) do
|
||||
stack = inv:remove_item(listname, ItemStack(i .. " 1"))
|
||||
if not stack:is_empty() then break end
|
||||
end
|
||||
@ -263,7 +258,7 @@ local function allow_metadata_inventory_put(pos, listname, index, stack, player)
|
||||
return 0
|
||||
end
|
||||
if listname == "src" then
|
||||
if is_water_bucket(stack) then
|
||||
if water_bucket[stack:get_name()] then
|
||||
return stack:get_count()
|
||||
else
|
||||
return 0
|
||||
@ -594,7 +589,7 @@ tubelib.register_node("biogasmachines:freezer", { "biogasmachines:freezer_active
|
||||
|
||||
on_push_item = function(pos, side, item)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if is_water_bucket(item) then
|
||||
if water_bucket[item:get_name()] then
|
||||
return tubelib.put_item(meta, "src", item)
|
||||
elseif item:get_name() == "tubelib_addons1:biogas" then
|
||||
return tubelib.put_item(meta, "fuel", item)
|
||||
@ -650,7 +645,7 @@ if minetest.get_modpath("unified_inventory") then
|
||||
width = 1,
|
||||
height = 1,
|
||||
})
|
||||
for _, i in ipairs(water_buckets) do
|
||||
for i, _ in pairs(water_bucket) do
|
||||
unified_inventory.register_craft({
|
||||
type = "freezing",
|
||||
items = { i },
|
||||
|
@ -9,9 +9,8 @@
|
||||
Helper file for all machines that accept water through pipes from
|
||||
'pipeworks' mod.
|
||||
|
||||
Note: due to pipeworks being WIP, the only valid water connection
|
||||
for now is from top or bottom - machine face orientation is apparently
|
||||
ignored by pipe logic, 'back' for pipes means always param2 = 0 (z+).
|
||||
Note: machine face orientation is apparently ignored by pipe logic,
|
||||
'back' for pipes means always param2 = 0 (z+).
|
||||
|
||||
License: LGPLv2.1+
|
||||
=======================================================================
|
||||
@ -19,21 +18,27 @@
|
||||
]]--
|
||||
|
||||
-- all pipeworks objects that can carry water but are not junctions
|
||||
local pipeworks_straight_objects = {
|
||||
"pipeworks:straight_pipe_loaded",
|
||||
"pipeworks:entry_panel_loaded",
|
||||
"pipeworks:valve_on_loaded",
|
||||
"pipeworks:flow_sensor_loaded",
|
||||
local pipeworks_straight_object = {
|
||||
["pipeworks:straight_pipe_loaded"] = true,
|
||||
["pipeworks:entry_panel_loaded"] = true,
|
||||
["pipeworks:valve_on_loaded"] = true,
|
||||
["pipeworks:flow_sensor_loaded"] = true,
|
||||
}
|
||||
|
||||
-- direction attributes for pipe connections
|
||||
local ctable = {
|
||||
["top"] = { dv = { x = 0, y = 1, z = 0 }, p2 = { 17 } },
|
||||
["bottom"] = { dv = { x = 0, y = -1, z = 0 }, p2 = { 17 } },
|
||||
["front"] = { dv = { x = 0, y = 0, z = -1 }, p2 = { 0, 2 } },
|
||||
["back"] = { dv = { x = 0, y = 0, z = 1 }, p2 = { 0, 2 } },
|
||||
["left"] = { dv = { x = -1, y = 0, z = 0 }, p2 = { 1, 3 } },
|
||||
["right"] = { dv = { x = 1, y = 0, z = 0 }, p2 = { 1, 3 } },
|
||||
["top"] = { dv = { x = 0, y = 1, z = 0 },
|
||||
p2 = { [17] = true } },
|
||||
["bottom"] = { dv = { x = 0, y = -1, z = 0 },
|
||||
p2 = { [17] = true } },
|
||||
["front"] = { dv = { x = 0, y = 0, z = -1 },
|
||||
p2 = { [0] = true, [2] = true } },
|
||||
["back"] = { dv = { x = 0, y = 0, z = 1 },
|
||||
p2 = { [0] = true, [2] = true } },
|
||||
["left"] = { dv = { x = -1, y = 0, z = 0 },
|
||||
p2 = { [1] = true, [3] = true } },
|
||||
["right"] = { dv = { x = 1, y = 0, z = 0 },
|
||||
p2 = { [1] = true, [3] = true } },
|
||||
}
|
||||
|
||||
--[[
|
||||
@ -42,14 +47,6 @@ local ctable = {
|
||||
------
|
||||
]]--
|
||||
|
||||
-- check if node is in array
|
||||
function biogasmachines.is_member_of(name, array)
|
||||
for _, n in ipairs(array) do
|
||||
if n == name then return true end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-- Check if machine is connected to pipe network and water flows into machine
|
||||
-- Parameters: node position, node object (optional)
|
||||
-- Returns: true if water is flowing into device node
|
||||
@ -74,10 +71,8 @@ function biogasmachines.is_pipe_with_water(pos, opt_node)
|
||||
"^pipeworks:pipe_.*_loaded") then
|
||||
return true
|
||||
end
|
||||
if d_node and biogasmachines.is_member_of(
|
||||
d_node.param2, ctable[d].p2)
|
||||
and biogasmachines.is_member_of(
|
||||
d_node.name, pipeworks_straight_objects)
|
||||
if d_node and ctable[d].p2[d_node.param2]
|
||||
and pipeworks_straight_object[d_node.name]
|
||||
then
|
||||
return true
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user