commit | author | age
|
f3d8b4
|
1 |
minetest.swap_node = minetest.swap_node or function(pos, node) |
S |
2 |
local oldmeta = minetest.get_meta(pos):to_table() |
|
3 |
minetest.set_node(pos, node) |
|
4 |
minetest.get_meta(pos):from_table(oldmeta) |
|
5 |
end |
|
6 |
|
|
7 |
-- Only changes name, keeps other params |
|
8 |
function technic.swap_node(pos, name) |
|
9 |
local node = minetest.get_node(pos) |
|
10 |
if node.name ~= name then |
|
11 |
node.name = name |
|
12 |
minetest.swap_node(pos, node) |
|
13 |
end |
|
14 |
return node.name |
|
15 |
end |
|
16 |
|
00d7c9
|
17 |
-- Fully charge RE chargeable item. |
Z |
18 |
-- Must be defined early to reference in item definitions. |
|
19 |
function technic.refill_RE_charge(stack) |
|
20 |
local max_charge = technic.power_tools[stack:get_name()] |
|
21 |
if not max_charge then return stack end |
|
22 |
technic.set_RE_wear(stack, max_charge, max_charge) |
|
23 |
local meta = minetest.deserialize(stack:get_metadata()) or {} |
|
24 |
meta.charge = max_charge |
|
25 |
stack:set_metadata(minetest.serialize(meta)) |
|
26 |
return stack |
|
27 |
end |
0e6b3c
|
28 |
|
R |
29 |
-------------------------------------------------------------------------------- |
|
30 |
local function resolve_name(function_name) |
|
31 |
local a = _G |
|
32 |
for key in string.gmatch(function_name, "([^%.]+)(%.?)") do |
|
33 |
if a[key] then |
|
34 |
a = a[key] |
|
35 |
else |
|
36 |
return nil |
|
37 |
end |
|
38 |
end |
|
39 |
return a |
|
40 |
end |
|
41 |
|
|
42 |
function technic.function_exists(function_name) |
|
43 |
return type(resolve_name(function_name)) == 'function' |
|
44 |
end |
|
45 |
-------------------------------------------------------------------------------- |