Use nodebox for rendering cables

This commit is contained in:
mrkubax10 2023-03-11 19:50:49 +01:00
parent 4e7499279c
commit 7ce091f423
5 changed files with 149 additions and 42 deletions

16
api.lua
View File

@ -131,13 +131,15 @@ industrialtest.api.powerFlow=function(pos)
transferred=true transferred=true
end end
local def=minetest.registered_nodes[minetest.get_node(neighbourPositions[key]).name] local def=minetest.registered_nodes[minetest.get_node(neighbourPositions[key]).name]
local updateFormspec=def._industrialtest_updateFormspec if def then
if updateFormspec then local updateFormspec=def._industrialtest_updateFormspec
updateFormspec(value) if updateFormspec then
end updateFormspec(value)
local onPowerFlow=def._industrialtest_onPowerFlow end
if onPowerFlow and transferred then local onPowerFlow=def._industrialtest_onPowerFlow
onPowerFlow(neighbourPositions[key],industrialtest.api.getOppositeSide(key)) if onPowerFlow and transferred then
onPowerFlow(neighbourPositions[key],industrialtest.api.getOppositeSide(key))
end
end end
minetest.get_node_timer(neighbourPositions[key]):start(industrialtest.updateDelay) minetest.get_node_timer(neighbourPositions[key]):start(industrialtest.updateDelay)
if not industrialtest.api.isFullyCharged(value) then if not industrialtest.api.isFullyCharged(value) then

View File

@ -16,39 +16,139 @@
local S=minetest.get_translator("industrialtest") local S=minetest.get_translator("industrialtest")
local definition={ local function registerCable(name,displayName,material,size,flow)
description=S("Copper Cable"), local definition={
tiles={"industrialtest_copper_cable.png"}, description=S(displayName.." Cable"),
on_construct=function(pos) inventory_image="industrialtest_"..name.."_cable_inv.png",
local meta=minetest.get_meta(pos) tiles={"industrialtest_"..name.."_cable.png"},
industrialtest.api.addPowerStorage(meta,390,390,"aaaaaa") wield_image="industrialtest_"..name.."_cable_inv.png",
end, paramtype="light",
on_timer=function(pos) sunlight_propagates=true,
local meta=minetest.get_meta(pos) drawtype="nodebox",
local afterFlow,_=industrialtest.api.powerFlow(pos) node_box={
meta:set_string("industrialtest.ioConfig","aaaaaa") type="connected",
if not industrialtest.api.isFullyCharged(meta) then fixed={
industrialtest.api.triggerNeighbours(pos) -size,
-size,
-size,
size,
size,
size
},
connect_top={
-size,
-size,
-size,
size,
0.5,
size
},
connect_bottom={
-size,
-0.5,
-size,
size,
size,
size
},
connect_front={
-size,
-size,
-0.5,
size,
size,
size,
},
connect_left={
-0.5,
-size,
-size,
size,
size,
size
},
connect_back={
-size,
-size,
-size,
size,
size,
0.5
},
connect_right={
-size,
-size,
-size,
0.5,
size,
size
}
},
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,_=industrialtest.api.powerFlow(pos)
meta:set_string("industrialtest.ioConfig","aaaaaa")
if not industrialtest.api.isFullyCharged(meta) then
industrialtest.api.triggerNeighbours(pos)
end
return (afterFlow and meta:get_int("industrialtest.powerAmount")>0)
end,
_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 end
return (afterFlow and meta:get_int("industrialtest.api.powerAmount")>0)
end,
_industrialtest_hasPowerInput=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
}
if industrialtest.mtgAvailable then
definition.groups={
cracky=1,
level=1,
oddly_breakable_by_hand=1
} }
definition.sound=default.node_sound_metal_defaults() if industrialtest.mtgAvailable then
elseif industrialtest.mclAvailable then definition.groups={
definition.groups={pickaxey=1} cracky=1,
definition._mcl_blast_resistance=1 level=1,
definition._mcl_hardness=0.5 oddly_breakable_by_hand=1
}
definition.sound=default.node_sound_metal_defaults()
elseif industrialtest.mclAvailable then
definition.groups={pickaxey=1}
definition._mcl_blast_resistance=1
definition._mcl_hardness=0.5
definition.sound=mcl_sounds.node_sound_metal_defaults()
end
definition.groups._industrialtest_hasPowerInput=1
minetest.register_node("industrialtest:"..name.."_cable",definition)
minetest.register_craft({
type="shaped",
output="industrialtest:"..name.."_cable 6",
recipe={
{material,material,material},
{"","",""},
{"","",""}
}
})
minetest.register_craft({
type="shaped",
output="industrialtest:"..name.."_cable 6",
recipe={
{"","",""},
{material,material,material},
{"","",""}
}
})
minetest.register_craft({
type="shaped",
output="industrialtest:"..name.."_cable 6",
recipe={
{"","",""},
{"","",""},
{material,material,material}
}
})
end end
minetest.register_node("industrialtest:copper_cable",definition)
registerCable("copper","Copper",industrialtest.elementKeys.copperIngot,0.15,216)

View File

@ -480,6 +480,7 @@ if industrialtest.mclAvailable then
-- assign element keys for elements that are required later -- assign element keys for elements that are required later
industrialtest.elementKeys.stick="mcl_core:stick" industrialtest.elementKeys.stick="mcl_core:stick"
industrialtest.elementKeys.ironIngot="mcl_core:iron_ingot" industrialtest.elementKeys.ironIngot="mcl_core:iron_ingot"
industrialtest.elementKeys.copperIngot="mcl_copper:copper_ingot"
industrialtest.elementKeys.powerCarrier="mesecons:mesecon" industrialtest.elementKeys.powerCarrier="mesecons:mesecon"
industrialtest.elementKeys.furnace="mcl_furnaces:furnace" industrialtest.elementKeys.furnace="mcl_furnaces:furnace"
@ -642,6 +643,7 @@ elseif industrialtest.mtgAvailable then
industrialtest.elementKeys.tinIngot="default:tin_ingot" industrialtest.elementKeys.tinIngot="default:tin_ingot"
industrialtest.elementKeys.bronzeIngot="default:bronze_ingot" industrialtest.elementKeys.bronzeIngot="default:bronze_ingot"
industrialtest.elementKeys.ironIngot="default:steel_ingot" industrialtest.elementKeys.ironIngot="default:steel_ingot"
industrialtest.elementKeys.copperIngot="default:copper_ingot"
industrialtest.elementKeys.stick="default:stick" industrialtest.elementKeys.stick="default:stick"
industrialtest.elementKeys.powerCarrier="default:mese_crystal_fragment" industrialtest.elementKeys.powerCarrier="default:mese_crystal_fragment"
industrialtest.elementKeys.furnace="default:furnace" industrialtest.elementKeys.furnace="default:furnace"

View File

@ -173,10 +173,12 @@ elseif industrialtest.mclAvailable then
definition.after_dig_node=function(pos,oldnode,oldmeta) definition.after_dig_node=function(pos,oldnode,oldmeta)
mclAfterDigNode(pos,oldmeta,{"charged","fuel"}) mclAfterDigNode(pos,oldmeta,{"charged","fuel"})
end end
definition.groups={pickaxey=1}
definition.sounds=mcl_sounds.node_sound_metal_defaults() definition.sounds=mcl_sounds.node_sound_metal_defaults()
definition._mcl_blast_resistance=3.5 definition._mcl_blast_resistance=3.5
definition._mcl_hardness=3.9 definition._mcl_hardness=3.9
end end
definition.groups._industrialtest_hasPowerOutput=1
minetest.register_node("industrialtest:generator",definition) minetest.register_node("industrialtest:generator",definition)
minetest.register_craft({ minetest.register_craft({
type="shaped", type="shaped",
@ -647,7 +649,6 @@ definition={
end end
end end
end, end,
_industrialtest_hasPowerInput=true,
_industrialtest_updateFormspec=function(meta) _industrialtest_updateFormspec=function(meta)
meta:set_string("formspec",electricFurnaceFormspec(meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity")*100,meta:get_float("srcTime")/meta:get_float("maxSrcTime")*100)) meta:set_string("formspec",electricFurnaceFormspec(meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity")*100,meta:get_float("srcTime")/meta:get_float("maxSrcTime")*100))
end end
@ -667,10 +668,12 @@ elseif industrialtest.mclAvailable then
definition.after_dig_node=function(pos,oldnode,oldmeta) definition.after_dig_node=function(pos,oldnode,oldmeta)
mclAfterDigNode(pos,oldmeta,{"src","powerStorage","dst","upgrades"}) mclAfterDigNode(pos,oldmeta,{"src","powerStorage","dst","upgrades"})
end end
definition.groups={pickaxey=1}
definition.sounds=mcl_sounds.node_sound_metal_defaults() definition.sounds=mcl_sounds.node_sound_metal_defaults()
definition._mcl_blast_resistance=3 definition._mcl_blast_resistance=3
definition._mcl_hardness=3.5 definition._mcl_hardness=3.5
end end
definition.groups._industrialtest_hasPowerInput=1
minetest.register_node("industrialtest:electric_furnace",definition) minetest.register_node("industrialtest:electric_furnace",definition)
minetest.register_craft({ minetest.register_craft({
type="shaped", type="shaped",

View File

@ -42,7 +42,7 @@ minetest.register_craft({
-- Node callbacks -- Node callbacks
minetest.register_on_placenode(function(pos,newNode) minetest.register_on_placenode(function(pos,newNode)
local def=minetest.registered_nodes[newNode.name] local def=minetest.registered_nodes[newNode.name]
if def and def._industrialtest_hasPowerInput then if def and def.groups and def.groups._industrialtest_hasPowerInput then
industrialtest.api.triggerNeighbours(pos) industrialtest.api.triggerNeighbours(pos)
end end
end) end)