diff options
-rw-r--r-- | mesecons/init.lua | 3 | ||||
-rw-r--r-- | mesecons/services.lua | 11 | ||||
-rw-r--r-- | mesecons/textures/jeija_close_window.png | bin | 0 -> 323 bytes | |||
-rw-r--r-- | mesecons/textures/jeija_microcontroller_bottom.png | bin | 0 -> 550 bytes | |||
-rw-r--r-- | mesecons/textures/jeija_microcontroller_sides.png | bin | 0 -> 613 bytes | |||
-rw-r--r-- | mesecons/util.lua | 31 | ||||
-rw-r--r-- | mesecons_mvps/init.lua | 1 | ||||
-rw-r--r-- | mesecons_random/init.lua | 2 | ||||
-rw-r--r-- | mesecons_receiver/init.lua | 10 | ||||
-rw-r--r-- | mesecons_wires/depends.txt | 1 | ||||
-rw-r--r-- | mesecons_wires/doc/mesecon/description.html | 1 | ||||
-rwxr-xr-x | mesecons_wires/doc/mesecon/preview.png | bin | 0 -> 29946 bytes | |||
-rw-r--r-- | mesecons_wires/doc/mesecon/recipe.png | bin | 0 -> 3932 bytes | |||
-rw-r--r-- | mesecons_wires/init.lua | 247 | ||||
-rw-r--r-- | player_textures/textures/player_Jordach.png | bin | 2955 -> 1992 bytes |
15 files changed, 288 insertions, 19 deletions
diff --git a/mesecons/init.lua b/mesecons/init.lua index 3ab4f4a..6b36e69 100644 --- a/mesecons/init.lua +++ b/mesecons/init.lua @@ -132,8 +132,5 @@ print("[OK] Mesecons") -- To be removed in future releases dofile(minetest.get_modpath("mesecons").."/legacy.lua"); ---The actual wires -dofile(minetest.get_modpath("mesecons").."/wires.lua"); - --Services like turnoff receptor on dignode and so on dofile(minetest.get_modpath("mesecons").."/services.lua"); diff --git a/mesecons/services.lua b/mesecons/services.lua index 343410a..1abbc0c 100644 --- a/mesecons/services.lua +++ b/mesecons/services.lua @@ -1,7 +1,7 @@ -- Dig and place services -mesecon.on_placenode = function (pos, node) - mesecon.update_autoconnect(pos, node) +mesecon.on_placenode = function(pos, node) + mesecon.execute_autoconnect_hooks_now(pos, node) -- Receptors: Send on signal when active if mesecon.is_receptor_on(node.name) then @@ -52,16 +52,15 @@ mesecon.on_placenode = function (pos, node) end end -mesecon.on_dignode = function (pos, node) +mesecon.on_dignode = function(pos, node) if mesecon.is_conductor_on(node) then mesecon.receptor_off(pos, mesecon.conductor_get_rules(node)) elseif mesecon.is_receptor_on(node.name) then mesecon.receptor_off(pos, mesecon.receptor_get_rules(node)) end - mesecon.queue:add_action(pos, "update_autoconnect", {node}) -end -mesecon.queue:add_function("update_autoconnect", mesecon.update_autoconnect) + mesecon.execute_autoconnect_hooks_queue(pos, node) +end minetest.register_on_placenode(mesecon.on_placenode) minetest.register_on_dignode(mesecon.on_dignode) diff --git a/mesecons/textures/jeija_close_window.png b/mesecons/textures/jeija_close_window.png Binary files differnew file mode 100644 index 0000000..5c27c6c --- /dev/null +++ b/mesecons/textures/jeija_close_window.png diff --git a/mesecons/textures/jeija_microcontroller_bottom.png b/mesecons/textures/jeija_microcontroller_bottom.png Binary files differnew file mode 100644 index 0000000..3a9161e --- /dev/null +++ b/mesecons/textures/jeija_microcontroller_bottom.png diff --git a/mesecons/textures/jeija_microcontroller_sides.png b/mesecons/textures/jeija_microcontroller_sides.png Binary files differnew file mode 100644 index 0000000..b367644 --- /dev/null +++ b/mesecons/textures/jeija_microcontroller_sides.png diff --git a/mesecons/util.lua b/mesecons/util.lua index 3827dce..d95f216 100644 --- a/mesecons/util.lua +++ b/mesecons/util.lua @@ -273,3 +273,34 @@ mesecon.forceloaded_blocks = mesecon.file2table("mesecon_forceloaded") minetest.register_on_shutdown(function() mesecon.table2file("mesecon_forceloaded", mesecon.forceloaded_blocks) end) + +-- Autoconnect Hooks +-- Nodes like conductors may change their appearance and their connection rules +-- right after being placed or after being dug, e.g. the default wires use this +-- to automatically connect to linking nodes after placement. +-- After placement, the update function will be executed immediately so that the +-- possibly changed rules can be taken into account when recalculating the circuit. +-- After digging, the update function will be queued and executed after +-- recalculating the circuit. The update function must take care of updating the +-- node at the given position itself, but also all of the other nodes the given +-- position may have (had) a linking connection to. +mesecon.autoconnect_hooks = {} + +-- name: A unique name for the hook, e.g. "foowire". Used to name the actionqueue function. +-- fct: The update function with parameters function(pos, node) +function mesecon.register_autoconnect_hook(name, fct) + mesecon.autoconnect_hooks[name] = fct + mesecon.queue:add_function("autoconnect_hook_"..name, fct) +end + +function mesecon.execute_autoconnect_hooks_now(pos, node) + for _, fct in pairs(mesecon.autoconnect_hooks) do + fct(pos, node) + end +end + +function mesecon.execute_autoconnect_hooks_queue(pos, node) + for name in pairs(mesecon.autoconnect_hooks) do + mesecon.queue:add_action(pos, "autoconnect_hook_"..name, {node}) + end +end diff --git a/mesecons_mvps/init.lua b/mesecons_mvps/init.lua index 1707408..2c6161b 100644 --- a/mesecons_mvps/init.lua +++ b/mesecons_mvps/init.lua @@ -200,7 +200,6 @@ end mesecon.register_on_mvps_move(function(moved_nodes) for _, n in ipairs(moved_nodes) do mesecon.on_placenode(n.pos, n.node) - mesecon.update_autoconnect(n.pos) end end) diff --git a/mesecons_random/init.lua b/mesecons_random/init.lua index e37886b..4c1d299 100644 --- a/mesecons_random/init.lua +++ b/mesecons_random/init.lua @@ -9,7 +9,7 @@ minetest.register_node("mesecons_random:removestone", { mesecons = {effector = { action_on = function (pos, node) minetest.remove_node(pos) - mesecon.update_autoconnect(pos) + mesecon.on_dignode(pos, node) end }} }) diff --git a/mesecons_receiver/init.lua b/mesecons_receiver/init.lua index 36f4659..9284e57 100644 --- a/mesecons_receiver/init.lua +++ b/mesecons_receiver/init.lua @@ -104,13 +104,8 @@ function mesecon.receiver_place(rcpt_pos) if string.find(nn.name, "mesecons:wire_") ~= nil then minetest.dig_node(pos) - if mesecon.is_power_on(rcpt_pos) then - minetest.set_node(pos, {name = "mesecons_receiver:receiver_on", param2 = node.param2}) - mesecon.receptor_on(pos, receiver_get_rules(node)) - else - minetest.set_node(pos, {name = "mesecons_receiver:receiver_off", param2 = node.param2}) - end - mesecon.update_autoconnect(pos) + minetest.set_node(pos, {name = "mesecons_receiver:receiver_off", param2 = node.param2}) + mesecon.on_placenode(pos, nn) end end @@ -121,7 +116,6 @@ function mesecon.receiver_remove(rcpt_pos, dugnode) minetest.dig_node(pos) local node = {name = "mesecons:wire_00000000_off"} minetest.set_node(pos, node) - mesecon.update_autoconnect(pos) mesecon.on_placenode(pos, node) end end diff --git a/mesecons_wires/depends.txt b/mesecons_wires/depends.txt new file mode 100644 index 0000000..acaa924 --- /dev/null +++ b/mesecons_wires/depends.txt @@ -0,0 +1 @@ +mesecons diff --git a/mesecons_wires/doc/mesecon/description.html b/mesecons_wires/doc/mesecon/description.html new file mode 100644 index 0000000..f217be9 --- /dev/null +++ b/mesecons_wires/doc/mesecon/description.html @@ -0,0 +1 @@ +Mesecons are the wires, use them to connect effectors with receptors. diff --git a/mesecons_wires/doc/mesecon/preview.png b/mesecons_wires/doc/mesecon/preview.png Binary files differnew file mode 100755 index 0000000..f81e5cb --- /dev/null +++ b/mesecons_wires/doc/mesecon/preview.png diff --git a/mesecons_wires/doc/mesecon/recipe.png b/mesecons_wires/doc/mesecon/recipe.png Binary files differnew file mode 100644 index 0000000..72f9210 --- /dev/null +++ b/mesecons_wires/doc/mesecon/recipe.png diff --git a/mesecons_wires/init.lua b/mesecons_wires/init.lua new file mode 100644 index 0000000..879cfa1 --- /dev/null +++ b/mesecons_wires/init.lua @@ -0,0 +1,247 @@ +-- naming scheme: wire:(xp)(zp)(xm)(zm)(xpyp)(zpyp)(xmyp)(zmyp)_on/off +-- where x= x direction, z= z direction, y= y direction, p = +1, m = -1, e.g. xpym = {x=1, y=-1, z=0} +-- The (xp)/(zpyp)/.. statements shall be replaced by either 0 or 1 +-- Where 0 means the wire has no visual connection to that direction and +-- 1 means that the wire visually connects to that other node. + +-- ####################### +-- ## Update wire looks ## +-- ####################### + +-- self_pos = pos of any mesecon node, from_pos = pos of conductor to getconnect for +local wire_getconnect = function (from_pos, self_pos) + local node = minetest.get_node(self_pos) + if minetest.registered_nodes[node.name] + and minetest.registered_nodes[node.name].mesecons then + -- rules of node to possibly connect to + local rules = {} + if (minetest.registered_nodes[node.name].mesecon_wire) then + rules = mesecon.rules.default + else + rules = mesecon.get_any_rules(node) + end + + for _, r in ipairs(mesecon.flattenrules(rules)) do + if (vector.equals(vector.add(self_pos, r), from_pos)) then + return true + end + end + end + return false +end + +-- Update this node +local wire_updateconnect = function (pos) + local connections = {} + + for _, r in ipairs(mesecon.rules.default) do + if wire_getconnect(pos, vector.add(pos, r)) then + table.insert(connections, r) + end + end + + local nid = {} + for _, vec in ipairs(connections) do + -- flat component + if vec.x == 1 then nid[0] = "1" end + if vec.z == 1 then nid[1] = "1" end + if vec.x == -1 then nid[2] = "1" end + if vec.z == -1 then nid[3] = "1" end + + -- slopy component + if vec.y == 1 then + if vec.x == 1 then nid[4] = "1" end + if vec.z == 1 then nid[5] = "1" end + if vec.x == -1 then nid[6] = "1" end + if vec.z == -1 then nid[7] = "1" end + end + end + + local nodeid = (nid[0] or "0")..(nid[1] or "0")..(nid[2] or "0")..(nid[3] or "0") + ..(nid[4] or "0")..(nid[5] or "0")..(nid[6] or "0")..(nid[7] or "0") + + local state_suffix = string.find(minetest.get_node(pos).name, "_off") and "_off" or "_on" + minetest.set_node(pos, {name = "mesecons:wire_"..nodeid..state_suffix}) +end + +local update_on_place_dig = function (pos, node) + -- Update placed node (get_node again as it may have been dug) + local nn = minetest.get_node(pos) + if (minetest.registered_nodes[nn.name]) + and (minetest.registered_nodes[nn.name].mesecon_wire) then + wire_updateconnect(pos) + end + + -- Update nodes around it + local rules = {} + if minetest.registered_nodes[node.name] + and minetest.registered_nodes[node.name].mesecon_wire then + rules = mesecon.rules.default + else + rules = mesecon.get_any_rules(node) + end + if (not rules) then return end + + for _, r in ipairs(mesecon.flattenrules(rules)) do + local np = vector.add(pos, r) + if minetest.registered_nodes[minetest.get_node(np).name] + and minetest.registered_nodes[minetest.get_node(np).name].mesecon_wire then + wire_updateconnect(np) + end + end +end + +mesecon.register_autoconnect_hook("wire", update_on_place_dig) + +-- ############################ +-- ## Wire node registration ## +-- ############################ +-- Nodeboxes: +local box_center = {-1/16, -.5, -1/16, 1/16, -.5+1/16, 1/16} +local box_bump1 = { -2/16, -8/16, -2/16, 2/16, -13/32, 2/16 } + +local nbox_nid = +{ + [0] = {1/16, -.5, -1/16, 8/16, -.5+1/16, 1/16}, -- x positive + [1] = {-1/16, -.5, 1/16, 1/16, -.5+1/16, 8/16}, -- z positive + [2] = {-8/16, -.5, -1/16, -1/16, -.5+1/16, 1/16}, -- x negative + [3] = {-1/16, -.5, -8/16, 1/16, -.5+1/16, -1/16}, -- z negative + + [4] = {.5-1/16, -.5+1/16, -1/16, .5, .4999+1/16, 1/16}, -- x positive up + [5] = {-1/16, -.5+1/16, .5-1/16, 1/16, .4999+1/16, .5}, -- z positive up + [6] = {-.5, -.5+1/16, -1/16, -.5+1/16, .4999+1/16, 1/16}, -- x negative up + [7] = {-1/16, -.5+1/16, -.5, 1/16, .4999+1/16, -.5+1/16} -- z negative up +} + +local tiles_off = { "mesecons_wire_off.png" } +local tiles_on = { "mesecons_wire_on.png" } + +local selectionbox = +{ + type = "fixed", + fixed = {-.5, -.5, -.5, .5, -.5+4/16, .5} +} + +-- go to the next nodeid (ex.: 01000011 --> 01000100) +local nid_inc = function() end +nid_inc = function (nid) + local i = 0 + while nid[i-1] ~= 1 do + nid[i] = (nid[i] ~= 1) and 1 or 0 + i = i + 1 + end + + -- BUT: Skip impossible nodeids: + if ((nid[0] == 0 and nid[4] == 1) or (nid[1] == 0 and nid[5] == 1) + or (nid[2] == 0 and nid[6] == 1) or (nid[3] == 0 and nid[7] == 1)) then + return nid_inc(nid) + end + + return i <= 8 +end + +register_wires = function() + local nid = {} + while true do + -- Create group specifiction and nodeid string (see note above for details) + local nodeid = (nid[0] or "0")..(nid[1] or "0")..(nid[2] or "0")..(nid[3] or "0") + ..(nid[4] or "0")..(nid[5] or "0")..(nid[6] or "0")..(nid[7] or "0") + + -- Calculate nodebox + local nodebox = {type = "fixed", fixed={box_center}} + for i=0,7 do + if nid[i] == 1 then + table.insert(nodebox.fixed, nbox_nid[i]) + end + end + + -- Add bump to nodebox if curved + if (nid[0] == 1 and nid[1] == 1) or (nid[1] == 1 and nid[2] == 1) + or (nid[2] == 1 and nid[3] == 1) or (nid[3] == 1 and nid[0] == 1) then + table.insert(nodebox.fixed, box_bump1) + end + + -- If nothing to connect to, still make a nodebox of a straight wire + if nodeid == "00000000" then + nodebox.fixed = {-8/16, -.5, -1/16, 8/16, -.5+1/16, 1/16} + end + + local rules = {} + if (nid[0] == 1) then table.insert(rules, vector.new( 1, 0, 0)) end + if (nid[1] == 1) then table.insert(rules, vector.new( 0, 0, 1)) end + if (nid[2] == 1) then table.insert(rules, vector.new(-1, 0, 0)) end + if (nid[3] == 1) then table.insert(rules, vector.new( 0, 0, -1)) end + + if (nid[0] == 1) then table.insert(rules, vector.new( 1, -1, 0)) end + if (nid[1] == 1) then table.insert(rules, vector.new( 0, -1, 1)) end + if (nid[2] == 1) then table.insert(rules, vector.new(-1, -1, 0)) end + if (nid[3] == 1) then table.insert(rules, vector.new( 0, -1, -1)) end + + if (nid[4] == 1) then table.insert(rules, vector.new( 1, 1, 0)) end + if (nid[5] == 1) then table.insert(rules, vector.new( 0, 1, 1)) end + if (nid[6] == 1) then table.insert(rules, vector.new(-1, 1, 0)) end + if (nid[7] == 1) then table.insert(rules, vector.new( 0, 1, -1)) end + + local meseconspec_off = { conductor = { + rules = rules, + state = mesecon.state.off, + onstate = "mesecons:wire_"..nodeid.."_on" + }} + + local meseconspec_on = { conductor = { + rules = rules, + state = mesecon.state.on, + offstate = "mesecons:wire_"..nodeid.."_off" + }} + + local groups_on = {dig_immediate = 3, mesecon_conductor_craftable = 1, + not_in_creative_inventory = 1} + local groups_off = {dig_immediate = 3, mesecon_conductor_craftable = 1} + if nodeid ~= "00000000" then + groups_off["not_in_creative_inventory"] = 1 + end + + mesecon.register_node(":mesecons:wire_"..nodeid, { + description = "Mesecon", + drawtype = "nodebox", + inventory_image = "mesecons_wire_inv.png", + wield_image = "mesecons_wire_inv.png", + paramtype = "light", + paramtype2 = "facedir", + sunlight_propagates = true, + selection_box = selectionbox, + node_box = nodebox, + walkable = false, + drop = "mesecons:wire_00000000_off", + mesecon_wire = true + }, {tiles = tiles_off, mesecons = meseconspec_off, groups = groups_off}, + {tiles = tiles_on, mesecons = meseconspec_on, groups = groups_on}) + + if (nid_inc(nid) == false) then return end + end +end +register_wires() + +-- ############## +-- ## Crafting ## +-- ############## +minetest.register_craft({ + type = "cooking", + output = "mesecons:wire_00000000_off 2", + recipe = "default:mese_crystal_fragment", + cooktime = 3, +}) + +minetest.register_craft({ + type = "cooking", + output = "mesecons:wire_00000000_off 18", + recipe = "default:mese_crystal", + cooktime = 15, +}) + +minetest.register_craft({ + type = "cooking", + output = "mesecons:wire_00000000_off 162", + recipe = "default:mese", + cooktime = 30, +}) diff --git a/player_textures/textures/player_Jordach.png b/player_textures/textures/player_Jordach.png Binary files differindex d1204a6..e21eff5 100644 --- a/player_textures/textures/player_Jordach.png +++ b/player_textures/textures/player_Jordach.png |