diff --git a/compat/logistica.lua b/compat/logistica.lua new file mode 100644 index 0000000..4f78448 --- /dev/null +++ b/compat/logistica.lua @@ -0,0 +1,66 @@ +-- IndustrialTest +-- Copyright (C) 2024 mrkubax10 + +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation, either version 3 of the License, or +-- (at your option) any later version. + +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. + +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + +local oldInsertItemstackForRequester=logistica.insert_itemstack_for_requester + +-- Logistica overrides +function logistica.insert_itemstack_for_requester(requesterPos,itemstack,limitByRequest) + local result=oldInsertItemstackForRequester(requesterPos, itemstack, limitByRequest) + + local targetPos=logistica.get_requester_target(requesterPos) + local def=minetest.registered_nodes[minetest.get_node(targetPos).name] + if def._logistica_afterRequesterItemstackInsert then + def._logistica_afterRequesterItemstackInsert(targetPos) + end + + return result +end + +local onInjectorTimer=logistica.on_timer_powered(function(pos,elapsed) + local result=logistica.on_injector_timer(pos,elapsed) + minetest.debug("here") + + local targetPos=logistica.get_injector_target(pos) + local def=minetest.registered_nodes[minetest.get_node(targetPos).name] + if def._logistica_afterInjectorItemstackTake then + def._logistica_afterInjectorItemstackTake(targetPos) + end + + return result +end) + +for _,name in ipairs(logistica.group_get_all_nodes_for_group("injectors")) do + local override={ + on_timer=onInjectorTimer + } + minetest.override_item(name,override) +end + +local function startNodeTimer(pos) + minetest.get_node_timer(pos):start(industrialtest.updateDelay) +end + +local function addLogisticaCompatibility(name) + local override={ + _logistica_afterRequesterItemstackInsert=startNodeTimer, + _logistica_afterInjectorItemstackTake=startNodeTimer + } + minetest.override_item(name,override) +end + +for _,name in ipairs(industrialtest.api.tags.usesTimer) do + addLogisticaCompatibility(name) +end diff --git a/compatibility.lua b/compatibility.lua index b7f4092..13685e4 100644 --- a/compatibility.lua +++ b/compatibility.lua @@ -40,6 +40,7 @@ elseif industrialtest.mclAvailable then industrialtest.mods.mclRubber=minetest.get_modpath("mcl_rubber") end industrialtest.mods.pipeworks=minetest.get_modpath("pipeworks") +industrialtest.mods.logistica=minetest.get_modpath("logistica") industrialtest.mods.mesecons=minetest.get_modpath("mesecons") if industrialtest.mtgAvailable and not industrialtest.mods._3dArmor then diff --git a/init.lua b/init.lua index e630538..30539f6 100644 --- a/init.lua +++ b/init.lua @@ -90,6 +90,9 @@ dofile(modpath.."/crafts.lua") if industrialtest.mods.pipeworks then dofile(modpath.."/compat/pipeworks.lua") end +if industrialtest.mods.logistica then + dofile(modpath.."/compat/logistica.lua") +end if industrialtest.mods.mesecons then dofile(modpath.."/compat/mesecons.lua") end diff --git a/machines/common.lua b/machines/common.lua index e3b8114..7464e8c 100644 --- a/machines/common.lua +++ b/machines/common.lua @@ -439,6 +439,7 @@ function industrialtest.internal.registerMachine(config) end minetest.register_node("industrialtest:"..config.name.."_active",definition) end + industrialtest.api.addTag("industrialtest:"..config.name,"usesTimer") end local function craftResultProxy(method,item) diff --git a/mod.conf b/mod.conf index 0107c54..1f0c421 100644 --- a/mod.conf +++ b/mod.conf @@ -1,5 +1,5 @@ name=industrialtest description=Adds various machinery -optional_depends=default,bucket,3d_armor,mcl_core,mcl_copper,mcl_armor,mcl_deepslate,mcl_nether,mcl_buckets,mcl_util,mcl_dye,mcl_rubber,pipeworks,mesecons +optional_depends=default,bucket,3d_armor,mcl_core,mcl_copper,mcl_armor,mcl_deepslate,mcl_nether,mcl_buckets,mcl_util,mcl_dye,mcl_rubber,pipeworks,logistica,mesecons author=IndustrialTest Team title=IndustrialTest