Refactor cables
This commit is contained in:
parent
47b85df93c
commit
52f5a5c672
184
cables.lua
184
cables.lua
@ -15,27 +15,43 @@
|
|||||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
local S=minetest.get_translator("industrialtest")
|
local S=minetest.get_translator("industrialtest")
|
||||||
local cable={}
|
|
||||||
|
|
||||||
cable.onConstruct=function(pos)
|
industrialtest.Cable={}
|
||||||
|
|
||||||
|
function industrialtest.Cable.onConstruct(self,pos)
|
||||||
local connections=industrialtest.api.getConnections(pos)
|
local connections=industrialtest.api.getConnections(pos)
|
||||||
for _,conn in ipairs(connections) do
|
for _,conn in ipairs(connections) do
|
||||||
local meta=minetest.get_meta(conn)
|
local meta=minetest.get_meta(conn)
|
||||||
if industrialtest.api.isNetworkMaster(meta) then
|
if industrialtest.api.isNetworkMaster(meta) then
|
||||||
industrialtest.api.createNetworkMapForNode(conn)
|
industrialtest.api.createNetworkMapForNode(conn)
|
||||||
|
local networkNode=minetest.get_node(conn)
|
||||||
|
local def=minetest.registered_nodes[networkNode.name]
|
||||||
|
if def and def._industrialtest_self then
|
||||||
|
def._industrialtest_self:triggerIfNeeded(conn)
|
||||||
|
else
|
||||||
|
-- Support for bare definitions that don't use industrialtest pseudo-OOP
|
||||||
|
minetest.get_node_timer(conn):start(industrialtest.config.updateDelay)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
local networks=industrialtest.api.isAttachedToNetwork(meta)
|
local networks=industrialtest.api.isAttachedToNetwork(meta)
|
||||||
if networks then
|
if networks then
|
||||||
for _,network in ipairs(networks) do
|
for _,network in ipairs(networks) do
|
||||||
industrialtest.api.createNetworkMapForNode(network)
|
industrialtest.api.createNetworkMapForNode(network)
|
||||||
minetest.get_node_timer(network):start(industrialtest.updateDelay)
|
local networkNode=minetest.get_node(network)
|
||||||
|
local def=minetest.registered_nodes[networkNode.name]
|
||||||
|
if def and def._industrialtest_self then
|
||||||
|
def._industrialtest_self:triggerIfNeeded(network)
|
||||||
|
else
|
||||||
|
-- Support for bare definitions that don't use industrialtest pseudo-OOP
|
||||||
|
minetest.get_node_timer(network):start(industrialtest.config.updateDelay)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
cable.onDestruct=function(pos)
|
function industrialtest.Cable.onDestruct(self,pos)
|
||||||
local meta=minetest.get_meta(pos)
|
local meta=minetest.get_meta(pos)
|
||||||
local networks=industrialtest.api.isAttachedToNetwork(meta)
|
local networks=industrialtest.api.isAttachedToNetwork(meta)
|
||||||
if networks then
|
if networks then
|
||||||
@ -45,14 +61,16 @@ cable.onDestruct=function(pos)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function registerCable(name,displayName,size,flow,registerInsulated)
|
function industrialtest.Cable.createDefinitionTable(self,description,inventoryImage,tile,insulated)
|
||||||
local definition={
|
local size=(insulated and self.size+0.02 or self.size)
|
||||||
description=S(displayName.." Cable"),
|
local def={
|
||||||
inventory_image="industrialtest_"..name.."_cable_inv.png",
|
description=description,
|
||||||
tiles={"industrialtest_"..name.."_cable.png"},
|
inventory_image=inventoryImage,
|
||||||
wield_image="industrialtest_"..name.."_cable_inv.png",
|
wield_image=inventoryImage,
|
||||||
|
tiles={tile},
|
||||||
paramtype="light",
|
paramtype="light",
|
||||||
sunlight_propagates=true,
|
sunlight_propagates=true,
|
||||||
|
use_texture_alpha=(self.transparent and "clip" or "opaque"),
|
||||||
drawtype="nodebox",
|
drawtype="nodebox",
|
||||||
node_box={
|
node_box={
|
||||||
type="connected",
|
type="connected",
|
||||||
@ -118,39 +136,64 @@ local function registerCable(name,displayName,size,flow,registerInsulated)
|
|||||||
"group:_industrialtest_hasPowerOutput",
|
"group:_industrialtest_hasPowerOutput",
|
||||||
"group:_industrialtest_cable"
|
"group:_industrialtest_cable"
|
||||||
},
|
},
|
||||||
on_construct=cable.onConstruct,
|
on_construct=function(pos)
|
||||||
on_destruct=cable.onDestruct,
|
self:onConstruct(pos)
|
||||||
_industrialtest_cableFlow=flow
|
end,
|
||||||
|
on_destruct=function(pos)
|
||||||
|
self:onDestruct(pos)
|
||||||
|
end,
|
||||||
|
_industrialtest_cableFlow=self.flow
|
||||||
}
|
}
|
||||||
|
|
||||||
if industrialtest.mtgAvailable then
|
if industrialtest.mtgAvailable then
|
||||||
definition.groups={
|
def.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()
|
def.sound=default.node_sound_metal_defaults()
|
||||||
elseif industrialtest.mclAvailable then
|
elseif industrialtest.mclAvailable then
|
||||||
definition.groups={
|
def.groups={
|
||||||
handy=1,
|
handy=1,
|
||||||
pickaxey=1
|
pickaxey=1
|
||||||
}
|
}
|
||||||
definition._mcl_blast_resistance=1
|
def._mcl_blast_resistance=1
|
||||||
definition._mcl_hardness=0.5
|
def._mcl_hardness=0.5
|
||||||
definition.sound=mcl_sounds.node_sound_metal_defaults()
|
def.sound=mcl_sounds.node_sound_metal_defaults()
|
||||||
end
|
end
|
||||||
definition.groups._industrialtest_cable=1
|
def.groups._industrialtest_cable=1
|
||||||
minetest.register_node("industrialtest:"..name.."_cable",definition)
|
|
||||||
if registerInsulated then
|
return def
|
||||||
definition=table.copy(definition)
|
end
|
||||||
definition.description=S("Insulated "..displayName.." Cable")
|
|
||||||
definition.inventory_image="industrialtest_insulated_"..name.."_cable_inv.png"
|
function industrialtest.Cable.register(self)
|
||||||
definition.tiles={"industrialtest_insulated_"..name.."_cable.png"}
|
local def=self:createDefinitionTable(self.description,self.inventoryImage,self.tile,false)
|
||||||
definition.wield_image="industrialtest_insulated_"..name.."_cable_inv.png"
|
minetest.register_node(self.name,def)
|
||||||
minetest.register_node("industrialtest:insulated_"..name.."_cable",definition)
|
|
||||||
|
if self.insulated then
|
||||||
|
def=self:createDefinitionTable(self.insulated.description,self.insulated.inventoryImage,self.insulated.tile,true)
|
||||||
|
minetest.register_node(self.insulated.name,def)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
registerCable("tin","Tin",0.19,industrialtest.api.lvPowerFlow,true)
|
industrialtest.TinCable=table.copy(industrialtest.Cable)
|
||||||
|
industrialtest.internal.unpackTableInto(industrialtest.TinCable,{
|
||||||
|
name="industrialtest:tin_cable",
|
||||||
|
description=S("Tin Cable"),
|
||||||
|
inventoryImage="industrialtest_tin_cable_inv.png",
|
||||||
|
tile="industrialtest_tin_cable.png",
|
||||||
|
size=0.19,
|
||||||
|
flow=industrialtest.api.lvPowerFlow,
|
||||||
|
insulated={
|
||||||
|
name="industrialtest:insulated_tin_cable",
|
||||||
|
description=S("Insulated Tin Cable"),
|
||||||
|
inventoryImage="industrialtest_insulated_tin_cable_inv.png",
|
||||||
|
tile="industrialtest_insulated_tin_cable.png"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
industrialtest.TinCable:register()
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
type="shaped",
|
type="shaped",
|
||||||
output="industrialtest:tin_cable 6",
|
output="industrialtest:tin_cable 6",
|
||||||
@ -158,6 +201,7 @@ minetest.register_craft({
|
|||||||
{industrialtest.elementKeys.tinIngot,industrialtest.elementKeys.tinIngot,industrialtest.elementKeys.tinIngot}
|
{industrialtest.elementKeys.tinIngot,industrialtest.elementKeys.tinIngot,industrialtest.elementKeys.tinIngot}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
type="shapeless",
|
type="shapeless",
|
||||||
output="industrialtest:insulated_tin_cable",
|
output="industrialtest:insulated_tin_cable",
|
||||||
@ -166,6 +210,7 @@ minetest.register_craft({
|
|||||||
industrialtest.elementKeys.rubber
|
industrialtest.elementKeys.rubber
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
type="shaped",
|
type="shaped",
|
||||||
output="industrialtest:insulated_tin_cable 6",
|
output="industrialtest:insulated_tin_cable 6",
|
||||||
@ -175,13 +220,31 @@ minetest.register_craft({
|
|||||||
{industrialtest.elementKeys.rubber,industrialtest.elementKeys.rubber,industrialtest.elementKeys.rubber}
|
{industrialtest.elementKeys.rubber,industrialtest.elementKeys.rubber,industrialtest.elementKeys.rubber}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
industrialtest.api.registerCableFormerRecipe({
|
industrialtest.api.registerCableFormerRecipe({
|
||||||
output="industrialtest:tin_cable 12",
|
output="industrialtest:tin_cable 12",
|
||||||
recipe=industrialtest.elementKeys.tinIngot,
|
recipe=industrialtest.elementKeys.tinIngot,
|
||||||
time=1
|
time=1
|
||||||
})
|
})
|
||||||
|
|
||||||
registerCable("copper","Copper",0.15,industrialtest.api.mvPowerFlow,true)
|
industrialtest.CopperCable=table.copy(industrialtest.Cable)
|
||||||
|
industrialtest.internal.unpackTableInto(industrialtest.CopperCable,{
|
||||||
|
name="industrialtest:copper_cable",
|
||||||
|
description=S("Copper Cable"),
|
||||||
|
inventoryImage="industrialtest_copper_cable_inv.png",
|
||||||
|
tile="industrialtest_copper_cable.png",
|
||||||
|
size=0.15,
|
||||||
|
flow=industrialtest.api.mvPowerFlow,
|
||||||
|
insulated={
|
||||||
|
name="industrialtest:insulated_copper_cable",
|
||||||
|
description=S("Insulated Copper Cable"),
|
||||||
|
inventoryImage="industrialtest_insulated_copper_cable_inv.png",
|
||||||
|
tile="industrialtest_insulated_copper_cable.png"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
industrialtest.CopperCable:register()
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
type="shaped",
|
type="shaped",
|
||||||
output="industrialtest:copper_cable 6",
|
output="industrialtest:copper_cable 6",
|
||||||
@ -189,6 +252,7 @@ minetest.register_craft({
|
|||||||
{industrialtest.elementKeys.copperIngot,industrialtest.elementKeys.copperIngot,industrialtest.elementKeys.copperIngot}
|
{industrialtest.elementKeys.copperIngot,industrialtest.elementKeys.copperIngot,industrialtest.elementKeys.copperIngot}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
type="shapeless",
|
type="shapeless",
|
||||||
output="industrialtest:insulated_copper_cable",
|
output="industrialtest:insulated_copper_cable",
|
||||||
@ -197,6 +261,7 @@ minetest.register_craft({
|
|||||||
industrialtest.elementKeys.rubber
|
industrialtest.elementKeys.rubber
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
type="shaped",
|
type="shaped",
|
||||||
output="industrialtest:insulated_copper_cable 6",
|
output="industrialtest:insulated_copper_cable 6",
|
||||||
@ -206,12 +271,30 @@ minetest.register_craft({
|
|||||||
{industrialtest.elementKeys.rubber,industrialtest.elementKeys.rubber,industrialtest.elementKeys.rubber}
|
{industrialtest.elementKeys.rubber,industrialtest.elementKeys.rubber,industrialtest.elementKeys.rubber}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
industrialtest.api.registerCableFormerRecipe({
|
industrialtest.api.registerCableFormerRecipe({
|
||||||
output="industrialtest:copper_cable 12",
|
output="industrialtest:copper_cable 12",
|
||||||
recipe=industrialtest.elementKeys.copperIngot
|
recipe=industrialtest.elementKeys.copperIngot
|
||||||
})
|
})
|
||||||
|
|
||||||
registerCable("gold","Gold",0.15,industrialtest.api.hvPowerFlow,true)
|
industrialtest.GoldCable=table.copy(industrialtest.Cable)
|
||||||
|
industrialtest.internal.unpackTableInto(industrialtest.GoldCable,{
|
||||||
|
name="industrialtest:gold_cable",
|
||||||
|
description=S("Gold Cable"),
|
||||||
|
inventoryImage="industrialtest_gold_cable_inv.png",
|
||||||
|
tile="industrialtest_gold_cable.png",
|
||||||
|
size=0.15,
|
||||||
|
flow=industrialtest.api.hvPowerFlow,
|
||||||
|
insulated={
|
||||||
|
name="industrialtest:insulated_gold_cable",
|
||||||
|
description=S("Insulated Gold Cable"),
|
||||||
|
inventoryImage="industrialtest_insulated_gold_cable_inv.png",
|
||||||
|
tile="industrialtest_insulated_gold_cable.png"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
industrialtest.GoldCable:register()
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
type="shaped",
|
type="shaped",
|
||||||
output="industrialtest:gold_cable 6",
|
output="industrialtest:gold_cable 6",
|
||||||
@ -219,6 +302,7 @@ minetest.register_craft({
|
|||||||
{industrialtest.elementKeys.goldIngot,industrialtest.elementKeys.goldIngot,industrialtest.elementKeys.goldIngot}
|
{industrialtest.elementKeys.goldIngot,industrialtest.elementKeys.goldIngot,industrialtest.elementKeys.goldIngot}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
type="shapeless",
|
type="shapeless",
|
||||||
output="industrialtest:insulated_gold_cable",
|
output="industrialtest:insulated_gold_cable",
|
||||||
@ -227,6 +311,7 @@ minetest.register_craft({
|
|||||||
industrialtest.elementKeys.rubber
|
industrialtest.elementKeys.rubber
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
type="shaped",
|
type="shaped",
|
||||||
output="industrialtest:insulated_gold_cable 6",
|
output="industrialtest:insulated_gold_cable 6",
|
||||||
@ -236,12 +321,30 @@ minetest.register_craft({
|
|||||||
{industrialtest.elementKeys.rubber,industrialtest.elementKeys.rubber,industrialtest.elementKeys.rubber}
|
{industrialtest.elementKeys.rubber,industrialtest.elementKeys.rubber,industrialtest.elementKeys.rubber}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
industrialtest.api.registerCableFormerRecipe({
|
industrialtest.api.registerCableFormerRecipe({
|
||||||
output="industrialtest:gold_cable 12",
|
output="industrialtest:gold_cable 12",
|
||||||
recipe=industrialtest.elementKeys.goldIngot
|
recipe=industrialtest.elementKeys.goldIngot
|
||||||
})
|
})
|
||||||
|
|
||||||
registerCable("iron","Iron",0.15,industrialtest.api.evPowerFlow,true)
|
industrialtest.IronCable=table.copy(industrialtest.Cable)
|
||||||
|
industrialtest.internal.unpackTableInto(industrialtest.IronCable,{
|
||||||
|
name="industrialtest:iron_cable",
|
||||||
|
description=S("Iron Cable"),
|
||||||
|
inventoryImage="industrialtest_iron_cable_inv.png",
|
||||||
|
tile="industrialtest_iron_cable.png",
|
||||||
|
size=0.15,
|
||||||
|
flow=industrialtest.api.evPowerFlow,
|
||||||
|
insulated={
|
||||||
|
name="industrialtest:insulated_iron_cable",
|
||||||
|
description=S("Insulated Iron Cable"),
|
||||||
|
inventoryImage="industrialtest_insulated_iron_cable_inv.png",
|
||||||
|
tile="industrialtest_insulated_iron_cable.png"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
industrialtest.IronCable:register()
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
type="shaped",
|
type="shaped",
|
||||||
output="industrialtest:iron_cable 6",
|
output="industrialtest:iron_cable 6",
|
||||||
@ -249,6 +352,7 @@ minetest.register_craft({
|
|||||||
{"industrialtest:refined_iron_ingot","industrialtest:refined_iron_ingot","industrialtest:refined_iron_ingot"}
|
{"industrialtest:refined_iron_ingot","industrialtest:refined_iron_ingot","industrialtest:refined_iron_ingot"}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
type="shapeless",
|
type="shapeless",
|
||||||
output="industrialtest:insulated_iron_cable",
|
output="industrialtest:insulated_iron_cable",
|
||||||
@ -257,6 +361,7 @@ minetest.register_craft({
|
|||||||
industrialtest.elementKeys.rubber
|
industrialtest.elementKeys.rubber
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
type="shaped",
|
type="shaped",
|
||||||
output="industrialtest:insulated_iron_cable 6",
|
output="industrialtest:insulated_iron_cable 6",
|
||||||
@ -266,13 +371,26 @@ minetest.register_craft({
|
|||||||
{industrialtest.elementKeys.rubber,industrialtest.elementKeys.rubber,industrialtest.elementKeys.rubber}
|
{industrialtest.elementKeys.rubber,industrialtest.elementKeys.rubber,industrialtest.elementKeys.rubber}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
industrialtest.api.registerCableFormerRecipe({
|
industrialtest.api.registerCableFormerRecipe({
|
||||||
output="industrialtest:iron_cable 12",
|
output="industrialtest:iron_cable 12",
|
||||||
recipe="industrialtest:refined_iron_ingot",
|
recipe="industrialtest:refined_iron_ingot",
|
||||||
time=3
|
time=3
|
||||||
})
|
})
|
||||||
|
|
||||||
registerCable("glass_fibre","Glass Fibre",0.15,industrialtest.api.ivPowerFlow,false)
|
industrialtest.GlassFibreCable=table.copy(industrialtest.Cable)
|
||||||
|
industrialtest.internal.unpackTableInto(industrialtest.GlassFibreCable,{
|
||||||
|
name="industrialtest:glass_fibre_cable",
|
||||||
|
description=S("Glass Fibre Cable"),
|
||||||
|
inventoryImage="industrialtest_glass_fibre_cable_inv.png",
|
||||||
|
transparent=true,
|
||||||
|
tile="industrialtest_glass_fibre_cable.png",
|
||||||
|
size=0.12,
|
||||||
|
flow=industrialtest.api.ivPowerFlow
|
||||||
|
})
|
||||||
|
|
||||||
|
industrialtest.GlassFibreCable:register()
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
type="shaped",
|
type="shaped",
|
||||||
output="industrialtest:glass_fibre_cable 4",
|
output="industrialtest:glass_fibre_cable 4",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user