From c0d3bd2abbeb8db0d640a604af1c9756f79f4881 Mon Sep 17 00:00:00 2001 From: Jeija Date: Thu, 13 Dec 2012 18:42:45 +0100 Subject: [PATCH] Include experimental vertical wires (needs textures) --- mesecons/internal.lua | 7 +- mesecons/presets.lua | 38 +++--- mesecons_extrawires/init.lua | 1 + mesecons_extrawires/tjunction.lua | 4 +- mesecons_extrawires/vertical.lua | 204 ++++++++++++++++++++++++++++++ mesecons_microcontroller/init.lua | 8 +- 6 files changed, 235 insertions(+), 27 deletions(-) create mode 100644 mesecons_extrawires/vertical.lua diff --git a/mesecons/internal.lua b/mesecons/internal.lua index 575bee3..0249728 100644 --- a/mesecons/internal.lua +++ b/mesecons/internal.lua @@ -281,7 +281,7 @@ function mesecon:turnon(pos) if mesecon:is_conductor_off(node.name) then local rules = mesecon:conductor_get_rules(node) - mesecon:swap_node(pos, mesecon:get_conductor_on(node.name)) + minetest.env:add_node(pos, {name = mesecon:get_conductor_on(node.name)}) for _, rule in ipairs(rules) do local np = mesecon:addPosRule(pos, rule) @@ -300,12 +300,12 @@ function mesecon:turnon(pos) end end -function mesecon:turnoff(pos) --receptor rules used because output could have been dug +function mesecon:turnoff(pos) local node = minetest.env:get_node(pos) if mesecon:is_conductor_on(node.name) then local rules = mesecon:conductor_get_rules(node) - mesecon:swap_node(pos, mesecon:get_conductor_off(node.name)) + minetest.env:add_node(pos, {name = mesecon:get_conductor_off(node.name)}) for _, rule in ipairs(rules) do local np = mesecon:addPosRule(pos, rule) @@ -363,7 +363,6 @@ end function mesecon:rules_link(output, input, dug_outputrules) --output/input are positions (outputrules optional, used if node has been dug) local outputnode = minetest.env:get_node(output) local inputnode = minetest.env:get_node(input) - local outputrules = dug_outputrules local inputrules diff --git a/mesecons/presets.lua b/mesecons/presets.lua index 9988d22..6c8d3ea 100644 --- a/mesecons/presets.lua +++ b/mesecons/presets.lua @@ -3,26 +3,32 @@ mesecon.state = {} mesecon.rules.default = {{x=0, y=0, z=-1}, -{x=1, y=0, z=0}, -{x=-1, y=0, z=0}, -{x=0, y=0, z=1}, -{x=1, y=1, z=0}, -{x=1, y=-1, z=0}, -{x=-1, y=1, z=0}, -{x=-1, y=-1, z=0}, -{x=0, y=1, z=1}, -{x=0, y=-1, z=1}, -{x=0, y=1, z=-1}, -{x=0, y=-1, z=-1}} + {x=1, y=0, z=0}, + {x=-1, y=0, z=0}, + {x=0, y=0, z=1}, + {x=1, y=1, z=0}, + {x=1, y=-1, z=0}, + {x=-1, y=1, z=0}, + {x=-1, y=-1, z=0}, + {x=0, y=1, z=1}, + {x=0, y=-1, z=1}, + {x=0, y=1, z=-1}, + {x=0, y=-1, z=-1}} mesecon.rules.buttonlike = {{x = 1, y = 0, z = 0}, -{x = 1, y = 1, z = 0}, -{x = 1, y =-1, z = 0}, -{x = 1, y =-1, z = 1}, -{x = 1, y =-1, z =-1}, -{x = 2, y = 0, z = 0}} + {x = 1, y = 1, z = 0}, + {x = 1, y =-1, z = 0}, + {x = 1, y =-1, z = 1}, + {x = 1, y =-1, z =-1}, + {x = 2, y = 0, z = 0}} +mesecon.rules.flat = +{{x = 1, y = 0, z = 0}, + {x =-1, y = 0, z = 0}, + {x = 0, y = 0, z = 1}, + {x = 0, y = 0, z =-1}} + mesecon.rules.buttonlike_get = function(node) local rules = mesecon.rules.buttonlike if node.param2 == 2 then diff --git a/mesecons_extrawires/init.lua b/mesecons_extrawires/init.lua index c9e0773..31dfcd2 100644 --- a/mesecons_extrawires/init.lua +++ b/mesecons_extrawires/init.lua @@ -1,3 +1,4 @@ -- dofile(minetest.get_modpath("mesecons_extrawires").."/crossing.lua"); -- The crossing code is not active right now because it is hard to maintain dofile(minetest.get_modpath("mesecons_extrawires").."/tjunction.lua"); +dofile(minetest.get_modpath("mesecons_extrawires").."/vertical.lua"); diff --git a/mesecons_extrawires/tjunction.lua b/mesecons_extrawires/tjunction.lua index 9f0c125..cb16cfb 100644 --- a/mesecons_extrawires/tjunction.lua +++ b/mesecons_extrawires/tjunction.lua @@ -41,7 +41,7 @@ minetest.register_node("mesecons_extrawires:tjunction_on", { sunlight_propagates = true, selection_box = tjunction_selectionbox, node_box = tjunction_nodebox, - groups = {dig_immediate = 3, mesecon = 3, mesecon_conductor_craftable=1, not_in_creative_inventory = 1}, + groups = {dig_immediate = 3, mesecon_conductor_craftable=1, not_in_creative_inventory = 1}, drop = "mesecons_insulated:insulated_off", mesecons = {conductor = { @@ -68,7 +68,7 @@ minetest.register_node("mesecons_extrawires:tjunction_off", { sunlight_propagates = true, selection_box = tjunction_selectionbox, node_box = tjunction_nodebox, - groups = {dig_immediate = 3, mesecon = 3, mesecon_conductor_craftable=1}, + groups = {dig_immediate = 3, mesecon_conductor_craftable=1}, mesecons = {conductor = { state = mesecon.state.off, diff --git a/mesecons_extrawires/vertical.lua b/mesecons_extrawires/vertical.lua new file mode 100644 index 0000000..64e6e80 --- /dev/null +++ b/mesecons_extrawires/vertical.lua @@ -0,0 +1,204 @@ +local vbox = { + type = "fixed", + fixed = {-1/16, -.5, -1/16, 1/16, .5, 1/16} +} + +local tbox = { + type = "fixed", + fixed = {{-.5, -.5, -.5, .5, -.5 + 1/16, .5}} +} + +local bbox = { + type = "fixed", + fixed = {{ -.5, -.5, -.5, .5, -.5+1/16, .5}, + {-1/16, -.5, -1/16, 1/16, .5 , 1/16}} +} + +local vrules = +{{x = 0, y = 1, z = 0}, + {x = 0, y =-1, z = 0}} + +local trules = +{{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 =-1, z = 0}} + +local brules = +{{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 = 1, z = 0}} + +local vertical_updatepos = function (pos) + local node = minetest.env:get_node(pos) + if minetest.registered_nodes[node.name].is_vertical_conductor then + local node_above = minetest.env:get_node(addPosRule(pos, vrules[1])) + local node_below = minetest.env:get_node(addPosRule(pos, vrules[2])) + local namestate = minetest.registered_nodes[node.name].vertical_conductor_state + + -- above and below: vertical mesecon + if minetest.registered_nodes[node_above.name].is_vertical_conductor + and minetest.registered_nodes[node_below.name].is_vertical_conductor then + minetest.env:add_node (pos, + {name = "mesecons_extrawires:vertical_"..namestate}) + + -- above only: bottom + elseif minetest.registered_nodes[node_above.name].is_vertical_conductor + and not minetest.registered_nodes[node_below.name].is_vertical_conductor then + minetest.env:add_node (pos, + {name = "mesecons_extrawires:vertical_bottom_"..namestate}) + + -- below only: top + elseif not minetest.registered_nodes[node_above.name].is_vertical_conductor + and minetest.registered_nodes[node_below.name].is_vertical_conductor then + minetest.env:add_node (pos, + {name = "mesecons_extrawires:vertical_top_"..namestate}) + else -- no vertical wire above, no vertical wire below: use default wire + minetest.env:add_node (pos, + {name = "mesecons_extrawires:vertical_"..namestate}) + end + end +end + +local vertical_update = function (pos, node) + print("update") + vertical_updatepos(pos) -- this one + vertical_updatepos(addPosRule(pos, vrules[1])) -- above + vertical_updatepos(addPosRule(pos, vrules[2])) -- below +end + +-- Vertical wire +minetest.register_node("mesecons_extrawires:vertical_on", { + description = "Vertical mesecon", + drawtype = "nodebox", + tiles = {"wires_vertical_on.png"}, + walkable = false, + paramtype = "light", + sunlight_propagates = true, + groups = {dig_immediate = 3}, + selection_box = vbox, + node_box = vbox, + is_vertical_conductor = true, + vertical_conductor_state = "on", + mesecons = {conductor = { + state = mesecon.state.on, + offstate = "mesecons_extrawires:vertical_off", + rules = vrules + }}, + drop = {"mesecons_extrawires:vertical_off"}, + after_place_node = vertical_update, + after_dig_node = vertical_update +}) + +minetest.register_node("mesecons_extrawires:vertical_off", { + description = "Vertical mesecon", + drawtype = "nodebox", + tiles = {"wires_vertical_off.png"}, + walkable = false, + paramtype = "light", + sunlight_propagates = true, + groups = {dig_immediate = 3}, + selection_box = vbox, + node_box = vbox, + is_vertical_conductor = true, + vertical_conductor_state = "off", + mesecons = {conductor = { + state = mesecon.state.off, + onstate = "mesecons_extrawires:vertical_on", + rules = vrules + }}, + after_place_node = vertical_update, + after_dig_node = vertical_update +}) + +-- Vertical wire top +minetest.register_node("mesecons_extrawires:vertical_top_on", { + description = "Vertical mesecon", + drawtype = "nodebox", + tiles = {"wires_vertical_on.png"}, + walkable = false, + paramtype = "light", + sunlight_propagates = true, + groups = {dig_immediate = 3}, + selection_box = tbox, + node_box = tbox, + is_vertical_conductor = true, + vertical_conductor_state = "on", + mesecons = {conductor = { + state = mesecon.state.on, + offstate = "mesecons_extrawires:vertical_top_off", + rules = trules + }}, + drop = {"mesecons_extrawires:vertical_off"}, + after_place_node = vertical_update, + after_dig_node = vertical_update +}) + +minetest.register_node("mesecons_extrawires:vertical_top_off", { + description = "Vertical mesecon", + drawtype = "nodebox", + tiles = {"wires_vertical_off.png"}, + walkable = false, + paramtype = "light", + sunlight_propagates = true, + groups = {dig_immediate = 3}, + selection_box = tbox, + node_box = tbox, + is_vertical_conductor = true, + vertical_conductor_state = "off", + mesecons = {conductor = { + state = mesecon.state.off, + onstate = "mesecons_extrawires:vertical_top_on", + rules = trules + }}, + drop = {"mesecons_extrawires:vertical_off"}, + after_place_node = vertical_update, + after_dig_node = vertical_update +}) + +-- Vertical wire bottom +minetest.register_node("mesecons_extrawires:vertical_bottom_on", { + description = "Vertical mesecon", + drawtype = "nodebox", + tiles = {"wires_vertical_on.png"}, + walkable = false, + paramtype = "light", + sunlight_propagates = true, + vertical_conductor_state = "on", + groups = {dig_immediate = 3}, + selection_box = bbox, + node_box = bbox, + mesecons = {conductor = { + state = mesecon.state.on, + offstate = "mesecons_extrawires:vertical_bottom_off", + rules = brules + }}, + drop = {"mesecons_extrawires:vertical_off"}, + after_place_node = vertical_update, + after_dig_node = vertical_update +}) + +minetest.register_node("mesecons_extrawires:vertical_bottom_off", { + description = "Vertical mesecon", + drawtype = "nodebox", + tiles = {"wires_vertical_off.png"}, + walkable = false, + paramtype = "light", + sunlight_propagates = true, + groups = {dig_immediate = 3}, + selection_box = bbox, + node_box = bbox, + is_vertical_conductor = true, + vertical_conductor_state = "off", + mesecons = {conductor = { + state = mesecon.state.off, + onstate = "mesecons_extrawires:vertical_bottom_on", + rules = brules + }}, + drop = {"mesecons_extrawires:vertical_off"}, + after_place_node = vertical_update, + after_dig_node = vertical_update +}) diff --git a/mesecons_microcontroller/init.lua b/mesecons_microcontroller/init.lua index a359d05..3117880 100644 --- a/mesecons_microcontroller/init.lua +++ b/mesecons_microcontroller/init.lua @@ -584,14 +584,12 @@ end --Real I/O functions function yc_action(pos, L) --L-->Lvirtual local Lv = yc_get_virtual_portstates(pos) - local metatable = minetest.env:get_meta(pos):to_table() local name = "mesecons_microcontroller:microcontroller" ..tonumber(L.d and 1 or 0) ..tonumber(L.c and 1 or 0) ..tonumber(L.b and 1 or 0) ..tonumber(L.a and 1 or 0) - minetest.env:add_node(pos, {name=name}) - minetest.env:get_meta(pos):from_table(metatable) + mesecon:swap_node(pos, name) yc_action_setports(pos, L, Lv) end @@ -630,7 +628,7 @@ function yc_set_portstate(port, state, L) return L end -function yc_get_real_portstates(pos) +function yc_get_real_portstates(pos) -- port powered or not (by itself or from outside)? rulesA = mesecon:get_rules("mesecons_microcontroller:microcontroller0001") rulesB = mesecon:get_rules("mesecons_microcontroller:microcontroller0010") rulesC = mesecon:get_rules("mesecons_microcontroller:microcontroller0100") @@ -644,7 +642,7 @@ function yc_get_real_portstates(pos) return L end -function yc_get_virtual_portstates(pos) +function yc_get_virtual_portstates(pos) -- portstates according to the name name = minetest.env:get_node(pos).name b, a = string.find(name, ":microcontroller") if a == nil then return nil end