Mess around with electricity a bit
This commit is contained in:
parent
0e87b2c9a2
commit
b2e0b10214
@ -93,12 +93,12 @@ PyuTest.make_node("pyutest_blocks:tnt", "TNT", {
|
||||
end)
|
||||
end,
|
||||
|
||||
__on_electricity_activated = function(pos, node, clicker, sender_pos)
|
||||
__on_electricity_activated = function(pos, node, sender_pos)
|
||||
minetest.after(3, function()
|
||||
if minetest.get_node(pos).name ~= "pyutest_blocks:tnt" then
|
||||
return
|
||||
end
|
||||
PyuTest.create_explosion(pos, 3, true, 7, clicker, true)
|
||||
PyuTest.create_explosion(pos, 3, true, 7)
|
||||
end)
|
||||
end,
|
||||
})
|
||||
|
1
mods/ITEMS/pyutest_electricity/components.lua
Normal file
1
mods/ITEMS/pyutest_electricity/components.lua
Normal file
@ -0,0 +1 @@
|
||||
-- Nodes that can power other nodes
|
@ -6,7 +6,7 @@ local delay_multipliers = {
|
||||
}
|
||||
|
||||
local function index_name(n)
|
||||
if n == 1 then
|
||||
if n == 1 or n == nil then
|
||||
return "pyutest_electricity:zinc_wire"
|
||||
else
|
||||
return string.format("pyutest_electricity:zinc_wire_%d", n)
|
||||
@ -18,6 +18,7 @@ for i, v in ipairs(delay_multipliers) do
|
||||
snappy = PyuTest.BLOCK_NORMAL,
|
||||
not_in_creative_inventory = i ~= 1 and 1 or nil
|
||||
}, "#bed3d4", {
|
||||
drop = index_name(),
|
||||
on_rightclick = function (pos, node, clicker)
|
||||
local ni = v
|
||||
|
||||
@ -29,15 +30,11 @@ for i, v in ipairs(delay_multipliers) do
|
||||
|
||||
minetest.set_node(pos, {name = index_name(ni)})
|
||||
end
|
||||
}, function(def, pos, node, clicker, sender_pos)
|
||||
minetest.after(PyuTest.ELECTRICITY_TICK * v, function()
|
||||
def.__on_electricity_activated(pos, node, clicker, sender_pos)
|
||||
end)
|
||||
end, string.format("pyutest-wire-d%d.png", i))
|
||||
}, string.format("pyutest-wire-d%d.png", i), v)
|
||||
end
|
||||
|
||||
minetest.register_craft({
|
||||
output = string.format("%s 4", index_name(1)),
|
||||
output = string.format("%s 4", index_name()),
|
||||
recipe = {
|
||||
"pyutest_ores:zinc_ingot"
|
||||
},
|
||||
|
@ -1,6 +1,8 @@
|
||||
-- Nodes that are to be powered by other nodes
|
||||
|
||||
PyuTest.make_electricity_device("pyutest_electricity:freezer_device", "Freezer Device", {
|
||||
cracky = PyuTest.BLOCK_FAST
|
||||
}, {"pyutest-freezer.png"}, "pyutest_blocks:ice_block", nil, function (pos, node, clicker, sender_pos)
|
||||
}, {"pyutest-freezer.png"}, "pyutest_blocks:ice_block", nil, function (pos, node, sender_pos)
|
||||
PyuTest.dorange(pos, 2, function(p)
|
||||
local n = minetest.get_node(p)
|
||||
|
||||
@ -16,7 +18,7 @@ end)
|
||||
|
||||
PyuTest.make_electricity_device("pyutest_electricity:heater_device", "Heater Device", {
|
||||
cracky = PyuTest.BLOCK_FAST
|
||||
}, {"pyutest-heater.png"}, "pyutest_blocks:fire", nil, function (pos, node, clicker, sender_pos)
|
||||
}, {"pyutest-heater.png"}, "pyutest_blocks:fire", nil, function (pos, node, sender_pos)
|
||||
PyuTest.dorange(pos, 2, function(p)
|
||||
local n = minetest.get_node(p)
|
||||
|
||||
@ -35,7 +37,7 @@ end)
|
||||
|
||||
PyuTest.make_electricity_device("pyutest_electricity:lamp_device", "Lamp Device", {
|
||||
cracky = PyuTest.BLOCK_FAST,
|
||||
}, {"pyutest-lamp.png"}, "pyutest_blocks:light", nil, function (pos, node, clicker, sender_pos)
|
||||
}, {"pyutest-lamp.png"}, "pyutest_blocks:light", nil, function (pos, node, sender_pos)
|
||||
minetest.set_node(pos, {name = "pyutest_electricity:lamp_device_on"})
|
||||
end)
|
||||
|
||||
@ -45,6 +47,6 @@ PyuTest.make_electricity_device("pyutest_electricity:lamp_device_on", "Lamp Devi
|
||||
}, {"pyutest-lamp.png"}, nil, {
|
||||
light_source = minetest.LIGHT_MAX,
|
||||
drop = "pyutest_electricity:lamp_device"
|
||||
}, function (pos, node, clicker, sender_pos)
|
||||
}, function (pos, node, sender_pos)
|
||||
minetest.set_node(pos, {name = "pyutest_electricity:lamp_device"})
|
||||
end)
|
||||
|
@ -2,6 +2,14 @@ local modpath = minetest.get_modpath("pyutest_electricity")
|
||||
|
||||
PyuTest.ELECTRICITY_TICK = 1 / 1000
|
||||
|
||||
PyuTest.electricity_activate = function(pos, node, sender_pos)
|
||||
local def = minetest.registered_nodes[node.name]
|
||||
|
||||
if def.__on_electricity_activated then
|
||||
def.__on_electricity_activated(pos, node, sender_pos)
|
||||
end
|
||||
end
|
||||
|
||||
PyuTest.make_button = function(id, desc, groups, tiles)
|
||||
PyuTest.make_node(id, desc, PyuTest.util.tableconcat(groups, {
|
||||
electric = 1
|
||||
@ -15,21 +23,16 @@ PyuTest.make_button = function(id, desc, groups, tiles)
|
||||
|
||||
for _, v in pairs(PyuTest.get_neighbours(pos)) do
|
||||
local n = minetest.get_node(v)
|
||||
local def = minetest.registered_nodes[n.name]
|
||||
minetest.after(PyuTest.ELECTRICITY_TICK, function()
|
||||
if def.__on_electricity_activated then
|
||||
def.__on_electricity_activated(v, n, clicker, pos)
|
||||
end
|
||||
PyuTest.electricity_activate(v, n, pos)
|
||||
end)
|
||||
end
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
PyuTest.make_wire = function(id, desc, groups, color, opts, efn, texture)
|
||||
local fn = efn or function(def, pos, node, clicker, sender_pos)
|
||||
def.__on_electricity_activated(pos, node, clicker, sender_pos)
|
||||
end
|
||||
PyuTest.make_wire = function(id, desc, groups, color, opts, texture, delay)
|
||||
local del = PyuTest.ELECTRICITY_TICK * delay
|
||||
|
||||
PyuTest.make_node(id, desc, PyuTest.util.tableconcat(groups, {
|
||||
electric = 1
|
||||
@ -46,20 +49,17 @@ PyuTest.make_wire = function(id, desc, groups, color, opts, efn, texture)
|
||||
walkable = false,
|
||||
inventory_image = "pyutest-wire.png",
|
||||
|
||||
__on_electricity_activated = function(pos, node, clicker, sender_pos)
|
||||
__on_electricity_activated = function(pos, node, sender_pos)
|
||||
for _, v in pairs(PyuTest.get_neighbours(pos)) do
|
||||
local n = minetest.get_node(v)
|
||||
local def = minetest.registered_nodes[n.name]
|
||||
|
||||
-- To prevent infinite loops
|
||||
if v == sender_pos then
|
||||
goto continue
|
||||
end
|
||||
|
||||
minetest.after(PyuTest.ELECTRICITY_TICK, function()
|
||||
if def.__on_electricity_activated then
|
||||
fn(def, v, n, clicker, pos)
|
||||
end
|
||||
minetest.after(tonumber(del), function()
|
||||
PyuTest.electricity_activate(v, n, sender_pos)
|
||||
end)
|
||||
|
||||
::continue::
|
||||
@ -68,11 +68,11 @@ PyuTest.make_wire = function(id, desc, groups, color, opts, efn, texture)
|
||||
}))
|
||||
end
|
||||
|
||||
PyuTest.make_electricity_device = function(id, desc, groups, tiles, craftitem, opts, eafn)
|
||||
PyuTest.make_electricity_device = function(id, desc, groups, tiles, craftitem, opts, afn)
|
||||
PyuTest.make_node(id, desc, PyuTest.util.tableconcat(groups, {
|
||||
electric = 1
|
||||
}), tiles, PyuTest.util.tableconcat(opts or {}, {
|
||||
__on_electricity_activated = eafn
|
||||
__on_electricity_activated = afn,
|
||||
}))
|
||||
|
||||
-- Dont create a recipe if it is nil
|
||||
@ -94,7 +94,7 @@ PyuTest.make_button("pyutest_electricity:button", "Button", {
|
||||
|
||||
PyuTest.make_wire("pyutest_electricity:copper_wire", "Copper Wire", {
|
||||
snappy = PyuTest.BLOCK_NORMAL
|
||||
}, "darkgoldenrod")
|
||||
}, "darkgoldenrod", nil, nil, 1)
|
||||
|
||||
|
||||
minetest.register_craft({
|
||||
@ -116,3 +116,4 @@ minetest.register_craft({
|
||||
|
||||
dofile(modpath.."/devices.lua")
|
||||
dofile(modpath.."/delayer.lua")
|
||||
dofile(modpath.."/components.lua")
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 139 B After Width: | Height: | Size: 139 B |
Loading…
x
Reference in New Issue
Block a user