A little refactoring...
This commit is contained in:
parent
0c293f58e9
commit
3bb18e195e
@ -30,6 +30,7 @@ include("util_node_is")
|
||||
include("util_toolcaps")
|
||||
include("util_stack")
|
||||
include("util_phealth")
|
||||
include("util_facedir")
|
||||
include("match")
|
||||
|
||||
include("fx_digparticles")
|
||||
|
57
mods/nc_api/util_facedir.lua
Normal file
57
mods/nc_api/util_facedir.lua
Normal file
@ -0,0 +1,57 @@
|
||||
-- LUALOCALS < ---------------------------------------------------------
|
||||
local ipairs, nodecore, pairs, vector
|
||||
= ipairs, nodecore, pairs, vector
|
||||
-- LUALOCALS > ---------------------------------------------------------
|
||||
|
||||
local alldirs = {}
|
||||
for k, v in pairs(nodecore.dirs()) do
|
||||
alldirs[v.n] = v
|
||||
end
|
||||
|
||||
local facedirs = {
|
||||
{"u", "w"},
|
||||
{"u", "n"},
|
||||
{"u", "e"},
|
||||
{"n", "u"},
|
||||
{"n", "w"},
|
||||
{"n", "d"},
|
||||
{"n", "e"},
|
||||
{"s", "d"},
|
||||
{"s", "w"},
|
||||
{"s", "u"},
|
||||
{"s", "e"},
|
||||
{"e", "s"},
|
||||
{"e", "u"},
|
||||
{"e", "n"},
|
||||
{"e", "d"},
|
||||
{"w", "s"},
|
||||
{"w", "d"},
|
||||
{"w", "n"},
|
||||
{"w", "u"},
|
||||
{"d", "s"},
|
||||
{"d", "e"},
|
||||
{"d", "n"},
|
||||
{"d", "w"},
|
||||
[0] = {"u", "s"}
|
||||
}
|
||||
|
||||
local function cross(a, b)
|
||||
return {
|
||||
x = a.y * b.z - a.z * b.y,
|
||||
y = a.z * b.x - a.x * b.z,
|
||||
z = a.x * b.y - a.y * b.x
|
||||
}
|
||||
end
|
||||
|
||||
for _, t in ipairs(facedirs) do
|
||||
t.t = alldirs[t[1]]
|
||||
t.f = alldirs[t[2]]
|
||||
t[2] = nil
|
||||
t[1] = nil
|
||||
t.l = cross(t.t, t.f)
|
||||
t.r = vector.multiply(t.l, -1)
|
||||
t.b = vector.multiply(t.t, -1)
|
||||
t.k = vector.multiply(t.f, -1)
|
||||
end
|
||||
|
||||
nodecore.facedirs = facedirs
|
@ -203,3 +203,11 @@ function nodecore.quenched(pos)
|
||||
{x = pos.x + 1, y = pos.y + 1, z = pos.z + 1},
|
||||
{"group:coolant"}) > 0
|
||||
end
|
||||
|
||||
function nodecore.node_spin(pos, node, clicker, itemstack, pointed_thing)
|
||||
node = node or minetest.get_node(pos)
|
||||
node.param2 = node.param2 + 1
|
||||
if node.param2 >= 24 then node.param2 = node.param2 - 24 end
|
||||
minetest.swap_node(pos, node)
|
||||
return itemstack
|
||||
end
|
||||
|
@ -1,73 +1,35 @@
|
||||
-- LUALOCALS < ---------------------------------------------------------
|
||||
local ipairs, minetest, nodecore, pairs, vector
|
||||
= ipairs, minetest, nodecore, pairs, vector
|
||||
local minetest, nodecore, pairs, vector
|
||||
= minetest, nodecore, pairs, vector
|
||||
-- LUALOCALS > ---------------------------------------------------------
|
||||
|
||||
local alldirs = {
|
||||
e = {x = 1, y = 0, z = 0},
|
||||
w = {x = -1, y = 0, z = 0},
|
||||
u = {x = 0, y = 1, z = 0},
|
||||
d = {x = 0, y = -1, z = 0},
|
||||
n = {x = 0, y = 0, z = 1},
|
||||
s = {x = 0, y = 0, z = -1}
|
||||
}
|
||||
|
||||
local facedirs = {
|
||||
{"u", "w"},
|
||||
{"u", "n"},
|
||||
{"u", "e"},
|
||||
{"n", "u"},
|
||||
{"n", "w"},
|
||||
{"n", "d"},
|
||||
{"n", "e"},
|
||||
{"s", "d"},
|
||||
{"s", "w"},
|
||||
{"s", "u"},
|
||||
{"s", "e"},
|
||||
{"e", "s"},
|
||||
{"e", "u"},
|
||||
{"e", "n"},
|
||||
{"e", "d"},
|
||||
{"w", "s"},
|
||||
{"w", "d"},
|
||||
{"w", "n"},
|
||||
{"w", "u"},
|
||||
{"d", "s"},
|
||||
{"d", "e"},
|
||||
{"d", "n"},
|
||||
{"d", "w"},
|
||||
[0] = {"u", "s"}
|
||||
}
|
||||
|
||||
local function cross(a, b)
|
||||
return {
|
||||
x = a.y * b.z - a.z * b.y,
|
||||
y = a.z * b.x - a.x * b.z,
|
||||
z = a.x * b.y - a.y * b.x
|
||||
}
|
||||
end
|
||||
|
||||
for _, t in ipairs(facedirs) do
|
||||
t.t = alldirs[t[1]]
|
||||
t.f = alldirs[t[2]]
|
||||
t[2] = nil
|
||||
t[1] = nil
|
||||
t.l = cross(t.t, t.f)
|
||||
t.r = vector.multiply(t.l, -1)
|
||||
t.b = vector.multiply(t.t, -1)
|
||||
t.k = vector.multiply(t.f, -1)
|
||||
end
|
||||
|
||||
function nodecore.node_spin(pos, node, clicker, itemstack, pointed_thing)
|
||||
node = node or minetest.get_node(pos)
|
||||
node.param2 = node.param2 + 1
|
||||
if node.param2 >= 24 then node.param2 = node.param2 - 24 end
|
||||
minetest.swap_node(pos, node)
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local optic_queue = {}
|
||||
|
||||
local function scan(pos, dir)
|
||||
local p = {x = pos.x, y = pos.y, z = pos.z}
|
||||
for i = 1, 16 do
|
||||
p = vector.add(p, dir)
|
||||
local node = minetest.get_node(p)
|
||||
if p.name == "ignore" then return end
|
||||
if p.name ~= "air" then return p, node end
|
||||
end
|
||||
end
|
||||
|
||||
local hash = minetest.hash_node_position
|
||||
local unhash = minetest.get_position_from_hash
|
||||
|
||||
function nodecore.optic_recv(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local data = meta:get_string("nc_optic")
|
||||
if (not data) or (data == "") then return {} end
|
||||
data = minetest.deserialize(data)
|
||||
for k, v in pairs(data) do
|
||||
local hit = scan(pos, minetest.
|
||||
end
|
||||
|
||||
function nodecore.optic_emit(pos, dir, switch)
|
||||
end
|
||||
|
||||
function nodecore.optic_check(pos)
|
||||
optic_queue[minetest.hash_node_position(pos)] = pos
|
||||
end
|
||||
@ -82,16 +44,6 @@ nodecore.register_limited_abm({
|
||||
action = nodecore.optic_check
|
||||
})
|
||||
|
||||
local function scan(pos, dir)
|
||||
local p = {x = pos.x, y = pos.y, z = pos.z}
|
||||
for i = 1, 16 do
|
||||
p = vector.add(p, dir)
|
||||
local node = minetest.get_node(p)
|
||||
if p.name == "ignore" then return end
|
||||
if p.name ~= "air" then return p, node end
|
||||
end
|
||||
end
|
||||
|
||||
function nodecore.optic_emit(pos, dir)
|
||||
local hit, node = scan(pos, dir)
|
||||
-- XXX: LEFT OFF HERE
|
||||
@ -101,7 +53,7 @@ local function optic_process(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
local def = minetest.registered_items[node.name] or {}
|
||||
if def and def.optic_check then return def.optic_check(pos, node, def) end
|
||||
for _, dir in pairs(alldirs) do
|
||||
for _, dir in pairs(nodecore.dirs()) do
|
||||
local p, node = scan(pos, dir)
|
||||
if node then
|
||||
local def = minetest.registered_items[node.name] or {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user