forked from mrkubax10/industrialtest
Add insulated copper cable
This commit is contained in:
parent
ad502c257c
commit
97247bdac1
49
cables.lua
49
cables.lua
@ -94,18 +94,39 @@ local function registerCable(name,displayName,material,size,flow)
|
|||||||
end,
|
end,
|
||||||
on_timer=function(pos)
|
on_timer=function(pos)
|
||||||
local meta=minetest.get_meta(pos)
|
local meta=minetest.get_meta(pos)
|
||||||
local afterFlow,_=industrialtest.api.powerFlow(pos)
|
local afterFlow,transferred=industrialtest.api.powerFlow(pos)
|
||||||
meta:set_string("industrialtest.ioConfig","aaaaaa")
|
meta:set_string("industrialtest.ioConfig","aaaaaa")
|
||||||
if not industrialtest.api.isFullyCharged(meta) then
|
if not industrialtest.api.isFullyCharged(meta) then
|
||||||
industrialtest.api.triggerNeighbours(pos)
|
industrialtest.api.triggerNeighbours(pos)
|
||||||
end
|
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)
|
return (afterFlow and meta:get_int("industrialtest.powerAmount")>0)
|
||||||
end,
|
end,
|
||||||
|
_industrialtest_electrocution=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={
|
||||||
@ -149,6 +170,30 @@ local function registerCable(name,displayName,material,size,flow)
|
|||||||
{material,material,material}
|
{material,material,material}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
definition=table.copy(definition)
|
||||||
|
definition.description=S("Insulated "..displayName.." Cable")
|
||||||
|
definition.inventory_image="industrialtest_insulated_"..name.."_cable_inv.png"
|
||||||
|
definition.tiles={"industrialtest_insulated_copper_cable.png"}
|
||||||
|
definition.wield_image="industrialtest_insulated_"..name.."_cable_inv.png"
|
||||||
|
definition._industrialtest_electrocution=nil
|
||||||
|
minetest.register_node("industrialtest:insulated_"..name.."_cable",definition)
|
||||||
|
minetest.register_craft({
|
||||||
|
type="shapeless",
|
||||||
|
output="industrialtest:insulated_"..name.."_cable",
|
||||||
|
recipe={
|
||||||
|
"industrialtest:"..name.."_cable",
|
||||||
|
"industrialtest:rubber"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
minetest.register_craft({
|
||||||
|
type="shaped",
|
||||||
|
output="industrialtest:insulated_"..name.."_cable 6",
|
||||||
|
recipe={
|
||||||
|
{"industrialtest:rubber","industrialtest:rubber","industrialtest:rubber"},
|
||||||
|
{"industrialtest:"..name.."_ingot","industrialtest:"..name.."_ingot","industrialtest:"..name.."_ingot"},
|
||||||
|
{"industrialtest:rubber","industrialtest:rubber","industrialtest:rubber"}
|
||||||
|
}
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
registerCable("copper","Copper",industrialtest.elementKeys.copperIngot,0.15,216)
|
registerCable("copper","Copper",industrialtest.elementKeys.copperIngot,0.15,216)
|
||||||
|
Loading…
Reference in New Issue
Block a user