Generate network map while constructing generator for testing

This commit is contained in:
2023-11-13 20:37:50 +01:00
parent c02bddb433
commit c3b49b68e1
4 changed files with 58 additions and 46 deletions

View File

@@ -86,47 +86,9 @@ local function registerCable(name,displayName,size,flow,registerInsulated)
},
connects_to={
"group:_industrialtest_hasPowerInput",
"group:_industrialtest_hasPowerOutput"
},
on_construct=function(pos)
local meta=minetest.get_meta(pos)
industrialtest.api.addPowerStorage(meta,flow,flow,"aaaaaa")
end,
on_timer=function(pos)
local meta=minetest.get_meta(pos)
local afterFlow,transferred=industrialtest.api.powerFlow(pos)
meta:set_string("industrialtest.ioConfig","aaaaaa")
if not industrialtest.api.isFullyCharged(meta) then
industrialtest.api.triggerNeighbours(pos)
end
if transferred then
local node=minetest.get_node(pos)
local def=minetest.registered_nodes[node.name]
if def._industrialtest_electrocution then
local players=minetest.get_connected_players()
for _,value in ipairs(players) do
-- Note: don't use vector.distance here because we don't need actual distance between two
-- vectors to determine if player is within range if we use squared range
local playerPos=value:get_pos()
local dx=pos.x-playerPos.x
local dy=pos.y-playerPos.y
local dz=pos.z-playerPos.z
local dist=math.pow(dx,2)+math.pow(dy,2)+math.pow(dz,2)
if dist<=0.60 then
local hp=value:get_hp()
value:set_hp(hp-0.5,"Electrocution")
end
end
end
end
return (afterFlow and meta:get_int("industrialtest.powerAmount")>0)
end,
_industrialtest_electrocution=true,
_industrialtest_onPowerFlow=function(pos,side)
local meta=minetest.get_meta(pos)
industrialtest.api.changeIoConfig(meta,side,"i")
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
end,
"group:_industrialtest_hasPowerOutput",
"group:_industrialtest_cable"
}
}
if industrialtest.mtgAvailable then
definition.groups={
@@ -141,7 +103,6 @@ local function registerCable(name,displayName,size,flow,registerInsulated)
definition._mcl_hardness=0.5
definition.sound=mcl_sounds.node_sound_metal_defaults()
end
definition.groups._industrialtest_hasPowerInput=1
definition.groups._industrialtest_cable=1
minetest.register_node("industrialtest:"..name.."_cable",definition)
if registerInsulated then
@@ -150,7 +111,6 @@ local function registerCable(name,displayName,size,flow,registerInsulated)
definition.inventory_image="industrialtest_insulated_"..name.."_cable_inv.png"
definition.tiles={"industrialtest_insulated_"..name.."_cable.png"}
definition.wield_image="industrialtest_insulated_"..name.."_cable_inv.png"
definition._industrialtest_electrocution=nil
minetest.register_node("industrialtest:insulated_"..name.."_cable",definition)
end
end