Rogier
2015-03-11 4874e290256c195d2abebf406797aaa2bf42582a
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)
15     technic.machines[tier]    = {}
16     technic.cables[tier]      = {}
17 end
18
19 function technic.register_machine(tier, nodename, machine_type)
20     if not technic.machines[tier] then
21         return
22     end
23     technic.machines[tier][nodename] = machine_type
24 end
25
26 function technic.register_power_tool(craftitem, max_charge)
27     technic.power_tools[craftitem] = max_charge
28 end
29
30
31 -- Utility functions. Not sure exactly what they do.. water.lua uses the two first.
32 function technic.get_RE_item_load(load1, max_load)
33     if load1 == 0 then load1 = 65535 end
34     local temp = 65536 - load1
35     temp = temp / 65535 * max_load
36     return math.floor(temp + 0.5)
37 end
38
39 function technic.set_RE_item_load(load1, max_load)
40     if load1 == 0 then return 65535 end
41     local temp = load1 / max_load * 65535
42     temp = 65536 - temp
43     return math.floor(temp)
44 end
45
46 -- Wear down a tool depending on the remaining charge.
eac484 47 function technic.set_RE_wear(itemstack, item_load, max_load)
99fd5d 48     if (minetest.registered_items[itemstack:get_name()].wear_represents or "mechanical_wear") ~= "technic_RE_charge" then return itemstack end
db2025 49     local temp
Z 50     if item_load == 0 then
51         temp = 0
52     else
53         temp = 65536 - math.floor(item_load / max_load * 65535)
54         if temp > 65535 then temp = 65535 end
55         if temp < 1 then temp = 1 end
56     end
eac484 57     itemstack:set_wear(temp)
S 58     return itemstack
ee0765 59 end