commit | author | age
|
ee0765
|
1 |
-- This file includes the functions and data structures for registering machines and tools for LV, MV, HV types. |
S |
2 |
-- We use the technic namespace for these functions and data to avoid eventual conflict. |
|
3 |
|
|
4 |
technic.receiver = "RE" |
|
5 |
technic.producer = "PR" |
623fca
|
6 |
technic.producer_receiver = "PR_RE" |
ee0765
|
7 |
technic.battery = "BA" |
S |
8 |
|
|
9 |
technic.machines = {} |
|
10 |
technic.power_tools = {} |
f4ac2b
|
11 |
technic.networks = {} |
N |
12 |
|
ee0765
|
13 |
|
S |
14 |
function technic.register_tier(tier, description) |
6b8007
|
15 |
technic.machines[tier] = {} |
ee0765
|
16 |
end |
S |
17 |
|
|
18 |
function technic.register_machine(tier, nodename, machine_type) |
|
19 |
if not technic.machines[tier] then |
|
20 |
return |
|
21 |
end |
|
22 |
technic.machines[tier][nodename] = machine_type |
|
23 |
end |
|
24 |
|
|
25 |
function technic.register_power_tool(craftitem, max_charge) |
|
26 |
technic.power_tools[craftitem] = max_charge |
|
27 |
end |
|
28 |
|
|
29 |
|
|
30 |
-- Utility functions. Not sure exactly what they do.. water.lua uses the two first. |
|
31 |
function technic.get_RE_item_load(load1, max_load) |
|
32 |
if load1 == 0 then load1 = 65535 end |
|
33 |
local temp = 65536 - load1 |
|
34 |
temp = temp / 65535 * max_load |
|
35 |
return math.floor(temp + 0.5) |
|
36 |
end |
|
37 |
|
|
38 |
function technic.set_RE_item_load(load1, max_load) |
|
39 |
if load1 == 0 then return 65535 end |
|
40 |
local temp = load1 / max_load * 65535 |
|
41 |
temp = 65536 - temp |
|
42 |
return math.floor(temp) |
|
43 |
end |
|
44 |
|
|
45 |
-- Wear down a tool depending on the remaining charge. |
eac484
|
46 |
function technic.set_RE_wear(itemstack, item_load, max_load) |
99fd5d
|
47 |
if (minetest.registered_items[itemstack:get_name()].wear_represents or "mechanical_wear") ~= "technic_RE_charge" then return itemstack end |
db2025
|
48 |
local temp |
Z |
49 |
if item_load == 0 then |
|
50 |
temp = 0 |
|
51 |
else |
|
52 |
temp = 65536 - math.floor(item_load / max_load * 65535) |
|
53 |
if temp > 65535 then temp = 65535 end |
|
54 |
if temp < 1 then temp = 1 end |
|
55 |
end |
eac484
|
56 |
itemstack:set_wear(temp) |
S |
57 |
return itemstack |
ee0765
|
58 |
end |