Generify groups, fixing a bug with cached network id lookup, and allowing other mods to use group system via api
This commit is contained in:
parent
4c34fe155e
commit
ab440e19e9
@ -72,7 +72,7 @@ minetest.register_on_player_receive_fields(logistica.on_receive_access_point_for
|
||||
function logistica.register_access_point(desc, name, tiles)
|
||||
local lname = string.lower(name:gsub(" ", "_"))
|
||||
local access_point_name = "logistica:"..lname
|
||||
logistica.misc_machines[access_point_name] = true
|
||||
logistica.GROUPS.misc_machines.register(access_point_name)
|
||||
local grps = {oddly_breakable_by_hand = 3, cracky = 3, handy = 1, pickaxey = 1, [logistica.TIER_ACCESS_POINT] = 1 }
|
||||
grps[logistica.TIER_ALL] = 1
|
||||
local def = {
|
||||
|
@ -125,7 +125,7 @@ function logistica.register_bucket_emptier(desc, name, tiles)
|
||||
local lname = name:gsub("%s", "_"):lower()
|
||||
local emptier_name = "logistica:"..lname
|
||||
|
||||
logistica.bucket_emptiers[emptier_name] = true
|
||||
logistica.GROUPS.bucket_emptiers.register(emptier_name)
|
||||
local def = {
|
||||
description = S(desc),
|
||||
tiles = tiles,
|
||||
|
@ -138,7 +138,7 @@ end)
|
||||
function logistica.register_bucket_filler(desc, name, tiles)
|
||||
local lname = string.lower(name:gsub(" ", "_"))
|
||||
local filler_name = "logistica:"..lname
|
||||
logistica.bucket_fillers[filler_name] = true
|
||||
logistica.GROUPS.bucket_fillers.register(filler_name)
|
||||
local grps = {oddly_breakable_by_hand = 3, cracky = 3, handy = 1, pickaxey = 1, }
|
||||
grps[logistica.TIER_ALL] = 1
|
||||
local def = {
|
||||
|
@ -7,7 +7,7 @@ function logistica.register_cable(desc, name, customNodeBox, customTiles, custom
|
||||
local lname = string.lower(name)
|
||||
local cable_name = "logistica:" .. lname
|
||||
local cable_group = logistica.TIER_ALL
|
||||
logistica.cables[cable_name] = name
|
||||
logistica.GROUPS.cables.register(cable_name)
|
||||
local cnb = customNodeBox or {}
|
||||
local tiles = customTiles or { "logistica_" .. lname .. ".png" }
|
||||
|
||||
|
@ -78,7 +78,7 @@ function logistica.register_cable_toggleable(desc, name, tilesOn, tilesOff)
|
||||
}
|
||||
|
||||
if state == "on" then
|
||||
logistica.cables[cable_name] = name
|
||||
logistica.GROUPS.cables.register(cable_name)
|
||||
def.groups[logistica.TIER_ALL] = 1
|
||||
def.groups.not_in_creative_inventory = 1
|
||||
else
|
||||
|
@ -175,7 +175,7 @@ end)
|
||||
function logistica.register_cobble_generator_supplier(desc, name, tiles)
|
||||
local lname = string.lower(name:gsub(" ", "_"))
|
||||
local supplier_name = "logistica:"..lname
|
||||
logistica.suppliers[supplier_name] = true
|
||||
logistica.GROUPS.suppliers.register(supplier_name)
|
||||
local grps = {oddly_breakable_by_hand = 3, cracky = 3, handy = 1, pickaxey = 1 }
|
||||
grps[logistica.TIER_ALL] = 1
|
||||
local def = {
|
||||
|
@ -80,7 +80,7 @@ function logistica.register_controller(name, def)
|
||||
local controller_group = logistica.TIER_ALL
|
||||
local tier = logistica.TIER_ALL
|
||||
local controller_name = "logistica:" .. string.lower(name:gsub(" ", "_"))
|
||||
logistica.controllers[controller_name] = tier
|
||||
logistica.GROUPS.controllers.register(controller_name)
|
||||
|
||||
local on_construct = function(pos)
|
||||
logistica.start_controller_timer(pos)
|
||||
@ -91,7 +91,6 @@ function logistica.register_controller(name, def)
|
||||
def.groups = {}
|
||||
end
|
||||
def.groups[controller_group] = 1
|
||||
def.groups[logistica.TIER_CONTROLLER] = 1
|
||||
def.on_timer = logistica.on_controller_timer
|
||||
def.on_construct = on_construct
|
||||
def.after_dig_node = logistica.on_controller_change
|
||||
|
@ -154,7 +154,7 @@ end)
|
||||
function logistica.register_crafting_supplier(desc, name, tiles)
|
||||
local lname = string.lower(name:gsub(" ", "_"))
|
||||
local supplier_name = "logistica:"..lname
|
||||
logistica.craftsups[supplier_name] = true
|
||||
logistica.GROUPS.crafting_suppliers.register(supplier_name)
|
||||
local grps = {oddly_breakable_by_hand = 3, cracky = 3, handy = 1, pickaxey = 1, }
|
||||
grps[logistica.TIER_ALL] = 1
|
||||
local def = {
|
||||
|
@ -127,7 +127,7 @@ end)
|
||||
function logistica.register_injector(description, name, transferRate, tiles)
|
||||
local lname = string.lower(name:gsub(" ", "_"))
|
||||
local injectorName = "logistica:"..lname
|
||||
logistica.injectors[injectorName] = true
|
||||
logistica.GROUPS.injectors.register(injectorName)
|
||||
local grps = {oddly_breakable_by_hand = 3, cracky = 3, handy = 1, pickaxey = 1 }
|
||||
grps[logistica.TIER_ALL] = 1
|
||||
local def = {
|
||||
|
@ -110,7 +110,7 @@ end)
|
||||
function logistica.register_item_storage(desc, name, tiles)
|
||||
local lname = string.lower(name:gsub(" ", "_"))
|
||||
local item_storage_name = "logistica:"..lname
|
||||
logistica.item_storage[item_storage_name] = true
|
||||
logistica.GROUPS.item_storage.register(item_storage_name)
|
||||
local grps = {oddly_breakable_by_hand = 3, cracky = 3, handy = 1, pickaxey = 1 }
|
||||
grps[logistica.TIER_ALL] = 1
|
||||
local def = {
|
||||
|
@ -119,7 +119,7 @@ end)
|
||||
function logistica.register_lava_furnace_fueler(description, name, tiles)
|
||||
local lname = string.lower(name:gsub(" ", "_"))
|
||||
local fuelerName = "logistica:"..lname
|
||||
logistica.misc_machines[fuelerName] = true
|
||||
logistica.GROUPS.misc_machines.register(fuelerName)
|
||||
local grps = {oddly_breakable_by_hand = 3, cracky = 3, handy = 1, pickaxey = 1, }
|
||||
grps[logistica.TIER_ALL] = 1
|
||||
local def = {
|
||||
|
@ -367,7 +367,7 @@ function logistica.register_mass_storage(simpleName, description, numSlots, numI
|
||||
local grps = {cracky = 1, choppy = 1, oddly_breakable_by_hand = 1, pickaxey = 3, axey = 3, handy = 1}
|
||||
numUpgradeSlots = logistica.clamp(numUpgradeSlots, 0, 4)
|
||||
grps[logistica.TIER_ALL] = 1
|
||||
logistica.mass_storage[storageName] = true
|
||||
logistica.GROUPS.mass_storage.register(storageName)
|
||||
|
||||
local def = {
|
||||
description = description.."\n(Empty)",
|
||||
|
@ -115,8 +115,8 @@ function logistica.register_pump(desc, name, tiles, tilesOn)
|
||||
local pump_name = "logistica:"..lname
|
||||
local pump_name_on = pump_name.."_on"
|
||||
|
||||
logistica.pumps[pump_name] = true
|
||||
logistica.pumps[pump_name_on] = true
|
||||
logistica.GROUPS.pumps.register(pump_name)
|
||||
logistica.GROUPS.pumps.register(pump_name_on)
|
||||
|
||||
local def = {
|
||||
description = S(desc),
|
||||
|
@ -128,7 +128,7 @@ end)
|
||||
function logistica.register_requester(description, name, transferRate, tiles)
|
||||
local lname = string.lower(name:gsub(" ", "_"))
|
||||
local requester_name = "logistica:"..lname
|
||||
logistica.requesters[requester_name] = true
|
||||
logistica.GROUPS.requesters.register(requester_name)
|
||||
local grps = {oddly_breakable_by_hand = 3, cracky = 3, handy = 1, pickaxey = 1, }
|
||||
grps[logistica.TIER_ALL] = 1
|
||||
local def = {
|
||||
|
@ -159,7 +159,7 @@ for _, variantName in ipairs(variants) do
|
||||
def.drops = nodeName
|
||||
def.logistica.liquidName = LIQUID_NONE
|
||||
minetest.register_node(nodeName, def)
|
||||
logistica.reservoirs[nodeName] = true
|
||||
logistica.GROUPS.reservoirs.register(nodeName)
|
||||
end
|
||||
|
||||
--[[
|
||||
@ -185,7 +185,7 @@ function logistica.register_reservoir(liquidName, liquidDesc, bucketItemName, li
|
||||
def.inventory_image = make_inv_image(variantName, liquidTexture)
|
||||
|
||||
minetest.register_node(nodeName, def)
|
||||
logistica.reservoirs[nodeName] = true
|
||||
logistica.GROUPS.reservoirs.register(nodeName)
|
||||
|
||||
logistica.reservoir_register_names(lname, bucketItemName, optEmptyBucketName, liquidDesc, liquidTexture, sourceNodeName)
|
||||
end
|
||||
|
@ -105,7 +105,7 @@ end)
|
||||
function logistica.register_supplier(desc, name, inventorySize, tiles)
|
||||
local lname = string.lower(name:gsub(" ", "_"))
|
||||
local supplier_name = "logistica:"..lname
|
||||
logistica.suppliers[supplier_name] = true
|
||||
logistica.GROUPS.suppliers.register(supplier_name)
|
||||
local grps = {oddly_breakable_by_hand = 3, cracky = 3, handy = 1, pickaxey = 1 }
|
||||
grps[logistica.TIER_ALL] = 1
|
||||
local def = {
|
||||
|
@ -72,7 +72,7 @@ end
|
||||
function logistica.register_trashcan(desc, name, tiles)
|
||||
local lname = string.lower(name:gsub(" ", "_"))
|
||||
local trashcan_name = "logistica:"..lname
|
||||
logistica.trashcans[trashcan_name] = true
|
||||
logistica.GROUPS.trashcans.register(trashcan_name)
|
||||
local grps = {oddly_breakable_by_hand = 3, cracky = 3, handy = 1, pickaxey = 1, }
|
||||
grps[logistica.TIER_ALL] = 1
|
||||
local def = {
|
||||
|
@ -107,7 +107,7 @@ end)
|
||||
function logistica.register_vaccuum_chest(desc, name, inventorySize, tiles)
|
||||
local lname = string.lower(name:gsub(" ", "_"))
|
||||
local vaccuum_name = "logistica:"..lname
|
||||
logistica.vaccuum_suppliers[vaccuum_name] = true
|
||||
logistica.GROUPS.vaccuum_suppliers.register(vaccuum_name)
|
||||
local grps = {oddly_breakable_by_hand = 3, cracky = 3, handy = 1, pickaxey = 1 }
|
||||
grps[logistica.TIER_ALL] = 1
|
||||
local def = {
|
||||
|
@ -9,7 +9,7 @@ end
|
||||
function logistica.on_controller_timer(pos, _)
|
||||
local node = minetest.get_node_or_nil(pos)
|
||||
if not node then return true end -- what?
|
||||
if not logistica.is_controller(node.name) then return false end
|
||||
if not logistica.GROUPS.controllers.is(node.name) then return false end
|
||||
|
||||
local network = logistica.get_network_or_nil(pos)
|
||||
if not network then
|
||||
|
206
logic/groups.lua
206
logic/groups.lua
@ -1,89 +1,183 @@
|
||||
logistica.cables = {}
|
||||
logistica.controllers = {}
|
||||
logistica.injectors = {}
|
||||
logistica.requesters = {}
|
||||
logistica.suppliers = {}
|
||||
logistica.craftsups = {}
|
||||
logistica.bucket_emptiers = {}
|
||||
logistica.bucket_fillers = {}
|
||||
logistica.pumps = {}
|
||||
logistica.mass_storage = {}
|
||||
logistica.item_storage = {}
|
||||
logistica.misc_machines = {}
|
||||
logistica.trashcans = {}
|
||||
logistica.vaccuum_suppliers = {}
|
||||
logistica.reservoirs = {}
|
||||
|
||||
local logistica_groups = {}
|
||||
local network_groups = {}
|
||||
|
||||
logistica.TIER_ALL = "logistica_all_tiers"
|
||||
logistica.GROUP_ALL = "group:" .. logistica.TIER_ALL
|
||||
logistica.TIER_CONTROLLER = "logistica_controller"
|
||||
logistica.TIER_CABLE_OFF = "logistica_cable_off"
|
||||
logistica.GROUP_CABLE_OFF = "group:" .. logistica.TIER_CABLE_OFF
|
||||
logistica.TIER_ACCESS_POINT = "logistica_acspt"
|
||||
|
||||
function logistica.is_machine(name)
|
||||
return logistica.is_requester(name) or logistica.is_supplier(name) or logistica.is_mass_storage(name)
|
||||
or logistica.is_item_storage(name) or logistica.is_controller(name) or logistica.is_injector(name)
|
||||
or logistica.is_crafting_supplier(name) or logistica.is_trashcan(name) or logistica.is_vaccuum_supplier(name)
|
||||
or logistica.is_misc(name) or logistica.is_reservoir(name) or logistica.is_bucket_filler(name)
|
||||
or logistica.is_bucket_emptier(name) or logistica.is_pump(name)
|
||||
-- default groups, and shortcut for checking them
|
||||
|
||||
local function make_group_table(groupName, networkGroup)
|
||||
return {
|
||||
name = groupName,
|
||||
networkGroup = networkGroup,
|
||||
-- returns true if the given nodeName belongs to this group, false otherwise
|
||||
is = function(nodeName)
|
||||
return logistica.group_check(groupName, nodeName)
|
||||
end,
|
||||
-- returns true if registering the node name succeeds, false if the node name already exists
|
||||
register = function(nodeName)
|
||||
return logistica.group_register_node(groupName, nodeName)
|
||||
end,
|
||||
-- returns which network group this general group maps to
|
||||
network_group = function()
|
||||
return logistica.group_get_mapped_network_group(groupName)
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
function logistica.is_cable(name)
|
||||
return logistica.cables[name] ~= nil
|
||||
-- The default network groups of Logistica.
|
||||
-- These have special meaning and are treated with special actions. Each node group above must
|
||||
-- map to one network group, though multiple node groups can map to the same network group<br>
|
||||
-- More can be registered via logistica.network_group_register
|
||||
logistica.NETWORK_GROUPS = {
|
||||
cables = "cables",
|
||||
requesters = "requesters",
|
||||
injectors = "injectors",
|
||||
suppliers = "suppliers",
|
||||
mass_storage = "mass_storage",
|
||||
item_storage = "item_storage",
|
||||
misc = "misc",
|
||||
trashcans = "trashcans",
|
||||
reservoirs = "reservoirs",
|
||||
}
|
||||
|
||||
-- The default node groups of Logistica, with utility shorthand attached.<br>
|
||||
-- More can be registered via logistica.group_register_type, and other related functions (see API below)
|
||||
logistica.GROUPS = {
|
||||
cables = make_group_table("cables", logistica.NETWORK_GROUPS.cables),
|
||||
controllers = make_group_table("controllers", nil),
|
||||
injectors = make_group_table("injectors", logistica.NETWORK_GROUPS.injectors),
|
||||
requesters = make_group_table("requesters", logistica.NETWORK_GROUPS.requesters),
|
||||
suppliers = make_group_table("suppliers", logistica.NETWORK_GROUPS.suppliers),
|
||||
crafting_suppliers = make_group_table("craftsups", logistica.NETWORK_GROUPS.suppliers),
|
||||
bucket_emptiers = make_group_table("bucket_emptiers", logistica.NETWORK_GROUPS.suppliers),
|
||||
bucket_fillers = make_group_table("bucket_fillers", logistica.NETWORK_GROUPS.suppliers),
|
||||
pumps = make_group_table("pumps", logistica.NETWORK_GROUPS.misc),
|
||||
mass_storage = make_group_table("mass_storage", logistica.NETWORK_GROUPS.mass_storage),
|
||||
item_storage = make_group_table("item_storage", logistica.NETWORK_GROUPS.item_storage),
|
||||
misc_machines = make_group_table("misc_machines", logistica.NETWORK_GROUPS.misc),
|
||||
trashcans = make_group_table("trashcans", logistica.NETWORK_GROUPS.trashcans),
|
||||
vaccuum_suppliers = make_group_table("vaccuum_suppliers", logistica.NETWORK_GROUPS.suppliers),
|
||||
reservoirs = make_group_table("reservoirs", logistica.NETWORK_GROUPS.reservoirs),
|
||||
}
|
||||
|
||||
----------------------------------------------------------------
|
||||
-- Public API
|
||||
----------------------------------------------------------------
|
||||
|
||||
--------------------------------
|
||||
-- Helpers
|
||||
--------------------------------
|
||||
|
||||
-- this is a utility function that checks if a nodeName is in any logistica node group, except cables
|
||||
function logistica.is_machine(nodeName)
|
||||
local group = logistica.group_get_node_group_name(nodeName)
|
||||
return group ~= nil and group ~= logistica.GROUPS.cables.name
|
||||
end
|
||||
|
||||
function logistica.is_requester(name)
|
||||
return logistica.requesters[name] ~= nil
|
||||
-- shorthand for calling group_get_node_group_name followed by group_get_mapped_network_group
|
||||
-- returns nil if it has no node group, or it maps to no network group
|
||||
function logistica.get_network_group_for_node_name(nodeName)
|
||||
local nodeGroup = logistica.group_get_node_group_name(nodeName)
|
||||
if not nodeGroup then return nil end
|
||||
return logistica.group_get_mapped_network_group(nodeGroup)
|
||||
end
|
||||
|
||||
function logistica.is_supplier(name)
|
||||
return logistica.suppliers[name] ~= nil
|
||||
--------------------------------
|
||||
-- Node Groups
|
||||
--------------------------------
|
||||
|
||||
-- Logistica node group registration. Node groups are mostly used for looking up types of nodes, and
|
||||
-- to also map them to network groups, to allow them to connect to a network.<br>
|
||||
-- returns true/false if registering of a new group type succeeds<br>
|
||||
-- `groupName` must be non-nil, string and unique - the name of the node group to register<br>
|
||||
-- `networGroupItMapsTo` should be an existing network group (e.g. one of the default or a newly registered one)
|
||||
-- or it could be `nil` if the given node group is not meant to connect to a network
|
||||
function logistica.group_register_type(groupName, networkGroupItMapsTo)
|
||||
if type(groupName) ~= "string" or logistica_groups[groupName] ~= nil then return false end
|
||||
logistica_groups[groupName] = { _networkGroup = networkGroupItMapsTo }
|
||||
return true
|
||||
end
|
||||
|
||||
function logistica.is_crafting_supplier(name)
|
||||
return logistica.craftsups[name] ~= nil
|
||||
-- returns true/false if the given group exists and the nodeName wasn't already part of that group
|
||||
function logistica.group_register_node(groupName, nodeName)
|
||||
if not logistica_groups[groupName] or logistica_groups[groupName][nodeName] ~= nil then return false end
|
||||
logistica_groups[groupName][nodeName] = true
|
||||
end
|
||||
|
||||
function logistica.is_mass_storage(name)
|
||||
return logistica.mass_storage[name] ~= nil
|
||||
-- returns true if groupName exists and nodeName is a registered member of that group
|
||||
function logistica.group_check(groupName, nodeName)
|
||||
return logistica_groups[groupName] and logistica_groups[groupName][nodeName]
|
||||
end
|
||||
|
||||
function logistica.is_item_storage(name)
|
||||
return logistica.item_storage[name] ~= nil
|
||||
-- returns a copy of the group names as a lua set {groupName = true, groupTwo = true, ...}
|
||||
function logistica.group_get_all_group_names()
|
||||
local copy = {}
|
||||
for k, _ in pairs(logistica_groups) do copy[k] = true end
|
||||
return copy
|
||||
end
|
||||
|
||||
function logistica.is_controller(name)
|
||||
return logistica.controllers[name] ~= nil
|
||||
-- returns the group name (a string) to which the given nodeName belongs to, or nil if it doesn't belong to any group
|
||||
function logistica.group_get_node_group_name(nodeName)
|
||||
for k, v in pairs(logistica_groups) do
|
||||
if v[nodeName] then return k end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function logistica.is_injector(name)
|
||||
return logistica.injectors[name] ~= nil
|
||||
--------------------------------
|
||||
-- Network groups
|
||||
--------------------------------
|
||||
|
||||
-- Network Group registration
|
||||
-- These should be used along side logistica.group.group_register_type to map those general group types
|
||||
-- to these network-specific group types<br>
|
||||
-- You can re-use the default groups if necessary, so long as the new nodes registered provide same interaction capabilities.<br>
|
||||
-- Any of these groups can be accessed via logistica.get_network_or_nil(..).network_group_name -
|
||||
-- which contains a lua set of hashed node positions that are connected to this network<br>
|
||||
-- `group_name` must be lowercase only, and contain no spaces - if any are present, they will be removed and then the group registered<br>
|
||||
-- returns nil if registration failed, or the actual registered group name if it succeeds
|
||||
-- (which will be identical to passed in group_name if that followed all the requirements are followed)
|
||||
function logistica.network_group_register(group_name)
|
||||
local lname = group_name:lower():gsub(" ", "")
|
||||
if network_groups[lname] then return nil end
|
||||
network_groups[lname] = true
|
||||
return lname
|
||||
end
|
||||
|
||||
function logistica.is_misc(name)
|
||||
return logistica.misc_machines[name] ~= nil
|
||||
-- returns which network group this general group maps to,
|
||||
-- or nil if the given group doesn't exist, or it doesn't map to any network group
|
||||
function logistica.group_get_mapped_network_group(groupName)
|
||||
if not logistica_groups[groupName] then return nil end
|
||||
return logistica_groups[groupName]._networkGroup
|
||||
end
|
||||
|
||||
function logistica.is_trashcan(name)
|
||||
return logistica.trashcans[name] ~= nil
|
||||
-- returns true/false if the network group has already been registered
|
||||
function logistica.network_group_exists(group_name)
|
||||
local lname = group_name:lower():gsub(" ", "")
|
||||
return network_groups[lname] ~= nil
|
||||
end
|
||||
|
||||
function logistica.is_vaccuum_supplier(name)
|
||||
return logistica.vaccuum_suppliers[name] ~= nil
|
||||
----------------------------------------------------------------
|
||||
-- Register all the default/built-in network groups, and then all node groups
|
||||
----------------------------------------------------------------
|
||||
|
||||
for _, v in pairs(logistica.NETWORK_GROUPS) do
|
||||
logistica.network_group_register(v)
|
||||
end
|
||||
|
||||
function logistica.is_reservoir(name)
|
||||
return logistica.reservoirs[name] ~= nil
|
||||
for _, v in pairs(logistica.GROUPS) do
|
||||
logistica.group_register_type(v.name, v.networkGroup)
|
||||
end
|
||||
|
||||
function logistica.is_bucket_filler(name)
|
||||
return logistica.bucket_fillers[name] ~= nil
|
||||
end
|
||||
|
||||
function logistica.is_bucket_emptier(name)
|
||||
return logistica.bucket_emptiers[name] ~= nil
|
||||
end
|
||||
|
||||
function logistica.is_pump(name)
|
||||
return logistica.pumps[name] ~= nil
|
||||
-- due to this copy, this had to be placed below the registration
|
||||
local network_groups_copy = table.copy(network_groups)
|
||||
-- returns a copy of all the network groups as a lua set<br>
|
||||
-- WARNING The copy is static, so treat it as read-only!
|
||||
function logistica.network_group_get_all()
|
||||
return network_groups_copy
|
||||
end
|
||||
|
@ -18,24 +18,15 @@ local adjecent = {
|
||||
|
||||
local function has_machine(network, id)
|
||||
if not network then return false end
|
||||
if network.requesters[id]
|
||||
or network.suppliers[id]
|
||||
or network.mass_storage[id]
|
||||
or network.item_storage[id]
|
||||
or network.injectors[id]
|
||||
or network.misc[id]
|
||||
or network.trashcans[id]
|
||||
or network.reservoirs[id]
|
||||
then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
for networkGroup, v in pairs(logistica.network_group_get_all()) do
|
||||
if network[networkGroup][id] ~= nil then return true end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function network_contains_hash(network, hash)
|
||||
if hash == network.controller then return true end
|
||||
if network.cables[hash] then return true end
|
||||
if network[logistica.NETWORK_GROUPS.cables][hash] then return true end
|
||||
if has_machine(network, hash) then return true end
|
||||
return false
|
||||
end
|
||||
@ -141,7 +132,7 @@ local function find_adjecent_networks(pos)
|
||||
for _, adj in pairs(adjecent) do
|
||||
local otherPos = vector.add(pos, adj)
|
||||
local otherNodeName = minetest.get_node(otherPos).name
|
||||
if logistica.is_cable(otherNodeName) or logistica.is_controller(otherNodeName) then
|
||||
if logistica.GROUPS.cables.is(otherNodeName) or logistica.GROUPS.controllers.is(otherNodeName) then
|
||||
local otherNetwork = logistica.get_network_or_nil(otherPos)
|
||||
if otherNetwork ~= nil then
|
||||
if currNetwork == nil then currNetwork = otherNetwork
|
||||
@ -174,56 +165,23 @@ local function recursive_scan_for_nodes_for_controller(network, positionHashes,
|
||||
local otherHash = p2h(otherPos)
|
||||
if network.controller ~= otherHash
|
||||
and not has_machine(network, otherHash)
|
||||
and network.cables[otherHash] == nil then
|
||||
and network[logistica.NETWORK_GROUPS.cables][otherHash] == nil then
|
||||
local existingNetwork = logistica.get_network_id_or_nil(otherPos)
|
||||
if existingNetwork ~= nil and existingNetwork ~= network then
|
||||
return CREATE_NETWORK_STATUS_FAIL_OTHER_NETWORK
|
||||
end
|
||||
local valid = false
|
||||
if logistica.is_cable(otherName) then
|
||||
network.cables[otherHash] = true
|
||||
local nodeNetworkGroup = logistica.get_network_group_for_node_name(otherName)
|
||||
if nodeNetworkGroup == logistica.NETWORK_GROUPS.cables then -- cables get special treatment
|
||||
network[nodeNetworkGroup][otherHash] = true
|
||||
connections[otherHash] = true
|
||||
valid = true
|
||||
end
|
||||
if logistica.is_requester(otherName) then
|
||||
network.requesters[otherHash] = true
|
||||
valid = true
|
||||
end
|
||||
if logistica.is_injector(otherName) then
|
||||
network.injectors[otherHash] = true
|
||||
valid = true
|
||||
end
|
||||
if logistica.is_supplier(otherName)
|
||||
or logistica.is_crafting_supplier(otherName)
|
||||
or logistica.is_vaccuum_supplier(otherName)
|
||||
or logistica.is_bucket_filler(otherName)
|
||||
or logistica.is_bucket_emptier(otherName)
|
||||
then
|
||||
network.suppliers[otherHash] = true
|
||||
valid = true
|
||||
end
|
||||
if logistica.is_mass_storage(otherName) then
|
||||
network.mass_storage[otherHash] = true
|
||||
valid = true
|
||||
end
|
||||
if logistica.is_item_storage(otherName) then
|
||||
network.item_storage[otherHash] = true
|
||||
valid = true
|
||||
end
|
||||
if logistica.is_misc(otherName)
|
||||
or logistica.is_pump(otherName)
|
||||
then
|
||||
network.misc[otherHash] = true
|
||||
valid = true
|
||||
end
|
||||
if logistica.is_trashcan(otherName) then
|
||||
network.trashcans[otherHash] = true
|
||||
valid = true
|
||||
end
|
||||
if logistica.is_reservoir(otherName) then
|
||||
network.reservoirs[otherHash] = true
|
||||
elseif nodeNetworkGroup ~= nil then
|
||||
-- all machines, except controllers, should be added to network
|
||||
network[nodeNetworkGroup][otherHash] = true
|
||||
valid = true
|
||||
end
|
||||
|
||||
if valid then
|
||||
newToScan = newToScan + 1
|
||||
set_cache_network_id(minetest.get_meta(otherPos), network.controller)
|
||||
@ -251,18 +209,14 @@ local function create_network(controllerPosition, oldNetworkName)
|
||||
meta:set_string("infotext", "Controller of Network: "..networkName)
|
||||
network.controller = controllerHash
|
||||
network.name = networkName
|
||||
network.cables = {}
|
||||
network.requesters = {}
|
||||
network.injectors = {}
|
||||
network.suppliers = {}
|
||||
network.mass_storage = {}
|
||||
network.item_storage = {}
|
||||
network.misc = {}
|
||||
network.trashcans = {}
|
||||
for group, _ in pairs(logistica.network_group_get_all()) do
|
||||
network[group] = {}
|
||||
end
|
||||
-- caches aren't groups, so add them manually
|
||||
network.storage_cache = {}
|
||||
network.supplier_cache = {}
|
||||
network.requester_cache = {}
|
||||
network.reservoirs = {}
|
||||
|
||||
local startPos = {}
|
||||
startPos[controllerHash] = true
|
||||
local status = recursive_scan_for_nodes_for_controller(network, startPos)
|
||||
@ -399,7 +353,7 @@ local MISC_OPS = {
|
||||
local function cable_can_extend_network_from(pos)
|
||||
local node = minetest.get_node_or_nil(pos)
|
||||
if not node then return false end
|
||||
return logistica.is_cable(node.name) or logistica.is_controller(node.name)
|
||||
return logistica.GROUPS.cables.is(node.name) or logistica.GROUPS.controllers.is(node.name)
|
||||
end
|
||||
|
||||
----------------------------------------------------------------
|
||||
@ -416,7 +370,7 @@ function logistica.try_to_wake_up_network(pos)
|
||||
|
||||
logistica.load_position(conPos)
|
||||
local node = minetest.get_node(conPos)
|
||||
if logistica.is_controller(node.name) then
|
||||
if logistica.GROUPS.controllers.is(node.name) then
|
||||
local nodeDef = minetest.registered_nodes[node.name]
|
||||
if nodeDef.on_timer then
|
||||
nodeDef.on_timer(conPos, 1)
|
||||
@ -437,11 +391,11 @@ function logistica.on_cable_change(pos, oldNode, optMeta, wasPlacedOverride)
|
||||
if networkEnd then
|
||||
if not placed then -- removed a network end
|
||||
local network = logistica.get_network_or_nil(pos, optMeta)
|
||||
if network then network.cables[p2h(pos)] = nil end
|
||||
if network then network[logistica.NETWORK_GROUPS.cables][p2h(pos)] = nil end
|
||||
elseif cable_can_extend_network_from(connections[1]) then
|
||||
local otherNetwork = logistica.get_network_or_nil(connections[1])
|
||||
if otherNetwork then
|
||||
otherNetwork.cables[p2h(pos)] = true
|
||||
otherNetwork[logistica.NETWORK_GROUPS.cables][p2h(pos)] = true
|
||||
set_cache_network_id(minetest.get_meta(pos), otherNetwork.controller)
|
||||
end
|
||||
end
|
||||
@ -469,7 +423,7 @@ function logistica.on_cable_change(pos, oldNode, optMeta, wasPlacedOverride)
|
||||
if placed and allConnectionsHaveSameNetwork then
|
||||
local addToNetwork = logistica.get_network_by_id_or_nil(firstNetworkId)
|
||||
if addToNetwork then
|
||||
addToNetwork.cables[p2h(pos)] = true
|
||||
addToNetwork[logistica.NETWORK_GROUPS.cables][p2h(pos)] = true
|
||||
set_cache_network_id(minetest.get_meta(pos), addToNetwork.controller)
|
||||
end
|
||||
else
|
||||
|
@ -147,17 +147,19 @@ function logistica.take_stack_from_suppliers(stackToTake, network, collectorFunc
|
||||
local pos = h2p(hash)
|
||||
logistica.load_position(pos)
|
||||
local nodeName = minetest.get_node(pos).name
|
||||
if logistica.is_supplier(nodeName)
|
||||
or logistica.is_vaccuum_supplier(nodeName)
|
||||
or logistica.is_bucket_emptier(nodeName)
|
||||
and (type == nil or type == "normal")
|
||||
if (type == nil or type == "normal")
|
||||
and (
|
||||
logistica.GROUPS.suppliers.is(nodeName)
|
||||
or logistica.GROUPS.vaccuum_suppliers.is(nodeName)
|
||||
or logistica.GROUPS.bucket_emptiers.is(nodeName)
|
||||
)
|
||||
then
|
||||
normalSupplierResult = logistica.take_item_from_supplier(pos, takeStack, network, collectorFunc, useMetadata, dryRun)
|
||||
remaining = normalSupplierResult.remaining
|
||||
elseif logistica.is_crafting_supplier(nodeName) and (type == nil or type == "crafting") then
|
||||
elseif (type == nil or type == "crafting") and logistica.GROUPS.crafting_suppliers.is(nodeName) then
|
||||
craftingSupplierResult = logistica.take_item_from_crafting_supplier(pos, takeStack, network, collectorFunc, useMetadata, dryRun, depth)
|
||||
remaining = craftingSupplierResult.remaining
|
||||
elseif logistica.is_bucket_filler(nodeName) and (type == nil or type == "bucket") then
|
||||
elseif (type == nil or type == "bucket") and logistica.GROUPS.bucket_fillers.is(nodeName) then
|
||||
bucketFillerResult = logistica.take_item_from_bucket_filler(pos, takeStack, network, collectorFunc, isAutomatedRequest, dryRun, depth)
|
||||
remaining = bucketFillerResult.remaining
|
||||
end
|
||||
|
@ -106,7 +106,7 @@ local function put_liquid_in_neighboring_reservoirs(pumpPosition, bucketItemStac
|
||||
local neighborPos = vector.add(pumpPosition, v)
|
||||
logistica.load_position(neighborPos)
|
||||
local neighborNode = minetest.get_node_or_nil(neighborPos)
|
||||
if neighborNode and logistica.is_reservoir(neighborNode.name) then
|
||||
if neighborNode and logistica.GROUPS.reservoirs.is(neighborNode.name) then
|
||||
local resultStack = logistica.reservoir_use_item_on(neighborPos, bucketItemStack, neighborNode)
|
||||
if resultStack ~= nil then return true end
|
||||
end
|
||||
|
@ -27,7 +27,7 @@ local function get_meta(pos)
|
||||
end
|
||||
|
||||
local function is_prohibited_logistica_machine(name)
|
||||
return logistica.is_machine(name) and not logistica.is_bucket_emptier(name)
|
||||
return logistica.is_machine(name) and not logistica.GROUPS.bucket_emptiers.is(name)
|
||||
end
|
||||
|
||||
local function get_max_rate_for_requester(pos)
|
||||
|
@ -161,7 +161,7 @@ end
|
||||
-- returns the liquid name for the reservoir; or "" if there's no liquid stored, or nil if its not a reservoir
|
||||
function logistica.reservoir_get_liquid_name(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
if not logistica.is_reservoir(node.name) then return nil end
|
||||
if not logistica.GROUPS.reservoirs.is(node.name) then return nil end
|
||||
local def = minetest.registered_nodes[node.name]
|
||||
if not def or not def.logistica or not def.logistica.liquidName then return nil end
|
||||
return def.logistica.liquidName
|
||||
@ -170,7 +170,7 @@ end
|
||||
-- return {currentLevel, maxLevel} measured in buckets; or nil if its not a reservoir
|
||||
function logistica.reservoir_get_liquid_level(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
if not logistica.is_reservoir(node.name) then return nil end
|
||||
if not logistica.GROUPS.reservoirs.is(node.name) then return nil end
|
||||
local def = minetest.registered_nodes[node.name]
|
||||
if not def or not def.logistica or not def.logistica.maxBuckets then return nil end
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
@ -31,7 +31,7 @@ end
|
||||
-- tries to put the given item in this supplier, returns what's leftover
|
||||
function logistica.put_item_in_supplier(pos, stack)
|
||||
local nodeName = minetest.get_node(pos).name
|
||||
if not logistica.is_supplier(nodeName) then return stack end
|
||||
if not logistica.GROUPS.suppliers.is(nodeName) then return stack end
|
||||
local nodeDef = minetest.registered_nodes[nodeName]
|
||||
if not nodeDef or not nodeDef.logistica then return stack end
|
||||
if not nodeDef.logistica.supplierMayAccept then return stack end
|
||||
|
@ -33,7 +33,7 @@ local function collect_items_into(pos, distance)
|
||||
local inserted = 0
|
||||
|
||||
local nodeName = minetest.get_node(pos).name
|
||||
if not logistica.is_vaccuum_supplier(nodeName) then return inserted end
|
||||
if not logistica.GROUPS.vaccuum_suppliers.is(nodeName) then return inserted end
|
||||
local nodeDef = minetest.registered_nodes[nodeName]
|
||||
if not nodeDef or not nodeDef.logistica or not nodeDef.on_metadata_inventory_put then
|
||||
return inserted
|
||||
|
@ -10,7 +10,7 @@ minetest.register_tool("logistica:hyperspanner",{
|
||||
local pos = pointed_thing.under
|
||||
if not placer or not pos then return end
|
||||
local node = minetest.get_node_or_nil(pos)
|
||||
if not node or not (logistica.is_machine(node.name) or logistica.is_cable(node.name)) then return end
|
||||
if not node or not (logistica.is_machine(node.name) or logistica.GROUPS.cables.is(node.name)) then return end
|
||||
local network = logistica.get_network_name_or_nil(pos) or S("<NONE>")
|
||||
logistica.show_popup(
|
||||
placer:get_player_name(),
|
||||
|
@ -24,7 +24,7 @@ local function get_lists(targetPosition, usePushLists)
|
||||
local node = minetest.get_node(targetPosition)
|
||||
|
||||
local allowedLists = {}
|
||||
if logistica.is_bucket_emptier(node.name) then
|
||||
if logistica.GROUPS.bucket_emptiers.is(node.name) then
|
||||
if usePushLists then allowedLists = logisticaBucketEmptierAllowedPush
|
||||
else return {} end -- can only push to bucket emptier, it acts as a supplier so no need to pull
|
||||
elseif logistica.is_machine(node.name) then return {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user