mirror of
https://github.com/minetest-mods/mesecons.git
synced 2025-01-30 18:00:19 +01:00
add static middle vertical wire
This commit is contained in:
parent
75bd1e8be6
commit
15a95bbf38
@ -1,3 +1,3 @@
|
|||||||
name = mesecons_extrawires
|
name = mesecons_extrawires
|
||||||
depends = default, mesecons
|
depends = default, mesecons, mesecons_insulated
|
||||||
optional_depends = screwdriver
|
optional_depends = screwdriver
|
||||||
|
@ -38,38 +38,82 @@ local bottom_rules = {
|
|||||||
{x=0, y=2, z=0} -- receive power from pressure plate / detector / ... 2 nodes above
|
{x=0, y=2, z=0} -- receive power from pressure plate / detector / ... 2 nodes above
|
||||||
}
|
}
|
||||||
|
|
||||||
local vertical_updatepos = function (pos)
|
local static_middle_rules_unrotated_normal = {
|
||||||
local node = minetest.get_node(pos)
|
{x=1, y=0, z=0},
|
||||||
if minetest.registered_nodes[node.name]
|
{x=-1, y=0, z=0},
|
||||||
and minetest.registered_nodes[node.name].is_vertical_conductor then
|
{x=0, y=0, z=1},
|
||||||
local node_above = minetest.get_node(vector.add(pos, vertical_rules[1]))
|
{x=0, y=0, z=-1},
|
||||||
local node_below = minetest.get_node(vector.add(pos, vertical_rules[2]))
|
{x=0, y=1, z=0},
|
||||||
|
{x=0, y=2, z=0}, -- receive power from pressure plate / detector / ... 2 nodes above
|
||||||
local above = minetest.registered_nodes[node_above.name]
|
{x=0, y=-1, z=0},
|
||||||
and minetest.registered_nodes[node_above.name].is_vertical_conductor
|
}
|
||||||
local below = minetest.registered_nodes[node_below.name]
|
local static_middle_rules_unrotated_minimum = {
|
||||||
and minetest.registered_nodes[node_below.name].is_vertical_conductor
|
{x=0, y=1, z=0},
|
||||||
|
{x=0, y=2, z=0}, -- receive power from pressure plate / detector / ... 2 nodes above
|
||||||
mesecon.on_dignode(pos, node)
|
{x=0, y=-1, z=0},
|
||||||
|
}
|
||||||
-- Always place offstate conductor and let mesecon.on_placenode take care
|
local function static_middle_rules(node)
|
||||||
local newname = "mesecons_extrawires:vertical_"
|
if node.param2 == 1 then
|
||||||
if above and below then -- above and below: vertical mesecon
|
return static_middle_rules_unrotated_normal
|
||||||
newname = newname .. "off"
|
end
|
||||||
elseif above and not below then -- above only: bottom
|
-- rotate static_middle_rules_unrotated_minimum
|
||||||
newname = newname .. "bottom_off"
|
local r = mesecon.rotate_rules_up(static_middle_rules_unrotated_minimum)
|
||||||
elseif not above and below then -- below only: top
|
if node.param2 == 0 then -- upside down
|
||||||
newname = newname .. "top_off"
|
return mesecon.rotate_rules_up(r)
|
||||||
else -- no vertical wire above, no vertical wire below: use bottom
|
elseif node.param2 == 2 then
|
||||||
newname = newname .. "bottom_off"
|
return mesecon.rotate_rules_left(mesecon.rotate_rules_left(r))
|
||||||
end
|
elseif node.param2 == 3 then
|
||||||
|
return r
|
||||||
minetest.set_node(pos, {name = newname})
|
elseif node.param2 == 4 then
|
||||||
mesecon.on_placenode(pos, {name = newname})
|
return mesecon.rotate_rules_left(r)
|
||||||
|
else
|
||||||
|
return mesecon.rotate_rules_right(r)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local vertical_update = function (pos, node)
|
local function is_dynamic_vertical_wire(node)
|
||||||
|
local nodedef = minetest.registered_nodes[node.name]
|
||||||
|
return nodedef and nodedef.is_vertical_conductor
|
||||||
|
end
|
||||||
|
|
||||||
|
local function is_vertical_conductor(node)
|
||||||
|
if node.name ~= "mesecons_extrawires:vertical_static_middle_off" and
|
||||||
|
node.name ~= "mesecons_extrawires:vertical_static_middle_on" then
|
||||||
|
return is_dynamic_vertical_wire(node)
|
||||||
|
end
|
||||||
|
return node.param2 == 1 or node.param2 == 0
|
||||||
|
end
|
||||||
|
|
||||||
|
local function vertical_updatepos(pos)
|
||||||
|
local node = minetest.get_node(pos)
|
||||||
|
if not is_dynamic_vertical_wire(node) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local node_above = minetest.get_node(vector.add(pos, vertical_rules[1]))
|
||||||
|
local node_below = minetest.get_node(vector.add(pos, vertical_rules[2]))
|
||||||
|
|
||||||
|
local above = is_vertical_conductor(node_above)
|
||||||
|
local below = is_vertical_conductor(node_below)
|
||||||
|
|
||||||
|
mesecon.on_dignode(pos, node)
|
||||||
|
|
||||||
|
-- Always place offstate conductor and let mesecon.on_placenode take care
|
||||||
|
local newname = "mesecons_extrawires:vertical_"
|
||||||
|
if above and below then -- above and below: vertical mesecon
|
||||||
|
newname = newname .. "off"
|
||||||
|
elseif above and not below then -- above only: bottom
|
||||||
|
newname = newname .. "bottom_off"
|
||||||
|
elseif not above and below then -- below only: top
|
||||||
|
newname = newname .. "top_off"
|
||||||
|
else -- no vertical wire above, no vertical wire below: use bottom
|
||||||
|
newname = newname .. "bottom_off"
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.set_node(pos, {name = newname})
|
||||||
|
mesecon.on_placenode(pos, {name = newname})
|
||||||
|
end
|
||||||
|
|
||||||
|
local function vertical_update(pos)
|
||||||
vertical_updatepos(pos) -- this one
|
vertical_updatepos(pos) -- this one
|
||||||
vertical_updatepos(vector.add(pos, vertical_rules[1])) -- above
|
vertical_updatepos(vector.add(pos, vertical_rules[1])) -- above
|
||||||
vertical_updatepos(vector.add(pos, vertical_rules[2])) -- below
|
vertical_updatepos(vector.add(pos, vertical_rules[2])) -- below
|
||||||
@ -90,17 +134,17 @@ mesecon.register_node("mesecons_extrawires:vertical", {
|
|||||||
after_place_node = vertical_update,
|
after_place_node = vertical_update,
|
||||||
after_dig_node = vertical_update,
|
after_dig_node = vertical_update,
|
||||||
sounds = default.node_sound_defaults(),
|
sounds = default.node_sound_defaults(),
|
||||||
},{
|
}, {
|
||||||
tiles = {"mesecons_wire_off.png"},
|
tiles = {"mesecons_wire_off.png"},
|
||||||
groups = {dig_immediate=3},
|
groups = {dig_immediate = 3},
|
||||||
mesecons = {conductor = {
|
mesecons = {conductor = {
|
||||||
state = mesecon.state.off,
|
state = mesecon.state.off,
|
||||||
onstate = "mesecons_extrawires:vertical_on",
|
onstate = "mesecons_extrawires:vertical_on",
|
||||||
rules = vertical_rules,
|
rules = vertical_rules,
|
||||||
}}
|
}}
|
||||||
},{
|
}, {
|
||||||
tiles = {"mesecons_wire_on.png"},
|
tiles = {"mesecons_wire_on.png"},
|
||||||
groups = {dig_immediate=3, not_in_creative_inventory=1},
|
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
|
||||||
mesecons = {conductor = {
|
mesecons = {conductor = {
|
||||||
state = mesecon.state.on,
|
state = mesecon.state.on,
|
||||||
offstate = "mesecons_extrawires:vertical_off",
|
offstate = "mesecons_extrawires:vertical_off",
|
||||||
@ -116,7 +160,7 @@ mesecon.register_node("mesecons_extrawires:vertical_top", {
|
|||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
is_ground_content = false,
|
is_ground_content = false,
|
||||||
sunlight_propagates = true,
|
sunlight_propagates = true,
|
||||||
groups = {dig_immediate=3, not_in_creative_inventory=1},
|
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
|
||||||
selection_box = top_box,
|
selection_box = top_box,
|
||||||
node_box = top_box,
|
node_box = top_box,
|
||||||
is_vertical_conductor = true,
|
is_vertical_conductor = true,
|
||||||
@ -124,14 +168,14 @@ mesecon.register_node("mesecons_extrawires:vertical_top", {
|
|||||||
after_place_node = vertical_update,
|
after_place_node = vertical_update,
|
||||||
after_dig_node = vertical_update,
|
after_dig_node = vertical_update,
|
||||||
sounds = default.node_sound_defaults(),
|
sounds = default.node_sound_defaults(),
|
||||||
},{
|
}, {
|
||||||
tiles = {"mesecons_wire_off.png"},
|
tiles = {"mesecons_wire_off.png"},
|
||||||
mesecons = {conductor = {
|
mesecons = {conductor = {
|
||||||
state = mesecon.state.off,
|
state = mesecon.state.off,
|
||||||
onstate = "mesecons_extrawires:vertical_top_on",
|
onstate = "mesecons_extrawires:vertical_top_on",
|
||||||
rules = top_rules,
|
rules = top_rules,
|
||||||
}}
|
}}
|
||||||
},{
|
}, {
|
||||||
tiles = {"mesecons_wire_on.png"},
|
tiles = {"mesecons_wire_on.png"},
|
||||||
mesecons = {conductor = {
|
mesecons = {conductor = {
|
||||||
state = mesecon.state.on,
|
state = mesecon.state.on,
|
||||||
@ -156,15 +200,17 @@ mesecon.register_node("mesecons_extrawires:vertical_bottom", {
|
|||||||
after_place_node = vertical_update,
|
after_place_node = vertical_update,
|
||||||
after_dig_node = vertical_update,
|
after_dig_node = vertical_update,
|
||||||
sounds = default.node_sound_defaults(),
|
sounds = default.node_sound_defaults(),
|
||||||
},{
|
}, {
|
||||||
tiles = {"mesecons_wire_off.png"},
|
tiles = {"mesecons_wire_off.png", "jeija_insulated_wire_sides_off.png",
|
||||||
|
"mesecons_wire_off.png"},
|
||||||
mesecons = {conductor = {
|
mesecons = {conductor = {
|
||||||
state = mesecon.state.off,
|
state = mesecon.state.off,
|
||||||
onstate = "mesecons_extrawires:vertical_bottom_on",
|
onstate = "mesecons_extrawires:vertical_bottom_on",
|
||||||
rules = bottom_rules,
|
rules = bottom_rules,
|
||||||
}}
|
}}
|
||||||
},{
|
}, {
|
||||||
tiles = {"mesecons_wire_on.png"},
|
tiles = {"mesecons_wire_on.png", "jeija_insulated_wire_sides_on.png",
|
||||||
|
"mesecons_wire_on.png"},
|
||||||
mesecons = {conductor = {
|
mesecons = {conductor = {
|
||||||
state = mesecon.state.on,
|
state = mesecon.state.on,
|
||||||
offstate = "mesecons_extrawires:vertical_bottom_off",
|
offstate = "mesecons_extrawires:vertical_bottom_off",
|
||||||
@ -172,6 +218,53 @@ mesecon.register_node("mesecons_extrawires:vertical_bottom", {
|
|||||||
}}
|
}}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- Static vertical wire middle
|
||||||
|
mesecon.register_node("mesecons_extrawires:vertical_static_middle", {
|
||||||
|
description = "Static middle vertical mesecon",
|
||||||
|
drawtype = "nodebox",
|
||||||
|
walkable = false,
|
||||||
|
paramtype = "light",
|
||||||
|
paramtype2 = "wallmounted", -- yes, rotatable
|
||||||
|
place_param2 = 1, -- but no automatic rotation
|
||||||
|
node_placement_prediction = "", -- also no client-side automatic rotation
|
||||||
|
is_ground_content = false,
|
||||||
|
sunlight_propagates = true,
|
||||||
|
selection_box = bottom_box,
|
||||||
|
node_box = bottom_box,
|
||||||
|
after_place_node = vertical_update,
|
||||||
|
after_dig_node = vertical_update,
|
||||||
|
sounds = default.node_sound_defaults(),
|
||||||
|
on_rotate = minetest.global_exists("screwdriver") and function(pos, node, _, mode, _)
|
||||||
|
if mode == screwdriver.ROTATE_FACE then -- left click
|
||||||
|
node.param2 = node.param2 + 1
|
||||||
|
else -- right click
|
||||||
|
node.param2 = node.param2 - 1
|
||||||
|
end
|
||||||
|
node.param2 = node.param2 % 6
|
||||||
|
minetest.swap_node(pos, node)
|
||||||
|
vertical_update(pos)
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
}, {
|
||||||
|
groups = {dig_immediate = 3},
|
||||||
|
tiles = {"mesecons_wire_off.png"},
|
||||||
|
mesecons = {conductor = {
|
||||||
|
state = mesecon.state.off,
|
||||||
|
onstate = "mesecons_extrawires:vertical_static_middle_on",
|
||||||
|
rules = static_middle_rules,
|
||||||
|
}}
|
||||||
|
}, {
|
||||||
|
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
|
||||||
|
tiles = {"mesecons_wire_on.png"},
|
||||||
|
mesecons = {conductor = {
|
||||||
|
state = mesecon.state.on,
|
||||||
|
offstate = "mesecons_extrawires:vertical_static_middle_off",
|
||||||
|
rules = static_middle_rules,
|
||||||
|
}}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
-- crafting
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "mesecons_extrawires:vertical_off 3",
|
output = "mesecons_extrawires:vertical_off 3",
|
||||||
recipe = {
|
recipe = {
|
||||||
@ -185,3 +278,17 @@ minetest.register_craft({
|
|||||||
output = "mesecons:wire_00000000_off",
|
output = "mesecons:wire_00000000_off",
|
||||||
recipe = {{"mesecons_extrawires:vertical_off"}}
|
recipe = {{"mesecons_extrawires:vertical_off"}}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
minetest.register_craft({
|
||||||
|
output = "mesecons_extrawires:vertical_static_middle_off 5",
|
||||||
|
recipe = {
|
||||||
|
{"", "mesecons_extrawires:vertical_off", ""},
|
||||||
|
{"", "mesecons_extrawires:vertical_off", ""},
|
||||||
|
{"mesecons_extrawires:vertical_off", "mesecons_extrawires:vertical_off", "mesecons_extrawires:vertical_off"}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_craft({
|
||||||
|
output = "mesecons_extrawires:vertical_off",
|
||||||
|
recipe = {{"mesecons_extrawires:vertical_static_middle_off"}}
|
||||||
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user