2012-03-05 19:21:26 +01:00
|
|
|
--MESECON TORCHES
|
|
|
|
|
2012-12-27 10:50:20 +01:00
|
|
|
local rotate_torch_rules = function (rules, param2)
|
|
|
|
if param2 == 5 then
|
2014-11-22 15:42:22 +01:00
|
|
|
return mesecon.rotate_rules_right(rules)
|
2012-12-27 10:50:20 +01:00
|
|
|
elseif param2 == 2 then
|
2014-11-22 15:42:22 +01:00
|
|
|
return mesecon.rotate_rules_right(mesecon.rotate_rules_right(rules)) --180 degrees
|
2012-12-27 10:50:20 +01:00
|
|
|
elseif param2 == 4 then
|
2014-11-22 15:42:22 +01:00
|
|
|
return mesecon.rotate_rules_left(rules)
|
2012-12-27 10:50:20 +01:00
|
|
|
elseif param2 == 1 then
|
2014-11-22 15:42:22 +01:00
|
|
|
return mesecon.rotate_rules_down(rules)
|
2012-12-27 10:50:20 +01:00
|
|
|
elseif param2 == 0 then
|
2014-11-22 15:42:22 +01:00
|
|
|
return mesecon.rotate_rules_up(rules)
|
2012-12-27 10:50:20 +01:00
|
|
|
else
|
|
|
|
return rules
|
2012-12-09 00:42:30 +01:00
|
|
|
end
|
2012-12-27 10:50:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local torch_get_output_rules = function(node)
|
|
|
|
local rules = {
|
|
|
|
{x = 1, y = 0, z = 0},
|
|
|
|
{x = 0, y = 0, z = 1},
|
|
|
|
{x = 0, y = 0, z =-1},
|
|
|
|
{x = 0, y = 1, z = 0},
|
|
|
|
{x = 0, y =-1, z = 0}}
|
|
|
|
|
|
|
|
return rotate_torch_rules(rules, node.param2)
|
2012-12-09 00:42:30 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local torch_get_input_rules = function(node)
|
2012-12-27 10:50:20 +01:00
|
|
|
local rules = {{x = -2, y = 0, z = 0},
|
|
|
|
{x = -1, y = 1, z = 0}}
|
2012-12-09 00:42:30 +01:00
|
|
|
|
2012-12-27 10:50:20 +01:00
|
|
|
return rotate_torch_rules(rules, node.param2)
|
2012-12-09 00:42:30 +01:00
|
|
|
end
|
|
|
|
|
2012-03-05 19:21:26 +01:00
|
|
|
minetest.register_craft({
|
2013-04-28 12:40:08 +02:00
|
|
|
output = "mesecons_torch:mesecon_torch_on 4",
|
2012-12-09 00:42:30 +01:00
|
|
|
recipe = {
|
2012-12-27 10:50:20 +01:00
|
|
|
{"group:mesecon_conductor_craftable"},
|
|
|
|
{"default:stick"},}
|
2012-03-05 19:21:26 +01:00
|
|
|
})
|
|
|
|
|
2012-12-27 10:50:20 +01:00
|
|
|
local torch_selectionbox =
|
|
|
|
{
|
|
|
|
type = "wallmounted",
|
|
|
|
wall_top = {-0.1, 0.5-0.6, -0.1, 0.1, 0.5, 0.1},
|
|
|
|
wall_bottom = {-0.1, -0.5, -0.1, 0.1, -0.5+0.6, 0.1},
|
|
|
|
wall_side = {-0.5, -0.1, -0.1, -0.5+0.6, 0.1, 0.1},
|
|
|
|
}
|
|
|
|
|
2012-03-05 19:21:26 +01:00
|
|
|
minetest.register_node("mesecons_torch:mesecon_torch_off", {
|
2012-12-09 00:42:30 +01:00
|
|
|
drawtype = "torchlike",
|
|
|
|
tiles = {"jeija_torches_off.png", "jeija_torches_off_ceiling.png", "jeija_torches_off_side.png"},
|
|
|
|
inventory_image = "jeija_torches_off.png",
|
|
|
|
paramtype = "light",
|
|
|
|
walkable = false,
|
|
|
|
paramtype2 = "wallmounted",
|
2012-12-27 10:50:20 +01:00
|
|
|
selection_box = torch_selectionbox,
|
|
|
|
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
|
|
|
|
drop = "mesecons_torch:mesecon_torch_on",
|
2012-12-09 00:42:30 +01:00
|
|
|
mesecons = {receptor = {
|
|
|
|
state = mesecon.state.off,
|
2012-12-27 10:50:20 +01:00
|
|
|
rules = torch_get_output_rules
|
2012-12-09 00:42:30 +01:00
|
|
|
}}
|
2012-03-05 19:21:26 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_node("mesecons_torch:mesecon_torch_on", {
|
2012-06-05 04:20:04 +02:00
|
|
|
drawtype = "torchlike",
|
2012-08-20 10:12:10 +02:00
|
|
|
tiles = {"jeija_torches_on.png", "jeija_torches_on_ceiling.png", "jeija_torches_on_side.png"},
|
2012-06-05 04:20:04 +02:00
|
|
|
inventory_image = "jeija_torches_on.png",
|
|
|
|
wield_image = "jeija_torches_on.png",
|
|
|
|
paramtype = "light",
|
|
|
|
sunlight_propagates = true,
|
|
|
|
walkable = false,
|
|
|
|
paramtype2 = "wallmounted",
|
2012-12-27 10:50:20 +01:00
|
|
|
selection_box = torch_selectionbox,
|
2012-12-09 00:42:30 +01:00
|
|
|
groups = {dig_immediate=3},
|
2015-05-11 06:28:56 +02:00
|
|
|
light_source = default.LIGHT_MAX-5,
|
2012-06-05 04:20:04 +02:00
|
|
|
description="Mesecon Torch",
|
2012-12-09 00:42:30 +01:00
|
|
|
mesecons = {receptor = {
|
|
|
|
state = mesecon.state.on,
|
2012-12-27 10:50:20 +01:00
|
|
|
rules = torch_get_output_rules
|
|
|
|
}},
|
2012-06-05 04:20:04 +02:00
|
|
|
})
|
2012-03-05 19:21:26 +01:00
|
|
|
|
|
|
|
minetest.register_abm({
|
2012-12-27 10:50:20 +01:00
|
|
|
nodenames = {"mesecons_torch:mesecon_torch_off","mesecons_torch:mesecon_torch_on"},
|
|
|
|
interval = 1,
|
|
|
|
chance = 1,
|
|
|
|
action = function(pos, node)
|
|
|
|
local is_powered = false
|
|
|
|
for _, rule in ipairs(torch_get_input_rules(node)) do
|
2014-11-22 15:42:22 +01:00
|
|
|
local src = mesecon.addPosRule(pos, rule)
|
|
|
|
if mesecon.is_power_on(src) then
|
2012-12-27 10:50:20 +01:00
|
|
|
is_powered = true
|
|
|
|
end
|
|
|
|
end
|
2012-03-29 11:35:23 +02:00
|
|
|
|
2012-12-27 10:50:20 +01:00
|
|
|
if is_powered then
|
|
|
|
if node.name == "mesecons_torch:mesecon_torch_on" then
|
2013-12-01 02:20:01 +01:00
|
|
|
minetest.swap_node(pos, {name = "mesecons_torch:mesecon_torch_off", param2 = node.param2})
|
2014-11-22 15:42:22 +01:00
|
|
|
mesecon.receptor_off(pos, torch_get_output_rules(node))
|
2012-12-27 10:50:20 +01:00
|
|
|
end
|
|
|
|
elseif node.name == "mesecons_torch:mesecon_torch_off" then
|
2013-12-01 02:20:01 +01:00
|
|
|
minetest.swap_node(pos, {name = "mesecons_torch:mesecon_torch_on", param2 = node.param2})
|
2014-11-22 15:42:22 +01:00
|
|
|
mesecon.receptor_on(pos, torch_get_output_rules(node))
|
2012-12-27 10:50:20 +01:00
|
|
|
end
|
|
|
|
end
|
2012-03-05 19:21:26 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
-- Param2 Table (Block Attached To)
|
|
|
|
-- 5 = z-1
|
|
|
|
-- 3 = x-1
|
|
|
|
-- 4 = z+1
|
|
|
|
-- 2 = x+1
|
|
|
|
-- 0 = y+1
|
|
|
|
-- 1 = y-1
|