Some various fixes and changes in machine.lua and electric_machine.lua

This commit is contained in:
mrkubax10 2025-03-31 11:54:47 +02:00
parent 38b08bcb0d
commit b18b6e5a32
2 changed files with 26 additions and 19 deletions

View File

@ -29,7 +29,7 @@ function industrialtest.ElectricMachine.onConstruct(self,pos)
industrialtest.api.createNetworkMapForNode(conn)
local def=minetest.get_node(conn)
if def and def._industrialtest_self then
def._industrialtest_self:requestPower(conn)
def._industrialtest_self:flowPower(conn)
else
-- Support for bare definitions that don't use industrialtest pseudo-OOP
minetest.get_node_timer(conn):start(industrialtest.updateDelay)
@ -41,12 +41,12 @@ function industrialtest.ElectricMachine.onConstruct(self,pos)
if networks then
for _,network in ipairs(networks) do
industrialtest.api.createNetworkMapForNode(network)
local def=minetest.get_node(network)
local def=minetest.registered_nodes[minetest.get_node(network).name]
if def and def._industrialtest_self then
def._industrialtest_self:requestPower(network)
def._industrialtest_self:flowPower(network)
else
-- Support for bare definitions that don't use industrialtest pseudo-OOP
minetest.get_node_timer(conn):start(industrialtest.updateDelay)
minetest.get_node_timer(network):start(industrialtest.updateDelay)
end
end
end
@ -152,7 +152,7 @@ function industrialtest.ElectricMachine.onMetadataInventoryPut(self,pos,listname
industrialtest.Machine.onMetadataInventoryPut(self,pos,listname,index,stack)
end
function industrialtest.ElectricMachine.requestPower(self,pos)
function industrialtest.ElectricMachine.flowPower(self,pos)
if not self.hasPowerOutput then
return
end
@ -167,23 +167,28 @@ function industrialtest.ElectricMachine.requestPower(self,pos)
self:triggerIfNeeded(pos)
end
function industrialtest.ElectricMachine.requestPower(self,pos)
local meta=minetest.get_meta(pos)
local networks=industrialtest.api.isAttachedToNetwork(meta)
if networks then
for _,network in ipairs(networks) do
local def=minetest.registered_nodes[minetest.get_node(network).name]
if def and def._industrialtest_self then
def._industrialtest_self:flowPower(network)
else
-- Support for bare definitions that don't use industrialtest pseudo-OOP
minetest.get_node_timer(network):start(industrialtest.updateDelay)
end
end
end
end
function industrialtest.ElectricMachine.powerExchange(self,pos)
local meta=minetest.get_meta(pos)
local shouldRerunTimer=false
if self.hasPowerInput and not industrialtest.api.isFullyCharged(meta) then
local networks=industrialtest.api.isAttachedToNetwork(meta)
if networks then
for _,network in ipairs(networks) do
local def=minetest.registered_nodes[minetest.get_node(network).name]
if def and def._industrialtest_self then
def._industrialtest_self:requestPower(network)
else
-- Support for bare definitions that don't use industrialtest pseudo-OOP
minetest.get_node_timer(network):start(industrialtest.updateDelay)
end
end
end
self:requestPower(pos)
shouldRerunTimer=shouldRerunTimer or not industrialtest.api.isFullyCharged(meta)
end

View File

@ -18,8 +18,10 @@ industrialtest.Machine={}
function industrialtest.Machine.onConstruct(self,pos)
local meta=minetest.get_meta(pos)
meta:set_string("formspec",self:getFormspec(pos))
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
if not self.withoutFormspec then
meta:set_string("formspec",self:getFormspec(pos))
end
self:trigger(pos)
end
function industrialtest.Machine.onDestruct(self)