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