initial commit
subgame + mods
1
mods/mesecons/.gitignore
vendored
Executable file
@ -0,0 +1 @@
|
||||
*~
|
1
mods/mesecons/.mesecons_blinkyplant/depends.txt
Executable file
@ -0,0 +1 @@
|
||||
mesecons
|
102
mods/mesecons/.mesecons_blinkyplant/init.lua
Executable file
@ -0,0 +1,102 @@
|
||||
-- The BLINKY_PLANT
|
||||
minetest.register_node("mesecons_blinkyplant:blinky_plant", {
|
||||
drawtype = "plantlike",
|
||||
visual_scale = 1,
|
||||
tiles = {"jeija_blinky_plant_off.png"},
|
||||
inventory_image = "jeija_blinky_plant_off.png",
|
||||
walkable = false,
|
||||
groups = {dig_immediate=3, not_in_creative_inventory=1},
|
||||
drop="mesecons_blinkyplant:blinky_plant_off 1",
|
||||
description="Deactivated Blinky Plant",
|
||||
sounds = default.node_sound_leaves_defaults(),
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.3, -0.5, -0.3, 0.3, -0.5+0.7, 0.3},
|
||||
},
|
||||
mesecons = {receptor = {
|
||||
state = mesecon.state.off
|
||||
}},
|
||||
on_rightclick = function(pos, node, clicker)
|
||||
minetest.set_node(pos, {name="mesecons_blinkyplant:blinky_plant_off"})
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_blinkyplant:blinky_plant_off", {
|
||||
drawtype = "plantlike",
|
||||
visual_scale = 1,
|
||||
tiles = {"jeija_blinky_plant_off.png"},
|
||||
inventory_image = "jeija_blinky_plant_off.png",
|
||||
paramtype = "light",
|
||||
walkable = false,
|
||||
groups = {dig_immediate=3, mesecon=2},
|
||||
description="Blinky Plant",
|
||||
sounds = default.node_sound_leaves_defaults(),
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.3, -0.5, -0.3, 0.3, -0.5+0.7, 0.3},
|
||||
},
|
||||
mesecons = {receptor = {
|
||||
state = mesecon.state.off
|
||||
}},
|
||||
on_rightclick = function(pos, node, clicker)
|
||||
minetest.set_node(pos, {name="mesecons_blinkyplant:blinky_plant"})
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_blinkyplant:blinky_plant_on", {
|
||||
drawtype = "plantlike",
|
||||
visual_scale = 1,
|
||||
tiles = {"jeija_blinky_plant_on.png"},
|
||||
inventory_image = "jeija_blinky_plant_off.png",
|
||||
paramtype = "light",
|
||||
walkable = false,
|
||||
groups = {dig_immediate=3, not_in_creative_inventory=1, mesecon=2},
|
||||
drop="mesecons_blinkyplant:blinky_plant_off 1",
|
||||
light_source = LIGHT_MAX-7,
|
||||
description = "Blinky Plant",
|
||||
sounds = default.node_sound_leaves_defaults(),
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.3, -0.5, -0.3, 0.3, -0.5+0.7, 0.3},
|
||||
},
|
||||
mesecons = {receptor = {
|
||||
state = mesecon.state.on
|
||||
}},
|
||||
on_rightclick = function(pos, node, clicker)
|
||||
minetest.set_node(pos, {name = "mesecons_blinkyplant:blinky_plant"})
|
||||
mesecon:receptor_off(pos)
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "mesecons_blinkyplant:blinky_plant_off 1",
|
||||
recipe = {
|
||||
{"","group:mesecon_conductor_craftable",""},
|
||||
{"","group:mesecon_conductor_craftable",""},
|
||||
{"default:sapling","default:sapling","default:sapling"},
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_abm(
|
||||
{nodenames = {"mesecons_blinkyplant:blinky_plant_off"},
|
||||
interval = BLINKY_PLANT_INTERVAL,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
--minetest.remove_node(pos)
|
||||
minetest.add_node(pos, {name="mesecons_blinkyplant:blinky_plant_on"})
|
||||
nodeupdate(pos)
|
||||
mesecon:receptor_on(pos)
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"mesecons_blinkyplant:blinky_plant_on"},
|
||||
interval = BLINKY_PLANT_INTERVAL,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
--minetest.remove_node(pos)
|
||||
minetest.add_node(pos, {name="mesecons_blinkyplant:blinky_plant_off"})
|
||||
nodeupdate(pos)
|
||||
mesecon:receptor_off(pos)
|
||||
end,
|
||||
})
|
BIN
mods/mesecons/.mesecons_blinkyplant/textures/jeija_blinky_plant_off.png
Executable file
After Width: | Height: | Size: 454 B |
BIN
mods/mesecons/.mesecons_blinkyplant/textures/jeija_blinky_plant_on.png
Executable file
After Width: | Height: | Size: 463 B |
2
mods/mesecons/.mesecons_detector/depends.txt
Executable file
@ -0,0 +1,2 @@
|
||||
mesecons
|
||||
mesecons_materials
|
110
mods/mesecons/.mesecons_detector/init.lua
Executable file
@ -0,0 +1,110 @@
|
||||
-- Object detector
|
||||
-- Detects players in a certain radius
|
||||
-- The radius can be specified in mesecons/settings.lua
|
||||
|
||||
local object_detector_make_formspec = function (pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("formspec", "size[9,2.5]" ..
|
||||
"field[0.3, 0;9,2;scanname;Name of player to scan for (empty for any):;${scanname}]"..
|
||||
"field[0.3,1.5;4,2;digiline_channel;Digiline Channel (optional):;${digiline_channel}]"..
|
||||
"button_exit[7,0.75;2,3;;Save]")
|
||||
end
|
||||
|
||||
local object_detector_on_receive_fields = function(pos, formname, fields)
|
||||
if not fields.scanname or not fields.digiline_channel then return end;
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("scanname", fields.scanname)
|
||||
meta:set_string("digiline_channel", fields.digiline_channel)
|
||||
object_detector_make_formspec(pos)
|
||||
end
|
||||
|
||||
-- returns true if player was found, false if not
|
||||
local object_detector_scan = function (pos)
|
||||
local objs = minetest.get_objects_inside_radius(pos, OBJECT_DETECTOR_RADIUS)
|
||||
for k, obj in pairs(objs) do
|
||||
local isname = obj:get_player_name() -- "" is returned if it is not a player; "" ~= nil!
|
||||
local scanname = minetest.get_meta(pos):get_string("scanname")
|
||||
if (isname == scanname and isname ~= "") or (isname ~= "" and scanname == "") then -- player with scanname found or not scanname specified
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-- set player name when receiving a digiline signal on a specific channel
|
||||
object_detector_digiline = {
|
||||
effector = {
|
||||
action = function (pos, node, channel, msg)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local active_channel = meta:get_string("digiline_channel")
|
||||
if channel == active_channel then
|
||||
meta:set_string("scanname", msg)
|
||||
object_detector_make_formspec(pos)
|
||||
end
|
||||
end,
|
||||
}
|
||||
}
|
||||
|
||||
minetest.register_node("mesecons_detector:object_detector_off", {
|
||||
tiles = {"default_steel_block.png", "default_steel_block.png", "jeija_object_detector_off.png", "jeija_object_detector_off.png", "jeija_object_detector_off.png", "jeija_object_detector_off.png"},
|
||||
paramtype = "light",
|
||||
walkable = true,
|
||||
groups = {cracky=3},
|
||||
description="Player Detector",
|
||||
mesecons = {receptor = {
|
||||
state = mesecon.state.off
|
||||
}},
|
||||
on_construct = object_detector_make_formspec,
|
||||
on_receive_fields = object_detector_on_receive_fields,
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
digiline = object_detector_digiline
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_detector:object_detector_on", {
|
||||
tiles = {"default_steel_block.png", "default_steel_block.png", "jeija_object_detector_on.png", "jeija_object_detector_on.png", "jeija_object_detector_on.png", "jeija_object_detector_on.png"},
|
||||
paramtype = "light",
|
||||
walkable = true,
|
||||
groups = {cracky=3,not_in_creative_inventory=1},
|
||||
drop = 'mesecons_detector:object_detector_off',
|
||||
mesecons = {receptor = {
|
||||
state = mesecon.state.on
|
||||
}},
|
||||
on_construct = object_detector_make_formspec,
|
||||
on_receive_fields = object_detector_on_receive_fields,
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
digiline = object_detector_digiline
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'mesecons_detector:object_detector_off',
|
||||
recipe = {
|
||||
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
|
||||
{"default:steel_ingot", "mesecons_luacontroller:luacontroller0000", "default:steel_ingot"},
|
||||
{"default:steel_ingot", "group:mesecon_conductor_craftable", "default:steel_ingot"},
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_abm(
|
||||
{nodenames = {"mesecons_detector:object_detector_off"},
|
||||
interval = 1.0,
|
||||
chance = 1,
|
||||
action = function(pos)
|
||||
if object_detector_scan(pos) then
|
||||
minetest.swap_node(pos, {name = "mesecons_detector:object_detector_on"})
|
||||
mesecon:receptor_on(pos)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_abm(
|
||||
{nodenames = {"mesecons_detector:object_detector_on"},
|
||||
interval = 1.0,
|
||||
chance = 1,
|
||||
action = function(pos)
|
||||
if not object_detector_scan(pos) then
|
||||
minetest.swap_node(pos, {name = "mesecons_detector:object_detector_off"})
|
||||
mesecon:receptor_off(pos)
|
||||
end
|
||||
end,
|
||||
})
|
BIN
mods/mesecons/.mesecons_detector/textures/jeija_object_detector_off.png
Executable file
After Width: | Height: | Size: 712 B |
BIN
mods/mesecons/.mesecons_detector/textures/jeija_object_detector_on.png
Executable file
After Width: | Height: | Size: 735 B |
6
mods/mesecons/.mesecons_gates/depends.txt
Executable file
@ -0,0 +1,6 @@
|
||||
mesecons
|
||||
mesecons_microcontroller
|
||||
mesecons_delayer
|
||||
|
||||
mesecons_torch
|
||||
mesecons_materials
|
222
mods/mesecons/.mesecons_gates/init.lua
Executable file
@ -0,0 +1,222 @@
|
||||
function gate_rotate_rules(node)
|
||||
for rotations = 0, node.param2 - 1 do
|
||||
rules = mesecon:rotate_rules_left(rules)
|
||||
end
|
||||
return rules
|
||||
end
|
||||
|
||||
function gate_get_output_rules(node)
|
||||
rules = {{x=1, y=0, z=0}}
|
||||
return gate_rotate_rules(node)
|
||||
end
|
||||
|
||||
function gate_get_input_rules_oneinput(node)
|
||||
rules = {{x=-1, y=0, z=0}, {x=1, y=0, z=0}}
|
||||
return gate_rotate_rules(node)
|
||||
end
|
||||
|
||||
function gate_get_input_rules_twoinputs(node)
|
||||
rules = {
|
||||
{x=0, y=0, z=1},
|
||||
{x=0, y=0, z=-1},
|
||||
{x=1, y=0, z=0}}
|
||||
return gate_rotate_rules(node)
|
||||
end
|
||||
|
||||
function update_gate(pos, node, rulename, newstate)
|
||||
yc_update_real_portstates(pos, node, rulename, newstate)
|
||||
gate = get_gate(pos)
|
||||
L = rotate_ports(
|
||||
yc_get_real_portstates(pos),
|
||||
minetest.get_node(pos).param2
|
||||
)
|
||||
if gate == "diode" then
|
||||
set_gate(pos, L.a)
|
||||
elseif gate == "not" then
|
||||
set_gate(pos, not L.a)
|
||||
elseif gate == "nand" then
|
||||
set_gate(pos, not(L.b and L.d))
|
||||
elseif gate == "and" then
|
||||
set_gate(pos, L.b and L.d)
|
||||
elseif gate == "xor" then
|
||||
set_gate(pos, (L.b and not L.d) or (not L.b and L.d))
|
||||
end
|
||||
end
|
||||
|
||||
function set_gate(pos, on)
|
||||
gate = get_gate(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if on ~= gate_state(pos) then
|
||||
if mesecon.do_overheat(pos) then
|
||||
pop_gate(pos)
|
||||
else
|
||||
local node = minetest.get_node(pos)
|
||||
if on then
|
||||
minetest.swap_node(pos, {name = "mesecons_gates:"..gate.."_on", param2=node.param2})
|
||||
mesecon:receptor_on(pos,
|
||||
gate_get_output_rules(node))
|
||||
else
|
||||
minetest.swap_node(pos, {name = "mesecons_gates:"..gate.."_off", param2=node.param2})
|
||||
mesecon:receptor_off(pos,
|
||||
gate_get_output_rules(node))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function get_gate(pos)
|
||||
return minetest.registered_nodes[minetest.get_node(pos).name].mesecons_gate
|
||||
end
|
||||
|
||||
function gate_state(pos)
|
||||
name = minetest.get_node(pos).name
|
||||
return string.find(name, "_on") ~= nil
|
||||
end
|
||||
|
||||
function pop_gate(pos)
|
||||
gate = get_gate(pos)
|
||||
minetest.remove_node(pos)
|
||||
minetest.after(0.2, function (pos)
|
||||
mesecon:receptor_off(pos, mesecon.rules.flat)
|
||||
end , pos) -- wait for pending parsings
|
||||
minetest.add_item(pos, "mesecons_gates:"..gate.."_off")
|
||||
end
|
||||
|
||||
function rotate_ports(L, param2)
|
||||
for rotations=0, param2-1 do
|
||||
port = L.a
|
||||
L.a = L.b
|
||||
L.b = L.c
|
||||
L.c = L.d
|
||||
L.d = port
|
||||
end
|
||||
return L
|
||||
end
|
||||
|
||||
gates = {
|
||||
{name = "diode", inputnumber = 1},
|
||||
{name = "not" , inputnumber = 1},
|
||||
{name = "nand" , inputnumber = 2},
|
||||
{name = "and" , inputnumber = 2},
|
||||
{name = "xor" , inputnumber = 2}}
|
||||
|
||||
local onoff, drop, nodename, description, groups
|
||||
for _, gate in ipairs(gates) do
|
||||
if gate.inputnumber == 1 then
|
||||
get_rules = gate_get_input_rules_oneinput
|
||||
elseif gate.inputnumber == 2 then
|
||||
get_rules = gate_get_input_rules_twoinputs
|
||||
end
|
||||
for on = 0, 1 do
|
||||
nodename = "mesecons_gates:"..gate.name
|
||||
if on == 1 then
|
||||
onoff = "on"
|
||||
drop = nodename.."_off"
|
||||
nodename = nodename.."_"..onoff
|
||||
description = "You hacker you!"
|
||||
groups = {dig_immediate=2, not_in_creative_inventory=1, overheat = 1}
|
||||
else
|
||||
onoff = "off"
|
||||
drop = nil
|
||||
nodename = nodename.."_"..onoff
|
||||
description = gate.name.." Gate"
|
||||
groups = {dig_immediate=2, overheat = 1}
|
||||
end
|
||||
|
||||
tiles = "jeija_microcontroller_bottom.png^"..
|
||||
"jeija_gate_"..onoff..".png^"..
|
||||
"jeija_gate_"..gate.name..".png"
|
||||
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-8/16, -8/16, -8/16, 8/16, -7/16, 8/16 },
|
||||
},
|
||||
}
|
||||
|
||||
local mesecon_state
|
||||
if on == 1 then
|
||||
mesecon_state = mesecon.state.on
|
||||
else
|
||||
mesecon_state = mesecon.state.off
|
||||
end
|
||||
|
||||
minetest.register_node(nodename, {
|
||||
description = description,
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
drawtype = "nodebox",
|
||||
tiles = {tiles},
|
||||
inventory_image = tiles,
|
||||
selection_box = node_box,
|
||||
node_box = node_box,
|
||||
walkable = true,
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
update_gate(pos)
|
||||
end,
|
||||
groups = groups,
|
||||
drop = drop,
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
mesecons_gate = gate.name,
|
||||
mesecons =
|
||||
{
|
||||
receptor =
|
||||
{
|
||||
state = mesecon_state,
|
||||
rules = gate_get_output_rules
|
||||
},
|
||||
effector =
|
||||
{
|
||||
rules = get_rules,
|
||||
action_change = update_gate
|
||||
}
|
||||
}
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'mesecons_gates:diode_off',
|
||||
recipe = {
|
||||
{'', '', ''},
|
||||
{'mesecons:mesecon', 'mesecons_torch:mesecon_torch_on', 'mesecons_torch:mesecon_torch_on'},
|
||||
{'', '', ''},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'mesecons_gates:not_off',
|
||||
recipe = {
|
||||
{'', '', ''},
|
||||
{'mesecons:mesecon', 'mesecons_torch:mesecon_torch_on', 'mesecons:mesecon'},
|
||||
{'', '', ''},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'mesecons_gates:and_off',
|
||||
recipe = {
|
||||
{'mesecons:mesecon', '', ''},
|
||||
{'', 'mesecons_materials:silicon', 'mesecons:mesecon'},
|
||||
{'mesecons:mesecon', '', ''},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'mesecons_gates:nand_off',
|
||||
recipe = {
|
||||
{'mesecons:mesecon', '', ''},
|
||||
{'', 'mesecons_materials:silicon', 'mesecons_torch:mesecon_torch_on'},
|
||||
{'mesecons:mesecon', '', ''},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'mesecons_gates:xor_off',
|
||||
recipe = {
|
||||
{'mesecons:mesecon', '', ''},
|
||||
{'', 'mesecons_materials:silicon', 'mesecons_materials:silicon'},
|
||||
{'mesecons:mesecon', '', ''},
|
||||
},
|
||||
})
|
BIN
mods/mesecons/.mesecons_gates/textures/jeija_gate_and.png
Executable file
After Width: | Height: | Size: 233 B |
BIN
mods/mesecons/.mesecons_gates/textures/jeija_gate_diode.png
Executable file
After Width: | Height: | Size: 231 B |
BIN
mods/mesecons/.mesecons_gates/textures/jeija_gate_nand.png
Executable file
After Width: | Height: | Size: 251 B |
BIN
mods/mesecons/.mesecons_gates/textures/jeija_gate_not.png
Executable file
After Width: | Height: | Size: 241 B |
BIN
mods/mesecons/.mesecons_gates/textures/jeija_gate_off.png
Executable file
After Width: | Height: | Size: 195 B |
BIN
mods/mesecons/.mesecons_gates/textures/jeija_gate_on.png
Executable file
After Width: | Height: | Size: 195 B |
BIN
mods/mesecons/.mesecons_gates/textures/jeija_gate_xor.png
Executable file
After Width: | Height: | Size: 245 B |
1
mods/mesecons/.mesecons_luacontroller/depends.txt
Executable file
@ -0,0 +1 @@
|
||||
mesecons
|
560
mods/mesecons/.mesecons_luacontroller/init.lua
Executable file
@ -0,0 +1,560 @@
|
||||
-- Reference
|
||||
-- ports = get_real_portstates(pos): gets if inputs are powered from outside
|
||||
-- newport = merge_portstates(state1, state2): just does result = state1 or state2 for every port
|
||||
-- action_setports(pos, rule, state): activates/deactivates the mesecons according to the portstates (helper for action)
|
||||
-- action(pos, ports): Applies new portstates to a luacontroller at pos
|
||||
-- lc_update(pos): updates the controller at pos by executing the code
|
||||
-- reset_meta (pos, code, errmsg): performs a software-reset, installs new code and prints error messages
|
||||
-- reset (pos): performs a hardware reset, turns off all ports
|
||||
--
|
||||
-- The Sandbox
|
||||
-- The whole code of the controller runs in a sandbox,
|
||||
-- a very restricted environment.
|
||||
-- However, as this does not prevent you from using e.g. loops,
|
||||
-- we need to check for these prohibited commands first.
|
||||
-- Actually the only way to damage the server is to
|
||||
-- use too much memory from the sandbox.
|
||||
-- You can add more functions to the environment
|
||||
-- (see where local env is defined)
|
||||
-- Something nice to play is is appending minetest. to it.
|
||||
|
||||
local BASENAME = "mesecons_luacontroller:luacontroller"
|
||||
|
||||
local rules = {}
|
||||
rules.a = {x = -1, y = 0, z = 0, name="A"}
|
||||
rules.b = {x = 0, y = 0, z = 1, name="B"}
|
||||
rules.c = {x = 1, y = 0, z = 0, name="C"}
|
||||
rules.d = {x = 0, y = 0, z = -1, name="D"}
|
||||
|
||||
------------------
|
||||
-- Action stuff --
|
||||
------------------
|
||||
-- These helpers are required to set the portstates of the luacontroller
|
||||
|
||||
function lc_update_real_portstates(pos, rulename, newstate)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if rulename == nil then
|
||||
meta:set_int("real_portstates", 1)
|
||||
return
|
||||
end
|
||||
local n = meta:get_int("real_portstates") - 1
|
||||
if n < 0 then
|
||||
legacy_update_ports(pos)
|
||||
n = meta:get_int("real_portstates") - 1
|
||||
end
|
||||
local L = {}
|
||||
for i = 1, 4 do
|
||||
L[i] = n%2
|
||||
n = math.floor(n/2)
|
||||
end
|
||||
if rulename.x == nil then
|
||||
for _, rname in ipairs(rulename) do
|
||||
local port = ({4, 1, nil, 3, 2})[rname.x+2*rname.z+3]
|
||||
L[port] = (newstate == "on") and 1 or 0
|
||||
end
|
||||
else
|
||||
local port = ({4, 1, nil, 3, 2})[rulename.x+2*rulename.z+3]
|
||||
L[port] = (newstate == "on") and 1 or 0
|
||||
end
|
||||
meta:set_int("real_portstates", 1 + L[1] + 2*L[2] + 4*L[3] + 8*L[4])
|
||||
end
|
||||
|
||||
local get_real_portstates = function(pos) -- determine if ports are powered (by itself or from outside)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local L = {}
|
||||
local n = meta:get_int("real_portstates") - 1
|
||||
if n < 0 then
|
||||
return legacy_update_ports(pos)
|
||||
end
|
||||
for _, index in ipairs({"a", "b", "c", "d"}) do
|
||||
L[index] = ((n%2) == 1)
|
||||
n = math.floor(n/2)
|
||||
end
|
||||
return L
|
||||
end
|
||||
|
||||
local merge_portstates = function (ports, vports)
|
||||
local npo = {a=false, b=false, c=false, d=false}
|
||||
npo.a = vports.a or ports.a
|
||||
npo.b = vports.b or ports.b
|
||||
npo.c = vports.c or ports.c
|
||||
npo.d = vports.d or ports.d
|
||||
return npo
|
||||
end
|
||||
|
||||
local generate_name = function (ports)
|
||||
local overwrite = overwrite or {}
|
||||
local d = ports.d and 1 or 0
|
||||
local c = ports.c and 1 or 0
|
||||
local b = ports.b and 1 or 0
|
||||
local a = ports.a and 1 or 0
|
||||
return BASENAME..d..c..b..a
|
||||
end
|
||||
|
||||
local setport = function (pos, rule, state)
|
||||
if state then
|
||||
mesecon:receptor_on(pos, {rule})
|
||||
else
|
||||
mesecon:receptor_off(pos, {rule})
|
||||
end
|
||||
end
|
||||
|
||||
local action = function (pos, ports)
|
||||
local node = minetest.get_node(pos)
|
||||
local name = node.name
|
||||
local vports = minetest.registered_nodes[name].virtual_portstates
|
||||
local newname = generate_name(ports)
|
||||
|
||||
if name ~= newname and vports then
|
||||
local rules_on = {}
|
||||
local rules_off = {}
|
||||
|
||||
minetest.swap_node(pos, {name = newname, param2 = node.param2})
|
||||
|
||||
if ports.a ~= vports.a then setport(pos, rules.a, ports.a) end
|
||||
if ports.b ~= vports.b then setport(pos, rules.b, ports.b) end
|
||||
if ports.c ~= vports.c then setport(pos, rules.c, ports.c) end
|
||||
if ports.d ~= vports.d then setport(pos, rules.d, ports.d) end
|
||||
end
|
||||
end
|
||||
|
||||
--------------------
|
||||
-- Overheat stuff --
|
||||
--------------------
|
||||
|
||||
local overheat_off = function(pos)
|
||||
mesecon:receptor_off(pos, mesecon.rules.flat)
|
||||
end
|
||||
|
||||
-------------------
|
||||
-- Parsing stuff --
|
||||
-------------------
|
||||
|
||||
local code_prohibited = function(code)
|
||||
-- Clean code
|
||||
local prohibited = {"while", "for", "repeat", "until", "function", "goto"}
|
||||
for _, p in ipairs(prohibited) do
|
||||
if string.find(code, p) then
|
||||
return "Prohibited command: "..p
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local safe_print = function(param)
|
||||
print(dump(param))
|
||||
end
|
||||
|
||||
deep_copy = function(original, visited) --deep copy that removes functions
|
||||
visited = visited or {}
|
||||
if visited[original] ~= nil then --already visited this node
|
||||
return visited[original]
|
||||
end
|
||||
if type(original) == 'table' then --nested table
|
||||
local copy = {}
|
||||
visited[original] = copy
|
||||
for key, value in next, original, nil do
|
||||
copy[deep_copy(key, visited)] = deep_copy(value, visited)
|
||||
end
|
||||
setmetatable(copy, deep_copy(getmetatable(original), visited))
|
||||
return copy
|
||||
elseif type(original) == 'function' then --ignore functions
|
||||
return nil
|
||||
else --by-value type
|
||||
return original
|
||||
end
|
||||
end
|
||||
|
||||
local safe_serialize = function(value)
|
||||
return minetest.serialize(deep_copy(value))
|
||||
end
|
||||
|
||||
mesecon.queue:add_function("lc_interrupt", function (pos, iid, luac_id)
|
||||
-- There is no luacontroller anymore / it has been reprogrammed / replaced
|
||||
if (minetest.get_meta(pos):get_int("luac_id") ~= luac_id) then return end
|
||||
lc_update(pos, {type="interrupt", iid = iid})
|
||||
end)
|
||||
|
||||
local getinterrupt = function(pos)
|
||||
local interrupt = function (time, iid) -- iid = interrupt id
|
||||
if type(time) ~= "number" then return end
|
||||
luac_id = minetest.get_meta(pos):get_int("luac_id")
|
||||
mesecon.queue:add_action(pos, "lc_interrupt", {iid, luac_id}, time, iid, 1)
|
||||
end
|
||||
return interrupt
|
||||
end
|
||||
|
||||
local getdigiline_send = function(pos)
|
||||
if not digiline then return end
|
||||
-- Send messages on next serverstep
|
||||
return function(channel, msg)
|
||||
minetest.after(0, function()
|
||||
digiline:receptor_send(pos, digiline.rules.default, channel, msg)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
local create_environment = function(pos, mem, event)
|
||||
-- Gather variables for the environment
|
||||
local vports = minetest.registered_nodes[minetest.get_node(pos).name].virtual_portstates
|
||||
vports = {a = vports.a, b = vports.b, c = vports.c, d = vports.d}
|
||||
local rports = get_real_portstates(pos)
|
||||
|
||||
return {
|
||||
print = safe_print,
|
||||
pin = merge_portstates(vports, rports),
|
||||
port = vports,
|
||||
interrupt = getinterrupt(pos),
|
||||
digiline_send = getdigiline_send(pos),
|
||||
mem = mem,
|
||||
tostring = tostring,
|
||||
tonumber = tonumber,
|
||||
heat = minetest.get_meta(pos):get_int("heat"),
|
||||
heat_max = OVERHEAT_MAX,
|
||||
string = {
|
||||
byte = string.byte,
|
||||
char = string.char,
|
||||
find = string.find,
|
||||
format = string.format,
|
||||
gmatch = string.gmatch,
|
||||
gsub = string.gsub,
|
||||
len = string.len,
|
||||
lower = string.lower,
|
||||
upper = string.upper,
|
||||
match = string.match,
|
||||
rep = string.rep,
|
||||
reverse = string.reverse,
|
||||
sub = string.sub,
|
||||
},
|
||||
math = {
|
||||
abs = math.abs,
|
||||
acos = math.acos,
|
||||
asin = math.asin,
|
||||
atan = math.atan,
|
||||
atan2 = math.atan2,
|
||||
ceil = math.ceil,
|
||||
cos = math.cos,
|
||||
cosh = math.cosh,
|
||||
deg = math.deg,
|
||||
exp = math.exp,
|
||||
floor = math.floor,
|
||||
fmod = math.fmod,
|
||||
frexp = math.frexp,
|
||||
huge = math.huge,
|
||||
ldexp = math.ldexp,
|
||||
log = math.log,
|
||||
log10 = math.log10,
|
||||
max = math.max,
|
||||
min = math.min,
|
||||
modf = math.modf,
|
||||
pi = math.pi,
|
||||
pow = math.pow,
|
||||
rad = math.rad,
|
||||
random = math.random,
|
||||
sin = math.sin,
|
||||
sinh = math.sinh,
|
||||
sqrt = math.sqrt,
|
||||
tan = math.tan,
|
||||
tanh = math.tanh,
|
||||
},
|
||||
table = {
|
||||
insert = table.insert,
|
||||
maxn = table.maxn,
|
||||
remove = table.remove,
|
||||
sort = table.sort
|
||||
},
|
||||
event = event,
|
||||
}
|
||||
end
|
||||
|
||||
local create_sandbox = function (code, env)
|
||||
-- Create Sandbox
|
||||
if code:byte(1) == 27 then
|
||||
return _, "You Hacker You! Don't use binary code!"
|
||||
end
|
||||
f, msg = loadstring(code)
|
||||
if not f then return _, msg end
|
||||
setfenv(f, env)
|
||||
return f
|
||||
end
|
||||
|
||||
local lc_overheat = function (pos, meta)
|
||||
if mesecon.do_overheat(pos) then -- if too hot
|
||||
local node = minetest.get_node(pos)
|
||||
minetest.swap_node(pos, {name = BASENAME.."_burnt", param2 = node.param2})
|
||||
minetest.after(0.2, overheat_off, pos) -- wait for pending operations
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local load_memory = function(meta)
|
||||
return minetest.deserialize(meta:get_string("lc_memory")) or {}
|
||||
end
|
||||
|
||||
local save_memory = function(meta, mem)
|
||||
meta:set_string("lc_memory", safe_serialize(mem))
|
||||
end
|
||||
|
||||
local ports_invalid = function (var)
|
||||
if type(var) == "table" then
|
||||
return false
|
||||
end
|
||||
return "The ports you set are invalid"
|
||||
end
|
||||
|
||||
----------------------
|
||||
-- Parsing function --
|
||||
----------------------
|
||||
|
||||
lc_update = function (pos, event)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if lc_overheat(pos) then return end
|
||||
|
||||
-- load code & mem from memory
|
||||
local mem = load_memory(meta)
|
||||
local code = meta:get_string("code")
|
||||
|
||||
-- make sure code is ok and create environment
|
||||
local prohibited = code_prohibited(code)
|
||||
if prohibited then return prohibited end
|
||||
local env = create_environment(pos, mem, event)
|
||||
|
||||
-- create the sandbox and execute code
|
||||
local chunk, msg = create_sandbox (code, env)
|
||||
if not chunk then return msg end
|
||||
local success, msg = pcall(f)
|
||||
if not success then return msg end
|
||||
if ports_invalid(env.port) then return ports_invalid(env.port) end
|
||||
|
||||
save_memory(meta, mem)
|
||||
|
||||
-- Actually set the ports
|
||||
action(pos, env.port)
|
||||
end
|
||||
|
||||
local reset_meta = function(pos, code, errmsg)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("code", code)
|
||||
code = minetest.formspec_escape(code or "")
|
||||
errmsg = minetest.formspec_escape(errmsg or "")
|
||||
meta:set_string("formspec", "size[10,8]"..
|
||||
"background[-0.2,-0.25;10.4,8.75;jeija_luac_background.png]"..
|
||||
"textarea[0.2,0.6;10.2,5;code;;"..code.."]"..
|
||||
"image_button[3.75,6;2.5,1;jeija_luac_runbutton.png;program;]"..
|
||||
"image_button_exit[9.72,-0.25;0.425,0.4;jeija_close_window.png;exit;]"..
|
||||
"label[0.1,5;"..errmsg.."]")
|
||||
meta:set_int("heat", 0)
|
||||
meta:set_int("luac_id", math.random(1, 1000000))
|
||||
end
|
||||
|
||||
local reset = function (pos)
|
||||
action(pos, {a=false, b=false, c=false, d=false})
|
||||
end
|
||||
|
||||
-- ______
|
||||
-- |
|
||||
-- |
|
||||
-- | __ ___ _ __ _ _
|
||||
-- | | | | | |\ | | |_| | | | | |_ |_|
|
||||
-- |___| |______ |__| | \| | | \ |__| |_ |_ |_ |\
|
||||
-- |
|
||||
-- |
|
||||
--
|
||||
|
||||
-----------------------
|
||||
-- Node Registration --
|
||||
-----------------------
|
||||
|
||||
local output_rules={}
|
||||
local input_rules={}
|
||||
|
||||
local nodebox = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{ -8/16, -8/16, -8/16, 8/16, -7/16, 8/16 }, -- bottom slab
|
||||
{ -5/16, -7/16, -5/16, 5/16, -6/16, 5/16 }, -- circuit board
|
||||
{ -3/16, -6/16, -3/16, 3/16, -5/16, 3/16 }, -- IC
|
||||
}
|
||||
}
|
||||
|
||||
local selectionbox = {
|
||||
type = "fixed",
|
||||
fixed = { -8/16, -8/16, -8/16, 8/16, -5/16, 8/16 },
|
||||
}
|
||||
|
||||
local digiline = {
|
||||
receptor = {},
|
||||
effector = {
|
||||
action = function (pos, node, channel, msg)
|
||||
lc_update (pos, {type = "digiline", channel = channel, msg = msg})
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
for a = 0, 1 do -- 0 = off; 1 = on
|
||||
for b = 0, 1 do
|
||||
for c = 0, 1 do
|
||||
for d = 0, 1 do
|
||||
|
||||
local cid = tostring(d)..tostring(c)..tostring(b)..tostring(a)
|
||||
local nodename = BASENAME..cid
|
||||
local top = "jeija_luacontroller_top.png"
|
||||
if a == 1 then
|
||||
top = top.."^jeija_luacontroller_LED_A.png"
|
||||
end
|
||||
if b == 1 then
|
||||
top = top.."^jeija_luacontroller_LED_B.png"
|
||||
end
|
||||
if c == 1 then
|
||||
top = top.."^jeija_luacontroller_LED_C.png"
|
||||
end
|
||||
if d == 1 then
|
||||
top = top.."^jeija_luacontroller_LED_D.png"
|
||||
end
|
||||
|
||||
if a + b + c + d ~= 0 then
|
||||
groups = {dig_immediate=2, not_in_creative_inventory=1, overheat = 1}
|
||||
else
|
||||
groups = {dig_immediate=2, overheat = 1}
|
||||
end
|
||||
|
||||
output_rules[cid] = {}
|
||||
input_rules[cid] = {}
|
||||
if (a == 1) then table.insert(output_rules[cid], rules.a) end
|
||||
if (b == 1) then table.insert(output_rules[cid], rules.b) end
|
||||
if (c == 1) then table.insert(output_rules[cid], rules.c) end
|
||||
if (d == 1) then table.insert(output_rules[cid], rules.d) end
|
||||
|
||||
if (a == 0) then table.insert(input_rules[cid], rules.a) end
|
||||
if (b == 0) then table.insert(input_rules[cid], rules.b) end
|
||||
if (c == 0) then table.insert(input_rules[cid], rules.c) end
|
||||
if (d == 0) then table.insert(input_rules[cid], rules.d) end
|
||||
|
||||
local mesecons = {
|
||||
effector =
|
||||
{
|
||||
rules = input_rules[cid],
|
||||
action_change = function (pos, _, rulename, newstate)
|
||||
lc_update_real_portstates(pos, rulename, newstate)
|
||||
lc_update(pos, {type=newstate, pin=rulename})
|
||||
end,
|
||||
},
|
||||
receptor =
|
||||
{
|
||||
state = mesecon.state.on,
|
||||
rules = output_rules[cid]
|
||||
}
|
||||
}
|
||||
|
||||
minetest.register_node(nodename, {
|
||||
description = "Luacontroller",
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
top,
|
||||
"jeija_microcontroller_bottom.png",
|
||||
"jeija_microcontroller_sides.png",
|
||||
"jeija_microcontroller_sides.png",
|
||||
"jeija_microcontroller_sides.png",
|
||||
"jeija_microcontroller_sides.png"
|
||||
},
|
||||
|
||||
inventory_image = top,
|
||||
paramtype = "light",
|
||||
groups = groups,
|
||||
drop = BASENAME.."0000",
|
||||
sunlight_propagates = true,
|
||||
selection_box = selectionbox,
|
||||
node_box = nodebox,
|
||||
on_construct = reset_meta,
|
||||
on_receive_fields = function(pos, formname, fields)
|
||||
if not fields.program then
|
||||
return
|
||||
end
|
||||
reset(pos)
|
||||
reset_meta(pos, fields.code)
|
||||
local err = lc_update(pos, {type="program"})
|
||||
if err then
|
||||
print(err)
|
||||
reset_meta(pos, fields.code, err)
|
||||
end
|
||||
end,
|
||||
on_timer = handle_timer,
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
mesecons = mesecons,
|
||||
digiline = digiline,
|
||||
virtual_portstates = { a = a == 1, -- virtual portstates are
|
||||
b = b == 1, -- the ports the the
|
||||
c = c == 1, -- controller powers itself
|
||||
d = d == 1},-- so those that light up
|
||||
after_dig_node = function (pos, node)
|
||||
mesecon:receptor_off(pos, output_rules)
|
||||
end,
|
||||
is_luacontroller = true,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
------------------------------
|
||||
-- overheated luacontroller --
|
||||
------------------------------
|
||||
|
||||
local mesecons_burnt = {
|
||||
effector =
|
||||
{
|
||||
rules = mesecon.rules.flat,
|
||||
action_change = function (pos, _, rulename, newstate)
|
||||
-- only update portstates when changes are triggered
|
||||
lc_update_real_portstates(pos, rulename, newstate)
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
minetest.register_node(BASENAME .. "_burnt", {
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
"jeija_luacontroller_burnt_top.png",
|
||||
"jeija_microcontroller_bottom.png",
|
||||
"jeija_microcontroller_sides.png",
|
||||
"jeija_microcontroller_sides.png",
|
||||
"jeija_microcontroller_sides.png",
|
||||
"jeija_microcontroller_sides.png"
|
||||
},
|
||||
inventory_image = "jeija_luacontroller_burnt_top.png",
|
||||
paramtype = "light",
|
||||
groups = {dig_immediate=2, not_in_creative_inventory=1},
|
||||
drop = BASENAME.."0000",
|
||||
sunlight_propagates = true,
|
||||
selection_box = selectionbox,
|
||||
node_box = nodebox,
|
||||
on_construct = reset_meta,
|
||||
on_receive_fields = function(pos, formname, fields)
|
||||
if fields.quit then
|
||||
return
|
||||
end
|
||||
reset(pos)
|
||||
reset_meta(pos, fields.code)
|
||||
local err = lc_update(pos, {type="program"})
|
||||
if err then
|
||||
print(err)
|
||||
reset_meta(pos, fields.code, err)
|
||||
end
|
||||
end,
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
virtual_portstates = {a = false, b = false, c = false, d = false},
|
||||
mesecons = mesecons_burnt,
|
||||
})
|
||||
|
||||
------------------------
|
||||
-- Craft Registration --
|
||||
------------------------
|
||||
|
||||
minetest.register_craft({
|
||||
output = BASENAME.."0000 2",
|
||||
recipe = {
|
||||
{'mesecons_materials:silicon', 'mesecons_materials:silicon', 'group:mesecon_conductor_craftable'},
|
||||
{'mesecons_materials:silicon', 'mesecons_materials:silicon', 'group:mesecon_conductor_craftable'},
|
||||
{'group:mesecon_conductor_craftable', 'group:mesecon_conductor_craftable', ''},
|
||||
}
|
||||
})
|
||||
|
BIN
mods/mesecons/.mesecons_luacontroller/textures/jeija_luac_background.png
Executable file
After Width: | Height: | Size: 2.0 KiB |
BIN
mods/mesecons/.mesecons_luacontroller/textures/jeija_luac_runbutton.png
Executable file
After Width: | Height: | Size: 4.2 KiB |
BIN
mods/mesecons/.mesecons_luacontroller/textures/jeija_luacontroller_LED_A.png
Executable file
After Width: | Height: | Size: 3.5 KiB |
BIN
mods/mesecons/.mesecons_luacontroller/textures/jeija_luacontroller_LED_B.png
Executable file
After Width: | Height: | Size: 3.5 KiB |
BIN
mods/mesecons/.mesecons_luacontroller/textures/jeija_luacontroller_LED_C.png
Executable file
After Width: | Height: | Size: 3.5 KiB |
BIN
mods/mesecons/.mesecons_luacontroller/textures/jeija_luacontroller_LED_D.png
Executable file
After Width: | Height: | Size: 3.5 KiB |
BIN
mods/mesecons/.mesecons_luacontroller/textures/jeija_luacontroller_burnt_top.png
Executable file
After Width: | Height: | Size: 8.5 KiB |
BIN
mods/mesecons/.mesecons_luacontroller/textures/jeija_luacontroller_top.png
Executable file
After Width: | Height: | Size: 12 KiB |
BIN
mods/mesecons/.mesecons_microcontroller/MeseconMicro.odt
Executable file
BIN
mods/mesecons/.mesecons_microcontroller/MeseconMicro.pdf
Executable file
1
mods/mesecons/.mesecons_microcontroller/depends.txt
Executable file
@ -0,0 +1 @@
|
||||
mesecons
|
696
mods/mesecons/.mesecons_microcontroller/init.lua
Executable file
@ -0,0 +1,696 @@
|
||||
EEPROM_SIZE = 255
|
||||
|
||||
for a = 0, 1 do
|
||||
for b = 0, 1 do
|
||||
for c = 0, 1 do
|
||||
for d = 0, 1 do
|
||||
local nodename = "mesecons_microcontroller:microcontroller"..tostring(d)..tostring(c)..tostring(b)..tostring(a)
|
||||
local top = "jeija_microcontroller_top.png"
|
||||
if tostring(a) == "1" then
|
||||
top = top.."^jeija_microcontroller_LED_A.png"
|
||||
end
|
||||
if tostring(b) == "1" then
|
||||
top = top.."^jeija_microcontroller_LED_B.png"
|
||||
end
|
||||
if tostring(c) == "1" then
|
||||
top = top.."^jeija_microcontroller_LED_C.png"
|
||||
end
|
||||
if tostring(d) == "1" then
|
||||
top = top.."^jeija_microcontroller_LED_D.png"
|
||||
end
|
||||
if tostring(d)..tostring(c)..tostring(b)..tostring(a) ~= "0000" then
|
||||
groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 3, overheat = 1}
|
||||
else
|
||||
groups = {dig_immediate=2, mesecon = 3, overheat = 1}
|
||||
end
|
||||
local rules={}
|
||||
if (a == 1) then table.insert(rules, {x = -1, y = 0, z = 0}) end
|
||||
if (b == 1) then table.insert(rules, {x = 0, y = 0, z = 1}) end
|
||||
if (c == 1) then table.insert(rules, {x = 1, y = 0, z = 0}) end
|
||||
if (d == 1) then table.insert(rules, {x = 0, y = 0, z = -1}) end
|
||||
|
||||
local input_rules={}
|
||||
if (a == 0) then table.insert(input_rules, {x = -1, y = 0, z = 0, name = "A"}) end
|
||||
if (b == 0) then table.insert(input_rules, {x = 0, y = 0, z = 1, name = "B"}) end
|
||||
if (c == 0) then table.insert(input_rules, {x = 1, y = 0, z = 0, name = "C"}) end
|
||||
if (d == 0) then table.insert(input_rules, {x = 0, y = 0, z = -1, name = "D"}) end
|
||||
mesecon:add_rules(nodename, rules)
|
||||
|
||||
local mesecons = {effector =
|
||||
{
|
||||
rules = input_rules,
|
||||
action_change = function (pos, node, rulename, newstate)
|
||||
yc_update_real_portstates(pos, node, rulename, newstate)
|
||||
update_yc(pos)
|
||||
end
|
||||
}}
|
||||
if nodename ~= "mesecons_microcontroller:microcontroller0000" then
|
||||
mesecons.receptor = {
|
||||
state = mesecon.state.on,
|
||||
rules = rules
|
||||
}
|
||||
end
|
||||
|
||||
minetest.register_node(nodename, {
|
||||
description = "Microcontroller",
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
top,
|
||||
"jeija_microcontroller_bottom.png",
|
||||
"jeija_microcontroller_sides.png",
|
||||
"jeija_microcontroller_sides.png",
|
||||
"jeija_microcontroller_sides.png",
|
||||
"jeija_microcontroller_sides.png"
|
||||
},
|
||||
|
||||
sunlight_propagates = true,
|
||||
paramtype = "light",
|
||||
walkable = true,
|
||||
groups = groups,
|
||||
drop = "mesecons_microcontroller:microcontroller0000 1",
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = { -8/16, -8/16, -8/16, 8/16, -5/16, 8/16 },
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{ -8/16, -8/16, -8/16, 8/16, -7/16, 8/16 }, -- bottom slab
|
||||
{ -5/16, -7/16, -5/16, 5/16, -6/16, 5/16 }, -- circuit board
|
||||
{ -3/16, -6/16, -3/16, 3/16, -5/16, 3/16 }, -- IC
|
||||
}
|
||||
},
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("code", "")
|
||||
meta:set_string("formspec", "size[9,2.5]"..
|
||||
"field[0.256,-0.2;9,2;code;Code:;]"..
|
||||
"button[0 ,0.2;1.5,3;band;AND]"..
|
||||
"button[1.5,0.2;1.5,3;bxor;XOR]"..
|
||||
"button[3 ,0.2;1.5,3;bnot;NOT]"..
|
||||
"button[4.5,0.2;1.5,3;bnand;NAND]"..
|
||||
"button[6 ,0.2;1.5,3;btflop;T-Flop]"..
|
||||
"button[7.5,0.2;1.5,3;brsflop;RS-Flop]"..
|
||||
"button_exit[3.5,1;2,3;program;Program]")
|
||||
meta:set_string("infotext", "Unprogrammed Microcontroller")
|
||||
local r = ""
|
||||
for i=1, EEPROM_SIZE+1 do r=r.."0" end --Generate a string with EEPROM_SIZE*"0"
|
||||
meta:set_string("eeprom", r)
|
||||
end,
|
||||
on_receive_fields = function(pos, formanme, fields, sender)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if fields.band then
|
||||
fields.code = "sbi(C, A&B) :A and B are inputs, C is output"
|
||||
elseif fields.bxor then
|
||||
fields.code = "sbi(C, A~B) :A and B are inputs, C is output"
|
||||
elseif fields.bnot then
|
||||
fields.code = "sbi(B, !A) :A is input, B is output"
|
||||
elseif fields.bnand then
|
||||
fields.code = "sbi(C, !A|!B) :A and B are inputs, C is output"
|
||||
elseif fields.btflop then
|
||||
fields.code = "if(A)sbi(1,1);if(!A)sbi(B,!B)sbi(1,0); if(C)off(B,1); :A is input, B is output (Q), C is reset, toggles with falling edge"
|
||||
elseif fields.brsflop then
|
||||
fields.code = "if(A)on(C);if(B)off(C); :A is S (Set), B is R (Reset), C is output (R dominates)"
|
||||
end
|
||||
if fields.code == nil then return end
|
||||
|
||||
meta:set_string("code", fields.code)
|
||||
meta:set_string("formspec", "size[9,2.5]"..
|
||||
"field[0.256,-0.2;9,2;code;Code:;"..minetest.formspec_escape(fields.code).."]"..
|
||||
"button[0 ,0.2;1.5,3;band;AND]"..
|
||||
"button[1.5,0.2;1.5,3;bxor;XOR]"..
|
||||
"button[3 ,0.2;1.5,3;bnot;NOT]"..
|
||||
"button[4.5,0.2;1.5,3;bnand;NAND]"..
|
||||
"button[6 ,0.2;1.5,3;btflop;T-Flop]"..
|
||||
"button[7.5,0.2;1.5,3;brsflop;RS-Flop]"..
|
||||
"button_exit[3.5,1;2,3;program;Program]")
|
||||
meta:set_string("infotext", "Programmed Microcontroller")
|
||||
yc_reset (pos)
|
||||
update_yc(pos)
|
||||
end,
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
mesecons = mesecons,
|
||||
after_dig_node = function (pos, node)
|
||||
rules = mesecon:get_rules(node.name)
|
||||
mesecon:receptor_off(pos, rules)
|
||||
end,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'craft "mesecons_microcontroller:microcontroller0000" 2',
|
||||
recipe = {
|
||||
{'mesecons_materials:silicon', 'mesecons_materials:silicon', 'group:mesecon_conductor_craftable'},
|
||||
{'mesecons_materials:silicon', 'mesecons_materials:silicon', 'group:mesecon_conductor_craftable'},
|
||||
{'group:mesecon_conductor_craftable', 'group:mesecon_conductor_craftable', ''},
|
||||
}
|
||||
})
|
||||
|
||||
function yc_reset(pos)
|
||||
yc_action(pos, {a=false, b=false, c=false, d=false})
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_int("afterid", 0)
|
||||
local r = ""
|
||||
for i=1, EEPROM_SIZE+1 do r=r.."0" end --Generate a string with EEPROM_SIZE*"0"
|
||||
meta:set_string("eeprom", r)
|
||||
end
|
||||
|
||||
function update_yc(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
if (mesecon.do_overheat(pos)) then
|
||||
minetest.remove_node(pos)
|
||||
minetest.after(0.2, function (pos)
|
||||
mesecon:receptor_off(pos, mesecon.rules.flat)
|
||||
end , pos) -- wait for pending parsings
|
||||
minetest.add_item(pos, "mesecons_microcontroller:microcontroller0000")
|
||||
end
|
||||
|
||||
local code = meta:get_string("code")
|
||||
code = yc_code_remove_commentary(code)
|
||||
code = string.gsub(code, " ", "") --Remove all spaces
|
||||
code = string.gsub(code, " ", "") --Remove all tabs
|
||||
if yc_parsecode(code, pos) == nil then
|
||||
meta:set_string("infotext", "Code not valid!\n"..code)
|
||||
else
|
||||
meta:set_string("infotext", "Working Microcontroller\n"..code)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--Code Parsing
|
||||
function yc_code_remove_commentary(code)
|
||||
is_string = false
|
||||
for i = 1, #code do
|
||||
if code:sub(i, i) == '"' then
|
||||
is_string = not is_string --toggle is_string
|
||||
elseif code:sub(i, i) == ":" and not is_string then
|
||||
return code:sub(1, i-1)
|
||||
end
|
||||
end
|
||||
return code
|
||||
end
|
||||
|
||||
function yc_parsecode(code, pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local endi = 1
|
||||
local Lreal = yc_get_real_portstates(pos)
|
||||
local Lvirtual = yc_get_virtual_portstates(pos)
|
||||
if Lvirtual == nil then return nil end
|
||||
local c
|
||||
local eeprom = meta:get_string("eeprom")
|
||||
while true do
|
||||
command, endi = parse_get_command(code, endi)
|
||||
if command == nil then return nil end
|
||||
if command == true then break end --end of code
|
||||
if command == "if" then
|
||||
r, endi = yc_command_if(code, endi, yc_merge_portstates(Lreal, Lvirtual), eeprom)
|
||||
if r == nil then return nil end
|
||||
if r == true then -- nothing
|
||||
elseif r == false then
|
||||
endi_new = yc_skip_to_else (code, endi)
|
||||
if endi_new == nil then --else > not found
|
||||
endi = yc_skip_to_endif(code, endi)
|
||||
else
|
||||
endi = endi_new
|
||||
end
|
||||
if endi == nil then return nil end
|
||||
end
|
||||
else
|
||||
params, endi = parse_get_params(code, endi)
|
||||
if params == nil then return nil end
|
||||
end
|
||||
if command == "on" then
|
||||
L = yc_command_on (params, Lvirtual)
|
||||
elseif command == "off" then
|
||||
L = yc_command_off(params, Lvirtual)
|
||||
elseif command == "print" then
|
||||
local su = yc_command_print(params, eeprom, yc_merge_portstates(Lreal, Lvirtual))
|
||||
if su ~= true then return nil end
|
||||
elseif command == "after" then
|
||||
local su = yc_command_after(params, pos)
|
||||
if su == nil then return nil end
|
||||
elseif command == "sbi" then
|
||||
new_eeprom, Lvirtual = yc_command_sbi (params, eeprom, yc_merge_portstates(Lreal, Lvirtual), Lvirtual)
|
||||
if new_eeprom == nil then return nil
|
||||
else eeprom = new_eeprom end
|
||||
elseif command == "if" then --nothing
|
||||
else
|
||||
return nil
|
||||
end
|
||||
if Lvirtual == nil then return nil end
|
||||
if eeprom == nil then return nil else
|
||||
minetest.get_meta(pos):set_string("eeprom", eeprom) end
|
||||
end
|
||||
yc_action(pos, Lvirtual)
|
||||
return true
|
||||
end
|
||||
|
||||
function parse_get_command(code, starti)
|
||||
i = starti
|
||||
s = nil
|
||||
while s ~= "" do
|
||||
s = string.sub(code, i, i)
|
||||
if s == "(" then
|
||||
return string.sub(code, starti, i-1), i + 1 -- i: ( i+1 after (
|
||||
end
|
||||
if s == ";" and starti == i then
|
||||
starti = starti + 1
|
||||
i = starti
|
||||
elseif s == ">" then
|
||||
starti = yc_skip_to_endif(code, starti)
|
||||
if starti == nil then return nil end
|
||||
i = starti
|
||||
else
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
|
||||
if starti == i-1 then
|
||||
return true, true
|
||||
end
|
||||
return nil, nil
|
||||
end
|
||||
|
||||
function parse_get_params(code, starti)
|
||||
i = starti
|
||||
s = nil
|
||||
local params = {}
|
||||
local is_string = false
|
||||
while s ~= "" do
|
||||
s = string.sub(code, i, i)
|
||||
if code:sub(i, i) == '"' then
|
||||
is_string = (is_string==false) --toggle is_string
|
||||
end
|
||||
if s == ")" and is_string == false then
|
||||
table.insert(params, string.sub(code, starti, i-1)) -- i: ) i+1 after )
|
||||
return params, i + 1
|
||||
end
|
||||
if s == "," and is_string == false then
|
||||
table.insert(params, string.sub(code, starti, i-1)) -- i: ) i+1 after )
|
||||
starti = i + 1
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
return nil, nil
|
||||
end
|
||||
|
||||
function yc_parse_get_eeprom_param(cond, starti)
|
||||
i = starti
|
||||
s = nil
|
||||
local addr
|
||||
while s ~= "" do
|
||||
s = string.sub(cond, i, i)
|
||||
if string.find("0123456789", s) == nil or s == "" then
|
||||
addr = string.sub(cond, starti, i-1) -- i: last number i+1 after last number
|
||||
return addr, i
|
||||
end
|
||||
if s == "," then return nil, nil end
|
||||
i = i + 1
|
||||
end
|
||||
return nil, nil
|
||||
end
|
||||
|
||||
function yc_skip_to_endif(code, starti)
|
||||
local i = starti
|
||||
local s = false
|
||||
local open_ifs = 1
|
||||
while s ~= nil and s~= "" do
|
||||
s = code:sub(i, i)
|
||||
if s == "i" and code:sub(i+1, i+1) == "f" then --if in µCScript
|
||||
open_ifs = open_ifs + 1
|
||||
end
|
||||
if s == ";" then
|
||||
open_ifs = open_ifs - 1
|
||||
end
|
||||
if open_ifs == 0 then
|
||||
return i + 1
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function yc_skip_to_else(code, starti)
|
||||
local i = starti
|
||||
local s = false
|
||||
local open_ifs = 1
|
||||
while s ~= nil and s~= "" do
|
||||
s = code:sub(i, i)
|
||||
if s == "i" and code:sub(i+1, i+1) == "f" then --if in µCScript
|
||||
open_ifs = open_ifs + 1
|
||||
end
|
||||
if s == ";" then
|
||||
open_ifs = open_ifs - 1
|
||||
end
|
||||
if open_ifs == 1 and s == ">" then
|
||||
return i + 1
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
--Commands
|
||||
function yc_command_on(params, L)
|
||||
local rules = {}
|
||||
for i, port in ipairs(params) do
|
||||
L = yc_set_portstate (port, true, L)
|
||||
end
|
||||
return L
|
||||
end
|
||||
|
||||
function yc_command_off(params, L)
|
||||
local rules = {}
|
||||
for i, port in ipairs(params) do
|
||||
L = yc_set_portstate (port, false, L)
|
||||
end
|
||||
return L
|
||||
end
|
||||
|
||||
function yc_command_print(params, eeprom, L)
|
||||
local s = ""
|
||||
for i, param in ipairs(params) do
|
||||
if param:sub(1,1) == '"' and param:sub(#param, #param) == '"' then
|
||||
s = s..param:sub(2, #param-1)
|
||||
else
|
||||
r = yc_command_parsecondition(param, L, eeprom)
|
||||
if r == "1" or r == "0" then
|
||||
s = s..r
|
||||
else return nil end
|
||||
end
|
||||
end
|
||||
print(s) --don't remove
|
||||
return true
|
||||
end
|
||||
|
||||
function yc_command_sbi(params, eeprom, L, Lv)
|
||||
if params[1]==nil or params[2]==nil or params[3] ~=nil then return nil end
|
||||
local status = yc_command_parsecondition(params[2], L, eeprom)
|
||||
|
||||
if status == nil then return nil, nil end
|
||||
|
||||
if string.find("ABCD", params[1])~=nil and #params[1]==1 then --is a port
|
||||
if status == "1" then
|
||||
Lv = yc_set_portstate (params[1], true, Lv)
|
||||
else
|
||||
Lv = yc_set_portstate (params[1], false, Lv)
|
||||
end
|
||||
return eeprom, Lv;
|
||||
end
|
||||
|
||||
--is an eeprom address
|
||||
new_eeprom = "";
|
||||
for i=1, #eeprom do
|
||||
if tonumber(params[1])==i then
|
||||
new_eeprom = new_eeprom..status
|
||||
else
|
||||
new_eeprom = new_eeprom..eeprom:sub(i, i)
|
||||
end
|
||||
end
|
||||
return new_eeprom, Lv
|
||||
end
|
||||
|
||||
-- after (delay)
|
||||
function yc_command_after(params, pos)
|
||||
if params[1] == nil or params[2] == nil or params[3] ~= nil then return nil end
|
||||
|
||||
--get time (maximum time is 200)
|
||||
local time = tonumber(params[1])
|
||||
if time == nil or time > 200 then
|
||||
return nil
|
||||
end
|
||||
|
||||
--get code in quotes "code"
|
||||
if string.sub(params[2], 1, 1) ~= '"' or string.sub(params[2], #params[2], #params[2]) ~= '"' then return nil end
|
||||
local code = string.sub(params[2], 2, #params[2] - 1)
|
||||
|
||||
local afterid = math.random(10000)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_int("afterid", afterid)
|
||||
minetest.after(time, yc_command_after_execute, {pos = pos, code = code, afterid = afterid})
|
||||
return true
|
||||
end
|
||||
|
||||
function yc_command_after_execute(params)
|
||||
local meta = minetest.get_meta(params.pos)
|
||||
if meta:get_int("afterid") == params.afterid then --make sure the node has not been changed
|
||||
if yc_parsecode(params.code, params.pos) == nil then
|
||||
meta:set_string("infotext", "Code in after() not valid!")
|
||||
else
|
||||
if code ~= nil then
|
||||
meta:set_string("infotext", "Working Microcontroller\n"..code)
|
||||
else
|
||||
meta:set_string("infotext", "Working Microcontroller")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--If
|
||||
function yc_command_if(code, starti, L, eeprom)
|
||||
local cond, endi = yc_command_if_getcondition(code, starti)
|
||||
if cond == nil then return nil end
|
||||
|
||||
cond = yc_command_parsecondition(cond, L, eeprom)
|
||||
|
||||
if cond == "0" then result = false
|
||||
elseif cond == "1" then result = true
|
||||
else result = nil end
|
||||
if result == nil then end
|
||||
return result, endi --endi from local cond, endi = yc_command_if_getcondition(code, starti)
|
||||
end
|
||||
|
||||
--Condition parsing
|
||||
function yc_command_if_getcondition(code, starti)
|
||||
i = starti
|
||||
s = nil
|
||||
local brackets = 1 --1 Bracket to close
|
||||
while s ~= "" do
|
||||
s = string.sub(code, i, i)
|
||||
|
||||
if s == ")" then
|
||||
brackets = brackets - 1
|
||||
end
|
||||
|
||||
if s == "(" then
|
||||
brackets = brackets + 1
|
||||
end
|
||||
|
||||
if brackets == 0 then
|
||||
return string.sub(code, starti, i-1), i + 1 -- i: ( i+1 after (
|
||||
end
|
||||
|
||||
i = i + 1
|
||||
end
|
||||
return nil, nil
|
||||
end
|
||||
|
||||
function yc_command_parsecondition(cond, L, eeprom)
|
||||
cond = string.gsub(cond, "A", tonumber(L.a and 1 or 0))
|
||||
cond = string.gsub(cond, "B", tonumber(L.b and 1 or 0))
|
||||
cond = string.gsub(cond, "C", tonumber(L.c and 1 or 0))
|
||||
cond = string.gsub(cond, "D", tonumber(L.d and 1 or 0))
|
||||
|
||||
|
||||
local i = 1
|
||||
local l = string.len(cond)
|
||||
while i<=l do
|
||||
local s = cond:sub(i,i)
|
||||
if s == "#" then
|
||||
addr, endi = yc_parse_get_eeprom_param(cond, i+1)
|
||||
buf = yc_eeprom_read(tonumber(addr), eeprom)
|
||||
if buf == nil then return nil end
|
||||
local call = cond:sub(i, endi-1)
|
||||
cond = string.gsub(cond, call, buf)
|
||||
i = 0
|
||||
l = string.len(cond)
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
cond = string.gsub(cond, "!0", "1")
|
||||
cond = string.gsub(cond, "!1", "0")
|
||||
|
||||
local i = 2
|
||||
local l = string.len(cond)
|
||||
while i<=l do
|
||||
local s = cond:sub(i,i)
|
||||
local b = tonumber(cond:sub(i-1, i-1))
|
||||
local a = tonumber(cond:sub(i+1, i+1))
|
||||
if cond:sub(i+1, i+1) == nil then break end
|
||||
if s == "=" then
|
||||
if a==nil then return nil end
|
||||
if b==nil then return nil end
|
||||
if a == b then buf = "1" end
|
||||
if a ~= b then buf = "0" end
|
||||
cond = string.gsub(cond, b..s..a, buf)
|
||||
i = 1
|
||||
l = string.len(cond)
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
local i = 2
|
||||
local l = string.len(cond)
|
||||
while i<=l do
|
||||
local s = cond:sub(i,i)
|
||||
local b = tonumber(cond:sub(i-1, i-1))
|
||||
local a = tonumber(cond:sub(i+1, i+1))
|
||||
if cond:sub(i+1, i+1) == nil then break end
|
||||
if s == "&" then
|
||||
if a==nil then return nil end
|
||||
local buf = ((a==1) and (b==1))
|
||||
if buf == true then buf = "1" end
|
||||
if buf == false then buf = "0" end
|
||||
cond = string.gsub(cond, b..s..a, buf)
|
||||
i = 1
|
||||
l = string.len(cond)
|
||||
end
|
||||
if s == "|" then
|
||||
if a==nil then return nil end
|
||||
local buf = ((a == 1) or (b == 1))
|
||||
if buf == true then buf = "1" end
|
||||
if buf == false then buf = "0" end
|
||||
cond = string.gsub(cond, b..s..a, buf)
|
||||
i = 1
|
||||
l = string.len(cond)
|
||||
end
|
||||
if s == "~" then
|
||||
if a==nil then return nil end
|
||||
local buf = (((a == 1) or (b == 1)) and not((a==1) and (b==1)))
|
||||
if buf == true then buf = "1" end
|
||||
if buf == false then buf = "0" end
|
||||
cond = string.gsub(cond, b..s..a, buf)
|
||||
i = 1
|
||||
l = string.len(cond)
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
return cond
|
||||
end
|
||||
|
||||
--Virtual-Hardware functions
|
||||
function yc_eeprom_read(number, eeprom)
|
||||
if number == nil then return nil, nil end
|
||||
value = eeprom:sub(number, number)
|
||||
if value == nil then return nil, nil end
|
||||
return value, endi
|
||||
end
|
||||
|
||||
--Real I/O functions
|
||||
function yc_action(pos, L) --L-->Lvirtual
|
||||
local Lv = yc_get_virtual_portstates(pos)
|
||||
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)
|
||||
local node = minetest.get_node(pos)
|
||||
minetest.swap_node(pos, {name = name, param2 = node.param2})
|
||||
|
||||
yc_action_setports(pos, L, Lv)
|
||||
end
|
||||
|
||||
function yc_action_setports(pos, L, Lv)
|
||||
local name = "mesecons_microcontroller:microcontroller"
|
||||
local rules
|
||||
if Lv.a ~= L.a then
|
||||
rules = mesecon:get_rules(name.."0001")
|
||||
if L.a == true then mesecon:receptor_on(pos, rules)
|
||||
else mesecon:receptor_off(pos, rules) end
|
||||
end
|
||||
if Lv.b ~= L.b then
|
||||
rules = mesecon:get_rules(name.."0010")
|
||||
if L.b == true then mesecon:receptor_on(pos, rules)
|
||||
else mesecon:receptor_off(pos, rules) end
|
||||
end
|
||||
if Lv.c ~= L.c then
|
||||
rules = mesecon:get_rules(name.."0100")
|
||||
if L.c == true then mesecon:receptor_on(pos, rules)
|
||||
else mesecon:receptor_off(pos, rules) end
|
||||
end
|
||||
if Lv.d ~= L.d then
|
||||
rules = mesecon:get_rules(name.."1000")
|
||||
if L.d == true then mesecon:receptor_on(pos, rules)
|
||||
else mesecon:receptor_off(pos, rules) end
|
||||
end
|
||||
end
|
||||
|
||||
function yc_set_portstate(port, state, L)
|
||||
if port == "A" then L.a = state
|
||||
elseif port == "B" then L.b = state
|
||||
elseif port == "C" then L.c = state
|
||||
elseif port == "D" then L.d = state
|
||||
else return nil end
|
||||
return L
|
||||
end
|
||||
|
||||
function yc_update_real_portstates(pos, node, rulename, newstate)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if rulename == nil then
|
||||
meta:set_int("real_portstates", 1)
|
||||
return
|
||||
end
|
||||
local n = meta:get_int("real_portstates") - 1
|
||||
if n < 0 then
|
||||
legacy_update_ports(pos)
|
||||
n = meta:get_int("real_portstates") - 1
|
||||
end
|
||||
local L = {}
|
||||
for i = 1, 4 do
|
||||
L[i] = n%2
|
||||
n = math.floor(n/2)
|
||||
end
|
||||
if rulename.x == nil then
|
||||
for _, rname in ipairs(rulename) do
|
||||
local port = ({4, 1, nil, 3, 2})[rname.x+2*rname.z+3]
|
||||
L[port] = (newstate == "on") and 1 or 0
|
||||
end
|
||||
else
|
||||
local port = ({4, 1, nil, 3, 2})[rulename.x+2*rulename.z+3]
|
||||
L[port] = (newstate == "on") and 1 or 0
|
||||
end
|
||||
meta:set_int("real_portstates", 1 + L[1] + 2*L[2] + 4*L[3] + 8*L[4])
|
||||
end
|
||||
|
||||
function yc_get_real_portstates(pos) -- determine if ports are powered (by itself or from outside)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local L = {}
|
||||
local n = meta:get_int("real_portstates") - 1
|
||||
if n < 0 then
|
||||
return legacy_update_ports(pos)
|
||||
end
|
||||
for _, index in ipairs({"a", "b", "c", "d"}) do
|
||||
L[index] = ((n%2) == 1)
|
||||
n = math.floor(n/2)
|
||||
end
|
||||
return L
|
||||
end
|
||||
|
||||
function yc_get_virtual_portstates(pos) -- portstates according to the name
|
||||
name = minetest.get_node(pos).name
|
||||
b, a = string.find(name, ":microcontroller")
|
||||
if a == nil then return nil end
|
||||
a = a + 1
|
||||
|
||||
Lvirtual = {a=false, b=false, c=false, d=false}
|
||||
if name:sub(a , a ) == "1" then Lvirtual.d = true end
|
||||
if name:sub(a+1, a+1) == "1" then Lvirtual.c = true end
|
||||
if name:sub(a+2, a+2) == "1" then Lvirtual.b = true end
|
||||
if name:sub(a+3, a+3) == "1" then Lvirtual.a = true end
|
||||
return Lvirtual
|
||||
end
|
||||
|
||||
function yc_merge_portstates(Lreal, Lvirtual)
|
||||
local L = {a=false, b=false, c=false, d=false}
|
||||
if Lvirtual.a or Lreal.a then L.a = true end
|
||||
if Lvirtual.b or Lreal.b then L.b = true end
|
||||
if Lvirtual.c or Lreal.c then L.c = true end
|
||||
if Lvirtual.d or Lreal.d then L.d = true end
|
||||
return L
|
||||
end
|
BIN
mods/mesecons/.mesecons_microcontroller/textures/jeija_microcontroller_LED_A.png
Executable file
After Width: | Height: | Size: 1.2 KiB |
BIN
mods/mesecons/.mesecons_microcontroller/textures/jeija_microcontroller_LED_B.png
Executable file
After Width: | Height: | Size: 1.2 KiB |
BIN
mods/mesecons/.mesecons_microcontroller/textures/jeija_microcontroller_LED_C.png
Executable file
After Width: | Height: | Size: 1.2 KiB |
BIN
mods/mesecons/.mesecons_microcontroller/textures/jeija_microcontroller_LED_D.png
Executable file
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 550 B |
BIN
mods/mesecons/.mesecons_microcontroller/textures/jeija_microcontroller_sides.png
Executable file
After Width: | Height: | Size: 613 B |
BIN
mods/mesecons/.mesecons_microcontroller/textures/jeija_microcontroller_top.png
Executable file
After Width: | Height: | Size: 1.1 KiB |
3
mods/mesecons/.mesecons_movestones/depends.txt
Executable file
@ -0,0 +1,3 @@
|
||||
mesecons
|
||||
mesecons_materials
|
||||
mesecons_mvps
|
216
mods/mesecons/.mesecons_movestones/init.lua
Executable file
@ -0,0 +1,216 @@
|
||||
-- MOVESTONE
|
||||
-- Non-sticky:
|
||||
-- Moves along mesecon lines
|
||||
-- Pushes all blocks in front of it
|
||||
--
|
||||
-- Sticky one
|
||||
-- Moves along mesecon lines
|
||||
-- Pushes all block in front of it
|
||||
-- Pull all blocks in its back
|
||||
|
||||
function mesecon:get_movestone_direction(pos)
|
||||
getactivated = 0
|
||||
local lpos
|
||||
local getactivated = 0
|
||||
local rules = {
|
||||
{x=0, y=1, z=-1},
|
||||
{x=0, y=0, z=-1},
|
||||
{x=0, y=-1, z=-1},
|
||||
{x=0, y=1, z=1},
|
||||
{x=0, y=-1, z=1},
|
||||
{x=0, y=0, z=1},
|
||||
{x=1, y=0, z=0},
|
||||
{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=-1, y=0, z=0}}
|
||||
|
||||
lpos = {x=pos.x+1, y=pos.y, z=pos.z}
|
||||
for n = 1, 3 do
|
||||
if mesecon:is_power_on(lpos, rules[n].x, rules[n].y, rules[n].z) then
|
||||
return {x=0, y=0, z=-1}
|
||||
end
|
||||
end
|
||||
|
||||
lpos = {x = pos.x-1, y = pos.y, z = pos.z}
|
||||
for n=4, 6 do
|
||||
if mesecon:is_power_on(lpos, rules[n].x, rules[n].y, rules[n].z) then
|
||||
return {x=0, y=0, z=1}
|
||||
end
|
||||
end
|
||||
|
||||
lpos = {x = pos.x, y = pos.y, z = pos.z+1}
|
||||
for n=7, 9 do
|
||||
if mesecon:is_power_on(lpos, rules[n].x, rules[n].y, rules[n].z) then
|
||||
return {x=-1, y=0, z=0}
|
||||
end
|
||||
end
|
||||
|
||||
lpos = {x = pos.x, y = pos.y, z = pos.z-1}
|
||||
for n=10, 12 do
|
||||
if mesecon:is_power_on(lpos, rules[n].x, rules[n].y, rules[n].z) then
|
||||
return {x=1, y=0, z=0}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_node("mesecons_movestones:movestone", {
|
||||
tiles = {"jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_arrows.png", "jeija_movestone_arrows.png"},
|
||||
paramtype2 = "facedir",
|
||||
legacy_facedir_simple = true,
|
||||
groups = {cracky=3},
|
||||
description="Movestone",
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
mesecons = {effector = {
|
||||
action_on = function (pos, node)
|
||||
local direction=mesecon:get_movestone_direction(pos)
|
||||
if not direction then return end
|
||||
minetest.remove_node(pos)
|
||||
mesecon:update_autoconnect(pos)
|
||||
minetest.add_entity(pos, "mesecons_movestones:movestone_entity")
|
||||
end
|
||||
}}
|
||||
})
|
||||
|
||||
minetest.register_entity("mesecons_movestones:movestone_entity", {
|
||||
physical = false,
|
||||
visual = "sprite",
|
||||
textures = {"jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_arrows.png", "jeija_movestone_arrows.png"},
|
||||
collisionbox = {-0.5,-0.5,-0.5, 0.5, 0.5, 0.5},
|
||||
visual = "cube",
|
||||
lastdir = {x=0, y=0, z=0},
|
||||
|
||||
on_punch = function(self, hitter)
|
||||
self.object:remove()
|
||||
hitter:get_inventory():add_item("main", "mesecons_movestones:movestone")
|
||||
end,
|
||||
|
||||
on_step = function(self, dtime)
|
||||
local pos = self.object:getpos()
|
||||
pos.x, pos.y, pos.z = math.floor(pos.x+0.5), math.floor(pos.y+0.5), math.floor(pos.z+0.5)
|
||||
local direction = mesecon:get_movestone_direction(pos)
|
||||
|
||||
if not direction then -- no mesecon power
|
||||
--push only solid nodes
|
||||
local name = minetest.get_node(pos).name
|
||||
if name ~= "air" and name ~= "ignore"
|
||||
and ((not minetest.registered_nodes[name])
|
||||
or minetest.registered_nodes[name].liquidtype == "none") then
|
||||
mesecon:mvps_push(pos, self.lastdir, MOVESTONE_MAXIMUM_PUSH)
|
||||
end
|
||||
minetest.add_node(pos, {name="mesecons_movestones:movestone"})
|
||||
self.object:remove()
|
||||
return
|
||||
end
|
||||
|
||||
local success, stack, oldstack =
|
||||
mesecon:mvps_push(pos, direction, MOVESTONE_MAXIMUM_PUSH)
|
||||
if not success then -- Too large stack/stopper in the way
|
||||
minetest.add_node(pos, {name="mesecons_movestones:movestone"})
|
||||
self.object:remove()
|
||||
return
|
||||
else
|
||||
mesecon:mvps_process_stack (stack)
|
||||
mesecon:mvps_move_objects (pos, direction, oldstack)
|
||||
self.lastdir = direction
|
||||
end
|
||||
|
||||
self.object:setvelocity({x=direction.x*2, y=direction.y*2, z=direction.z*2})
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "mesecons_movestones:movestone 2",
|
||||
recipe = {
|
||||
{"default:stone", "default:stone", "default:stone"},
|
||||
{"group:mesecon_conductor_craftable", "group:mesecon_conductor_craftable", "group:mesecon_conductor_craftable"},
|
||||
{"default:stone", "default:stone", "default:stone"},
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
-- STICKY_MOVESTONE
|
||||
|
||||
minetest.register_node("mesecons_movestones:sticky_movestone", {
|
||||
tiles = {"jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_sticky_movestone.png", "jeija_sticky_movestone.png"},
|
||||
inventory_image = minetest.inventorycube("jeija_sticky_movestone.png", "jeija_movestone_side.png", "jeija_movestone_side.png"),
|
||||
paramtype2 = "facedir",
|
||||
legacy_facedir_simple = true,
|
||||
groups = {cracky=3},
|
||||
description="Sticky Movestone",
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
mesecons = {effector = {
|
||||
action_on = function (pos, node)
|
||||
local direction=mesecon:get_movestone_direction(pos)
|
||||
if not direction then return end
|
||||
minetest.remove_node(pos)
|
||||
mesecon:update_autoconnect(pos)
|
||||
minetest.add_entity(pos, "mesecons_movestones:sticky_movestone_entity")
|
||||
end
|
||||
}}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "mesecons_movestones:sticky_movestone 2",
|
||||
recipe = {
|
||||
{"mesecons_materials:glue", "mesecons_movestones:movestone", "mesecons_materials:glue"},
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_entity("mesecons_movestones:sticky_movestone_entity", {
|
||||
physical = false,
|
||||
visual = "sprite",
|
||||
textures = {"jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_sticky_movestone.png", "jeija_sticky_movestone.png"},
|
||||
collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
|
||||
visual = "cube",
|
||||
lastdir = {x=0, y=0, z=0},
|
||||
|
||||
on_punch = function(self, hitter)
|
||||
self.object:remove()
|
||||
hitter:get_inventory():add_item("main", 'mesecons_movestones:sticky_movestone')
|
||||
end,
|
||||
|
||||
on_step = function(self, dtime)
|
||||
local pos = self.object:getpos()
|
||||
pos.x, pos.y, pos.z = math.floor(pos.x+0.5), math.floor(pos.y+0.5), math.floor(pos.z+0.5)
|
||||
local direction = mesecon:get_movestone_direction(pos)
|
||||
|
||||
if not direction then -- no mesecon power
|
||||
--push only solid nodes
|
||||
local name = minetest.get_node(pos).name
|
||||
if name ~= "air" and name ~= "ignore"
|
||||
and ((not minetest.registered_nodes[name])
|
||||
or minetest.registered_nodes[name].liquidtype == "none") then
|
||||
mesecon:mvps_push(pos, self.lastdir, MOVESTONE_MAXIMUM_PUSH)
|
||||
--STICKY
|
||||
mesecon:mvps_pull_all(pos, self.lastdir)
|
||||
end
|
||||
minetest.add_node(pos, {name="mesecons_movestones:sticky_movestone"})
|
||||
self.object:remove()
|
||||
return
|
||||
end
|
||||
|
||||
local success, stack, oldstack =
|
||||
mesecon:mvps_push(pos, direction, MOVESTONE_MAXIMUM_PUSH)
|
||||
if not success then -- Too large stack/stopper in the way
|
||||
minetest.add_node(pos, {name="mesecons_movestones:sticky_movestone"})
|
||||
self.object:remove()
|
||||
return
|
||||
else
|
||||
mesecon:mvps_process_stack (stack)
|
||||
mesecon:mvps_move_objects (pos, direction, oldstack)
|
||||
self.lastdir = direction
|
||||
end
|
||||
|
||||
self.object:setvelocity({x=direction.x*2, y=direction.y*2, z=direction.z*2})
|
||||
|
||||
--STICKY
|
||||
mesecon:mvps_pull_all(pos, direction)
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
mesecon:register_mvps_unmov("mesecons_movestones:movestone_entity")
|
||||
mesecon:register_mvps_unmov("mesecons_movestones:sticky_movestone_entity")
|
BIN
mods/mesecons/.mesecons_movestones/textures/jeija_movestone_arrows.png
Executable file
After Width: | Height: | Size: 344 B |
BIN
mods/mesecons/.mesecons_movestones/textures/jeija_movestone_side.png
Executable file
After Width: | Height: | Size: 466 B |
BIN
mods/mesecons/.mesecons_movestones/textures/jeija_sticky_movestone.png
Executable file
After Width: | Height: | Size: 742 B |
1
mods/mesecons/.mesecons_noteblock/depends.txt
Executable file
@ -0,0 +1 @@
|
||||
mesecons
|
79
mods/mesecons/.mesecons_noteblock/init.lua
Executable file
@ -0,0 +1,79 @@
|
||||
minetest.register_node("mesecons_noteblock:noteblock", {
|
||||
description = "Noteblock",
|
||||
tiles = {"mesecons_noteblock.png"},
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
|
||||
drawtype = "allfaces_optional",
|
||||
visual_scale = 1.3,
|
||||
paramtype="light",
|
||||
after_place_node = function(pos)
|
||||
minetest.add_node(pos, {name="mesecons_noteblock:noteblock", param2=0})
|
||||
end,
|
||||
on_punch = function (pos, node) -- change sound when punched
|
||||
local param2 = node.param2+1
|
||||
if param2==12 then param2=0 end
|
||||
minetest.add_node(pos, {name = node.name, param2 = param2})
|
||||
mesecon.noteblock_play(pos, param2)
|
||||
end,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
mesecons = {effector = { -- play sound when activated
|
||||
action_on = function (pos, node)
|
||||
mesecon.noteblock_play(pos, node.param2)
|
||||
end
|
||||
}}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "mesecons_noteblock:noteblock 1",
|
||||
recipe = {
|
||||
{"group:wood", "group:wood", "group:wood"},
|
||||
{"group:mesecon_conductor_craftable", "default:steel_ingot", "group:mesecon_conductor_craftable"},
|
||||
{"group:wood", "group:wood", "group:wood"},
|
||||
}
|
||||
})
|
||||
|
||||
mesecon.noteblock_play = function (pos, param2)
|
||||
local soundname
|
||||
if param2==8 then
|
||||
soundname="mesecons_noteblock_a"
|
||||
elseif param2==9 then
|
||||
soundname="mesecons_noteblock_asharp"
|
||||
elseif param2==10 then
|
||||
soundname="mesecons_noteblock_b"
|
||||
elseif param2==11 then
|
||||
soundname="mesecons_noteblock_c"
|
||||
elseif param2==0 then
|
||||
soundname="mesecons_noteblock_csharp"
|
||||
elseif param2==1 then
|
||||
soundname="mesecons_noteblock_d"
|
||||
elseif param2==2 then
|
||||
soundname="mesecons_noteblock_dsharp"
|
||||
elseif param2==3 then
|
||||
soundname="mesecons_noteblock_e"
|
||||
elseif param2==4 then
|
||||
soundname="mesecons_noteblock_f"
|
||||
elseif param2==5 then
|
||||
soundname="mesecons_noteblock_fsharp"
|
||||
elseif param2==6 then
|
||||
soundname="mesecons_noteblock_g"
|
||||
elseif param2==7 then
|
||||
soundname="mesecons_noteblock_gsharp"
|
||||
end
|
||||
local block_below_name = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name
|
||||
if block_below_name == "default:glass" then
|
||||
soundname="mesecons_noteblock_hihat"
|
||||
end
|
||||
if block_below_name == "default:stone" then
|
||||
soundname="mesecons_noteblock_kick"
|
||||
end
|
||||
if block_below_name == "default:chest" then
|
||||
soundname="mesecons_noteblock_snare"
|
||||
end
|
||||
if block_below_name == "default:tree" then
|
||||
soundname="mesecons_noteblock_crash"
|
||||
end
|
||||
if block_below_name == "default:wood" then
|
||||
soundname="mesecons_noteblock_litecrash"
|
||||
end
|
||||
minetest.sound_play(soundname,
|
||||
{pos = pos, gain = 1.0, max_hear_distance = 32,})
|
||||
end
|
BIN
mods/mesecons/.mesecons_noteblock/sounds/mesecons_noteblock_a.ogg
Executable file
BIN
mods/mesecons/.mesecons_noteblock/sounds/mesecons_noteblock_asharp.ogg
Executable file
BIN
mods/mesecons/.mesecons_noteblock/sounds/mesecons_noteblock_b.ogg
Executable file
BIN
mods/mesecons/.mesecons_noteblock/sounds/mesecons_noteblock_c.ogg
Executable file
BIN
mods/mesecons/.mesecons_noteblock/sounds/mesecons_noteblock_crash.ogg
Executable file
BIN
mods/mesecons/.mesecons_noteblock/sounds/mesecons_noteblock_csharp.ogg
Executable file
BIN
mods/mesecons/.mesecons_noteblock/sounds/mesecons_noteblock_d.ogg
Executable file
BIN
mods/mesecons/.mesecons_noteblock/sounds/mesecons_noteblock_dsharp.ogg
Executable file
BIN
mods/mesecons/.mesecons_noteblock/sounds/mesecons_noteblock_e.ogg
Executable file
BIN
mods/mesecons/.mesecons_noteblock/sounds/mesecons_noteblock_f.ogg
Executable file
BIN
mods/mesecons/.mesecons_noteblock/sounds/mesecons_noteblock_fsharp.ogg
Executable file
BIN
mods/mesecons/.mesecons_noteblock/sounds/mesecons_noteblock_g.ogg
Executable file
BIN
mods/mesecons/.mesecons_noteblock/sounds/mesecons_noteblock_gsharp.ogg
Executable file
BIN
mods/mesecons/.mesecons_noteblock/sounds/mesecons_noteblock_hihat.ogg
Executable file
BIN
mods/mesecons/.mesecons_noteblock/sounds/mesecons_noteblock_kick.ogg
Executable file
BIN
mods/mesecons/.mesecons_noteblock/sounds/mesecons_noteblock_litecrash.ogg
Executable file
BIN
mods/mesecons/.mesecons_noteblock/sounds/mesecons_noteblock_snare.ogg
Executable file
BIN
mods/mesecons/.mesecons_noteblock/textures/mesecons_noteblock.png
Executable file
After Width: | Height: | Size: 900 B |
532
mods/mesecons/LICENSE.txt
Executable file
@ -0,0 +1,532 @@
|
||||
The LGPLv3 applies to all code in this project.
|
||||
The CC-BY-SA-3.0 license applies to textures and any other content in this project which is not source code.
|
||||
|
||||
=================================================================
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
|
||||
=================================================================
|
||||
|
||||
Creative Commons Legal Code
|
||||
|
||||
Attribution-ShareAlike 3.0 Unported
|
||||
|
||||
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
||||
LEGAL SERVICES. DISTRIBUTION OF THIS LICENSE DOES NOT CREATE AN
|
||||
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
||||
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
||||
REGARDING THE INFORMATION PROVIDED, AND DISCLAIMS LIABILITY FOR
|
||||
DAMAGES RESULTING FROM ITS USE.
|
||||
|
||||
License
|
||||
|
||||
THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE
|
||||
COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY
|
||||
COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS
|
||||
AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
|
||||
|
||||
BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE
|
||||
TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY
|
||||
BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS
|
||||
CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND
|
||||
CONDITIONS.
|
||||
|
||||
1. Definitions
|
||||
|
||||
a. "Adaptation" means a work based upon the Work, or upon the Work and
|
||||
other pre-existing works, such as a translation, adaptation,
|
||||
derivative work, arrangement of music or other alterations of a
|
||||
literary or artistic work, or phonogram or performance and includes
|
||||
cinematographic adaptations or any other form in which the Work may be
|
||||
recast, transformed, or adapted including in any form recognizably
|
||||
derived from the original, except that a work that constitutes a
|
||||
Collection will not be considered an Adaptation for the purpose of
|
||||
this License. For the avoidance of doubt, where the Work is a musical
|
||||
work, performance or phonogram, the synchronization of the Work in
|
||||
timed-relation with a moving image ("synching") will be considered an
|
||||
Adaptation for the purpose of this License.
|
||||
b. "Collection" means a collection of literary or artistic works, such as
|
||||
encyclopedias and anthologies, or performances, phonograms or
|
||||
broadcasts, or other works or subject matter other than works listed
|
||||
in Section 1(f) below, which, by reason of the selection and
|
||||
arrangement of their contents, constitute intellectual creations, in
|
||||
which the Work is included in its entirety in unmodified form along
|
||||
with one or more other contributions, each constituting separate and
|
||||
independent works in themselves, which together are assembled into a
|
||||
collective whole. A work that constitutes a Collection will not be
|
||||
considered an Adaptation (as defined below) for the purposes of this
|
||||
License.
|
||||
c. "Creative Commons Compatible License" means a license that is listed
|
||||
at http://creativecommons.org/compatiblelicenses that has been
|
||||
approved by Creative Commons as being essentially equivalent to this
|
||||
License, including, at a minimum, because that license: (i) contains
|
||||
terms that have the same purpose, meaning and effect as the License
|
||||
Elements of this License; and, (ii) explicitly permits the relicensing
|
||||
of adaptations of works made available under that license under this
|
||||
License or a Creative Commons jurisdiction license with the same
|
||||
License Elements as this License.
|
||||
d. "Distribute" means to make available to the public the original and
|
||||
copies of the Work or Adaptation, as appropriate, through sale or
|
||||
other transfer of ownership.
|
||||
e. "License Elements" means the following high-level license attributes
|
||||
as selected by Licensor and indicated in the title of this License:
|
||||
Attribution, ShareAlike.
|
||||
f. "Licensor" means the individual, individuals, entity or entities that
|
||||
offer(s) the Work under the terms of this License.
|
||||
g. "Original Author" means, in the case of a literary or artistic work,
|
||||
the individual, individuals, entity or entities who created the Work
|
||||
or if no individual or entity can be identified, the publisher; and in
|
||||
addition (i) in the case of a performance the actors, singers,
|
||||
musicians, dancers, and other persons who act, sing, deliver, declaim,
|
||||
play in, interpret or otherwise perform literary or artistic works or
|
||||
expressions of folklore; (ii) in the case of a phonogram the producer
|
||||
being the person or legal entity who first fixes the sounds of a
|
||||
performance or other sounds; and, (iii) in the case of broadcasts, the
|
||||
organization that transmits the broadcast.
|
||||
h. "Work" means the literary and/or artistic work offered under the terms
|
||||
of this License including without limitation any production in the
|
||||
literary, scientific and artistic domain, whatever may be the mode or
|
||||
form of its expression including digital form, such as a book,
|
||||
pamphlet and other writing; a lecture, address, sermon or other work
|
||||
of the same nature; a dramatic or dramatico-musical work; a
|
||||
choreographic work or entertainment in dumb show; a musical
|
||||
composition with or without words; a cinematographic work to which are
|
||||
assimilated works expressed by a process analogous to cinematography;
|
||||
a work of drawing, painting, architecture, sculpture, engraving or
|
||||
lithography; a photographic work to which are assimilated works
|
||||
expressed by a process analogous to photography; a work of applied
|
||||
art; an illustration, map, plan, sketch or three-dimensional work
|
||||
relative to geography, topography, architecture or science; a
|
||||
performance; a broadcast; a phonogram; a compilation of data to the
|
||||
extent it is protected as a copyrightable work; or a work performed by
|
||||
a variety or circus performer to the extent it is not otherwise
|
||||
considered a literary or artistic work.
|
||||
i. "You" means an individual or entity exercising rights under this
|
||||
License who has not previously violated the terms of this License with
|
||||
respect to the Work, or who has received express permission from the
|
||||
Licensor to exercise rights under this License despite a previous
|
||||
violation.
|
||||
j. "Publicly Perform" means to perform public recitations of the Work and
|
||||
to communicate to the public those public recitations, by any means or
|
||||
process, including by wire or wireless means or public digital
|
||||
performances; to make available to the public Works in such a way that
|
||||
members of the public may access these Works from a place and at a
|
||||
place individually chosen by them; to perform the Work to the public
|
||||
by any means or process and the communication to the public of the
|
||||
performances of the Work, including by public digital performance; to
|
||||
broadcast and rebroadcast the Work by any means including signs,
|
||||
sounds or images.
|
||||
k. "Reproduce" means to make copies of the Work by any means including
|
||||
without limitation by sound or visual recordings and the right of
|
||||
fixation and reproducing fixations of the Work, including storage of a
|
||||
protected performance or phonogram in digital form or other electronic
|
||||
medium.
|
||||
|
||||
2. Fair Dealing Rights. Nothing in this License is intended to reduce,
|
||||
limit, or restrict any uses free from copyright or rights arising from
|
||||
limitations or exceptions that are provided for in connection with the
|
||||
copyright protection under copyright law or other applicable laws.
|
||||
|
||||
3. License Grant. Subject to the terms and conditions of this License,
|
||||
Licensor hereby grants You a worldwide, royalty-free, non-exclusive,
|
||||
perpetual (for the duration of the applicable copyright) license to
|
||||
exercise the rights in the Work as stated below:
|
||||
|
||||
a. to Reproduce the Work, to incorporate the Work into one or more
|
||||
Collections, and to Reproduce the Work as incorporated in the
|
||||
Collections;
|
||||
b. to create and Reproduce Adaptations provided that any such Adaptation,
|
||||
including any translation in any medium, takes reasonable steps to
|
||||
clearly label, demarcate or otherwise identify that changes were made
|
||||
to the original Work. For example, a translation could be marked "The
|
||||
original work was translated from English to Spanish," or a
|
||||
modification could indicate "The original work has been modified.";
|
||||
c. to Distribute and Publicly Perform the Work including as incorporated
|
||||
in Collections; and,
|
||||
d. to Distribute and Publicly Perform Adaptations.
|
||||
e. For the avoidance of doubt:
|
||||
|
||||
i. Non-waivable Compulsory License Schemes. In those jurisdictions in
|
||||
which the right to collect royalties through any statutory or
|
||||
compulsory licensing scheme cannot be waived, the Licensor
|
||||
reserves the exclusive right to collect such royalties for any
|
||||
exercise by You of the rights granted under this License;
|
||||
ii. Waivable Compulsory License Schemes. In those jurisdictions in
|
||||
which the right to collect royalties through any statutory or
|
||||
compulsory licensing scheme can be waived, the Licensor waives the
|
||||
exclusive right to collect such royalties for any exercise by You
|
||||
of the rights granted under this License; and,
|
||||
iii. Voluntary License Schemes. The Licensor waives the right to
|
||||
collect royalties, whether individually or, in the event that the
|
||||
Licensor is a member of a collecting society that administers
|
||||
voluntary licensing schemes, via that society, from any exercise
|
||||
by You of the rights granted under this License.
|
||||
|
||||
The above rights may be exercised in all media and formats whether now
|
||||
known or hereafter devised. The above rights include the right to make
|
||||
such modifications as are technically necessary to exercise the rights in
|
||||
other media and formats. Subject to Section 8(f), all rights not expressly
|
||||
granted by Licensor are hereby reserved.
|
||||
|
||||
4. Restrictions. The license granted in Section 3 above is expressly made
|
||||
subject to and limited by the following restrictions:
|
||||
|
||||
a. You may Distribute or Publicly Perform the Work only under the terms
|
||||
of this License. You must include a copy of, or the Uniform Resource
|
||||
Identifier (URI) for, this License with every copy of the Work You
|
||||
Distribute or Publicly Perform. You may not offer or impose any terms
|
||||
on the Work that restrict the terms of this License or the ability of
|
||||
the recipient of the Work to exercise the rights granted to that
|
||||
recipient under the terms of the License. You may not sublicense the
|
||||
Work. You must keep intact all notices that refer to this License and
|
||||
to the disclaimer of warranties with every copy of the Work You
|
||||
Distribute or Publicly Perform. When You Distribute or Publicly
|
||||
Perform the Work, You may not impose any effective technological
|
||||
measures on the Work that restrict the ability of a recipient of the
|
||||
Work from You to exercise the rights granted to that recipient under
|
||||
the terms of the License. This Section 4(a) applies to the Work as
|
||||
incorporated in a Collection, but this does not require the Collection
|
||||
apart from the Work itself to be made subject to the terms of this
|
||||
License. If You create a Collection, upon notice from any Licensor You
|
||||
must, to the extent practicable, remove from the Collection any credit
|
||||
as required by Section 4(c), as requested. If You create an
|
||||
Adaptation, upon notice from any Licensor You must, to the extent
|
||||
practicable, remove from the Adaptation any credit as required by
|
||||
Section 4(c), as requested.
|
||||
b. You may Distribute or Publicly Perform an Adaptation only under the
|
||||
terms of: (i) this License; (ii) a later version of this License with
|
||||
the same License Elements as this License; (iii) a Creative Commons
|
||||
jurisdiction license (either this or a later license version) that
|
||||
contains the same License Elements as this License (e.g.,
|
||||
Attribution-ShareAlike 3.0 US)); (iv) a Creative Commons Compatible
|
||||
License. If you license the Adaptation under one of the licenses
|
||||
mentioned in (iv), you must comply with the terms of that license. If
|
||||
you license the Adaptation under the terms of any of the licenses
|
||||
mentioned in (i), (ii) or (iii) (the "Applicable License"), you must
|
||||
comply with the terms of the Applicable License generally and the
|
||||
following provisions: (I) You must include a copy of, or the URI for,
|
||||
the Applicable License with every copy of each Adaptation You
|
||||
Distribute or Publicly Perform; (II) You may not offer or impose any
|
||||
terms on the Adaptation that restrict the terms of the Applicable
|
||||
License or the ability of the recipient of the Adaptation to exercise
|
||||
the rights granted to that recipient under the terms of the Applicable
|
||||
License; (III) You must keep intact all notices that refer to the
|
||||
Applicable License and to the disclaimer of warranties with every copy
|
||||
of the Work as included in the Adaptation You Distribute or Publicly
|
||||
Perform; (IV) when You Distribute or Publicly Perform the Adaptation,
|
||||
You may not impose any effective technological measures on the
|
||||
Adaptation that restrict the ability of a recipient of the Adaptation
|
||||
from You to exercise the rights granted to that recipient under the
|
||||
terms of the Applicable License. This Section 4(b) applies to the
|
||||
Adaptation as incorporated in a Collection, but this does not require
|
||||
the Collection apart from the Adaptation itself to be made subject to
|
||||
the terms of the Applicable License.
|
||||
c. If You Distribute, or Publicly Perform the Work or any Adaptations or
|
||||
Collections, You must, unless a request has been made pursuant to
|
||||
Section 4(a), keep intact all copyright notices for the Work and
|
||||
provide, reasonable to the medium or means You are utilizing: (i) the
|
||||
name of the Original Author (or pseudonym, if applicable) if supplied,
|
||||
and/or if the Original Author and/or Licensor designate another party
|
||||
or parties (e.g., a sponsor institute, publishing entity, journal) for
|
||||
attribution ("Attribution Parties") in Licensor's copyright notice,
|
||||
terms of service or by other reasonable means, the name of such party
|
||||
or parties; (ii) the title of the Work if supplied; (iii) to the
|
||||
extent reasonably practicable, the URI, if any, that Licensor
|
||||
specifies to be associated with the Work, unless such URI does not
|
||||
refer to the copyright notice or licensing information for the Work;
|
||||
and (iv) , consistent with Ssection 3(b), in the case of an
|
||||
Adaptation, a credit identifying the use of the Work in the Adaptation
|
||||
(e.g., "French translation of the Work by Original Author," or
|
||||
"Screenplay based on original Work by Original Author"). The credit
|
||||
required by this Section 4(c) may be implemented in any reasonable
|
||||
manner; provided, however, that in the case of a Adaptation or
|
||||
Collection, at a minimum such credit will appear, if a credit for all
|
||||
contributing authors of the Adaptation or Collection appears, then as
|
||||
part of these credits and in a manner at least as prominent as the
|
||||
credits for the other contributing authors. For the avoidance of
|
||||
doubt, You may only use the credit required by this Section for the
|
||||
purpose of attribution in the manner set out above and, by exercising
|
||||
Your rights under this License, You may not implicitly or explicitly
|
||||
assert or imply any connection with, sponsorship or endorsement by the
|
||||
Original Author, Licensor and/or Attribution Parties, as appropriate,
|
||||
of You or Your use of the Work, without the separate, express prior
|
||||
written permission of the Original Author, Licensor and/or Attribution
|
||||
Parties.
|
||||
d. Except as otherwise agreed in writing by the Licensor or as may be
|
||||
otherwise permitted by applicable law, if You Reproduce, Distribute or
|
||||
Publicly Perform the Work either by itself or as part of any
|
||||
Adaptations or Collections, You must not distort, mutilate, modify or
|
||||
take other derogatory action in relation to the Work which would be
|
||||
prejudicial to the Original Author's honor or reputation. Licensor
|
||||
agrees that in those jurisdictions (e.g. Japan), in which any exercise
|
||||
of the right granted in Section 3(b) of this License (the right to
|
||||
make Adaptations) would be deemed to be a distortion, mutilation,
|
||||
modification or other derogatory action prejudicial to the Original
|
||||
Author's honor and reputation, the Licensor will waive or not assert,
|
||||
as appropriate, this Section, to the fullest extent permitted by the
|
||||
applicable national law, to enable You to reasonably exercise Your
|
||||
right under Section 3(b) of this License (right to make Adaptations)
|
||||
but not otherwise.
|
||||
|
||||
5. Representations, Warranties and Disclaimer
|
||||
|
||||
UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING, LICENSOR
|
||||
OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY
|
||||
KIND CONCERNING THE WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE,
|
||||
INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTIBILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF
|
||||
LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS,
|
||||
WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION
|
||||
OF IMPLIED WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU.
|
||||
|
||||
6. Limitation on Liability. EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE
|
||||
LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR
|
||||
ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES
|
||||
ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS
|
||||
BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
7. Termination
|
||||
|
||||
a. This License and the rights granted hereunder will terminate
|
||||
automatically upon any breach by You of the terms of this License.
|
||||
Individuals or entities who have received Adaptations or Collections
|
||||
from You under this License, however, will not have their licenses
|
||||
terminated provided such individuals or entities remain in full
|
||||
compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will
|
||||
survive any termination of this License.
|
||||
b. Subject to the above terms and conditions, the license granted here is
|
||||
perpetual (for the duration of the applicable copyright in the Work).
|
||||
Notwithstanding the above, Licensor reserves the right to release the
|
||||
Work under different license terms or to stop distributing the Work at
|
||||
any time; provided, however that any such election will not serve to
|
||||
withdraw this License (or any other license that has been, or is
|
||||
required to be, granted under the terms of this License), and this
|
||||
License will continue in full force and effect unless terminated as
|
||||
stated above.
|
||||
|
||||
8. Miscellaneous
|
||||
|
||||
a. Each time You Distribute or Publicly Perform the Work or a Collection,
|
||||
the Licensor offers to the recipient a license to the Work on the same
|
||||
terms and conditions as the license granted to You under this License.
|
||||
b. Each time You Distribute or Publicly Perform an Adaptation, Licensor
|
||||
offers to the recipient a license to the original Work on the same
|
||||
terms and conditions as the license granted to You under this License.
|
||||
c. If any provision of this License is invalid or unenforceable under
|
||||
applicable law, it shall not affect the validity or enforceability of
|
||||
the remainder of the terms of this License, and without further action
|
||||
by the parties to this agreement, such provision shall be reformed to
|
||||
the minimum extent necessary to make such provision valid and
|
||||
enforceable.
|
||||
d. No term or provision of this License shall be deemed waived and no
|
||||
breach consented to unless such waiver or consent shall be in writing
|
||||
and signed by the party to be charged with such waiver or consent.
|
||||
e. This License constitutes the entire agreement between the parties with
|
||||
respect to the Work licensed here. There are no understandings,
|
||||
agreements or representations with respect to the Work not specified
|
||||
here. Licensor shall not be bound by any additional provisions that
|
||||
may appear in any communication from You. This License may not be
|
||||
modified without the mutual written agreement of the Licensor and You.
|
||||
f. The rights granted under, and the subject matter referenced, in this
|
||||
License were drafted utilizing the terminology of the Berne Convention
|
||||
for the Protection of Literary and Artistic Works (as amended on
|
||||
September 28, 1979), the Rome Convention of 1961, the WIPO Copyright
|
||||
Treaty of 1996, the WIPO Performances and Phonograms Treaty of 1996
|
||||
and the Universal Copyright Convention (as revised on July 24, 1971).
|
||||
These rights and subject matter take effect in the relevant
|
||||
jurisdiction in which the License terms are sought to be enforced
|
||||
according to the corresponding provisions of the implementation of
|
||||
those treaty provisions in the applicable national law. If the
|
||||
standard suite of rights granted under applicable copyright law
|
||||
includes additional rights not granted under this License, such
|
||||
additional rights are deemed to be included in the License; this
|
||||
License is not intended to restrict the license of any rights under
|
||||
applicable law.
|
||||
|
||||
|
||||
Creative Commons Notice
|
||||
|
||||
Creative Commons is not a party to this License, and makes no warranty
|
||||
whatsoever in connection with the Work. Creative Commons will not be
|
||||
liable to You or any party on any legal theory for any damages
|
||||
whatsoever, including without limitation any general, special,
|
||||
incidental or consequential damages arising in connection to this
|
||||
license. Notwithstanding the foregoing two (2) sentences, if Creative
|
||||
Commons has expressly identified itself as the Licensor hereunder, it
|
||||
shall have all rights and obligations of Licensor.
|
||||
|
||||
Except for the limited purpose of indicating to the public that the
|
||||
Work is licensed under the CCPL, Creative Commons does not authorize
|
||||
the use by either party of the trademark "Creative Commons" or any
|
||||
related trademark or logo of Creative Commons without the prior
|
||||
written consent of Creative Commons. Any permitted use will be in
|
||||
compliance with Creative Commons' then-current trademark usage
|
||||
guidelines, as may be published on its website or otherwise made
|
||||
available upon request from time to time. For the avoidance of doubt,
|
||||
this trademark restriction does not form part of the License.
|
||||
|
||||
Creative Commons may be contacted at http://creativecommons.org/.
|
78
mods/mesecons/README.md
Executable file
@ -0,0 +1,78 @@
|
||||
########################################################################
|
||||
## __ __ _____ _____ _____ _____ _____ _ _ _____ ##
|
||||
## | \ / | | ___| | ___| | ___| | ___| | _ | | \ | | | ___| ##
|
||||
## | \/ | | |___ | |___ | |___ | | | | | | | \| | | |___ ##
|
||||
## | |\__/| | | ___| |___ | | ___| | | | | | | | | |___ | ##
|
||||
## | | | | | |___ ___| | | |___ | |___ | |_| | | |\ | ___| | ##
|
||||
## |_| |_| |_____| |_____| |_____| |_____| |_____| |_| \_| |_____| ##
|
||||
## ##
|
||||
########################################################################
|
||||
|
||||
MESECONS by Jeija and contributors
|
||||
|
||||
Mezzee-what?
|
||||
------------
|
||||
[Mesecons](http://mesecons.net/)! They're yellow, they're conductive, and they'll add a whole new dimension to Minetest's gameplay.
|
||||
|
||||
Mesecons is a mod for [Minetest](http://minetest.net/) that implements a ton of items related to digital circuitry, such as wires, buttons, lights, and even programmable controllers. Among other things, there are also pistons, solar panels, pressure plates, and note blocks.
|
||||
|
||||
Mesecons has a similar goal to Redstone in Minecraft, but works in its own way, with different rules and mechanics.
|
||||
|
||||
OK, I want in.
|
||||
--------------
|
||||
Go get it!
|
||||
|
||||
[DOWNLOADS PAGE](http://mesecons.net/downloads.php)
|
||||
|
||||
Now go ahead and install it like any other Minetest mod. Don't know how? Check out [the wonderful page about it](http://wiki.minetest.com/wiki/Mods) over at the Minetest Wiki. For your convenience, here's a quick summary:
|
||||
|
||||
1. If Mesecons is still in a ZIP file, extract the folder inside to somewhere on the computer.
|
||||
2. Make sure that when you open the folder, you can directly find `README.md` in the listing. If you just see another folder, move that folder up one level and delete the old one.
|
||||
3. Open up the Minetest mods folder - usually `/mods/`. If you see the `minetest` or folder inside of that, that is your mod folder instead.
|
||||
4. Copy the Mesecons folder into the mods folder.
|
||||
|
||||
Don't like some parts of Mesecons? Open up the Mesecons folder and delete the subfolder containing the mod you don't want. If you didn't want movestones, for example, all you have to do is delete the `mesecons_movestones` folder and they will no longer be available.
|
||||
|
||||
There are no dependencies - it will work right after installing!
|
||||
|
||||
How do I use this thing?
|
||||
------------------------
|
||||
How about a [quick overview video](https://www.youtube.com/watch?v=6kmeQj6iW5k)?
|
||||
|
||||
Or maybe a [comprehensive reference](http://mesecons.net/items.php) is your style?
|
||||
|
||||
An overview for the very newest of new beginners? How does [this one](http://uberi.mesecons.net/projects/MeseconsBasics/index.html) look?
|
||||
|
||||
Want to get more into building? Why not check out the [Mesecons Laboratory](http://uberi.mesecons.net/), a website dedicated to advanced Mesecons builders?
|
||||
|
||||
Want to contribute to Mesecons itself? Check out the [source code](https://github.com/Jeija/minetest-mod-mesecons)!
|
||||
|
||||
Who wrote it anyways?
|
||||
---------------------
|
||||
These awesome people made Mesecons possible!
|
||||
|
||||
| Contributor | Contribution |
|
||||
| --------------- | -------------------------------- |
|
||||
| Jat15 | Various tweaks. |
|
||||
| Jeija | **Main developer! Everything.** |
|
||||
| Jordach | Noteblock sounds. |
|
||||
| khonkhortistan | Code, recipes, textures. |
|
||||
| Kotolegokot | Nodeboxes for items. |
|
||||
| minerd247 | Textures. |
|
||||
| Nore/Novatux | Code. |
|
||||
| RealBadAngel | Fixes, improvements. |
|
||||
| sfan5 | Code, recipes, textures. |
|
||||
| suzenako | Piston sounds. |
|
||||
| Uberi/Temperest | Code, textures, documentation. |
|
||||
| VanessaE | Code, recipes, textures, design. |
|
||||
| Whiskers75 | Logic gates implementation. |
|
||||
|
||||
There are also a whole bunch of other people helping with everything from code to testing and feedback. Mesecons would also not be possible without their help!
|
||||
|
||||
Alright, how can I use it?
|
||||
--------------------------
|
||||
All textures in this project are licensed under the CC-BY-SA 3.0 (Creative Commons Attribution-ShareAlike 3.0 Generic). That means you can distribute and remix them as much as you want to, under the condition that you give credit to the authors and the project, and that if you remix and release them, they must be under the same or similar license to this one.
|
||||
|
||||
All code in this project is licensed under the LGPL version 3 or later. That means you have unlimited freedom to distribute and modify the work however you see fit, provided that if you decide to distribute it or any modified versions of it, you must also use the same license. The LGPL also grants the additional freedom to write extensions for the software and distribute them without the extensions being subject to the terms of the LGPL, although the software itself retains its license.
|
||||
|
||||
No warranty is provided, express or implied, for any part of the project.
|
1
mods/mesecons/mesecons/VERSION
Executable file
@ -0,0 +1 @@
|
||||
0.41 DEV
|
114
mods/mesecons/mesecons/actionqueue.lua
Executable file
@ -0,0 +1,114 @@
|
||||
mesecon.queue.actions={} -- contains all ActionQueue actions
|
||||
|
||||
function mesecon.queue:add_function(name, func)
|
||||
mesecon.queue.funcs[name] = func
|
||||
end
|
||||
|
||||
-- If add_action with twice the same overwritecheck and same position are called, the first one is overwritten
|
||||
-- use overwritecheck nil to never overwrite, but just add the event to the queue
|
||||
-- priority specifies the order actions are executed within one globalstep, highest first
|
||||
-- should be between 0 and 1
|
||||
function mesecon.queue:add_action(pos, func, params, time, overwritecheck, priority)
|
||||
-- Create Action Table:
|
||||
time = time or 0 -- time <= 0 --> execute, time > 0 --> wait time until execution
|
||||
priority = priority or 1
|
||||
local action = { pos=mesecon:tablecopy(pos),
|
||||
func=func,
|
||||
params=mesecon:tablecopy(params),
|
||||
time=time,
|
||||
owcheck=(overwritecheck and mesecon:tablecopy(overwritecheck)) or nil,
|
||||
priority=priority}
|
||||
|
||||
local toremove = nil
|
||||
-- Otherwise, add the action to the queue
|
||||
if overwritecheck then -- check if old action has to be overwritten / removed:
|
||||
for i, ac in ipairs(mesecon.queue.actions) do
|
||||
if(mesecon:cmpPos(pos, ac.pos)
|
||||
and mesecon:cmpAny(overwritecheck, ac.owcheck)) then
|
||||
toremove = i
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if (toremove ~= nil) then
|
||||
table.remove(mesecon.queue.actions, toremove)
|
||||
end
|
||||
|
||||
table.insert(mesecon.queue.actions, action)
|
||||
end
|
||||
|
||||
-- execute the stored functions on a globalstep
|
||||
-- if however, the pos of a function is not loaded (get_node_or_nil == nil), do NOT execute the function
|
||||
-- this makes sure that resuming mesecons circuits when restarting minetest works fine
|
||||
-- However, even that does not work in some cases, that's why we delay the time the globalsteps
|
||||
-- start to be execute by 5 seconds
|
||||
local get_highest_priority = function (actions)
|
||||
local highestp = -1, highesti
|
||||
for i, ac in ipairs(actions) do
|
||||
if ac.priority > highestp then
|
||||
highestp = ac.priority
|
||||
highesti = i
|
||||
end
|
||||
end
|
||||
|
||||
return highesti
|
||||
end
|
||||
|
||||
local m_time = 0
|
||||
minetest.register_globalstep(function (dtime)
|
||||
m_time = m_time + dtime
|
||||
if (m_time < MESECONS_RESUMETIME) then return end -- don't even try if server has not been running for XY seconds
|
||||
local actions = mesecon:tablecopy(mesecon.queue.actions)
|
||||
local actions_now={}
|
||||
|
||||
mesecon.queue.actions = {}
|
||||
|
||||
-- sort actions into two categories:
|
||||
-- those toexecute now (actions_now) and those to execute later (mesecon.queue.actions)
|
||||
for i, ac in ipairs(actions) do
|
||||
if ac.time > 0 then
|
||||
ac.time = ac.time - dtime -- executed later
|
||||
table.insert(mesecon.queue.actions, ac)
|
||||
else
|
||||
table.insert(actions_now, ac)
|
||||
end
|
||||
end
|
||||
|
||||
while(#actions_now > 0) do -- execute highest priorities first, until all are executed
|
||||
local hp = get_highest_priority(actions_now)
|
||||
mesecon.queue:execute(actions_now[hp])
|
||||
table.remove(actions_now, hp)
|
||||
end
|
||||
end)
|
||||
|
||||
function mesecon.queue:execute(action)
|
||||
mesecon.queue.funcs[action.func](action.pos, unpack(action.params))
|
||||
end
|
||||
|
||||
|
||||
-- Store and read the ActionQueue to / from a file
|
||||
-- so that upcoming actions are remembered when the game
|
||||
-- is restarted
|
||||
|
||||
local wpath = minetest.get_worldpath()
|
||||
local function file2table(filename)
|
||||
local f = io.open(filename, "r")
|
||||
if f==nil then return {} end
|
||||
local t = f:read("*all")
|
||||
f:close()
|
||||
if t=="" or t==nil then return {} end
|
||||
return minetest.deserialize(t)
|
||||
end
|
||||
|
||||
local function table2file(filename, table)
|
||||
local f = io.open(filename, "w")
|
||||
f:write(minetest.serialize(table))
|
||||
f:close()
|
||||
end
|
||||
|
||||
mesecon.queue.actions = file2table(wpath.."/mesecon_actionqueue")
|
||||
|
||||
minetest.register_on_shutdown(function()
|
||||
mesecon.queue.actions = table2file(wpath.."/mesecon_actionqueue", mesecon.queue.actions)
|
||||
end)
|
1
mods/mesecons/mesecons/depends.txt
Executable file
@ -0,0 +1 @@
|
||||
default
|
142
mods/mesecons/mesecons/init.lua
Executable file
@ -0,0 +1,142 @@
|
||||
-- |\ /| ____ ____ ____ _____ ____ _____
|
||||
-- | \ / | | | | | | | |\ | |
|
||||
-- | \/ | |___ ____ |___ | | | | \ | |____
|
||||
-- | | | | | | | | | \ | |
|
||||
-- | | |___ ____| |___ |____ |____| | \| ____|
|
||||
-- by Jeija, Uberi (Temperest), sfan5, VanessaE
|
||||
--
|
||||
--
|
||||
--
|
||||
-- This mod adds mesecons[=minecraft redstone] and different receptors/effectors to minetest.
|
||||
-- See the documentation on the forum for additional information, especially about crafting
|
||||
--
|
||||
--
|
||||
-- For developer documentation see the Developers' section on mesecons.TK
|
||||
--
|
||||
--
|
||||
--
|
||||
--Quick draft for the mesecons array in the node's definition
|
||||
--mesecons =
|
||||
--{
|
||||
-- receptor =
|
||||
-- {
|
||||
-- state = mesecon.state.on/off
|
||||
-- rules = rules/get_rules
|
||||
-- },
|
||||
-- effector =
|
||||
-- {
|
||||
-- action_on = function
|
||||
-- action_off = function
|
||||
-- action_change = function
|
||||
-- rules = rules/get_rules
|
||||
-- },
|
||||
-- conductor =
|
||||
-- {
|
||||
-- state = mesecon.state.on/off
|
||||
-- offstate = opposite state (for state = on only)
|
||||
-- onstate = opposite state (for state = off only)
|
||||
-- rules = rules/get_rules
|
||||
-- }
|
||||
--}
|
||||
|
||||
-- PUBLIC VARIABLES
|
||||
mesecon={} -- contains all functions and all global variables
|
||||
mesecon.queue={} -- contains the ActionQueue
|
||||
mesecon.queue.funcs={} -- contains all ActionQueue functions
|
||||
|
||||
-- Settings
|
||||
dofile(minetest.get_modpath("mesecons").."/settings.lua")
|
||||
|
||||
-- Presets (eg default rules)
|
||||
dofile(minetest.get_modpath("mesecons").."/presets.lua");
|
||||
|
||||
|
||||
-- Utilities like comparing positions,
|
||||
-- adding positions and rules,
|
||||
-- mostly things that make the source look cleaner
|
||||
dofile(minetest.get_modpath("mesecons").."/util.lua");
|
||||
|
||||
-- The ActionQueue
|
||||
-- Saves all the actions that have to be execute in the future
|
||||
dofile(minetest.get_modpath("mesecons").."/actionqueue.lua");
|
||||
|
||||
-- Internal stuff
|
||||
-- This is the most important file
|
||||
-- it handles signal transmission and basically everything else
|
||||
-- It is also responsible for managing the nodedef things,
|
||||
-- like calling action_on/off/change
|
||||
dofile(minetest.get_modpath("mesecons").."/internal.lua");
|
||||
|
||||
-- Deprecated stuff
|
||||
-- To be removed in future releases
|
||||
-- Currently there is nothing here
|
||||
dofile(minetest.get_modpath("mesecons").."/legacy.lua");
|
||||
|
||||
-- API
|
||||
-- these are the only functions you need to remember
|
||||
|
||||
mesecon.queue:add_function("receptor_on", function (pos, rules)
|
||||
rules = rules or mesecon.rules.default
|
||||
|
||||
-- if area (any of the rule targets) is not loaded, keep trying and call this again later
|
||||
for _, rule in ipairs(mesecon:flattenrules(rules)) do
|
||||
local np = mesecon:addPosRule(pos, rule)
|
||||
-- if area is not loaded, keep trying
|
||||
if minetest.get_node_or_nil(np) == nil then
|
||||
mesecon.queue:add_action(pos, "receptor_on", {rules}, nil, rules)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
-- execute action
|
||||
for _, rule in ipairs(mesecon:flattenrules(rules)) do
|
||||
local np = mesecon:addPosRule(pos, rule)
|
||||
local rulenames = mesecon:rules_link_rule_all(pos, rule)
|
||||
for _, rulename in ipairs(rulenames) do
|
||||
mesecon:turnon(np, rulename)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
function mesecon:receptor_on(pos, rules)
|
||||
mesecon.queue:add_action(pos, "receptor_on", {rules}, nil, rules)
|
||||
end
|
||||
|
||||
mesecon.queue:add_function("receptor_off", function (pos, rules)
|
||||
rules = rules or mesecon.rules.default
|
||||
|
||||
-- if area (any of the rule targets) is not loaded, keep trying and call this again later
|
||||
for _, rule in ipairs(mesecon:flattenrules(rules)) do
|
||||
local np = mesecon:addPosRule(pos, rule)
|
||||
if minetest.get_node_or_nil(np) == nil then
|
||||
mesecon.queue:add_action(pos, "receptor_off", {rules}, nil, rules)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
for _, rule in ipairs(mesecon:flattenrules(rules)) do
|
||||
local np = mesecon:addPosRule(pos, rule)
|
||||
local rulenames = mesecon:rules_link_rule_all(pos, rule)
|
||||
for _, rulename in ipairs(rulenames) do
|
||||
if not mesecon:connected_to_receptor(np, mesecon:invertRule(rule)) then
|
||||
mesecon:turnoff(np, rulename)
|
||||
else
|
||||
mesecon:changesignal(np, minetest.get_node(np), rulename, mesecon.state.off, 2)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
function mesecon:receptor_off(pos, rules)
|
||||
mesecon.queue:add_action(pos, "receptor_off", {rules}, nil, rules)
|
||||
end
|
||||
|
||||
--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");
|
||||
|
||||
if minetest.setting_getbool("log_mods") then
|
||||
minetest.log("action", "Carbone: [mesecons] loaded.")
|
||||
end
|
704
mods/mesecons/mesecons/internal.lua
Executable file
@ -0,0 +1,704 @@
|
||||
-- Internal.lua - The core of mesecons
|
||||
--
|
||||
-- For more practical developer resources see mesecons.tk
|
||||
--
|
||||
-- Function overview
|
||||
-- mesecon:get_effector(nodename) --> Returns the mesecons.effector -specifictation in the nodedef by the nodename
|
||||
-- mesecon:get_receptor(nodename) --> Returns the mesecons.receptor -specifictation in the nodedef by the nodename
|
||||
-- mesecon:get_conductor(nodename) --> Returns the mesecons.conductor-specifictation in the nodedef by the nodename
|
||||
-- mesecon:get_any_inputrules (node) --> Returns the rules of a node if it is a conductor or an effector
|
||||
-- mesecon:get_any_outputrules (node) --> Returns the rules of a node if it is a conductor or a receptor
|
||||
|
||||
-- RECEPTORS
|
||||
-- mesecon:is_receptor(nodename) --> Returns true if nodename is a receptor
|
||||
-- mesecon:is_receptor_on(nodename) --> Returns true if nodename is an receptor with state = mesecon.state.on
|
||||
-- mesecon:is_receptor_off(nodename) --> Returns true if nodename is an receptor with state = mesecon.state.off
|
||||
-- mesecon:receptor_get_rules(node) --> Returns the rules of the receptor (mesecon.rules.default if none specified)
|
||||
|
||||
-- EFFECTORS
|
||||
-- mesecon:is_effector(nodename) --> Returns true if nodename is an effector
|
||||
-- mesecon:is_effector_on(nodename) --> Returns true if nodename is an effector with nodedef.mesecons.effector.action_off
|
||||
-- mesecon:is_effector_off(nodename) --> Returns true if nodename is an effector with nodedef.mesecons.effector.action_on
|
||||
-- mesecon:effector_get_rules(node) --> Returns the input rules of the effector (mesecon.rules.default if none specified)
|
||||
|
||||
-- SIGNALS
|
||||
-- mesecon:activate(pos, node, recdepth) --> Activates the effector node at the specific pos (calls nodedef.mesecons.effector.action_on), higher recdepths are executed later
|
||||
-- mesecon:deactivate(pos, node, recdepth) --> Deactivates the effector node at the specific pos (calls nodedef.mesecons.effector.action_off), "
|
||||
-- mesecon:changesignal(pos, node, rulename, newstate) --> Changes the effector node at the specific pos (calls nodedef.mesecons.effector.action_change), "
|
||||
|
||||
-- RULES
|
||||
-- mesecon:add_rules(name, rules) | deprecated? --> Saves rules table by name
|
||||
-- mesecon:get_rules(name, rules) | deprecated? --> Loads rules table with name
|
||||
|
||||
-- CONDUCTORS
|
||||
-- mesecon:is_conductor(nodename) --> Returns true if nodename is a conductor
|
||||
-- mesecon:is_conductor_on(node) --> Returns true if node is a conductor with state = mesecon.state.on
|
||||
-- mesecon:is_conductor_off(node) --> Returns true if node is a conductor with state = mesecon.state.off
|
||||
-- mesecon:get_conductor_on(node_off) --> Returns the onstate nodename of the conductor
|
||||
-- mesecon:get_conductor_off(node_on) --> Returns the offstate nodename of the conductor
|
||||
-- mesecon:conductor_get_rules(node) --> Returns the input+output rules of a conductor (mesecon.rules.default if none specified)
|
||||
|
||||
-- HIGH-LEVEL Internals
|
||||
-- mesecon:is_power_on(pos) --> Returns true if pos emits power in any way
|
||||
-- mesecon:is_power_off(pos) --> Returns true if pos does not emit power in any way
|
||||
-- mesecon:turnon(pos, rulename) --> Returns true whatever there is at pos. Calls itself for connected nodes (if pos is a conductor) --> recursive, the rulename is the name of the input rule that caused calling turnon; Uses third parameter recdepth internally to determine how far away the current node is from the initial pos as it uses recursion
|
||||
-- mesecon:turnoff(pos, rulename) --> Turns off whatever there is at pos. Calls itself for connected nodes (if pos is a conductor) --> recursive, the rulename is the name of the input rule that caused calling turnoff; Uses third parameter recdepth internally to determine how far away the current node is from the initial pos as it uses recursion
|
||||
-- mesecon:connected_to_receptor(pos) --> Returns true if pos is connected to a receptor directly or via conductors; calls itself if pos is a conductor --> recursive
|
||||
-- mesecon:rules_link(output, input, dug_outputrules) --> Returns true if outputposition + outputrules = inputposition and inputposition + inputrules = outputposition (if the two positions connect)
|
||||
-- mesecon:rules_link_anydir(outp., inp., d_outpr.) --> Same as rules mesecon:rules_link but also returns true if output and input are swapped
|
||||
-- mesecon:is_powered(pos) --> Returns true if pos is powered by a receptor or a conductor
|
||||
|
||||
-- RULES ROTATION helpsers
|
||||
-- mesecon:rotate_rules_right(rules)
|
||||
-- mesecon:rotate_rules_left(rules)
|
||||
-- mesecon:rotate_rules_up(rules)
|
||||
-- mesecon:rotate_rules_down(rules)
|
||||
-- These functions return rules that have been rotated in the specific direction
|
||||
|
||||
-- General
|
||||
function mesecon:get_effector(nodename)
|
||||
if minetest.registered_nodes[nodename]
|
||||
and minetest.registered_nodes[nodename].mesecons
|
||||
and minetest.registered_nodes[nodename].mesecons.effector then
|
||||
return minetest.registered_nodes[nodename].mesecons.effector
|
||||
end
|
||||
end
|
||||
|
||||
function mesecon:get_receptor(nodename)
|
||||
if minetest.registered_nodes[nodename]
|
||||
and minetest.registered_nodes[nodename].mesecons
|
||||
and minetest.registered_nodes[nodename].mesecons.receptor then
|
||||
return minetest.registered_nodes[nodename].mesecons.receptor
|
||||
end
|
||||
end
|
||||
|
||||
function mesecon:get_conductor(nodename)
|
||||
if minetest.registered_nodes[nodename]
|
||||
and minetest.registered_nodes[nodename].mesecons
|
||||
and minetest.registered_nodes[nodename].mesecons.conductor then
|
||||
return minetest.registered_nodes[nodename].mesecons.conductor
|
||||
end
|
||||
end
|
||||
|
||||
function mesecon:get_any_outputrules (node)
|
||||
if mesecon:is_conductor(node.name) then
|
||||
return mesecon:conductor_get_rules(node)
|
||||
elseif mesecon:is_receptor(node.name) then
|
||||
return mesecon:receptor_get_rules(node)
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function mesecon:get_any_inputrules (node)
|
||||
if mesecon:is_conductor(node.name) then
|
||||
return mesecon:conductor_get_rules(node)
|
||||
elseif mesecon:is_effector(node.name) then
|
||||
return mesecon:effector_get_rules(node)
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-- Receptors
|
||||
-- Nodes that can power mesecons
|
||||
function mesecon:is_receptor_on(nodename)
|
||||
local receptor = mesecon:get_receptor(nodename)
|
||||
if receptor and receptor.state == mesecon.state.on then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function mesecon:is_receptor_off(nodename)
|
||||
local receptor = mesecon:get_receptor(nodename)
|
||||
if receptor and receptor.state == mesecon.state.off then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function mesecon:is_receptor(nodename)
|
||||
local receptor = mesecon:get_receptor(nodename)
|
||||
if receptor then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function mesecon:receptor_get_rules(node)
|
||||
local receptor = mesecon:get_receptor(node.name)
|
||||
if receptor then
|
||||
local rules = receptor.rules
|
||||
if type(rules) == 'function' then
|
||||
return rules(node)
|
||||
elseif rules then
|
||||
return rules
|
||||
end
|
||||
end
|
||||
|
||||
return mesecon.rules.default
|
||||
end
|
||||
|
||||
-- Effectors
|
||||
-- Nodes that can be powered by mesecons
|
||||
function mesecon:is_effector_on(nodename)
|
||||
local effector = mesecon:get_effector(nodename)
|
||||
if effector and effector.action_off then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function mesecon:is_effector_off(nodename)
|
||||
local effector = mesecon:get_effector(nodename)
|
||||
if effector and effector.action_on then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function mesecon:is_effector(nodename)
|
||||
local effector = mesecon:get_effector(nodename)
|
||||
if effector then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function mesecon:effector_get_rules(node)
|
||||
local effector = mesecon:get_effector(node.name)
|
||||
if effector then
|
||||
local rules = effector.rules
|
||||
if type(rules) == 'function' then
|
||||
return rules(node)
|
||||
elseif rules then
|
||||
return rules
|
||||
end
|
||||
end
|
||||
return mesecon.rules.default
|
||||
end
|
||||
|
||||
-- #######################
|
||||
-- # Signals (effectors) #
|
||||
-- #######################
|
||||
|
||||
-- Activation:
|
||||
mesecon.queue:add_function("activate", function (pos, rulename)
|
||||
node = minetest.get_node(pos)
|
||||
effector = mesecon:get_effector(node.name)
|
||||
|
||||
if effector and effector.action_on then
|
||||
effector.action_on(pos, node, rulename)
|
||||
end
|
||||
end)
|
||||
|
||||
function mesecon:activate(pos, node, rulename, recdepth)
|
||||
if rulename == nil then
|
||||
for _,rule in ipairs(mesecon:effector_get_rules(node)) do
|
||||
mesecon:activate(pos, node, rule, recdepth + 1)
|
||||
end
|
||||
return
|
||||
end
|
||||
mesecon.queue:add_action(pos, "activate", {rulename}, nil, rulename, 1 / recdepth)
|
||||
end
|
||||
|
||||
|
||||
-- Deactivation
|
||||
mesecon.queue:add_function("deactivate", function (pos, rulename)
|
||||
node = minetest.get_node(pos)
|
||||
effector = mesecon:get_effector(node.name)
|
||||
|
||||
if effector and effector.action_off then
|
||||
effector.action_off(pos, node, rulename)
|
||||
end
|
||||
end)
|
||||
|
||||
function mesecon:deactivate(pos, node, rulename, recdepth)
|
||||
if rulename == nil then
|
||||
for _,rule in ipairs(mesecon:effector_get_rules(node)) do
|
||||
mesecon:deactivate(pos, node, rule, recdepth + 1)
|
||||
end
|
||||
return
|
||||
end
|
||||
mesecon.queue:add_action(pos, "deactivate", {rulename}, nil, rulename, 1 / recdepth)
|
||||
end
|
||||
|
||||
|
||||
-- Change
|
||||
mesecon.queue:add_function("change", function (pos, rulename, changetype)
|
||||
node = minetest.get_node(pos)
|
||||
effector = mesecon:get_effector(node.name)
|
||||
|
||||
if effector and effector.action_change then
|
||||
effector.action_change(pos, node, rulename, changetype)
|
||||
end
|
||||
end)
|
||||
|
||||
function mesecon:changesignal(pos, node, rulename, newstate, recdepth)
|
||||
if rulename == nil then
|
||||
for _,rule in ipairs(mesecon:effector_get_rules(node)) do
|
||||
mesecon:changesignal(pos, node, rule, newstate, recdepth + 1)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
mesecon.queue:add_action(pos, "change", {rulename, newstate}, nil, rulename, 1 / recdepth)
|
||||
end
|
||||
|
||||
-- #########
|
||||
-- # Rules # "Database" for rulenames
|
||||
-- #########
|
||||
|
||||
function mesecon:add_rules(name, rules)
|
||||
mesecon.rules[name] = rules
|
||||
end
|
||||
|
||||
function mesecon:get_rules(name)
|
||||
return mesecon.rules[name]
|
||||
end
|
||||
|
||||
-- Conductors
|
||||
|
||||
function mesecon:is_conductor_on(node, rulename)
|
||||
local conductor = mesecon:get_conductor(node.name)
|
||||
if conductor then
|
||||
if conductor.state then
|
||||
return conductor.state == mesecon.state.on
|
||||
end
|
||||
if conductor.states then
|
||||
if not rulename then
|
||||
return mesecon:getstate(node.name, conductor.states) ~= 1
|
||||
end
|
||||
local bit = mesecon:rule2bit(rulename, mesecon:conductor_get_rules(node))
|
||||
local binstate = mesecon:getbinstate(node.name, conductor.states)
|
||||
return mesecon:get_bit(binstate, bit)
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function mesecon:is_conductor_off(node, rulename)
|
||||
local conductor = mesecon:get_conductor(node.name)
|
||||
if conductor then
|
||||
if conductor.state then
|
||||
return conductor.state == mesecon.state.off
|
||||
end
|
||||
if conductor.states then
|
||||
if not rulename then
|
||||
return mesecon:getstate(node.name, conductor.states) == 1
|
||||
end
|
||||
local bit = mesecon:rule2bit(rulename, mesecon:conductor_get_rules(node))
|
||||
local binstate = mesecon:getbinstate(node.name, conductor.states)
|
||||
return not mesecon:get_bit(binstate, bit)
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function mesecon:is_conductor(nodename)
|
||||
local conductor = mesecon:get_conductor(nodename)
|
||||
if conductor then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function mesecon:get_conductor_on(node_off, rulename)
|
||||
local conductor = mesecon:get_conductor(node_off.name)
|
||||
if conductor then
|
||||
if conductor.onstate then
|
||||
return conductor.onstate
|
||||
end
|
||||
if conductor.states then
|
||||
local bit = mesecon:rule2bit(rulename, mesecon:conductor_get_rules(node_off))
|
||||
local binstate = mesecon:getbinstate(node_off.name, conductor.states)
|
||||
binstate = mesecon:set_bit(binstate, bit, "1")
|
||||
return conductor.states[tonumber(binstate,2)+1]
|
||||
end
|
||||
end
|
||||
return offstate
|
||||
end
|
||||
|
||||
function mesecon:get_conductor_off(node_on, rulename)
|
||||
local conductor = mesecon:get_conductor(node_on.name)
|
||||
if conductor then
|
||||
if conductor.offstate then
|
||||
return conductor.offstate
|
||||
end
|
||||
if conductor.states then
|
||||
local bit = mesecon:rule2bit(rulename, mesecon:conductor_get_rules(node_on))
|
||||
local binstate = mesecon:getbinstate(node_on.name, conductor.states)
|
||||
binstate = mesecon:set_bit(binstate, bit, "0")
|
||||
return conductor.states[tonumber(binstate,2)+1]
|
||||
end
|
||||
end
|
||||
return onstate
|
||||
end
|
||||
|
||||
function mesecon:conductor_get_rules(node)
|
||||
local conductor = mesecon:get_conductor(node.name)
|
||||
if conductor then
|
||||
local rules = conductor.rules
|
||||
if type(rules) == 'function' then
|
||||
return rules(node)
|
||||
elseif rules then
|
||||
return rules
|
||||
end
|
||||
end
|
||||
return mesecon.rules.default
|
||||
end
|
||||
|
||||
-- some more general high-level stuff
|
||||
|
||||
function mesecon:is_power_on(pos, rulename)
|
||||
local node = minetest.get_node(pos)
|
||||
if mesecon:is_conductor_on(node, rulename) or mesecon:is_receptor_on(node.name) then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function mesecon:is_power_off(pos, rulename)
|
||||
local node = minetest.get_node(pos)
|
||||
if mesecon:is_conductor_off(node, rulename) or mesecon:is_receptor_off(node.name) then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function mesecon:turnon(pos, rulename, recdepth)
|
||||
recdepth = recdepth or 2
|
||||
local node = minetest.get_node(pos)
|
||||
|
||||
if(node.name == "ignore") then
|
||||
-- try turning on later again
|
||||
mesecon.queue:add_action(
|
||||
pos, "turnon", {rulename, recdepth + 1}, nil, true)
|
||||
end
|
||||
|
||||
if mesecon:is_conductor_off(node, rulename) then
|
||||
local rules = mesecon:conductor_get_rules(node)
|
||||
|
||||
if not rulename then
|
||||
for _, rule in ipairs(mesecon:flattenrules(rules)) do
|
||||
if mesecon:connected_to_receptor(pos, rule) then
|
||||
mesecon:turnon(pos, rule, recdepth + 1)
|
||||
end
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
minetest.swap_node(pos, {name = mesecon:get_conductor_on(node, rulename), param2 = node.param2})
|
||||
|
||||
for _, rule in ipairs(mesecon:rule2meta(rulename, rules)) do
|
||||
local np = mesecon:addPosRule(pos, rule)
|
||||
if(minetest.get_node(np).name == "ignore") then
|
||||
-- try turning on later again
|
||||
mesecon.queue:add_action(
|
||||
np, "turnon", {rulename, recdepth + 1}, nil, true)
|
||||
else
|
||||
local rulenames = mesecon:rules_link_rule_all(pos, rule)
|
||||
|
||||
for _, rulename in ipairs(rulenames) do
|
||||
mesecon:turnon(np, rulename, recdepth + 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif mesecon:is_effector(node.name) then
|
||||
mesecon:changesignal(pos, node, rulename, mesecon.state.on, recdepth)
|
||||
if mesecon:is_effector_off(node.name) then
|
||||
mesecon:activate(pos, node, rulename, recdepth)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
mesecon.queue:add_function("turnon", function (pos, rulename, recdepth)
|
||||
mesecon:turnon(pos, rulename, recdepth)
|
||||
end)
|
||||
|
||||
function mesecon:turnoff(pos, rulename, recdepth)
|
||||
recdepth = recdepth or 2
|
||||
local node = minetest.get_node(pos)
|
||||
|
||||
if(node.name == "ignore") then
|
||||
-- try turning on later again
|
||||
mesecon.queue:add_action(
|
||||
pos, "turnoff", {rulename, recdepth + 1}, nil, true)
|
||||
end
|
||||
|
||||
if mesecon:is_conductor_on(node, rulename) then
|
||||
local rules = mesecon:conductor_get_rules(node)
|
||||
minetest.swap_node(pos, {name = mesecon:get_conductor_off(node, rulename), param2 = node.param2})
|
||||
|
||||
for _, rule in ipairs(mesecon:rule2meta(rulename, rules)) do
|
||||
local np = mesecon:addPosRule(pos, rule)
|
||||
if(minetest.get_node(np).name == "ignore") then
|
||||
-- try turning on later again
|
||||
mesecon.queue:add_action(
|
||||
np, "turnoff", {rulename, recdepth + 1}, nil, true)
|
||||
else
|
||||
local rulenames = mesecon:rules_link_rule_all(pos, rule)
|
||||
|
||||
for _, rulename in ipairs(rulenames) do
|
||||
mesecon:turnoff(np, rulename, recdepth + 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif mesecon:is_effector(node.name) then
|
||||
mesecon:changesignal(pos, node, rulename, mesecon.state.off, recdepth)
|
||||
if mesecon:is_effector_on(node.name)
|
||||
and not mesecon:is_powered(pos) then
|
||||
mesecon:deactivate(pos, node, rulename, recdepth + 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
mesecon.queue:add_function("turnoff", function (pos, rulename, recdepth)
|
||||
mesecon:turnoff(pos, rulename, recdepth)
|
||||
end)
|
||||
|
||||
|
||||
function mesecon:connected_to_receptor(pos, rulename)
|
||||
local node = minetest.get_node(pos)
|
||||
|
||||
-- Check if conductors around are connected
|
||||
local rules = mesecon:get_any_inputrules(node)
|
||||
if not rules then return false end
|
||||
|
||||
for _, rule in ipairs(mesecon:rule2meta(rulename, rules)) do
|
||||
local rulenames = mesecon:rules_link_rule_all_inverted(pos, rule)
|
||||
for _, rname in ipairs(rulenames) do
|
||||
local np = mesecon:addPosRule(pos, rname)
|
||||
if mesecon:find_receptor_on(np, {}, mesecon:invertRule(rname)) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function mesecon:find_receptor_on(pos, checked, rulename)
|
||||
local node = minetest.get_node(pos)
|
||||
|
||||
if mesecon:is_receptor_on(node.name) then
|
||||
-- add current position to checked
|
||||
table.insert(checked, {x=pos.x, y=pos.y, z=pos.z})
|
||||
return true
|
||||
end
|
||||
|
||||
if mesecon:is_conductor(node.name) then
|
||||
local rules = mesecon:conductor_get_rules(node)
|
||||
local metaindex = mesecon:rule2metaindex(rulename, rules)
|
||||
-- find out if node has already been checked (to prevent from endless loop)
|
||||
for _, cp in ipairs(checked) do
|
||||
if mesecon:cmpPos(cp, pos) and cp.metaindex == metaindex then
|
||||
return false, checked
|
||||
end
|
||||
end
|
||||
-- add current position to checked
|
||||
table.insert(checked, {x=pos.x, y=pos.y, z=pos.z, metaindex = metaindex})
|
||||
for _, rule in ipairs(mesecon:rule2meta(rulename, rules)) do
|
||||
local rulenames = mesecon:rules_link_rule_all_inverted(pos, rule)
|
||||
for _, rname in ipairs(rulenames) do
|
||||
local np = mesecon:addPosRule(pos, rname)
|
||||
if mesecon:find_receptor_on(np, checked, mesecon:invertRule(rname)) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
-- find out if node has already been checked (to prevent from endless loop)
|
||||
for _, cp in ipairs(checked) do
|
||||
if mesecon:cmpPos(cp, pos) then
|
||||
return false, checked
|
||||
end
|
||||
end
|
||||
table.insert(checked, {x=pos.x, y=pos.y, z=pos.z})
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function mesecon:rules_link(output, input, dug_outputrules) --output/input are positions (outputrules optional, used if node has been dug), second return value: the name of the affected input rule
|
||||
local outputnode = minetest.get_node(output)
|
||||
local inputnode = minetest.get_node(input)
|
||||
local outputrules = dug_outputrules or mesecon:get_any_outputrules (outputnode)
|
||||
local inputrules = mesecon:get_any_inputrules (inputnode)
|
||||
if not outputrules or not inputrules then
|
||||
return
|
||||
end
|
||||
|
||||
for _, outputrule in ipairs(mesecon:flattenrules(outputrules)) do
|
||||
-- Check if output sends to input
|
||||
if mesecon:cmpPos(mesecon:addPosRule(output, outputrule), input) then
|
||||
for _, inputrule in ipairs(mesecon:flattenrules(inputrules)) do
|
||||
-- Check if input accepts from output
|
||||
if mesecon:cmpPos(mesecon:addPosRule(input, inputrule), output) then
|
||||
if inputrule.sx == nil or outputrule.sx == nil or mesecon:cmpSpecial(inputrule, outputrule) then
|
||||
return true, inputrule
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function mesecon:rules_link_rule_all(output, rule) --output/input are positions (outputrules optional, used if node has been dug), second return value: affected input rules
|
||||
local input = mesecon:addPosRule(output, rule)
|
||||
local inputnode = minetest.get_node(input)
|
||||
local inputrules = mesecon:get_any_inputrules (inputnode)
|
||||
if not inputrules then
|
||||
return {}
|
||||
end
|
||||
local rules = {}
|
||||
|
||||
for _, inputrule in ipairs(mesecon:flattenrules(inputrules)) do
|
||||
-- Check if input accepts from output
|
||||
if mesecon:cmpPos(mesecon:addPosRule(input, inputrule), output) then
|
||||
if inputrule.sx == nil or rule.sx == nil or mesecon:cmpSpecial(inputrule, rule) then
|
||||
rules[#rules+1] = inputrule
|
||||
end
|
||||
end
|
||||
end
|
||||
return rules
|
||||
end
|
||||
|
||||
function mesecon:rules_link_rule_all_inverted(input, rule)
|
||||
--local irule = mesecon:invertRule(rule)
|
||||
local output = mesecon:addPosRule(input, rule)
|
||||
local outputnode = minetest.get_node(output)
|
||||
local outputrules = mesecon:get_any_outputrules (outputnode)
|
||||
if not outputrules then
|
||||
return {}
|
||||
end
|
||||
local rules = {}
|
||||
|
||||
for _, outputrule in ipairs(mesecon:flattenrules(outputrules)) do
|
||||
if mesecon:cmpPos(mesecon:addPosRule(output, outputrule), input) then
|
||||
if outputrule.sx == nil or rule.sx == nil or mesecon:cmpSpecial(outputrule, rule) then
|
||||
rules[#rules+1] = mesecon:invertRule(outputrule)
|
||||
end
|
||||
end
|
||||
end
|
||||
return rules
|
||||
end
|
||||
|
||||
function mesecon:rules_link_anydir(pos1, pos2)
|
||||
return mesecon:rules_link(pos1, pos2) or mesecon:rules_link(pos2, pos1)
|
||||
end
|
||||
|
||||
function mesecon:is_powered(pos, rule)
|
||||
local node = minetest.get_node(pos)
|
||||
local rules = mesecon:get_any_inputrules(node)
|
||||
if not rules then return false end
|
||||
|
||||
if not rule then
|
||||
for _, rule in ipairs(mesecon:flattenrules(rules)) do
|
||||
local rulenames = mesecon:rules_link_rule_all_inverted(pos, rule)
|
||||
for _, rname in ipairs(rulenames) do
|
||||
local np = mesecon:addPosRule(pos, rname)
|
||||
local nn = minetest.get_node(np)
|
||||
if (mesecon:is_conductor_on (nn, mesecon:invertRule(rname)) or mesecon:is_receptor_on (nn.name)) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
local rulenames = mesecon:rules_link_rule_all_inverted(pos, rule)
|
||||
for _, rname in ipairs(rulenames) do
|
||||
local np = mesecon:addPosRule(pos, rname)
|
||||
local nn = minetest.get_node(np)
|
||||
if (mesecon:is_conductor_on (nn, mesecon:invertRule(rname)) or mesecon:is_receptor_on (nn.name)) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
--Rules rotation Functions:
|
||||
function mesecon:rotate_rules_right(rules)
|
||||
local nr = {}
|
||||
for i, rule in ipairs(rules) do
|
||||
if rule.sx then
|
||||
table.insert(nr, {
|
||||
x = -rule.z,
|
||||
y = rule.y,
|
||||
z = rule.x,
|
||||
sx = -rule.sz,
|
||||
sy = rule.sy,
|
||||
sz = rule.sx})
|
||||
else
|
||||
table.insert(nr, {
|
||||
x = -rule.z,
|
||||
y = rule.y,
|
||||
z = rule.x})
|
||||
end
|
||||
end
|
||||
return nr
|
||||
end
|
||||
|
||||
function mesecon:rotate_rules_left(rules)
|
||||
local nr = {}
|
||||
for i, rule in ipairs(rules) do
|
||||
if rule.sx then
|
||||
table.insert(nr, {
|
||||
x = rule.z,
|
||||
y = rule.y,
|
||||
z = -rule.x,
|
||||
sx = rule.sz,
|
||||
sy = rule.sy,
|
||||
sz = -rule.sx})
|
||||
else
|
||||
table.insert(nr, {
|
||||
x = rule.z,
|
||||
y = rule.y,
|
||||
z = -rule.x})
|
||||
end
|
||||
end
|
||||
return nr
|
||||
end
|
||||
|
||||
function mesecon:rotate_rules_down(rules)
|
||||
local nr = {}
|
||||
for i, rule in ipairs(rules) do
|
||||
if rule.sx then
|
||||
table.insert(nr, {
|
||||
x = -rule.y,
|
||||
y = rule.x,
|
||||
z = rule.z,
|
||||
sx = -rule.sy,
|
||||
sy = rule.sx,
|
||||
sz = rule.sz})
|
||||
else
|
||||
table.insert(nr, {
|
||||
x = -rule.y,
|
||||
y = rule.x,
|
||||
z = rule.z})
|
||||
end
|
||||
end
|
||||
return nr
|
||||
end
|
||||
|
||||
function mesecon:rotate_rules_up(rules)
|
||||
local nr = {}
|
||||
for i, rule in ipairs(rules) do
|
||||
if rule.sx then
|
||||
table.insert(nr, {
|
||||
x = rule.y,
|
||||
y = -rule.x,
|
||||
z = rule.z,
|
||||
sx = rule.sy,
|
||||
sy = -rule.sx,
|
||||
sz = rule.sz})
|
||||
else
|
||||
table.insert(nr, {
|
||||
x = rule.y,
|
||||
y = -rule.x,
|
||||
z = rule.z})
|
||||
end
|
||||
end
|
||||
return nr
|
||||
end
|
32
mods/mesecons/mesecons/legacy.lua
Executable file
@ -0,0 +1,32 @@
|
||||
minetest.swap_node = minetest.swap_node or function(pos, node)
|
||||
local data = minetest.get_meta(pos):to_table()
|
||||
minetest.add_node(pos, node)
|
||||
minetest.get_meta(pos):from_table(data)
|
||||
end
|
||||
|
||||
local rules = {}
|
||||
rules.a = {x = -1, y = 0, z = 0, name="A"}
|
||||
rules.b = {x = 0, y = 0, z = 1, name="B"}
|
||||
rules.c = {x = 1, y = 0, z = 0, name="C"}
|
||||
rules.d = {x = 0, y = 0, z = -1, name="D"}
|
||||
|
||||
function legacy_update_ports(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
L = {
|
||||
a = mesecon:is_power_on(mesecon:addPosRule(pos, rules.a),
|
||||
mesecon:invertRule(rules.a)) and
|
||||
mesecon:rules_link(mesecon:addPosRule(pos, rules.a), pos),
|
||||
b = mesecon:is_power_on(mesecon:addPosRule(pos, rules.b),
|
||||
mesecon:invertRule(rules.b)) and
|
||||
mesecon:rules_link(mesecon:addPosRule(pos, rules.b), pos),
|
||||
c = mesecon:is_power_on(mesecon:addPosRule(pos, rules.c),
|
||||
mesecon:invertRule(rules.c)) and
|
||||
mesecon:rules_link(mesecon:addPosRule(pos, rules.c), pos),
|
||||
d = mesecon:is_power_on(mesecon:addPosRule(pos, rules.d),
|
||||
mesecon:invertRule(rules.d)) and
|
||||
mesecon:rules_link(mesecon:addPosRule(pos, rules.d), pos),
|
||||
}
|
||||
local n = (L.a and 1 or 0) + (L.b and 2 or 0) + (L.c and 4 or 0) + (L.d and 8 or 0) + 1
|
||||
meta:set_int("real_portstates", n)
|
||||
return L
|
||||
end
|
38
mods/mesecons/mesecons/oldwires.lua
Executable file
@ -0,0 +1,38 @@
|
||||
minetest.register_node("mesecons:mesecon_off", {
|
||||
drawtype = "raillike",
|
||||
tiles = {"jeija_mesecon_off.png", "jeija_mesecon_curved_off.png", "jeija_mesecon_t_junction_off.png", "jeija_mesecon_crossing_off.png"},
|
||||
inventory_image = "jeija_mesecon_off.png",
|
||||
wield_image = "jeija_mesecon_off.png",
|
||||
paramtype = "light",
|
||||
is_ground_content = true,
|
||||
walkable = false,
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.5, -0.5, -0.5, 0.5, -0.45, 0.5},
|
||||
},
|
||||
groups = {dig_immediate=3, mesecon=1, mesecon_conductor_craftable=1},
|
||||
description="Mesecons",
|
||||
mesecons = {conductor={
|
||||
state = mesecon.state.off,
|
||||
onstate = "mesecons:mesecon_on"
|
||||
}}
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons:mesecon_on", {
|
||||
drawtype = "raillike",
|
||||
tiles = {"jeija_mesecon_on.png", "jeija_mesecon_curved_on.png", "jeija_mesecon_t_junction_on.png", "jeija_mesecon_crossing_on.png"},
|
||||
paramtype = "light",
|
||||
is_ground_content = true,
|
||||
walkable = false,
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.5, -0.5, -0.5, 0.5, -0.45, 0.5},
|
||||
},
|
||||
groups = {dig_immediate=3, not_in_creaive_inventory=1, mesecon=1},
|
||||
drop = "mesecons:mesecon_off 1",
|
||||
light_source = LIGHT_MAX-11,
|
||||
mesecons = {conductor={
|
||||
state = mesecon.state.on,
|
||||
offstate = "mesecons:mesecon_off"
|
||||
}}
|
||||
})
|
45
mods/mesecons/mesecons/presets.lua
Executable file
@ -0,0 +1,45 @@
|
||||
mesecon.rules = {}
|
||||
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}}
|
||||
|
||||
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}}
|
||||
|
||||
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
|
||||
rules=mesecon:rotate_rules_left(rules)
|
||||
elseif node.param2 == 3 then
|
||||
rules=mesecon:rotate_rules_right(mesecon:rotate_rules_right(rules))
|
||||
elseif node.param2 == 0 then
|
||||
rules=mesecon:rotate_rules_right(rules)
|
||||
end
|
||||
return rules
|
||||
end
|
||||
|
||||
mesecon.state.on = "on"
|
||||
mesecon.state.off = "off"
|
76
mods/mesecons/mesecons/services.lua
Executable file
@ -0,0 +1,76 @@
|
||||
-- Dig and place services
|
||||
|
||||
mesecon.on_placenode = function (pos, node)
|
||||
-- Receptors: Send on signal when active
|
||||
if mesecon:is_receptor_on(node.name) then
|
||||
mesecon:receptor_on(pos, mesecon:receptor_get_rules(node))
|
||||
end
|
||||
|
||||
-- Conductors: Send turnon signal when powered or replace by respective offstate conductor
|
||||
-- if placed conductor is an onstate one
|
||||
if mesecon:is_conductor(node.name) then
|
||||
if mesecon:is_powered(pos) then
|
||||
-- also call receptor_on if itself is powered already, so that neighboring
|
||||
-- conductors will be activated (when pushing an on-conductor with a piston)
|
||||
mesecon:turnon (pos)
|
||||
mesecon:receptor_on (pos, mesecon:conductor_get_rules(node))
|
||||
elseif mesecon:is_conductor_off(node.name) then
|
||||
minetest.swap_node(pos, {name = mesecon:get_conductor_off(node)})
|
||||
end
|
||||
end
|
||||
|
||||
-- Effectors: Send changesignal and activate or deactivate
|
||||
if mesecon:is_effector(node.name) then
|
||||
if mesecon:is_powered(pos) then
|
||||
mesecon:changesignal(pos, node, mesecon:effector_get_rules(node), "on", 1)
|
||||
mesecon:activate(pos, node, nil, 1)
|
||||
else
|
||||
mesecon:changesignal(pos, node, mesecon:effector_get_rules(node), "off", 1)
|
||||
mesecon:deactivate(pos, node, nil, 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
minetest.register_on_placenode(mesecon.on_placenode)
|
||||
minetest.register_on_dignode(mesecon.on_dignode)
|
||||
|
||||
-- Overheating service for fast circuits
|
||||
|
||||
-- returns true if heat is too high
|
||||
mesecon.do_overheat = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local heat = meta:get_int("heat") or 0
|
||||
|
||||
heat = heat + 1
|
||||
meta:set_int("heat", heat)
|
||||
|
||||
if heat < OVERHEAT_MAX then
|
||||
mesecon.queue:add_action(pos, "cooldown", {}, 1, nil, 0)
|
||||
else
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
mesecon.queue:add_function("cooldown", function (pos)
|
||||
if minetest.get_item_group(minetest.get_node(pos).name, "overheat") == 0 then
|
||||
return -- node has been moved, this one does not use overheating - ignore
|
||||
end
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
local heat = meta:get_int("heat")
|
||||
|
||||
if (heat > 0) then
|
||||
meta:set_int("heat", heat - 1)
|
||||
end
|
||||
end)
|
12
mods/mesecons/mesecons/settings.lua
Executable file
@ -0,0 +1,12 @@
|
||||
-- SETTINGS
|
||||
BLINKY_PLANT_INTERVAL = 3
|
||||
NEW_STYLE_WIRES = true -- true = new nodebox wires, false = old raillike wires
|
||||
PRESSURE_PLATE_INTERVAL = 0.1
|
||||
OBJECT_DETECTOR_RADIUS = 6
|
||||
PISTON_MAXIMUM_PUSH = 15
|
||||
MOVESTONE_MAXIMUM_PUSH = 100
|
||||
MESECONS_RESUMETIME = 4 -- time to wait when starting the server before
|
||||
-- processing the ActionQueue, don't set this too low
|
||||
OVERHEAT_MAX = 20 -- maximum heat of any component that directly sends an output
|
||||
-- signal when the input changes (e.g. luacontroller, gates)
|
||||
-- Unit: actions per second, checks are every 1 second
|
BIN
mods/mesecons/mesecons/textures/jeija_fiber.png
Executable file
After Width: | Height: | Size: 431 B |
BIN
mods/mesecons/mesecons/textures/jeija_glue.png
Executable file
After Width: | Height: | Size: 434 B |
BIN
mods/mesecons/mesecons/textures/jeija_mesecon_crossing_off.png
Executable file
After Width: | Height: | Size: 288 B |
BIN
mods/mesecons/mesecons/textures/jeija_mesecon_crossing_on.png
Executable file
After Width: | Height: | Size: 287 B |
BIN
mods/mesecons/mesecons/textures/jeija_mesecon_curved_off.png
Executable file
After Width: | Height: | Size: 254 B |
BIN
mods/mesecons/mesecons/textures/jeija_mesecon_curved_on.png
Executable file
After Width: | Height: | Size: 254 B |
BIN
mods/mesecons/mesecons/textures/jeija_mesecon_inverter_off.png
Executable file
After Width: | Height: | Size: 537 B |
BIN
mods/mesecons/mesecons/textures/jeija_mesecon_inverter_on.png
Executable file
After Width: | Height: | Size: 514 B |
BIN
mods/mesecons/mesecons/textures/jeija_mesecon_off.png
Executable file
After Width: | Height: | Size: 151 B |
BIN
mods/mesecons/mesecons/textures/jeija_mesecon_on.png
Executable file
After Width: | Height: | Size: 143 B |
BIN
mods/mesecons/mesecons/textures/jeija_mesecon_plug.png
Executable file
After Width: | Height: | Size: 533 B |
BIN
mods/mesecons/mesecons/textures/jeija_mesecon_socket_off.png
Executable file
After Width: | Height: | Size: 580 B |
BIN
mods/mesecons/mesecons/textures/jeija_mesecon_socket_on.png
Executable file
After Width: | Height: | Size: 546 B |
BIN
mods/mesecons/mesecons/textures/jeija_mesecon_switch_off.png
Executable file
After Width: | Height: | Size: 505 B |
BIN
mods/mesecons/mesecons/textures/jeija_mesecon_switch_on.png
Executable file
After Width: | Height: | Size: 618 B |
BIN
mods/mesecons/mesecons/textures/jeija_mesecon_switch_side.png
Executable file
After Width: | Height: | Size: 253 B |
BIN
mods/mesecons/mesecons/textures/jeija_mesecon_t_junction_off.png
Executable file
After Width: | Height: | Size: 277 B |
BIN
mods/mesecons/mesecons/textures/jeija_mesecon_t_junction_on.png
Executable file
After Width: | Height: | Size: 266 B |
BIN
mods/mesecons/mesecons/textures/jeija_silicon.png
Executable file
After Width: | Height: | Size: 636 B |
BIN
mods/mesecons/mesecons/textures/wires_bump_off.png
Executable file
After Width: | Height: | Size: 307 B |
BIN
mods/mesecons/mesecons/textures/wires_bump_on.png
Executable file
After Width: | Height: | Size: 346 B |
BIN
mods/mesecons/mesecons/textures/wires_full_off.png
Executable file
After Width: | Height: | Size: 378 B |
BIN
mods/mesecons/mesecons/textures/wires_full_on.png
Executable file
After Width: | Height: | Size: 366 B |
BIN
mods/mesecons/mesecons/textures/wires_inv.png
Executable file
After Width: | Height: | Size: 124 B |