Initial redstone circuit implementation of wires

This commit is contained in:
teknomunk 2024-11-25 06:09:28 -06:00
parent 73b928e32e
commit 32b3e6f4c1
15 changed files with 318 additions and 378 deletions

@ -1,299 +0,0 @@
-- 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.
local S = minetest.get_translator(minetest.get_current_modname())
-- #######################
-- ## Update wire looks ##
-- #######################
local wire_rules =
{{x=-1, y= 0, z= 0, spread=true},
{x= 1, y= 0, z= 0, spread=true},
{x= 0, y=-1, z= 0, spread=true},
{x= 0, y= 1, z= 0, spread=true},
{x= 0, y= 0, z=-1, spread=true},
{x= 0, y= 0, z= 1, spread=true},
{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}}
-- self_pos = pos of any mesecon node, from_pos = pos of conductor to getconnect for
local function wire_getconnect(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 = wire_rules
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 function wire_updateconnect(pos)
local connections = {}
for _, r in ipairs(wire_rules) 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 function update_on_place_dig(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 = wire_rules
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/64, 1/16}
local box_bump1 = { -2/16, -8/16, -2/16, 2/16, -.5+1/64, 2/16 }
local nbox_nid =
{
[0] = {1/16, -.5, -1/16, 8/16, -.5+1/64, 1/16}, -- x positive
[1] = {-1/16, -.5, 1/16, 1/16, -.5+1/64, 8/16}, -- z positive
[2] = {-8/16, -.5, -1/16, -1/16, -.5+1/64, 1/16}, -- x negative
[3] = {-1/16, -.5, -8/16, 1/16, -.5+1/64, -1/16}, -- z negative
[4] = {.5-1/16, -.5+1/16, -1/16, .5, .4999+1/64, 1/16}, -- x positive up
[5] = {-1/16, -.5+1/16, .5-1/16, 1/16, .4999+1/64, .5}, -- z positive up
[6] = {-.5, -.5+1/16, -1/16, -.5+1/16, .4999+1/64, 1/16}, -- x negative up
[7] = {-1/16, -.5+1/16, -.5, 1/16, .4999+1/64, -.5+1/16} -- z negative up
}
local selectionbox =
{
type = "fixed",
fixed = {-.5, -.5, -.5, .5, -.5+1/16, .5}
}
-- go to the next nodeid (ex.: 01000011 --> 01000100)
local function nid_inc() end
function nid_inc(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
local function register_wires()
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 meseconspec_off = { conductor = {
rules = wire_rules,
state = mesecon.state.off,
onstate = "mesecons:wire_"..nodeid.."_on"
}}
local meseconspec_on = { conductor = {
rules = wire_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, attached_node = 1, dig_by_water = 1,destroy_by_lava_flow=1, dig_by_piston = 1}
local groups_off = {dig_immediate = 3, mesecon_conductor_craftable = 1,
attached_node = 1, dig_by_water = 1,destroy_by_lava_flow=1, dig_by_piston = 1, craftitem = 1}
if nodeid ~= "00000000" then
groups_off["not_in_creative_inventory"] = 1
end
-- Wire textures
local ratio_off = 128
local ratio_on = 192
local crossing_off = "(redstone_redstone_dust_dot.png^redstone_redstone_dust_line0.png^(redstone_redstone_dust_line1.png^[transformR90))^[colorize:#FF0000:"..ratio_off
local crossing_on = "(redstone_redstone_dust_dot.png^redstone_redstone_dust_line0.png^(redstone_redstone_dust_line1.png^[transformR90))^[colorize:#FF0000:"..ratio_on
local straight0_off = "redstone_redstone_dust_line0.png^[colorize:#FF0000:"..ratio_off
local straight0_on = "redstone_redstone_dust_line0.png^[colorize:#FF0000:"..ratio_on
local straight1_off = "redstone_redstone_dust_line0.png^[colorize:#FF0000:"..ratio_off
local straight1_on = "redstone_redstone_dust_line0.png^[colorize:#FF0000:"..ratio_on
local dot_off = "redstone_redstone_dust_dot.png^[colorize:#FF0000:"..ratio_off
local dot_on = "redstone_redstone_dust_dot.png^[colorize:#FF0000:"..ratio_on
local tiles_off, tiles_on
local wirehelp, tt, longdesc, usagehelp, img, desc_off, desc_on
if nodeid == "00000000" then
-- Non-connected redstone wire
nodebox.fixed = {-8/16, -.5, -8/16, 8/16, -.5+1/64, 8/16}
-- “Dot” texture
tiles_off = { dot_off, dot_off, "blank.png", "blank.png", "blank.png", "blank.png" }
tiles_on = { dot_on, dot_on, "blank.png", "blank.png", "blank.png", "blank.png" }
tt = S("Transmits redstone power, powers mechanisms")
longdesc = S("Redstone is a versatile conductive mineral which transmits redstone power. It can be placed on the ground as a trail.").."\n"..
S("A redstone trail can be in two states: Powered or not powered. A powered redstone trail will power (and thus activate) adjacent redstone components.").."\n"..
S("Redstone power can be received from various redstone components, such as a block of redstone or a button. Redstone power is used to activate numerous mechanisms, such as redstone lamps or pistons.")
usagehelp = S("Place redstone on the ground to build a redstone trail. The trails will connect to each other automatically and it can also go over hills.").."\n\n"..
S("Read the help entries on the other redstone components to learn how redstone components interact.")
img = "redstone_redstone_dust.png"
desc_off = S("Redstone")
desc_on = S("Powered Redstone Spot (@1)", nodeid)
else
-- Connected redstone wire
table.insert(nodebox, box_center)
tiles_off = { crossing_off, crossing_off, straight0_off, straight1_off, straight0_off, straight1_off }
tiles_on = { crossing_on, crossing_on, straight0_on, straight1_on, straight0_on, straight1_on }
wirehelp = false
desc_off = S("Redstone Trail (@1)", nodeid)
desc_on = S("Powered Redstone Trail (@1)", nodeid)
end
mesecon.register_node(":mesecons:wire_"..nodeid, {
drawtype = "nodebox",
paramtype = "light",
use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true,
sunlight_propagates = true,
selection_box = selectionbox,
node_box = nodebox,
walkable = false,
drop = "mesecons:wire_00000000_off",
sounds = mcl_sounds.node_sound_defaults(),
is_ground_content = false,
mesecon_wire = true
},{
description = desc_off,
inventory_image = img,
wield_image = img,
_tt_help = tt,
_doc_items_create_entry = wirehelp,
_doc_items_longdesc = longdesc,
_doc_items_usagehelp = usagehelp,
tiles = tiles_off,
mesecons = meseconspec_off,
groups = groups_off,
},{
description = desc_on,
_doc_items_create_entry = false,
tiles = tiles_on,
mesecons = meseconspec_on,
groups = groups_on
})
-- Add Help entry aliases for e.g. making it identifiable by the lookup tool [doc_identifier]
if minetest.get_modpath("doc") then
if nodeid ~= "00000000" then
doc.add_entry_alias("nodes", "mesecons:wire_00000000_off", "nodes", "mesecons:wire_"..nodeid.."_off")
end
doc.add_entry_alias("nodes", "mesecons:wire_00000000_off", "nodes", "mesecons:wire_"..nodeid.."_on")
end
if (nid_inc(nid) == false) then return end
end
end
register_wires()
minetest.register_alias("mesecons:redstone", "mesecons:wire_00000000_off")
minetest.register_craft({
type = "cooking",
output = "mesecons:redstone",
recipe = "mcl_core:stone_with_redstone",
cooktime = 10,
})

@ -1,11 +0,0 @@
# textdomain: mesecons_wires
Redstone is a versatile conductive mineral which transmits redstone power. It can be placed on the ground as a trail.=Redstone ist ein vielseitiges leitendes Mineral, der Redstoneenergie überträgt. Es kann auf dem Boden in Form einer Spur platziert werden.
A redstone trail can be in two states: Powered or not powered. A powered redstone trail will power (and thus activate) adjacent redstone components.=Eine Redstonespur kann einen von zwei Zuständen annehmen: Bestromt und unbestromt. Eine bestromte Redstonespur wird benachbarte Redstonekomponenten bestromen (und somit aktivieren).
Redstone power can be received from various redstone components, such as a block of redstone or a button. Redstone power is used to activate numerous mechanisms, such as redstone lamps or pistons.=Redstoneenergie kann von verschiedenen Redstonekomponenten erhalten werden, wie zum Beispiel einem Redstoneblock oder einem Knopf. Redstoneenergie wird benutzt, um verschiedene Mechanismen zu aktivieren, wie Redstonelampen oder Kolben.
Place redstone on the ground to build a redstone trail. The trails will connect to each other automatically and it can also go over hills.=Platzieren Sie Redstone auf dem Boden, um eine Redstonespur auszulegen. Die Spuren werden sich automatisch miteinander verbinden und sie können auch über Hügel gehen.
Read the help entries on the other redstone components to learn how redstone components interact.=Lesen Sie die Hilfeeinträge über andere Redstonekomponenten, um zu erfahren, wie sie interagieren.
Redstone=Redstone
Powered Redstone Spot (@1)=Bestromter Redstoneklecks (@1)
Redstone Trail (@1)=Redstonespur (@1)
Powered Redstone Trail (@1)=Bestromte Redstonespur (@1)
Transmits redstone power, powers mechanisms=Überträgt Redstoneenergie, bestromt Mechanismen

@ -1,10 +0,0 @@
# textdomain: mesecons_wires
Redstone is a versatile conductive mineral which transmits redstone power. It can be placed on the ground as a trail.=Redstone es un mineral conductor versátil que transmite el poder de redstone. Se puede colocar en el suelo como un sendero.
A redstone trail can be in two states: Powered or not powered. A powered redstone trail will power (and thus activate) adjacent redstone components.=Un sendero de redstone puede estar en dos estados: alimentado o no alimentado. Un rastro de redstone alimentado alimentará (y por lo tanto activará) los componentes adyacentes de redstone.
Redstone power can be received from various redstone components, such as a block of redstone or a button. Redstone power is used to activate numerous mechanisms, such as redstone lamps or pistons.=El poder de Redstone se puede recibir de varios componentes de redstone, como un bloque de redstone o un botón. El poder de Redstone se utiliza para activar numerosos mecanismos, como las lámparas de redstone o los pistones.
Place redstone on the ground to build a redstone trail. The trails will connect to each other automatically and it can also go over hills.=Coloque redstone en el suelo para construir un sendero de redstone. Los senderos se conectarán entre sí de forma automática y también pueden pasar por colinas.
Read the help entries on the other redstone components to learn how redstone components interact.=Lea las entradas de ayuda en los otros componentes de redstone para aprender cómo interactúan los componentes de redstone.
Redstone=Redstone
Powered Redstone Spot (@1)=Punto de Redstone accionado (@1)
Redstone Trail (@1)=Sendero de Redstone (@1)
Powered Redstone Trail (@1)=Sendero de Redstone con motorizado (@1)

@ -1,11 +0,0 @@
# textdomain: mesecons_wires
Redstone is a versatile conductive mineral which transmits redstone power. It can be placed on the ground as a trail.=Redstone est un minéral conducteur polyvalent qui transmet la puissance de redstone. Il peut être placé au sol comme un sentier.
A redstone trail can be in two states: Powered or not powered. A powered redstone trail will power (and thus activate) adjacent redstone components.=Un sentier de redstone peut être dans deux états: alimenté ou non alimenté. Un sentier Redstone alimenté alimentera (et activera donc) les composants Redstone adjacents.
Redstone power can be received from various redstone components, such as a block of redstone or a button. Redstone power is used to activate numerous mechanisms, such as redstone lamps or pistons.=L'alimentation Redstone peut être reçue de divers composants Redstone, tels qu'un bloc de Redstone ou un bouton. La puissance Redstone est utilisée pour activer de nombreux mécanismes, tels que les lampes ou les pistons Redstone.
Place redstone on the ground to build a redstone trail. The trails will connect to each other automatically and it can also go over hills. An easy way to power a redstone trail is by placing a redstone torch.=Placez du redstone sur le sol pour construire un sentier de redstone. Les sentiers se connecteront automatiquement et pourront également traverser des collines. Un moyen facile d'alimenter une piste de redstone est de placer une torche de redstone.
Read the help entries on the other redstone components to learn how redstone components interact.=Lisez les entrées d'aide sur les autres composants Redstone pour savoir comment les composants Redstone interagissent.
Redstone=Redstone
Powered Redstone Spot (@1)=Spot Redstone alimenté (@1)
Redstone Trail (@1)=Sentier Redstone (@1)
Powered Redstone Trail (@1)=Sentier Redstone alimenté (@1)
Transmits redstone power, powers mechanisms=Transmet la puissance redstone, alimente les mécanismes

@ -1,11 +0,0 @@
# textdomain: mesecons_wires
Redstone is a versatile conductive mineral which transmits redstone power. It can be placed on the ground as a trail.=レッドストーンは、レッドストーン動力を伝達する多用途の導電性鉱物です。地面に導線を敷設できます。
A redstone trail can be in two states: Powered or not powered. A powered redstone trail will power (and thus activate) adjacent redstone components.=レッドストーン導線は、稼動と非稼動の2つの状態がとれます。稼動中のレッドストーン導線は、隣接するレッドストーン部品に動力を与えますつまり作動します
Redstone power can be received from various redstone components, such as a block of redstone or a button. Redstone power is used to activate numerous mechanisms, such as redstone lamps or pistons.=レッドストーン動力は、レッドストーンのブロックやボタンなど、さまざまなレッドストーン部品から受け取れます。レッドストーン動力は、レッドストーンランプやピストンなど、数々なメカニズムを作動させるために使われます。
Place redstone on the ground to build a redstone trail. The trails will connect to each other automatically and it can also go over hills. An easy way to power a redstone trail is by placing a redstone torch.=レッドストーンを地面に置くと、レッドストーン導線ができます。導線は自動的に相互接続され、丘を越えることもできます。レッドストーン導線に動力を伝える簡単な方法は、レッドストーントーチを置くことです。
Read the help entries on the other redstone components to learn how redstone components interact.=レッドストーン部品がどのように相互作用するかについては、他のレッドストーン部品のヘルプエントリーをお読みください。
Redstone=レッドストーン
Powered Redstone Spot (@1)=稼動中のレッドストーンスポット (@1)
Redstone Trail (@1)=レッドストーン導線 (@1)
Powered Redstone Trail (@1)=稼動中のレッドストーン導線 (@1)
Transmits redstone power, powers mechanisms=レッドストーン動力の伝達、メカニズム類の起動

@ -1,11 +0,0 @@
# textdomain: mesecons_wires
Redstone is a versatile conductive mineral which transmits redstone power. It can be placed on the ground as a trail.=Czerwienit jest wszechstronnym przewodzącym minerałem, który przewodzi energię czerwienitową. Może być położony na ziemi tworząc ścieżkę.
A redstone trail can be in two states: Powered or not powered. A powered redstone trail will power (and thus activate) adjacent redstone components.=Ścieżka czerwienitu może być w dwóch stanach: Zasilonym lub Nie zasilonym. Zasilona ścieżka będzie zasilać (a więc również aktywować) sąsiadujące mechanizmy czerwienitowe.
Redstone power can be received from various redstone components, such as a block of redstone or a button. Redstone power is used to activate numerous mechanisms, such as redstone lamps or pistons.=Energia czerwienitowa może być uzyskana z różnych mechanizmów czerwienitowych, takich jak blok czerwienitu czy przycisk. Energia czerwienitowa może być wykorzystywana do aktywowania różnych mechanizmów takich jak czerwienitowe lampy lub tłoki.
Place redstone on the ground to build a redstone trail. The trails will connect to each other automatically and it can also go over hills. An easy way to power a redstone trail is by placing a redstone torch.=Połóż czerwienit na ziemi aby stworzyć ścieżkę czerwienitu. Ścieżki połączą się ze sobą automatycznie, nawet jeśli istnieje różnica wysokości. Łatwym sposobem na zasilenie ścieżki czerwienitu jest postawienie czerwienitowej pochodni.
Read the help entries on the other redstone components to learn how redstone components interact.=Przeczytaj wpisy na temat innych czerwienitowych mechanizmów, by dowiedzieć się jak wchodzą ze sobą w interakcję.
Redstone=Czerwienit
Powered Redstone Spot (@1)=Zasilony punkt czerwienitu (@1)
Redstone Trail (@1)=Ścieżka czerwienitu (@1)
Powered Redstone Trail (@1)=Zasilona ścieżka czerwienitu (@1)
Transmits redstone power, powers mechanisms=Przekazuje energię czerwienitową, zasila mechanizmy

@ -1,11 +0,0 @@
# textdomain: mesecons_wires
Redstone is a versatile conductive mineral which transmits redstone power. It can be placed on the ground as a trail.=Редстоун является универсальным проводящим минералом, который передает сигнал красного камня. Он может размещаться на поверхности как дорожка.
A redstone trail can be in two states: Powered or not powered. A powered redstone trail will power (and thus activate) adjacent redstone components.=Дорожка редстоуна может быть в двух состояниях: подключенная или отключенная. Подключенная дорожка редстоуна будет снабжать (а значит, активировать) рядом стоящие компоненты редстоуна.
Redstone power can be received from various redstone components, such as a block of redstone or a button. Redstone power is used to activate numerous mechanisms, such as redstone lamps or pistons.=Сигнал редстоуна можно получать от различных компонентов редстоуна, таких как блок редстоуна или кнопка. Этот сигнал используется для активации многочисленных механизмов, таких как лампы или поршни.
Place redstone on the ground to build a redstone trail. The trails will connect to each other automatically and it can also go over hills. An easy way to power a redstone trail is by placing a redstone torch.=Поместите редстоун на землю, чтобы создать из него дорожку. Фрагменты дорожек будут соединяться между собой автоматически и могут даже проходить по холмам. Простой способ подать сигнал редстоуна к дорожке редстоуна это установка красного факела.
Read the help entries on the other redstone components to learn how redstone components interact.=Смотрите справочные записи к остальным компонентам редстоуна, чтобы узнать больше об их взаимодействии.
Redstone=Редстоун
Powered Redstone Spot (@1)=Подключенное пятно редстоуна (@1)
Redstone Trail (@1)=Дорожка редстоуна (@1)
Powered Redstone Trail (@1)=Подключенная дорожка редстоуна (@1)
Transmits redstone power, powers mechanisms=Передаёт сигнал редстоуна, подключает механизмы

@ -1,11 +0,0 @@
# textdomain: mesecons_wires
Redstone is a versatile conductive mineral which transmits redstone power. It can be placed on the ground as a trail.=
A redstone trail can be in two states: Powered or not powered. A powered redstone trail will power (and thus activate) adjacent redstone components.=
Redstone power can be received from various redstone components, such as a block of redstone or a button. Redstone power is used to activate numerous mechanisms, such as redstone lamps or pistons.=
Place redstone on the ground to build a redstone trail. The trails will connect to each other automatically and it can also go over hills. An easy way to power a redstone trail is by placing a redstone torch.=
Read the help entries on the other redstone components to learn how redstone components interact.=
Redstone=
Powered Redstone Spot (@1)=
Redstone Trail (@1)=
Powered Redstone Trail (@1)=
Transmits redstone power, powers mechanisms=

@ -1,3 +0,0 @@
name = mesecons_wires
depends = mesecons
optional_depends = doc

@ -0,0 +1,6 @@
local storage = core.get_mod_storage()
local mod = vl_redstone
function mod.build_netlist(pos)
end

@ -0,0 +1,33 @@
local function mesecons_compat_on_power_change(pos, node, def, power, old_power)
if power == 0 and old_power ~= 0 then
local hook = def.mesecons.effector.action_off
if hook then hook(pos) end
hook = def.mesecons.effector.action_change
if hook then hook(pos) end
end
if power ~= 0 and old_power == 0 then
local hook = def.mesecons.effector.action_on
if hook then hook(pos) end
hook = def.mesecons.effector.action_change
if hook then hook(pos) end
end
end
core.register_on_mods_loaded(function()
for name,def in pairs(core.registered_nodes) do
if def.mesecons and not def.vl_redstone then
local new_groups = table.copy(def.groups)
new_groups.redstone = 1
core.override_item(def.name,{
groups = new_groups,
vl_redstone = {
on_power_change = mesecons_compat_on_power_change,
sink = def.mesecons.effector and true,
source = def.mesecons.receptor and true,
}
})
end
end
end)

@ -0,0 +1,9 @@
local modname = core.get_current_modname()
local modpath = core.get_modpath(modname)
vl_redstone = {}
dofile(modpath.."/wire.lua")
dofile(modpath.."/circuit.lua")
dofile(modpath.."/compat.lua")

@ -0,0 +1,4 @@
name = vl_redstone
author = teknomunk
description = Redstone dust
depends = mcl_init

@ -0,0 +1,266 @@
local use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true
local box_center = {-1/16, -.5, -1/16, 1/16, -.5+1/64, 1/16}
local nodebox_parts = {
[0] = {1/16, -.5, -1/16, 8/16, -.5+1/64, 1/16}, -- x positive
[1] = {-1/16, -.5, 1/16, 1/16, -.5+1/64, 8/16}, -- z positive
[2] = {-8/16, -.5, -1/16, -1/16, -.5+1/64, 1/16}, -- x negative
[3] = {-1/16, -.5, -8/16, 1/16, -.5+1/64, -1/16}, -- z negative
[4] = {.5-1/16, -.5+1/16, -1/16, .5, .4999+1/64, 1/16}, -- x positive up
[5] = {-1/16, -.5+1/16, .5-1/16, 1/16, .4999+1/64, .5}, -- z positive up
[6] = {-.5, -.5+1/16, -1/16, -.5+1/16, .4999+1/64, 1/16}, -- x negative up
[7] = {-1/16, -.5+1/16, -.5, 1/16, .4999+1/64, -.5+1/16} -- z negative up
}
local dust = "redstone_redstone_dust_dot.png"
local flat = "(redstone_redstone_dust_dot.png^redstone_redstone_dust_line0.png^(redstone_redstone_dust_line1.png^[transformR90))"
local line = "redstone_redstone_dust_line0.png"
local connection_table = {
[ 0] = {"vl_redstone:dust", 0},
[ 1] = {"vl_redstone:trail_0", 0},
[ 2] = {"vl_redstone:trail_0", 3},
[ 3] = {"vl_redstone:corner_00", 0},
[ 4] = {"vl_redstone:trail_0", 2},
[ 5] = {"vl_redstone:line_00", 0},
[ 6] = {"vl_redstone:corner_00", 3},
[ 7] = {"vl_redstone:tee_000", 0},
[ 8] = {"vl_redstone:trail_0", 1},
[ 9] = {"vl_redstone:corner_00", 1},
[ 10] = {"vl_redstone:line_00", 1},
[ 11] = {"vl_redstone:tee_000", 1},
[ 12] = {"vl_redstone:corner_00", 2},
[ 13] = {"vl_redstone:tee_000", 2},
[ 14] = {"vl_redstone:tee_000", 3},
[ 15] = {"vl_redstone:cross_0000",0},
[ 16] = {"vl_redstone:trail_1", 0},
[ 18] = {"vl_redstone:corner_10", 0},
[ 20] = {"vl_redstone:line_01", 2},
[ 22] = {"vl_redstone:tee_100", 0},
[ 24] = {"vl_redstone:corner_01", 1},
[ 28] = {"vl_redstone:tee_001", 2},
[ 32] = {"vl_redstone:trail_1", 3},
[ 33] = {"vl_redstone:corner_01", 0},
[ 36] = {"vl_redstone:corner_10", 3},
[ 41] = {"vl_redstone:tee_001", 1},
[ 44] = {"vl_redstone:tee_100", 3},
[ 48] = {"vl_redstone:corner_11", 0},
[ 52] = {"vl_redstone:tee_110", 0},
[ 56] = {"vl_redstone:tee_011", 1},
[ 60] = {"vl_redstone:cross_0011",2},
[ 64] = {"vl_redstone:trail_1", 2},
[ 66] = {"vl_redstone:corner_01", 3},
[ 72] = {"vl_redstone:corner_10", 2},
[ 96] = {"vl_redstone:corner_11", 3},
[ 97] = {"vl_redstone:tee_011", 0},
[104] = {"vl_redstone:tee_110", 3},
[105] = {"vl_redstone:cross_0011",1},
[112] = {"vl_redstone:tee_111", 0},
[128] = {"vl_redstone:trail_1", 1},
[129] = {"vl_redstone:corner_10", 1},
[131] = {"vl_redstone:tee_100", 1},
[132] = {"vl_redstone:corner_01", 2},
[134] = {"vl_redstone:tee_001", 3},
[144] = {"vl_redstone:corner_11", 1},
[146] = {"vl_redstone:tee_110", 1},
[148] = {"vl_redstone:tee_011", 2},
[150] = {"vl_redstone:cross_0011",3},
[176] = {"vl_redstone:tee_111", 1},
[180] = {"vl_redstone:cross_0111",2},
[192] = {"vl_redstone:corner_11", 2},
[194] = {"vl_redstone:tee_011", 3},
[193] = {"vl_redstone:tee_110", 2},
[195] = {"vl_redstone:cross_0011",0},
[208] = {"vl_redstone:tee_111", 2},
[224] = {"vl_redstone:tee_111", 3},
[255] = {"vl_redstone:cross_1111",0},
}
print("#connection_table = "..#connection_table)
local parts = {
[1] = { 1, 0, 0, 1},
[2] = { 0, 0, 1, 2},
[3] = {-1, 0, 0, 4},
[4] = { 0, 0,-1, 8},
[5] = { 1, 1, 0, 16},
[6] = { 0, 1, 1, 32},
[7] = {-1, 1, 0, 64},
[8] = { 0, 1,-1, 128},
[9] = { 1,-1, 0, 1},
[10]= { 0,-1, 1, 2},
[11]= {-1,-1, 0, 4},
[12]= { 0,-1,-1, 8},
}
local function update_redstone_wire(orig, update_neighbor)
local mask = 0
for i = 1,12 do
local part = parts[i]
local pos = vector.offset(orig, part[1], part[2], part[3])
local node = core.get_node(pos)
local def = core.registered_nodes[node.name]
if def.groups.redstone or 0 ~= 0 then
mask = mask + part[4]
if update_neighbor and def.groups.redstone_wire or 0 ~= 0 then
update_redstone_wire(pos)
end
end
end
local connections = connection_table[mask]
if not connections then
print(dump{
me = core.get_node(orig),
mask = mask,
node = node,
})
connections = {"vl_redstone:dust", 0}
end
local node = {
name = connections[1],
param2 = connections[2],
}
core.set_node(orig, node)
end
local base_def = {
use_texture_alpha = use_texture_alpha,
type = "node",
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "color4dir",
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, -0.4375, 0.5},
}
},
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -0.4375, 0.5}
},
walkable = false,
inventory_image = "redstone_redstone_dust.png",
wield_image = "redstone_redstone_dust.png",
tiles = {dust, dust, line, line, line, line},
drop = "vl_redstone:dust",
is_ground_content = false,
sunlight_propogate = true,
groups = {
dig_by_piston = 1,
dig_immediate = 3,
creative_breakable = 1,
attached_node = 1,
craftitem = 1,
destroy_by_lava_flow = 1,
dig_by_water = 1,
redstone = 1,
redstone_wire = 1,
},
vl_block_update = update_restone_wire,
after_place_node = function(pos, placer, itemstack, pointed_thing)
update_redstone_wire(pos, true)
end,
after_dig_node = function(orig, oldnode, oldmetadata, digger)
for i = 1,12 do
local part = parts[i]
local pos = vector.offset(orig, part[1], part[2], part[3])
local node = core.get_node(pos)
if core.get_item_group(node.name, "redstone_wire") ~= 0 then
update_redstone_wire(pos)
end
end
end
}
minetest.register_node("vl_redstone:dust", base_def)
base_def = table.copy(base_def)
base_def.tiles = {flat, flat, line, line, line, line}
for a=0,1 do
local def = table.copy(base_def)
local fixed = {
box_center,
nodebox_parts[0]
}
if a==1 then table.insert(fixed, nodebox_parts[4]) end
def.node_box.fixed = fixed
minetest.register_node("vl_redstone:trail_"..a, def)
end
for a=0,1 do
for b=0,1 do
local def = table.copy(base_def)
local fixed = {
box_center,
nodebox_parts[0],
nodebox_parts[1]
}
if a==1 then table.insert(fixed, nodebox_parts[4]) end
if b==1 then table.insert(fixed, nodebox_parts[5]) end
def.node_box.fixed = fixed
minetest.register_node("vl_redstone:corner_"..a..b, def)
end
end
local options = {{0,0}, {0,1}, {1,1}}
for i = 1,3 do
a,b = unpack(options[i])
local def = table.copy(base_def)
local fixed = {
box_center,
nodebox_parts[0],
nodebox_parts[2],
}
if a==1 then table.insert(fixed, nodebox_parts[4]) end
if b==1 then table.insert(fixed, nodebox_parts[6]) end
def.node_box.fixed = fixed
minetest.register_node("vl_redstone:line_"..a..b, def)
end
for a=0,1 do
for b=0,1 do
for c=0,1 do
local def = table.copy(base_def)
local fixed = {
box_center,
nodebox_parts[0],
nodebox_parts[1],
nodebox_parts[2],
}
if a==1 then table.insert(fixed, nodebox_parts[4]) end
if b==1 then table.insert(fixed, nodebox_parts[5]) end
if c==1 then table.insert(fixed, nodebox_parts[6]) end
def.node_box.fixed = fixed
minetest.register_node("vl_redstone:tee_"..a..b..c, def)
end
end
end
local options = {{0,0,0,0}, {1,1,1,1}, {0,1,1,1}, {0,0,1,1}, {0,0,0,1}, {0,1,0,1}}
for i = 1,6 do
a,b,c,d = unpack(options[i])
local def = table.copy(base_def)
local fixed = {
box_center,
nodebox_parts[0],
nodebox_parts[1],
nodebox_parts[2],
nodebox_parts[3],
}
if a==1 then table.insert(fixed, nodebox_parts[4]) end
if b==1 then table.insert(fixed, nodebox_parts[5]) end
if c==1 then table.insert(fixed, nodebox_parts[6]) end
if d==1 then table.insert(fixed, nodebox_parts[7]) end
def.node_box.fixed = fixed
minetest.register_node("vl_redstone:cross_"..a..b..c..d, def)
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 B