Merge remote-tracking branch 'upstream/master'

This commit is contained in:
bri cassa 2022-06-25 16:50:22 +02:00
commit 3dd0eb7e4f
10 changed files with 58 additions and 92 deletions

View File

@ -72,7 +72,28 @@ function mesecon.rotate_rules_up(rules)
end
return nr
end
--
-- Returns a rules getter function that returns different rules depending on the node's horizontal rotation.
-- If param2 % 4 == 0, then the rules returned by the getter are a copy of base_rules.
function mesecon.horiz_rules_getter(base_rules)
local rotations = {mesecon.tablecopy(base_rules)}
for i = 2, 4 do
local right_rules = rotations[i - 1]
if not right_rules[1] or right_rules[1].x then
-- flat rules
rotations[i] = mesecon.rotate_rules_left(right_rules)
else
-- not flat
rotations[i] = {}
for j, rules in ipairs(right_rules) do
rotations[i][j] = mesecon.rotate_rules_left(rules)
end
end
end
return function(node)
return rotations[node.param2 % 4 + 1]
end
end
function mesecon.flattenrules(allrules)
--[[

View File

@ -1,19 +1,7 @@
-- Function that get the input/output rules of the delayer
local delayer_get_output_rules = function(node)
local rules = {{x = 0, y = 0, z = 1}}
for i = 0, node.param2 do
rules = mesecon.rotate_rules_left(rules)
end
return rules
end
local delayer_get_output_rules = mesecon.horiz_rules_getter({{x = 1, y = 0, z = 0}})
local delayer_get_input_rules = function(node)
local rules = {{x = 0, y = 0, z = -1}}
for i = 0, node.param2 do
rules = mesecon.rotate_rules_left(rules)
end
return rules
end
local delayer_get_input_rules = mesecon.horiz_rules_getter({{x = -1, y = 0, z = 0}})
-- Functions that are called after the delay time

View File

@ -3,17 +3,10 @@ local corner_selectionbox = {
fixed = { -16/32, -16/32, -16/32, 5/32, -12/32, 5/32 },
}
local corner_get_rules = function (node)
local rules =
{{x = 1, y = 0, z = 0},
{x = 0, y = 0, z = -1}}
for i = 0, node.param2 do
rules = mesecon.rotate_rules_left(rules)
end
return rules
end
local corner_get_rules = mesecon.horiz_rules_getter({
{x = 0, y = 0, z = -1},
{x = -1, y = 0, z = 0},
})
minetest.register_node("mesecons_extrawires:corner_on", {
drawtype = "mesh",

View File

@ -3,7 +3,7 @@ local doublecorner_selectionbox = {
fixed = { -8/16, -8/16, -8/16, 8/16, -6/16, 8/16 },
}
local rules = {
local doublecorner_get_rules = mesecon.horiz_rules_getter({
{
{ x = 1, y = 0, z = 0 },
{ x = 0, y = 0, z = 1 },
@ -12,19 +12,7 @@ local rules = {
{ x = -1, y = 0, z = 0 },
{ x = 0, y = 0, z = -1 },
},
}
local doublecorner_rules = {}
for k = 1, 4 do
doublecorner_rules[k] = table.copy(rules)
for i, r in ipairs(rules) do
rules[i] = mesecon.rotate_rules_left(r)
end
end
local function doublecorner_get_rules(node)
return doublecorner_rules[node.param2 % 4 + 1]
end
})
local doublecorner_states = {
"mesecons_extrawires:doublecorner_00",

View File

@ -10,18 +10,11 @@ local tjunction_selectionbox = {
fixed = { -16/32, -16/32, -16/32, 16/32, -12/32, 7/32 },
}
local tjunction_get_rules = function (node)
local rules =
{{x = 0, y = 0, z = 1},
{x = 1, y = 0, z = 0},
{x = 0, y = 0, z = -1}}
for i = 0, node.param2 do
rules = mesecon.rotate_rules_left(rules)
end
return rules
end
local tjunction_get_rules = mesecon.horiz_rules_getter({
{x = 1, y = 0, z = 0},
{x = 0, y = 0, z = -1},
{x = -1, y = 0, z = 0},
})
minetest.register_node("mesecons_extrawires:tjunction_on", {
drawtype = "nodebox",

View File

@ -11,25 +11,14 @@ local nodebox = {
},
}
local function gate_rotate_rules(node, rules)
for rotations = 0, node.param2 - 1 do
rules = mesecon.rotate_rules_left(rules)
end
return rules
end
local gate_get_output_rules = mesecon.horiz_rules_getter({{x = 1, y = 0, z = 0}})
local function gate_get_output_rules(node)
return gate_rotate_rules(node, {{x=1, y=0, z=0}})
end
local gate_get_input_rules_oneinput = mesecon.horiz_rules_getter({{x =-1, y = 0, z = 0}})
local function gate_get_input_rules_oneinput(node)
return gate_rotate_rules(node, {{x=-1, y=0, z=0}})
end
local function gate_get_input_rules_twoinputs(node)
return gate_rotate_rules(node, {{x=0, y=0, z=1, name="input1"},
{x=0, y=0, z=-1, name="input2"}})
end
local gate_get_input_rules_twoinputs = mesecon.horiz_rules_getter({
{x = 0, y = 0, z = 1, name = "input1"},
{x = 0, y = 0, z = -1, name = "input2"},
})
local function set_gate(pos, node, state)
local gate = minetest.registered_nodes[node.name]

View File

@ -64,8 +64,8 @@ minetest.register_node("mesecons_hydroturbine:hydro_turbine_on", {
local function is_flowing_water(pos)
local name = minetest.get_node(pos).name
local is_water = minetest.get_item_group(name, "water") > 0
local is_flowing = minetest.registered_items[name].liquidtype == "flowing"
return (is_water and is_flowing)
local def = minetest.registered_items[name]
return is_water and (def and def.liquidtype == "flowing")
end
minetest.register_abm({

View File

@ -1,11 +1,7 @@
local function insulated_wire_get_rules(node)
local rules = {{x = 1, y = 0, z = 0},
{x =-1, y = 0, z = 0}}
if node.param2 == 1 or node.param2 == 3 then
return mesecon.rotate_rules_right(rules)
end
return rules
end
local insulated_wire_get_rules = mesecon.horiz_rules_getter({
{x = 1, y = 0, z = 0},
{x = -1, y = 0, z = 0},
})
minetest.register_node("mesecons_insulated:insulated_on", {
drawtype = "nodebox",

View File

@ -470,7 +470,12 @@ local safe_globals = {
local function create_environment(pos, mem, event, itbl, send_warning)
-- Gather variables for the environment
local vports = minetest.registered_nodes[minetest.get_node(pos).name].virtual_portstates
local node_def = minetest.registered_nodes[minetest.get_node(pos).name]
if not node_def then return end
local vports = node_def.virtual_portstates
if not vports then return end
local vports_copy = {}
for k, v in pairs(vports) do vports_copy[k] = v end
local rports = get_real_port_states(pos)
@ -627,6 +632,7 @@ local function run_inner(pos, code, event)
-- Create environment
local itbl = {}
local env = create_environment(pos, mem, event, itbl, send_warning)
if not env then return false, "Env does not exist. Controller has been moved?" end
local success, msg
-- Create the sandbox and execute code

View File

@ -25,18 +25,10 @@ local up_rcvboxes = {
{6/16, -8/16, 1/16, 8/16, -7/16, -1/16}, -- Plate extension (East)
}
local receiver_get_rules = function (node)
local rules = { {x = 1, y = 0, z = 0},
{x = -2, y = 0, z = 0}}
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
local receiver_get_rules = mesecon.horiz_rules_getter({
{x = 0, y = 0, z = 1},
{x = 0, y = 0, z = -2},
})
mesecon.register_node("mesecons_receiver:receiver", {
drawtype = "nodebox",