forked from Mirrorlandia_minetest/mesecons
Vertical wire update.
This commit is contained in:
parent
e8d31c3e5a
commit
d9cc1d5aa1
@ -1,64 +1,68 @@
|
|||||||
local vbox = {
|
local vertical_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = {-1/16, -.5, -1/16, 1/16, .5, 1/16}
|
fixed = {-1/16, -8/16, -1/16, 1/16, 8/16, 1/16}
|
||||||
}
|
}
|
||||||
|
|
||||||
local tbox = {
|
local top_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = {{-.5, -.5, -.5, .5, -.5 + 1/16, .5}}
|
fixed = {{-8/16, -8/16, -8/16, 8/16, -7/16, 8/16}}
|
||||||
}
|
}
|
||||||
|
|
||||||
local bbox = {
|
local bottom_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = {{ -.5, -.5 , -.5, .5, -.5+1/16, .5},
|
fixed = {
|
||||||
{-1/16, -.5+1/16, -1/16, 1/16, .5 , 1/16}}
|
{-8/16, -8/16, -8/16, 8/16, -7/16, 8/16},
|
||||||
|
{-1/16, -7/16, -1/16, 1/16, 8/16, 1/16},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
local vrules =
|
local vertical_rules = {
|
||||||
{{x = 0, y = 1, z = 0},
|
{x=0, y=1, z=0},
|
||||||
{x = 0, y =-1, z = 0}}
|
{x=0, y=-1, z=0},
|
||||||
|
}
|
||||||
|
|
||||||
local trules =
|
local top_rules = {
|
||||||
{{x = 1, y = 0, z = 0},
|
{x=1,y=0, z=0},
|
||||||
{x =-1, y = 0, z = 0},
|
{x=-1,y=0, z=0},
|
||||||
{x = 0, y = 0, z = 1},
|
{x=0,y=0, z=1},
|
||||||
{x = 0, y = 0, z =-1},
|
{x=0,y=0, z=-1},
|
||||||
{x = 0, y =-1, z = 0}}
|
{x=0,y=-1, z=0},
|
||||||
|
}
|
||||||
|
|
||||||
local brules =
|
local bottom_rules = {
|
||||||
{{x = 1, y = 0, z = 0},
|
{x=1, y=0, z=0},
|
||||||
{x =-1, y = 0, z = 0},
|
{x=-1, y=0, z=0},
|
||||||
{x = 0, y = 0, z = 1},
|
{x=0, y=0, z=1},
|
||||||
{x = 0, y = 0, z =-1},
|
{x=0, y=0, z=-1},
|
||||||
{x = 0, y = 1, z = 0}}
|
{x=0, y=1, z=0},
|
||||||
|
}
|
||||||
|
|
||||||
local vertical_updatepos = function (pos)
|
local vertical_updatepos = function (pos)
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
if minetest.registered_nodes[node.name]
|
if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].is_vertical_conductor then
|
||||||
and minetest.registered_nodes[node.name].is_vertical_conductor then
|
local node_above = minetest.get_node(mesecon:addPosRule(pos, vertical_rules[1]))
|
||||||
local node_above = minetest.get_node(mesecon:addPosRule(pos, vrules[1]))
|
local node_below = minetest.get_node(mesecon:addPosRule(pos, vertical_rules[2]))
|
||||||
local node_below = minetest.get_node(mesecon:addPosRule(pos, vrules[2]))
|
|
||||||
local namestate = minetest.registered_nodes[node.name].vertical_conductor_state
|
local namestate = minetest.registered_nodes[node.name].vertical_conductor_state
|
||||||
|
|
||||||
local above = minetest.registered_nodes[node_above.name] and minetest.registered_nodes[node_above.name].is_vertical_conductor
|
local above = minetest.registered_nodes[node_above.name] and minetest.registered_nodes[node_above.name].is_vertical_conductor
|
||||||
local below = minetest.registered_nodes[node_below.name] and minetest.registered_nodes[node_below.name].is_vertical_conductor
|
local below = minetest.registered_nodes[node_below.name] and minetest.registered_nodes[node_below.name].is_vertical_conductor
|
||||||
|
|
||||||
if above and below then -- above and below: vertical mesecon
|
if above and below then -- above and below: vertical mesecon
|
||||||
minetest.add_node(pos, {name = "mesecons_extrawires:vertical_"..namestate})
|
minetest.add_node(pos, {name = "mesecons_extrawires:vertical_" .. namestate})
|
||||||
elseif above and not below then -- above only: bottom
|
elseif above and not below then -- above only: bottom
|
||||||
minetest.add_node(pos, {name = "mesecons_extrawires:vertical_bottom_"..namestate})
|
minetest.add_node(pos, {name = "mesecons_extrawires:vertical_bottom_" .. namestate})
|
||||||
elseif not above and below then -- below only: top
|
elseif not above and below then -- below only: top
|
||||||
minetest.add_node(pos, {name = "mesecons_extrawires:vertical_top_"..namestate})
|
minetest.add_node(pos, {name = "mesecons_extrawires:vertical_top_" .. namestate})
|
||||||
else -- no vertical wire above, no vertical wire below: use default wire
|
else -- no vertical wire above, no vertical wire below: use default wire
|
||||||
minetest.add_node(pos, {name = "mesecons_extrawires:vertical_"..namestate})
|
minetest.add_node(pos, {name = "mesecons_extrawires:vertical_" .. namestate})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local vertical_update = function (pos, node)
|
local vertical_update = function (pos, node)
|
||||||
vertical_updatepos(pos) -- this one
|
vertical_updatepos(pos) -- this one
|
||||||
vertical_updatepos(mesecon:addPosRule(pos, vrules[1])) -- above
|
vertical_updatepos(mesecon:addPosRule(pos, vertical_rules[1])) -- above
|
||||||
vertical_updatepos(mesecon:addPosRule(pos, vrules[2])) -- below
|
vertical_updatepos(mesecon:addPosRule(pos, vertical_rules[2])) -- below
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Vertical wire
|
-- Vertical wire
|
||||||
@ -69,19 +73,19 @@ minetest.register_node("mesecons_extrawires:vertical_on", {
|
|||||||
walkable = false,
|
walkable = false,
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
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 = vbox,
|
selection_box = vertical_box,
|
||||||
node_box = vbox,
|
node_box = vertical_box,
|
||||||
is_vertical_conductor = true,
|
is_vertical_conductor = true,
|
||||||
vertical_conductor_state = "on",
|
vertical_conductor_state = "on",
|
||||||
mesecons = {conductor = {
|
mesecons = {conductor = {
|
||||||
state = mesecon.state.on,
|
state = mesecon.state.on,
|
||||||
offstate = "mesecons_extrawires:vertical_off",
|
offstate = "mesecons_extrawires:vertical_off",
|
||||||
rules = vrules
|
rules = vertical_rules,
|
||||||
}},
|
}},
|
||||||
drop = "mesecons_extrawires:vertical_off",
|
drop = "mesecons_extrawires:vertical_off",
|
||||||
after_place_node = vertical_update,
|
after_place_node = vertical_update,
|
||||||
after_dig_node = vertical_update
|
after_dig_node = vertical_update,
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node("mesecons_extrawires:vertical_off", {
|
minetest.register_node("mesecons_extrawires:vertical_off", {
|
||||||
@ -91,18 +95,18 @@ minetest.register_node("mesecons_extrawires:vertical_off", {
|
|||||||
walkable = false,
|
walkable = false,
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
sunlight_propagates = true,
|
sunlight_propagates = true,
|
||||||
groups = {dig_immediate = 3},
|
groups = {dig_immediate=3},
|
||||||
selection_box = vbox,
|
selection_box = vertical_box,
|
||||||
node_box = vbox,
|
node_box = vertical_box,
|
||||||
is_vertical_conductor = true,
|
is_vertical_conductor = true,
|
||||||
vertical_conductor_state = "off",
|
vertical_conductor_state = "off",
|
||||||
mesecons = {conductor = {
|
mesecons = {conductor = {
|
||||||
state = mesecon.state.off,
|
state = mesecon.state.off,
|
||||||
onstate = "mesecons_extrawires:vertical_on",
|
onstate = "mesecons_extrawires:vertical_on",
|
||||||
rules = vrules
|
rules = vertical_rules,
|
||||||
}},
|
}},
|
||||||
after_place_node = vertical_update,
|
after_place_node = vertical_update,
|
||||||
after_dig_node = vertical_update
|
after_dig_node = vertical_update,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Vertical wire top
|
-- Vertical wire top
|
||||||
@ -113,19 +117,19 @@ minetest.register_node("mesecons_extrawires:vertical_top_on", {
|
|||||||
walkable = false,
|
walkable = false,
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
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 = tbox,
|
selection_box = top_box,
|
||||||
node_box = tbox,
|
node_box = top_box,
|
||||||
is_vertical_conductor = true,
|
is_vertical_conductor = true,
|
||||||
vertical_conductor_state = "on",
|
vertical_conductor_state = "on",
|
||||||
mesecons = {conductor = {
|
mesecons = {conductor = {
|
||||||
state = mesecon.state.on,
|
state = mesecon.state.on,
|
||||||
offstate = "mesecons_extrawires:vertical_top_off",
|
offstate = "mesecons_extrawires:vertical_top_off",
|
||||||
rules = trules
|
rules = top_rules,
|
||||||
}},
|
}},
|
||||||
drop = "mesecons_extrawires:vertical_off",
|
drop = "mesecons_extrawires:vertical_off",
|
||||||
after_place_node = vertical_update,
|
after_place_node = vertical_update,
|
||||||
after_dig_node = vertical_update
|
after_dig_node = vertical_update,
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node("mesecons_extrawires:vertical_top_off", {
|
minetest.register_node("mesecons_extrawires:vertical_top_off", {
|
||||||
@ -135,19 +139,19 @@ minetest.register_node("mesecons_extrawires:vertical_top_off", {
|
|||||||
walkable = false,
|
walkable = false,
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
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 = tbox,
|
selection_box = top_box,
|
||||||
node_box = tbox,
|
node_box = top_box,
|
||||||
is_vertical_conductor = true,
|
is_vertical_conductor = true,
|
||||||
vertical_conductor_state = "off",
|
vertical_conductor_state = "off",
|
||||||
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 = trules
|
rules = top_rules,
|
||||||
}},
|
}},
|
||||||
drop = "mesecons_extrawires:vertical_off",
|
drop = "mesecons_extrawires:vertical_off",
|
||||||
after_place_node = vertical_update,
|
after_place_node = vertical_update,
|
||||||
after_dig_node = vertical_update
|
after_dig_node = vertical_update,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Vertical wire bottom
|
-- Vertical wire bottom
|
||||||
@ -160,16 +164,16 @@ minetest.register_node("mesecons_extrawires:vertical_bottom_on", {
|
|||||||
sunlight_propagates = true,
|
sunlight_propagates = true,
|
||||||
vertical_conductor_state = "on",
|
vertical_conductor_state = "on",
|
||||||
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
|
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
|
||||||
selection_box = bbox,
|
selection_box = bottom_box,
|
||||||
node_box = bbox,
|
node_box = bottom_box,
|
||||||
mesecons = {conductor = {
|
mesecons = {conductor = {
|
||||||
state = mesecon.state.on,
|
state = mesecon.state.on,
|
||||||
offstate = "mesecons_extrawires:vertical_bottom_off",
|
offstate = "mesecons_extrawires:vertical_bottom_off",
|
||||||
rules = brules
|
rules = bottom_rules,
|
||||||
}},
|
}},
|
||||||
drop = "mesecons_extrawires:vertical_off",
|
drop = "mesecons_extrawires:vertical_off",
|
||||||
after_place_node = vertical_update,
|
after_place_node = vertical_update,
|
||||||
after_dig_node = vertical_update
|
after_dig_node = vertical_update,
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node("mesecons_extrawires:vertical_bottom_off", {
|
minetest.register_node("mesecons_extrawires:vertical_bottom_off", {
|
||||||
@ -180,18 +184,18 @@ minetest.register_node("mesecons_extrawires:vertical_bottom_off", {
|
|||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
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 = bbox,
|
selection_box = bottom_box,
|
||||||
node_box = bbox,
|
node_box = bottom_box,
|
||||||
is_vertical_conductor = true,
|
is_vertical_conductor = true,
|
||||||
vertical_conductor_state = "off",
|
vertical_conductor_state = "off",
|
||||||
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 = brules
|
rules = bottom_rules,
|
||||||
}},
|
}},
|
||||||
drop = "mesecons_extrawires:vertical_off",
|
drop = "mesecons_extrawires:vertical_off",
|
||||||
after_place_node = vertical_update,
|
after_place_node = vertical_update,
|
||||||
after_dig_node = vertical_update
|
after_dig_node = vertical_update,
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
|
Loading…
Reference in New Issue
Block a user