2017-08-06 06:46:25 +02:00
|
|
|
--[[
|
|
|
|
scriptblock = function (pos, node, sender, info, last, main_channel)
|
|
|
|
-- "pos" and "node" are the position and the node information of the scriptblock being ran.
|
|
|
|
-- "sender" would be the position of the node responsible for activating it.
|
|
|
|
-- "info" is any information the previous node has sent to it.
|
|
|
|
-- "last" is the information that "info" /was/ before it was last changed.
|
|
|
|
-- "channel" is the channel in which variables are stored.
|
|
|
|
blah blah blah
|
2017-08-07 17:37:16 +02:00
|
|
|
return new_info, faces -- Information to pass to the next node(s), and information on which adjacent spaces we should even try to signal to.
|
2017-08-06 06:46:25 +02:00
|
|
|
end
|
|
|
|
]]
|
|
|
|
|
2017-08-07 05:58:13 +02:00
|
|
|
-- These are aliases registered to aid various transitions (mostly changes in the node naming scheme, though).
|
|
|
|
minetest.register_alias("rmod:scriptblock_digiline", "rmod:scriptblock_digiline_receiver")
|
|
|
|
minetest.register_alias("rmod:scriptblock_mesecon", "rmod:scriptblock_mesecon_receiver")
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-08-06 20:54:28 +02:00
|
|
|
local program_channel = "Program channel"
|
|
|
|
|
2017-08-06 21:18:45 +02:00
|
|
|
local do_debug = false
|
2017-08-06 06:46:25 +02:00
|
|
|
local function debug(text)
|
|
|
|
if do_debug then minetest.chat_send_all("[SB] " .. text) end
|
|
|
|
end
|
|
|
|
|
|
|
|
local storage = minetest.get_mod_storage()
|
|
|
|
|
|
|
|
-- Each section of the RMod gets its own storage, to prevent interference.
|
|
|
|
-- RMod sections can still affect other sections, though only when intended.
|
|
|
|
local function get_storage()
|
|
|
|
return minetest.deserialize(storage:get_string("scriptblock")) or {}
|
|
|
|
end
|
|
|
|
local function set_storage(data)
|
|
|
|
return storage:set_string("scriptblock", minetest.serialize(data))
|
|
|
|
end
|
|
|
|
|
2017-08-07 00:20:14 +02:00
|
|
|
local function stringify(t)
|
2017-08-07 02:42:04 +02:00
|
|
|
if type(t) ~= "table" then return tostring(t) end
|
2017-08-07 00:20:14 +02:00
|
|
|
return minetest.serialize(t):sub(("return "):len()+1, -1)
|
|
|
|
end
|
|
|
|
|
2017-08-07 00:25:43 +02:00
|
|
|
local function compare(a, b)
|
|
|
|
-- Compare two tables by comparing their values -
|
|
|
|
-- also make sure to support nested tables.
|
|
|
|
if type(a) ~= "table" or type(b) ~= "table" then return a == b end
|
|
|
|
|
|
|
|
for i,j in pairs(a) do
|
|
|
|
if not compare(j, b[i]) then return false end
|
|
|
|
end
|
|
|
|
for i,j in pairs(b) do
|
|
|
|
if not compare(j, a[i]) then return false end
|
|
|
|
end
|
|
|
|
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2017-08-06 06:46:25 +02:00
|
|
|
-- To avoid lag and stack overflows, we add the data to a queue and then execute it with a globalstep.
|
|
|
|
local queue = {}
|
|
|
|
|
|
|
|
rmod.scriptblock = {}
|
|
|
|
|
|
|
|
rmod.scriptblock.run = function (pos, sender, info, last, channel)
|
|
|
|
local local_queue = {}
|
|
|
|
|
|
|
|
-- Get information about this script block we are told to execute.
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
local name = node.name
|
|
|
|
local def = minetest.registered_nodes[name]
|
|
|
|
|
|
|
|
-- If the block is a script block...
|
|
|
|
if def and def.scriptblock then
|
2017-08-07 17:37:16 +02:00
|
|
|
local new_info, faces = def.scriptblock(pos, node, sender, info, last, channel)
|
2017-08-06 06:46:25 +02:00
|
|
|
-- if new_info == rmod.scriptblock.stop_signal then return end -- Looks like the block doesn't want to conduct.
|
|
|
|
if not faces then
|
|
|
|
faces = {true, true, true, true, true, true}
|
|
|
|
end
|
|
|
|
-- Check neighboring nodes; if they also have scriptblock and aren't the sender, execute them.
|
|
|
|
for i=1,6 do
|
|
|
|
if faces[i] then
|
|
|
|
local dir = vector.new(0, 0, 0)
|
|
|
|
if i == 1 then dir.y = 1
|
|
|
|
elseif i == 2 then dir.y = -1
|
|
|
|
elseif i == 3 then dir.x = 1
|
|
|
|
elseif i == 4 then dir.x = -1
|
|
|
|
elseif i == 5 then dir.z = 1
|
|
|
|
elseif i == 6 then dir.z = -1 end
|
|
|
|
|
|
|
|
local new_pos = vector.add(pos, dir)
|
|
|
|
|
|
|
|
-- This is required, otherwise you'd have an unintentional feedback loop.
|
|
|
|
-- Feedback loops can still be created intentionally, though.
|
|
|
|
if not vector.equals(new_pos, sender) then
|
|
|
|
local new_node = minetest.get_node(new_pos)
|
|
|
|
local new_name = new_node.name
|
|
|
|
local new_def = minetest.registered_nodes[new_name]
|
|
|
|
|
|
|
|
if new_def and new_def.scriptblock then
|
2017-08-07 02:42:04 +02:00
|
|
|
local new_last
|
2017-08-07 17:37:16 +02:00
|
|
|
if new_info ~= nil then -- If something has been pushed to the stack,
|
|
|
|
new_last = info -- we update @last.
|
2017-08-07 02:42:04 +02:00
|
|
|
else
|
2017-08-07 17:37:16 +02:00
|
|
|
new_info = info -- Why bother updating it?
|
|
|
|
new_last = last
|
2017-08-07 02:42:04 +02:00
|
|
|
end
|
|
|
|
table.insert(local_queue, {new_pos, pos, new_info, new_last, channel})
|
2017-08-06 06:46:25 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return local_queue
|
|
|
|
end
|
|
|
|
rmod.scriptblock.escape = function (text, info, last)
|
2017-08-07 00:20:14 +02:00
|
|
|
-- We handle these separately, so that we don't need to stringify it.
|
2017-08-07 17:26:13 +02:00
|
|
|
local info = info
|
|
|
|
local last = last
|
|
|
|
|
2017-08-07 00:20:14 +02:00
|
|
|
if text == "@info" then return info end
|
|
|
|
if text == "@last" then return last end
|
|
|
|
|
|
|
|
if type(info) == "table" then info = stringify(info) or "" end
|
|
|
|
if type(last) == "table" then last = stringify(last) or "" end
|
2017-08-07 02:42:04 +02:00
|
|
|
return text and text:gsub("@info", tostring(info) or ""):gsub("@last", tostring(last) or "")-- or ""
|
2017-08-06 06:46:25 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local time = 0
|
|
|
|
minetest.register_globalstep(function (dtime)
|
2017-08-06 07:55:39 +02:00
|
|
|
-- time = time + dtime
|
|
|
|
-- if time > 0.05 then time = 0 else return end
|
2017-08-06 06:46:25 +02:00
|
|
|
|
|
|
|
local new_queue = {}
|
|
|
|
for i,data in pairs(queue) do
|
|
|
|
local new_list = rmod.scriptblock.run(unpack(data))
|
|
|
|
if new_list then
|
|
|
|
for _,new_item in pairs(new_list) do
|
|
|
|
table.insert(new_queue, new_item)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
queue = new_queue
|
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_node("rmod:scriptblock_set", {
|
|
|
|
description = "Scriptblock: Set",
|
|
|
|
tiles = {"rmod_scriptblock_set.png"},
|
|
|
|
groups = {oddly_breakable_by_hand = 1},
|
|
|
|
use_texture_alpha = true,
|
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("formspec", [[
|
2017-08-06 20:54:28 +02:00
|
|
|
field[channel;]] .. program_channel .. [[ (optional);${channel}]
|
2017-08-06 06:46:25 +02:00
|
|
|
field[varname;Varname;${varname}]
|
|
|
|
field[value;Value;${value}]
|
|
|
|
]])
|
|
|
|
end,
|
|
|
|
on_receive_fields = function(pos, formname, fields, sender)
|
|
|
|
local name = sender:get_player_name()
|
|
|
|
if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, {protection_bypass=true}) then
|
|
|
|
minetest.record_protection_violation(pos, name)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if (fields.channel) then
|
|
|
|
minetest.get_meta(pos):set_string("channel", fields.channel)
|
|
|
|
end
|
|
|
|
if (fields.varname) then
|
|
|
|
minetest.get_meta(pos):set_string("varname", fields.varname)
|
|
|
|
end
|
|
|
|
if (fields.value) then
|
|
|
|
minetest.get_meta(pos):set_string("value", fields.value)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
scriptblock = function (pos, node, sender, info, last, main_channel)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local channel = rmod.scriptblock.escape(meta:get_string("channel"), info, last)
|
|
|
|
local varname = rmod.scriptblock.escape(meta:get_string("varname"), info, last)
|
|
|
|
local value = rmod.scriptblock.escape(meta:get_string("value"), info, last)
|
|
|
|
|
|
|
|
local store = get_storage()
|
|
|
|
|
|
|
|
if channel == "" or not channel then channel = main_channel end
|
|
|
|
|
2017-08-07 02:42:04 +02:00
|
|
|
if not varname then varname = "" end
|
|
|
|
|
2017-08-06 06:46:25 +02:00
|
|
|
if not store[channel] then store[channel] = {} end
|
|
|
|
store[channel][varname] = value
|
|
|
|
|
|
|
|
set_storage(store)
|
|
|
|
|
2017-08-07 00:20:14 +02:00
|
|
|
debug("SET " .. channel .. "." .. tostring(varname) .. ": " .. tostring(value))
|
2017-08-06 06:46:25 +02:00
|
|
|
|
2017-08-07 17:37:16 +02:00
|
|
|
return
|
2017-08-06 06:46:25 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
minetest.register_node("rmod:scriptblock_get", {
|
|
|
|
description = "Scriptblock: Get",
|
|
|
|
tiles = {"rmod_scriptblock_get.png"},
|
|
|
|
groups = {oddly_breakable_by_hand = 1},
|
|
|
|
use_texture_alpha = true,
|
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("formspec", [[
|
2017-08-06 20:54:28 +02:00
|
|
|
field[channel;]] .. program_channel .. [[ (optional);${channel}]
|
2017-08-06 06:46:25 +02:00
|
|
|
field[varname;Varname;${varname}]
|
|
|
|
]])
|
|
|
|
end,
|
|
|
|
on_receive_fields = function(pos, formname, fields, sender)
|
|
|
|
local name = sender:get_player_name()
|
|
|
|
if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, {protection_bypass=true}) then
|
|
|
|
minetest.record_protection_violation(pos, name)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if (fields.channel) then
|
|
|
|
minetest.get_meta(pos):set_string("channel", fields.channel)
|
|
|
|
end
|
|
|
|
if (fields.varname) then
|
|
|
|
minetest.get_meta(pos):set_string("varname", fields.varname)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
scriptblock = function (pos, node, sender, info, last, main_channel)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local channel = rmod.scriptblock.escape(meta:get_string("channel"), info, last)
|
|
|
|
local varname = rmod.scriptblock.escape(meta:get_string("varname"), info, last)
|
|
|
|
|
|
|
|
local store = get_storage()
|
|
|
|
|
|
|
|
if channel == "" or not channel then channel = main_channel end
|
2017-08-07 02:42:04 +02:00
|
|
|
if not varname then return end
|
2017-08-06 06:46:25 +02:00
|
|
|
|
|
|
|
if not store[channel] then store[channel] = {} end
|
|
|
|
|
2017-08-07 00:20:14 +02:00
|
|
|
debug("GET " .. tostring(channel) .. "." .. tostring(varname) .. ": " .. tostring(store[channel][varname] or ""))
|
2017-08-06 06:46:25 +02:00
|
|
|
|
2017-08-07 02:42:04 +02:00
|
|
|
return store[channel][varname]
|
2017-08-06 06:46:25 +02:00
|
|
|
end
|
|
|
|
})
|
2017-08-07 05:58:13 +02:00
|
|
|
minetest.register_node("rmod:scriptblock_mesecon_receiver", {
|
|
|
|
description = "Scriptblock: Mesecon Receiver",
|
2017-08-06 06:46:25 +02:00
|
|
|
tiles = {"rmod_scriptblock_mesecon.png"},
|
|
|
|
groups = {oddly_breakable_by_hand = 1},
|
|
|
|
use_texture_alpha = true,
|
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("formspec", [[
|
2017-08-06 20:54:28 +02:00
|
|
|
field[channel;]] .. program_channel .. [[;${channel}]
|
2017-08-07 02:42:04 +02:00
|
|
|
field[info;Starting @info;${info}]
|
2017-08-06 06:46:25 +02:00
|
|
|
]])
|
|
|
|
end,
|
|
|
|
on_receive_fields = function(pos, formname, fields, sender)
|
|
|
|
local name = sender:get_player_name()
|
|
|
|
if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, {protection_bypass=true}) then
|
|
|
|
minetest.record_protection_violation(pos, name)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if (fields.channel) then
|
|
|
|
minetest.get_meta(pos):set_string("channel", fields.channel)
|
|
|
|
end
|
2017-08-07 02:42:04 +02:00
|
|
|
if (fields.info) then
|
|
|
|
minetest.get_meta(pos):set_string("info", fields.info)
|
|
|
|
end
|
2017-08-06 06:46:25 +02:00
|
|
|
end,
|
|
|
|
scriptblock = function (pos, node, sender, info, last, main_channel)
|
2017-08-07 17:37:16 +02:00
|
|
|
return
|
2017-08-06 06:46:25 +02:00
|
|
|
end,
|
|
|
|
mesecons = {effector = {
|
|
|
|
action_on = function (pos, node)
|
|
|
|
local meta = minetest.get_meta(pos)
|
2017-08-07 02:42:04 +02:00
|
|
|
local channel = meta:get_string("channel")
|
|
|
|
local info = meta:get_string("info")
|
2017-08-06 06:46:25 +02:00
|
|
|
|
|
|
|
debug("ACTIVATED")
|
2017-08-07 02:42:04 +02:00
|
|
|
table.insert(queue, {pos, pos, info or "", "", channel or ""})
|
2017-08-06 06:46:25 +02:00
|
|
|
end,
|
|
|
|
}}
|
|
|
|
})
|
|
|
|
minetest.register_node("rmod:scriptblock_print", {
|
|
|
|
description = "Scriptblock: Print",
|
|
|
|
tiles = {"rmod_scriptblock_print.png"},
|
|
|
|
groups = {oddly_breakable_by_hand = 1},
|
|
|
|
use_texture_alpha = true,
|
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("formspec", [[
|
2017-08-06 07:55:39 +02:00
|
|
|
field[player;Player (optional);${player}]
|
2017-08-06 06:46:25 +02:00
|
|
|
field[message;Message;${message}]
|
|
|
|
]])
|
|
|
|
end,
|
|
|
|
on_receive_fields = function(pos, formname, fields, sender)
|
|
|
|
local name = sender:get_player_name()
|
|
|
|
if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, {protection_bypass=true}) then
|
|
|
|
minetest.record_protection_violation(pos, name)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if (fields.player) then
|
|
|
|
minetest.get_meta(pos):set_string("player", fields.player)
|
|
|
|
end
|
|
|
|
if (fields.message) then
|
|
|
|
minetest.get_meta(pos):set_string("message", fields.message)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
scriptblock = function (pos, node, sender, info, last, main_channel)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local plr = rmod.scriptblock.escape(meta:get_string("player"), info, last)
|
|
|
|
local msg = rmod.scriptblock.escape(meta:get_string("message"), info, last)
|
|
|
|
|
2017-08-07 17:37:16 +02:00
|
|
|
if not plr then return end
|
|
|
|
if not msg then return end
|
2017-08-07 02:42:04 +02:00
|
|
|
|
2017-08-07 00:20:14 +02:00
|
|
|
if type(msg) == "table" then msg = stringify(msg) end
|
|
|
|
|
2017-08-06 06:46:25 +02:00
|
|
|
if plr == "" then
|
2017-08-07 00:20:14 +02:00
|
|
|
minetest.chat_send_all("Scriptblock -> all: " .. tostring(msg))
|
2017-08-06 06:46:25 +02:00
|
|
|
else
|
2017-08-07 00:20:14 +02:00
|
|
|
minetest.chat_send_player(plr, "Scriptblock -> you: " .. tostring(msg))
|
2017-08-06 06:46:25 +02:00
|
|
|
end
|
|
|
|
|
2017-08-07 17:37:16 +02:00
|
|
|
return
|
2017-08-06 06:46:25 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
minetest.register_node("rmod:scriptblock_if", {
|
2017-08-07 02:42:04 +02:00
|
|
|
description = "Scriptblock: If",
|
2017-08-06 06:46:25 +02:00
|
|
|
tiles = {"rmod_scriptblock_if_top.png", "rmod_scriptblock_if_bottom.png",
|
|
|
|
"rmod_scriptblock_if_right.png", "rmod_scriptblock_if_left.png",
|
|
|
|
"rmod_scriptblock_if_truth.png", "rmod_scriptblock_if_falsth.png"},
|
|
|
|
groups = {oddly_breakable_by_hand = 1},
|
|
|
|
use_texture_alpha = true,
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
scriptblock = function (pos, node, sender, info, last, main_channel)
|
2017-08-07 02:42:04 +02:00
|
|
|
-- compatibility for back when this was "IF EQUALS"
|
2017-08-06 06:46:25 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local a = rmod.scriptblock.escape(meta:get_string("a"), info, last)
|
|
|
|
local b = rmod.scriptblock.escape(meta:get_string("b"), info, last)
|
|
|
|
|
|
|
|
local facedir = node.param2
|
|
|
|
local dir = minetest.facedir_to_dir(facedir)
|
|
|
|
|
|
|
|
-- Y, -Y, X, -X, Z, -Z.
|
|
|
|
|
|
|
|
local truth = {}
|
|
|
|
local falsth = {}
|
|
|
|
if dir.x == 1 then truth[3] = true; falsth[4] = true
|
|
|
|
elseif dir.x == -1 then truth[4] = true; falsth[3] = true
|
|
|
|
elseif dir.z == 1 then truth[5] = true; falsth[6] = true
|
|
|
|
elseif dir.z == -1 then truth[6] = true; falsth[5] = true end
|
|
|
|
|
2017-08-07 00:25:43 +02:00
|
|
|
--[[if type(a) == "table" then
|
2017-08-07 00:20:14 +02:00
|
|
|
a = stringify(a) or a
|
2017-08-06 20:54:28 +02:00
|
|
|
end
|
|
|
|
if type(b) == "table" then
|
2017-08-07 00:20:14 +02:00
|
|
|
b = stringify(b) or b
|
2017-08-07 00:25:43 +02:00
|
|
|
end]]
|
2017-08-06 20:54:28 +02:00
|
|
|
|
2017-08-07 02:42:04 +02:00
|
|
|
if a == "" and b == "" then
|
2017-08-07 17:37:16 +02:00
|
|
|
return unpack(info and {nil, truth} or {nil, falsth})
|
2017-08-07 02:42:04 +02:00
|
|
|
else
|
2017-08-07 17:37:16 +02:00
|
|
|
return unpack(compare(a, b) and {nil, truth} or {nil, falsth})
|
2017-08-07 02:42:04 +02:00
|
|
|
end
|
2017-08-06 06:46:25 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
minetest.register_node("rmod:scriptblock_guide", {
|
|
|
|
description = "Scriptblock: One-Way Guide",
|
|
|
|
tiles = {"rmod_scriptblock_guide_top.png", "rmod_scriptblock_guide_bottom.png",
|
|
|
|
"rmod_scriptblock_guide_right.png", "rmod_scriptblock_guide_left.png",
|
|
|
|
"rmod_scriptblock_guide_front.png", "rmod_scriptblock_guide_back.png"},
|
|
|
|
groups = {oddly_breakable_by_hand = 1},
|
|
|
|
use_texture_alpha = true,
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
scriptblock = function (pos, node, sender, info, last, main_channel)
|
|
|
|
local facedir = node.param2
|
|
|
|
local dir = minetest.facedir_to_dir(facedir)
|
|
|
|
|
|
|
|
-- Y, -Y, X, -X, Z, -Z.
|
|
|
|
|
|
|
|
local guide = {}
|
|
|
|
if dir.x == 1 then guide[3] = true
|
|
|
|
elseif dir.x == -1 then guide[4] = true
|
|
|
|
elseif dir.z == 1 then guide[5] = true
|
|
|
|
elseif dir.z == -1 then guide[6] = true end
|
|
|
|
|
2017-08-07 17:37:16 +02:00
|
|
|
return nil, guide
|
2017-08-06 06:46:25 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_node("rmod:scriptblock_add", {
|
|
|
|
description = "Scriptblock: Add",
|
|
|
|
tiles = {"rmod_scriptblock_add.png"},
|
|
|
|
groups = {oddly_breakable_by_hand = 1},
|
|
|
|
use_texture_alpha = true,
|
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("formspec", [[
|
|
|
|
field[a;A;${a}]
|
|
|
|
field[b;B;${b}]
|
|
|
|
]])
|
|
|
|
end,
|
|
|
|
on_receive_fields = function(pos, formname, fields, sender)
|
|
|
|
local name = sender:get_player_name()
|
|
|
|
if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, {protection_bypass=true}) then
|
|
|
|
minetest.record_protection_violation(pos, name)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if (fields.a) then
|
|
|
|
minetest.get_meta(pos):set_string("a", fields.a)
|
|
|
|
end
|
|
|
|
if (fields.b) then
|
|
|
|
minetest.get_meta(pos):set_string("b", fields.b)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
scriptblock = function (pos, node, sender, info, last, main_channel)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local a = rmod.scriptblock.escape(meta:get_string("a"), info, last)
|
|
|
|
local b = rmod.scriptblock.escape(meta:get_string("b"), info, last)
|
|
|
|
|
|
|
|
local facedir = node.param2
|
|
|
|
local dir = minetest.facedir_to_dir(facedir)
|
|
|
|
|
2017-08-07 17:37:16 +02:00
|
|
|
return (tonumber(a) or 0) + (tonumber(b) or 0)
|
2017-08-06 06:46:25 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
minetest.register_node("rmod:scriptblock_subtract", {
|
|
|
|
description = "Scriptblock: Subtract",
|
|
|
|
tiles = {"rmod_scriptblock_subtract.png"},
|
|
|
|
groups = {oddly_breakable_by_hand = 1},
|
|
|
|
use_texture_alpha = true,
|
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("formspec", [[
|
|
|
|
field[a;A;${a}]
|
|
|
|
field[b;B;${b}]
|
|
|
|
]])
|
|
|
|
end,
|
|
|
|
on_receive_fields = function(pos, formname, fields, sender)
|
|
|
|
local name = sender:get_player_name()
|
|
|
|
if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, {protection_bypass=true}) then
|
|
|
|
minetest.record_protection_violation(pos, name)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if (fields.a) then
|
|
|
|
minetest.get_meta(pos):set_string("a", fields.a)
|
|
|
|
end
|
|
|
|
if (fields.b) then
|
|
|
|
minetest.get_meta(pos):set_string("b", fields.b)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
scriptblock = function (pos, node, sender, info, last, main_channel)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local a = rmod.scriptblock.escape(meta:get_string("a"), info, last)
|
|
|
|
local b = rmod.scriptblock.escape(meta:get_string("b"), info, last)
|
|
|
|
|
|
|
|
local facedir = node.param2
|
|
|
|
local dir = minetest.facedir_to_dir(facedir)
|
|
|
|
|
2017-08-07 17:37:16 +02:00
|
|
|
return (tonumber(a) or 0) - (tonumber(b) or 0)
|
2017-08-06 06:46:25 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
minetest.register_node("rmod:scriptblock_multiply", {
|
|
|
|
description = "Scriptblock: Multiply",
|
|
|
|
tiles = {"rmod_scriptblock_multiply.png"},
|
|
|
|
groups = {oddly_breakable_by_hand = 1},
|
|
|
|
use_texture_alpha = true,
|
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("formspec", [[
|
|
|
|
field[a;A;${a}]
|
|
|
|
field[b;B;${b}]
|
|
|
|
]])
|
|
|
|
end,
|
|
|
|
on_receive_fields = function(pos, formname, fields, sender)
|
|
|
|
local name = sender:get_player_name()
|
|
|
|
if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, {protection_bypass=true}) then
|
|
|
|
minetest.record_protection_violation(pos, name)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if (fields.a) then
|
|
|
|
minetest.get_meta(pos):set_string("a", fields.a)
|
|
|
|
end
|
|
|
|
if (fields.b) then
|
|
|
|
minetest.get_meta(pos):set_string("b", fields.b)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
scriptblock = function (pos, node, sender, info, last, main_channel)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local a = rmod.scriptblock.escape(meta:get_string("a"), info, last)
|
|
|
|
local b = rmod.scriptblock.escape(meta:get_string("b"), info, last)
|
|
|
|
|
|
|
|
local facedir = node.param2
|
|
|
|
local dir = minetest.facedir_to_dir(facedir)
|
|
|
|
|
2017-08-07 17:37:16 +02:00
|
|
|
return (tonumber(a) or 0) * (tonumber(b) or 0)
|
2017-08-06 06:46:25 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
minetest.register_node("rmod:scriptblock_divide", {
|
|
|
|
description = "Scriptblock: Divide",
|
|
|
|
tiles = {"rmod_scriptblock_divide.png"},
|
|
|
|
groups = {oddly_breakable_by_hand = 1},
|
|
|
|
use_texture_alpha = true,
|
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("formspec", [[
|
|
|
|
field[a;A;${a}]
|
|
|
|
field[b;B;${b}]
|
|
|
|
]])
|
|
|
|
end,
|
|
|
|
on_receive_fields = function(pos, formname, fields, sender)
|
|
|
|
local name = sender:get_player_name()
|
|
|
|
if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, {protection_bypass=true}) then
|
|
|
|
minetest.record_protection_violation(pos, name)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if (fields.a) then
|
|
|
|
minetest.get_meta(pos):set_string("a", fields.a)
|
|
|
|
end
|
|
|
|
if (fields.b) then
|
|
|
|
minetest.get_meta(pos):set_string("b", fields.b)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
scriptblock = function (pos, node, sender, info, last, main_channel)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local a = rmod.scriptblock.escape(meta:get_string("a"), info, last)
|
|
|
|
local b = rmod.scriptblock.escape(meta:get_string("b"), info, last)
|
|
|
|
|
|
|
|
local facedir = node.param2
|
|
|
|
local dir = minetest.facedir_to_dir(facedir)
|
|
|
|
|
2017-08-07 17:37:16 +02:00
|
|
|
return (tonumber(a) or 0) / (tonumber(b) or 0)
|
2017-08-07 17:26:13 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
minetest.register_node("rmod:scriptblock_modulo", {
|
|
|
|
description = "Scriptblock: Modulo",
|
|
|
|
tiles = {"rmod_scriptblock_modulo.png"},
|
|
|
|
groups = {oddly_breakable_by_hand = 1},
|
|
|
|
use_texture_alpha = true,
|
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("formspec", [[
|
|
|
|
field[a;A;${a}]
|
|
|
|
field[b;B;${b}]
|
|
|
|
]])
|
|
|
|
end,
|
|
|
|
on_receive_fields = function(pos, formname, fields, sender)
|
|
|
|
local name = sender:get_player_name()
|
|
|
|
if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, {protection_bypass=true}) then
|
|
|
|
minetest.record_protection_violation(pos, name)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if (fields.a) then
|
|
|
|
minetest.get_meta(pos):set_string("a", fields.a)
|
|
|
|
end
|
|
|
|
if (fields.b) then
|
|
|
|
minetest.get_meta(pos):set_string("b", fields.b)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
scriptblock = function (pos, node, sender, info, last, main_channel)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local a = rmod.scriptblock.escape(meta:get_string("a"), info, last)
|
|
|
|
local b = rmod.scriptblock.escape(meta:get_string("b"), info, last)
|
|
|
|
|
|
|
|
local facedir = node.param2
|
|
|
|
local dir = minetest.facedir_to_dir(facedir)
|
|
|
|
|
2017-08-07 17:37:16 +02:00
|
|
|
return (tonumber(a) or 0) % (tonumber(b) or 0)
|
2017-08-06 06:46:25 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2017-08-06 07:55:39 +02:00
|
|
|
minetest.register_node("rmod:scriptblock_player_detector", {
|
|
|
|
description = "Scriptblock: Player Detector",
|
|
|
|
tiles = {"rmod_scriptblock_player_detector.png"},
|
2017-08-06 06:46:25 +02:00
|
|
|
groups = {oddly_breakable_by_hand = 1},
|
|
|
|
use_texture_alpha = true,
|
|
|
|
scriptblock = function (pos, node, sender, info, last, main_channel)
|
|
|
|
local players = minetest.get_connected_players()
|
|
|
|
|
|
|
|
local nearest = nil
|
|
|
|
local min_distance = math.huge
|
|
|
|
for index, player in pairs(players) do
|
|
|
|
local distance = vector.distance(pos, player:getpos())
|
|
|
|
if distance < min_distance then
|
|
|
|
min_distance = distance
|
|
|
|
nearest = player:get_player_name()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return nearest or ""
|
|
|
|
end
|
|
|
|
})
|
2017-08-06 20:54:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
minetest.register_node("rmod:scriptblock_set_attribute", {
|
|
|
|
description = "Scriptblock: Set Attribute of Object",
|
|
|
|
tiles = {"rmod_scriptblock_set_attribute.png"},
|
|
|
|
groups = {oddly_breakable_by_hand = 1},
|
|
|
|
use_texture_alpha = true,
|
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("formspec", [[
|
|
|
|
field[propname;Attribute Name;${propname}]
|
|
|
|
field[value;Value;${value}]
|
|
|
|
]])
|
|
|
|
end,
|
|
|
|
on_receive_fields = function(pos, formname, fields, sender)
|
|
|
|
local name = sender:get_player_name()
|
|
|
|
if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, {protection_bypass=true}) then
|
|
|
|
minetest.record_protection_violation(pos, name)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if (fields.propname) then
|
|
|
|
minetest.get_meta(pos):set_string("propname", fields.propname)
|
|
|
|
end
|
|
|
|
if (fields.value) then
|
|
|
|
minetest.get_meta(pos):set_string("value", fields.value)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
scriptblock = function (pos, node, sender, info, last, main_channel)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local propname = rmod.scriptblock.escape(meta:get_string("propname"), info, last)
|
|
|
|
local value = rmod.scriptblock.escape(meta:get_string("value"), info, last)
|
|
|
|
|
2017-08-07 02:42:04 +02:00
|
|
|
if not propname then return end
|
|
|
|
|
2017-08-06 20:54:28 +02:00
|
|
|
if type(info) ~= "table" then
|
2017-08-07 00:20:14 +02:00
|
|
|
--[[if type(info) == "string" then
|
2017-08-06 20:54:28 +02:00
|
|
|
local deserialized = minetest.deserialize(info)
|
2017-08-07 17:37:16 +02:00
|
|
|
if deserialized then info = deserialized else return end
|
2017-08-07 00:20:14 +02:00
|
|
|
else]]
|
2017-08-07 17:37:16 +02:00
|
|
|
return
|
2017-08-07 00:20:14 +02:00
|
|
|
--end
|
2017-08-06 20:54:28 +02:00
|
|
|
end
|
2017-08-06 21:10:08 +02:00
|
|
|
|
|
|
|
-- We want to avoid problems like this:
|
|
|
|
-- serialize({nest = serialize({table})) =/= serialize({nest = {table}})
|
|
|
|
-- so we automatically deserialize the value if it can be deserialized.
|
2017-08-07 00:20:14 +02:00
|
|
|
--[[if type(value) == "string" then
|
2017-08-06 21:10:08 +02:00
|
|
|
local deserialized = minetest.deserialize(value)
|
|
|
|
if deserialized then value = deserialized end
|
2017-08-07 00:20:14 +02:00
|
|
|
end]]
|
2017-08-06 21:10:08 +02:00
|
|
|
|
2017-08-06 20:54:28 +02:00
|
|
|
info[propname] = value
|
|
|
|
|
2017-08-07 17:37:16 +02:00
|
|
|
return info
|
2017-08-06 20:54:28 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
minetest.register_node("rmod:scriptblock_get_attribute", {
|
|
|
|
description = "Scriptblock: Get Attribute of Object",
|
|
|
|
tiles = {"rmod_scriptblock_get_attribute.png"},
|
|
|
|
groups = {oddly_breakable_by_hand = 1},
|
|
|
|
use_texture_alpha = true,
|
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("formspec", [[
|
|
|
|
field[propname;Attribute Name;${propname}]
|
|
|
|
]])
|
|
|
|
end,
|
|
|
|
on_receive_fields = function(pos, formname, fields, sender)
|
|
|
|
local name = sender:get_player_name()
|
|
|
|
if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, {protection_bypass=true}) then
|
|
|
|
minetest.record_protection_violation(pos, name)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if (fields.propname) then
|
|
|
|
minetest.get_meta(pos):set_string("propname", fields.propname)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
scriptblock = function (pos, node, sender, info, last, main_channel)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local propname = rmod.scriptblock.escape(meta:get_string("propname"), info, last)
|
|
|
|
|
2017-08-07 02:42:04 +02:00
|
|
|
if not propname then return end
|
|
|
|
|
2017-08-06 20:54:28 +02:00
|
|
|
if type(info) ~= "table" then
|
2017-08-07 00:20:14 +02:00
|
|
|
--[[if type(info) == "string" then
|
2017-08-06 20:54:28 +02:00
|
|
|
local deserialized = minetest.deserialize(info)
|
2017-08-07 17:37:16 +02:00
|
|
|
if deserialized then info = deserialized else return end
|
2017-08-07 00:20:14 +02:00
|
|
|
else]]
|
2017-08-07 17:37:16 +02:00
|
|
|
return
|
2017-08-07 00:20:14 +02:00
|
|
|
--end
|
2017-08-06 20:54:28 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return info[propname]
|
|
|
|
end
|
|
|
|
})
|
|
|
|
minetest.register_node("rmod:scriptblock_new_object", {
|
|
|
|
description = "Scriptblock: New Object",
|
|
|
|
tiles = {"rmod_scriptblock_new_object.png"},
|
|
|
|
groups = {oddly_breakable_by_hand = 1},
|
|
|
|
use_texture_alpha = true,
|
|
|
|
scriptblock = function (pos, node, sender, info, last, main_channel)
|
|
|
|
return {}
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-08-07 05:58:13 +02:00
|
|
|
minetest.register_node("rmod:scriptblock_digiline_receiver", {
|
2017-08-06 20:54:28 +02:00
|
|
|
description = "Scriptblock: Digiline Receiver",
|
|
|
|
tiles = {"rmod_scriptblock_digiline.png"},
|
|
|
|
groups = {oddly_breakable_by_hand = 1},
|
|
|
|
use_texture_alpha = true,
|
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("formspec", [[
|
|
|
|
field[progchannel;]] .. program_channel .. [[;${progchannel}]
|
|
|
|
field[digichannel;Digiline channel;${digichannel}]
|
|
|
|
]])
|
|
|
|
end,
|
|
|
|
on_receive_fields = function(pos, formname, fields, sender)
|
|
|
|
local name = sender:get_player_name()
|
|
|
|
if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, {protection_bypass=true}) then
|
|
|
|
minetest.record_protection_violation(pos, name)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if (fields.digichannel) then
|
|
|
|
minetest.get_meta(pos):set_string("digichannel", fields.digichannel)
|
|
|
|
end
|
|
|
|
if (fields.progchannel) then
|
|
|
|
minetest.get_meta(pos):set_string("progchannel", fields.progchannel)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
scriptblock = function (pos, node, sender, info, last, main_channel)
|
2017-08-07 17:37:16 +02:00
|
|
|
return
|
2017-08-06 20:54:28 +02:00
|
|
|
end,
|
|
|
|
digiline = {
|
|
|
|
receptor = {},
|
|
|
|
effector = {
|
|
|
|
action = function (pos, node, msgchannel, msg)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local progchannel = meta:get_string("progchannel")
|
|
|
|
local digichannel = meta:get_string("digichannel")
|
|
|
|
|
|
|
|
if msgchannel ~= digichannel then debug("WRONG CHANNEL"); return end
|
|
|
|
|
|
|
|
debug("ACTIVATED")
|
2017-08-07 05:58:13 +02:00
|
|
|
table.insert(queue, {pos, pos, msg, "", progchannel or ""})
|
2017-08-06 20:54:28 +02:00
|
|
|
end,
|
|
|
|
}}
|
|
|
|
})
|
2017-08-07 02:42:04 +02:00
|
|
|
|
|
|
|
minetest.register_node("rmod:scriptblock_not", {
|
|
|
|
description = "Scriptblock: Not Gate",
|
|
|
|
tiles = {"rmod_scriptblock_not.png"},
|
|
|
|
groups = {oddly_breakable_by_hand = 1},
|
|
|
|
use_texture_alpha = true,
|
|
|
|
scriptblock = function (pos, node, sender, info, last, main_channel)
|
2017-08-07 17:37:16 +02:00
|
|
|
return not info
|
2017-08-07 02:42:04 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
minetest.register_node("rmod:scriptblock_and", {
|
|
|
|
description = "Scriptblock: And Gate",
|
|
|
|
tiles = {"rmod_scriptblock_and.png"},
|
|
|
|
groups = {oddly_breakable_by_hand = 1},
|
|
|
|
use_texture_alpha = true,
|
|
|
|
scriptblock = function (pos, node, sender, info, last, main_channel)
|
2017-08-07 17:37:16 +02:00
|
|
|
return info and last
|
2017-08-07 02:42:04 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
minetest.register_node("rmod:scriptblock_or", {
|
|
|
|
description = "Scriptblock: Or Gate",
|
|
|
|
tiles = {"rmod_scriptblock_or.png"},
|
|
|
|
groups = {oddly_breakable_by_hand = 1},
|
|
|
|
use_texture_alpha = true,
|
|
|
|
scriptblock = function (pos, node, sender, info, last, main_channel)
|
2017-08-07 17:37:16 +02:00
|
|
|
return info or last
|
2017-08-07 02:42:04 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_node("rmod:scriptblock_equals", {
|
|
|
|
description = "Scriptblock: Equals",
|
|
|
|
tiles = {"rmod_scriptblock_equals.png"},
|
|
|
|
groups = {oddly_breakable_by_hand = 1},
|
|
|
|
use_texture_alpha = true,
|
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("formspec", [[
|
|
|
|
field[a;A;${a}]
|
|
|
|
field[b;B;${b}]
|
|
|
|
]])
|
|
|
|
end,
|
|
|
|
on_receive_fields = function(pos, formname, fields, sender)
|
|
|
|
local name = sender:get_player_name()
|
|
|
|
if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, {protection_bypass=true}) then
|
|
|
|
minetest.record_protection_violation(pos, name)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if (fields.a) then
|
|
|
|
minetest.get_meta(pos):set_string("a", fields.a)
|
|
|
|
end
|
|
|
|
if (fields.b) then
|
|
|
|
minetest.get_meta(pos):set_string("b", fields.b)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
scriptblock = function (pos, node, sender, info, last, main_channel)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local a = rmod.scriptblock.escape(meta:get_string("a"), info, last)
|
|
|
|
local b = rmod.scriptblock.escape(meta:get_string("b"), info, last)
|
|
|
|
|
2017-08-07 17:37:16 +02:00
|
|
|
return compare(a, b)
|
2017-08-07 02:42:04 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
minetest.register_node("rmod:scriptblock_lt", {
|
|
|
|
description = "Scriptblock: Less than",
|
|
|
|
tiles = {"rmod_scriptblock_lt.png"},
|
|
|
|
groups = {oddly_breakable_by_hand = 1},
|
|
|
|
use_texture_alpha = true,
|
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("formspec", [[
|
|
|
|
field[a;A;${a}]
|
|
|
|
field[b;B;${b}]
|
|
|
|
]])
|
|
|
|
end,
|
|
|
|
on_receive_fields = function(pos, formname, fields, sender)
|
|
|
|
local name = sender:get_player_name()
|
|
|
|
if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, {protection_bypass=true}) then
|
|
|
|
minetest.record_protection_violation(pos, name)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if (fields.a) then
|
|
|
|
minetest.get_meta(pos):set_string("a", fields.a)
|
|
|
|
end
|
|
|
|
if (fields.b) then
|
|
|
|
minetest.get_meta(pos):set_string("b", fields.b)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
scriptblock = function (pos, node, sender, info, last, main_channel)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local a = rmod.scriptblock.escape(meta:get_string("a"), info, last)
|
|
|
|
local b = rmod.scriptblock.escape(meta:get_string("b"), info, last)
|
|
|
|
|
2017-08-07 17:37:16 +02:00
|
|
|
return (tonumber(a) or 0) < (tonumber(b) or 0)
|
2017-08-07 02:42:04 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
minetest.register_node("rmod:scriptblock_gt", {
|
|
|
|
description = "Scriptblock: Greater than",
|
|
|
|
tiles = {"rmod_scriptblock_gt.png"},
|
|
|
|
groups = {oddly_breakable_by_hand = 1},
|
|
|
|
use_texture_alpha = true,
|
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("formspec", [[
|
|
|
|
field[a;A;${a}]
|
|
|
|
field[b;B;${b}]
|
|
|
|
]])
|
|
|
|
end,
|
|
|
|
on_receive_fields = function(pos, formname, fields, sender)
|
|
|
|
local name = sender:get_player_name()
|
|
|
|
if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, {protection_bypass=true}) then
|
|
|
|
minetest.record_protection_violation(pos, name)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if (fields.a) then
|
|
|
|
minetest.get_meta(pos):set_string("a", fields.a)
|
|
|
|
end
|
|
|
|
if (fields.b) then
|
|
|
|
minetest.get_meta(pos):set_string("b", fields.b)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
scriptblock = function (pos, node, sender, info, last, main_channel)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local a = rmod.scriptblock.escape(meta:get_string("a"), info, last)
|
|
|
|
local b = rmod.scriptblock.escape(meta:get_string("b"), info, last)
|
|
|
|
|
2017-08-07 17:37:16 +02:00
|
|
|
return (tonumber(a) or 0) > (tonumber(b) or 0)
|
2017-08-07 02:42:04 +02:00
|
|
|
end,
|
|
|
|
})
|
2017-08-07 05:58:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-08-07 17:26:13 +02:00
|
|
|
minetest.register_node("rmod:scriptblock_type", {
|
|
|
|
description = "Scriptblock: Get Type",
|
|
|
|
tiles = {"rmod_scriptblock_type.png"},
|
|
|
|
groups = {oddly_breakable_by_hand = 1},
|
|
|
|
use_texture_alpha = true,
|
|
|
|
scriptblock = function (pos, node, sender, info, last, main_channel)
|
2017-08-07 17:37:16 +02:00
|
|
|
return type(info) == "table" and "object" or type(info)
|
2017-08-07 17:26:13 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
minetest.register_node("rmod:scriptblock_number", {
|
|
|
|
description = "Scriptblock: Number Literal",
|
|
|
|
tiles = {"rmod_scriptblock_number.png"},
|
|
|
|
groups = {oddly_breakable_by_hand = 1},
|
|
|
|
use_texture_alpha = true,
|
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("formspec", [[
|
|
|
|
field[number;Number literal;${number}]
|
|
|
|
]])
|
|
|
|
end,
|
|
|
|
on_receive_fields = function(pos, formname, fields, sender)
|
|
|
|
local name = sender:get_player_name()
|
|
|
|
if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, {protection_bypass=true}) then
|
|
|
|
minetest.record_protection_violation(pos, name)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if (fields.number) then
|
|
|
|
minetest.get_meta(pos):set_string("number", fields.number)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
scriptblock = function (pos, node, sender, info, last, main_channel)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local number = meta:get_string("number")
|
|
|
|
|
2017-08-07 17:37:16 +02:00
|
|
|
return tonumber(number)
|
2017-08-07 17:26:13 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
minetest.register_node("rmod:scriptblock_string", {
|
|
|
|
description = "Scriptblock: String Literal",
|
|
|
|
tiles = {"rmod_scriptblock_string.png"},
|
|
|
|
groups = {oddly_breakable_by_hand = 1},
|
|
|
|
use_texture_alpha = true,
|
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("formspec", [[
|
|
|
|
field[str;String literal;${str}]
|
|
|
|
]])
|
|
|
|
end,
|
|
|
|
on_receive_fields = function(pos, formname, fields, sender)
|
|
|
|
local name = sender:get_player_name()
|
|
|
|
if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, {protection_bypass=true}) then
|
|
|
|
minetest.record_protection_violation(pos, name)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if (fields.str) then
|
|
|
|
minetest.get_meta(pos):set_string("str", fields.str)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
scriptblock = function (pos, node, sender, info, last, main_channel)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local str = meta:get_string("str")
|
|
|
|
|
2017-08-07 17:37:16 +02:00
|
|
|
return str
|
2017-08-07 17:26:13 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2017-08-07 05:58:13 +02:00
|
|
|
minetest.register_node("rmod:scriptblock_digiline_sender", {
|
|
|
|
description = "Scriptblock: Digiline Sender",
|
|
|
|
tiles = {"rmod_scriptblock_digiline_sender.png"},
|
|
|
|
groups = {oddly_breakable_by_hand = 1},
|
|
|
|
use_texture_alpha = true,
|
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("formspec", [[
|
|
|
|
field[channel;Digiline channel;${channel}]
|
|
|
|
]])
|
|
|
|
end,
|
|
|
|
on_receive_fields = function(pos, formname, fields, sender)
|
|
|
|
local name = sender:get_player_name()
|
|
|
|
if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, {protection_bypass=true}) then
|
|
|
|
minetest.record_protection_violation(pos, name)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if (fields.channel) then
|
|
|
|
minetest.get_meta(pos):set_string("channel", fields.channel)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
scriptblock = function (pos, node, sender, info, last, main_channel)
|
2017-08-07 17:37:16 +02:00
|
|
|
if not digiline then return end
|
2017-08-07 05:58:13 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local channel = meta:get_string("channel")
|
|
|
|
|
|
|
|
digiline:receptor_send(pos, digiline.rules.default, channel, info)
|
2017-08-07 17:37:16 +02:00
|
|
|
return
|
2017-08-07 05:58:13 +02:00
|
|
|
end,
|
|
|
|
digiline = {
|
|
|
|
receptor = {},
|
2017-08-07 22:17:55 +02:00
|
|
|
effector = {action = function (pos, node, msgchannel, msg)
|
|
|
|
end,}
|
2017-08-07 05:58:13 +02:00
|
|
|
}
|
|
|
|
})
|