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

View File

@ -131,6 +131,7 @@ 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]
if def then
local updateFormspec=def._industrialtest_updateFormspec local updateFormspec=def._industrialtest_updateFormspec
if updateFormspec then if updateFormspec then
updateFormspec(value) updateFormspec(value)
@ -139,6 +140,7 @@ industrialtest.api.powerFlow=function(pos)
if onPowerFlow and transferred then if onPowerFlow and transferred then
onPowerFlow(neighbourPositions[key],industrialtest.api.getOppositeSide(key)) 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
roomAvailable=true roomAvailable=true

View File

@ -16,12 +16,81 @@
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"),
inventory_image="industrialtest_"..name.."_cable_inv.png",
tiles={"industrialtest_"..name.."_cable.png"},
wield_image="industrialtest_"..name.."_cable_inv.png",
paramtype="light",
sunlight_propagates=true,
drawtype="nodebox",
node_box={
type="connected",
fixed={
-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) on_construct=function(pos)
local meta=minetest.get_meta(pos) local meta=minetest.get_meta(pos)
industrialtest.api.addPowerStorage(meta,390,390,"aaaaaa") industrialtest.api.addPowerStorage(meta,flow,flow,"aaaaaa")
end, end,
on_timer=function(pos) on_timer=function(pos)
local meta=minetest.get_meta(pos) local meta=minetest.get_meta(pos)
@ -30,25 +99,56 @@ local definition={
if not industrialtest.api.isFullyCharged(meta) then if not industrialtest.api.isFullyCharged(meta) then
industrialtest.api.triggerNeighbours(pos) industrialtest.api.triggerNeighbours(pos)
end end
return (afterFlow and meta:get_int("industrialtest.api.powerAmount")>0) return (afterFlow and meta:get_int("industrialtest.powerAmount")>0)
end, end,
_industrialtest_hasPowerInput=true,
_industrialtest_onPowerFlow=function(pos,side) _industrialtest_onPowerFlow=function(pos,side)
local meta=minetest.get_meta(pos) local meta=minetest.get_meta(pos)
industrialtest.api.changeIoConfig(meta,side,"i") industrialtest.api.changeIoConfig(meta,side,"i")
minetest.get_node_timer(pos):start(industrialtest.updateDelay) minetest.get_node_timer(pos):start(industrialtest.updateDelay)
end end
} }
if industrialtest.mtgAvailable then if industrialtest.mtgAvailable then
definition.groups={ definition.groups={
cracky=1, cracky=1,
level=1, level=1,
oddly_breakable_by_hand=1 oddly_breakable_by_hand=1
} }
definition.sound=default.node_sound_metal_defaults() definition.sound=default.node_sound_metal_defaults()
elseif industrialtest.mclAvailable then elseif industrialtest.mclAvailable then
definition.groups={pickaxey=1} definition.groups={pickaxey=1}
definition._mcl_blast_resistance=1 definition._mcl_blast_resistance=1
definition._mcl_hardness=0.5 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)