commit | author | age
|
d9bf98
|
1 |
--load config |
4b1798
|
2 |
local sepchar = nil |
d9bf98
|
3 |
do |
E |
4 |
local sepcode = technic.config:get("thousand_separator") |
|
5 |
--default is SI style |
|
6 |
sepchar = sepcode and string.char(sepcode) or " " |
|
7 |
baresepchar = sepchar |
|
8 |
--handling if sepchar is magic... |
|
9 |
for magic in string.gmatch("().%+-*?[^$", ".") do |
|
10 |
if sepchar == magic then sepchar = "%"..sepchar end |
|
11 |
end |
|
12 |
end |
|
13 |
|
f3d8b4
|
14 |
-- Only changes name, keeps other params |
S |
15 |
function technic.swap_node(pos, name) |
|
16 |
local node = minetest.get_node(pos) |
|
17 |
if node.name ~= name then |
|
18 |
node.name = name |
|
19 |
minetest.swap_node(pos, node) |
|
20 |
end |
|
21 |
return node.name |
|
22 |
end |
|
23 |
|
00d7c9
|
24 |
-- Fully charge RE chargeable item. |
Z |
25 |
-- Must be defined early to reference in item definitions. |
|
26 |
function technic.refill_RE_charge(stack) |
|
27 |
local max_charge = technic.power_tools[stack:get_name()] |
|
28 |
if not max_charge then return stack end |
|
29 |
technic.set_RE_wear(stack, max_charge, max_charge) |
|
30 |
local meta = minetest.deserialize(stack:get_metadata()) or {} |
|
31 |
meta.charge = max_charge |
|
32 |
stack:set_metadata(minetest.serialize(meta)) |
|
33 |
return stack |
|
34 |
end |
0e6b3c
|
35 |
|
R |
36 |
local function resolve_name(function_name) |
|
37 |
local a = _G |
|
38 |
for key in string.gmatch(function_name, "([^%.]+)(%.?)") do |
|
39 |
if a[key] then |
|
40 |
a = a[key] |
|
41 |
else |
|
42 |
return nil |
|
43 |
end |
|
44 |
end |
|
45 |
return a |
|
46 |
end |
|
47 |
|
|
48 |
function technic.function_exists(function_name) |
|
49 |
return type(resolve_name(function_name)) == 'function' |
|
50 |
end |
7d5edc
|
51 |
|
c38da0
|
52 |
-- if the node is loaded, returns it. If it isn't loaded, load it and return nil. |
E |
53 |
function technic.get_or_load_node(pos) |
|
54 |
local node_or_nil = minetest.get_node_or_nil(pos) |
|
55 |
if node_or_nil then return node_or_nil end |
|
56 |
local vm = VoxelManip() |
|
57 |
local MinEdge, MaxEdge = vm:read_from_map(pos, pos) |
|
58 |
return nil |
|
59 |
end |
d9bf98
|
60 |
|
4b1798
|
61 |
function technic.prettynum(num) |
E |
62 |
local str, k = tostring(num), nil |
|
63 |
repeat |
|
64 |
str, k = str:gsub("^(-?%d+)(%d%d%d)", "%1"..sepchar.."%2") |
|
65 |
until k == 0 |
|
66 |
return str |
d9bf98
|
67 |
end |