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