commit | author | age
|
ee5c6c
|
1 |
-- LV Battery box and some other nodes... |
3bc6ca
|
2 |
technic.register_power_tool("technic:battery",10000) |
R |
3 |
technic.register_power_tool("technic:red_energy_crystal",100000) |
|
4 |
technic.register_power_tool("technic:green_energy_crystal",250000) |
|
5 |
technic.register_power_tool("technic:blue_energy_crystal",500000) |
82cba9
|
6 |
|
R |
7 |
minetest.register_craft({ |
19c9a0
|
8 |
output = 'technic:battery 1', |
S |
9 |
recipe = { |
|
10 |
{'default:wood', 'default:copper_ingot', 'default:wood'}, |
|
11 |
{'default:wood', 'moreores:tin_ingot', 'default:wood'}, |
|
12 |
{'default:wood', 'default:copper_ingot', 'default:wood'}, |
|
13 |
} |
|
14 |
}) |
82cba9
|
15 |
|
19c9a0
|
16 |
minetest.register_tool("technic:battery", { |
S |
17 |
description = "RE Battery", |
|
18 |
inventory_image = "technic_battery.png", |
|
19 |
tool_capabilities = { |
|
20 |
load=0, |
|
21 |
max_drop_level=0, |
|
22 |
groupcaps={ |
|
23 |
fleshy={times={}, uses=10000, maxlevel=0} |
|
24 |
} |
|
25 |
} |
|
26 |
}) |
82cba9
|
27 |
|
ee5c6c
|
28 |
-------------------------------------------- |
K |
29 |
-- The Battery box |
|
30 |
-------------------------------------------- |
82cba9
|
31 |
minetest.register_craftitem("technic:battery_box", { |
19c9a0
|
32 |
description = "Battery box", |
S |
33 |
stack_max = 99, |
|
34 |
}) |
82cba9
|
35 |
|
19c9a0
|
36 |
minetest.register_craft({ |
S |
37 |
output = 'technic:battery_box 1', |
|
38 |
recipe = { |
|
39 |
{'technic:battery', 'default:wood', 'technic:battery'}, |
|
40 |
{'technic:battery', 'default:copper_ingot', 'technic:battery'}, |
|
41 |
{'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'}, |
|
42 |
} |
|
43 |
}) |
82cba9
|
44 |
|
ee5c6c
|
45 |
local battery_box_formspec = |
3a3700
|
46 |
"invsize[8,9;]".. |
R |
47 |
"image[1,1;1,2;technic_power_meter_bg.png]".. |
|
48 |
"list[current_name;src;3,1;1,1;]".. |
|
49 |
"list[current_name;dst;5,1;1,1;]".. |
3bc6ca
|
50 |
"label[0,0;LV Battery Box]".. |
3a3700
|
51 |
"label[3,0;Charge]".. |
R |
52 |
"label[5,0;Discharge]".. |
|
53 |
"label[1,3;Power level]".. |
922d25
|
54 |
"list[current_player;main;0,5;8,4;]".. |
R |
55 |
"background[-0.19,-0.25;8.4,9.75;ui_form_bg.png]".. |
|
56 |
"background[0,0;8,4;ui_lv_battery_box.png]".. |
|
57 |
"background[0,5;8,4;ui_main_inventory.png]" |
82cba9
|
58 |
|
19c9a0
|
59 |
minetest.register_node("technic:battery_box", { |
S |
60 |
description = "LV Battery Box", |
|
61 |
tiles = {"technic_battery_box_top.png", "technic_battery_box_bottom.png", |
|
62 |
"technic_battery_box_side0.png", "technic_battery_box_side0.png", |
|
63 |
"technic_battery_box_side0.png", "technic_battery_box_side0.png"}, |
|
64 |
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, |
|
65 |
sounds = default.node_sound_wood_defaults(), |
|
66 |
drop="technic:battery_box", |
|
67 |
on_construct = function(pos) |
|
68 |
local meta = minetest.env:get_meta(pos) |
|
69 |
local inv = meta:get_inventory() |
|
70 |
meta:set_string("infotext", "Battery box") |
|
71 |
meta:set_float("technic_power_machine", 1) |
|
72 |
meta:set_string("formspec", battery_box_formspec) |
|
73 |
meta:set_int("LV_EU_demand", 0) -- How much can this node charge |
|
74 |
meta:set_int("LV_EU_supply", 0) -- How much can this node discharge |
|
75 |
meta:set_int("LV_EU_input", 0) -- How much power is this machine getting. |
|
76 |
meta:set_float("internal_EU_charge", 0) |
|
77 |
inv:set_size("src", 1) |
|
78 |
inv:set_size("dst", 1) |
|
79 |
end, |
|
80 |
can_dig = function(pos,player) |
|
81 |
local meta = minetest.env:get_meta(pos); |
|
82 |
local inv = meta:get_inventory() |
|
83 |
if not inv:is_empty("src") or not inv:is_empty("dst") then |
|
84 |
minetest.chat_send_player(player:get_player_name(), |
|
85 |
"Machine cannot be removed because it is not empty"); |
|
86 |
return false |
|
87 |
else |
8e03d7
|
88 |
return true |
19c9a0
|
89 |
end |
S |
90 |
end, |
|
91 |
}) |
82cba9
|
92 |
|
R |
93 |
|
|
94 |
for i=1,8,1 do |
8e03d7
|
95 |
minetest.register_node( |
R |
96 |
"technic:battery_box"..i, { |
|
97 |
description = "LV Battery Box", |
19c9a0
|
98 |
tiles = {"technic_battery_box_top.png", "technic_battery_box_bottom.png", |
S |
99 |
"technic_battery_box_side0.png^technic_power_meter"..i..".png", |
|
100 |
"technic_battery_box_side0.png^technic_power_meter"..i..".png", |
|
101 |
"technic_battery_box_side0.png^technic_power_meter"..i..".png", |
|
102 |
"technic_battery_box_side0.png^technic_power_meter"..i..".png"}, |
8e03d7
|
103 |
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, |
R |
104 |
sounds = default.node_sound_wood_defaults(), |
|
105 |
drop="technic:battery_box", |
|
106 |
can_dig = function(pos,player) |
ee5c6c
|
107 |
local meta = minetest.env:get_meta(pos); |
K |
108 |
local inv = meta:get_inventory() |
|
109 |
if not inv:is_empty("src") or not inv:is_empty("dst") then |
|
110 |
minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty"); |
|
111 |
return false |
|
112 |
else |
|
113 |
return true |
|
114 |
end |
|
115 |
end, |
8e03d7
|
116 |
}) |
82cba9
|
117 |
end |
R |
118 |
|
8e03d7
|
119 |
minetest.register_abm( |
R |
120 |
{nodenames = {"technic:battery_box","technic:battery_box1","technic:battery_box2","technic:battery_box3","technic:battery_box4", |
|
121 |
"technic:battery_box5","technic:battery_box6","technic:battery_box7","technic:battery_box8"}, |
|
122 |
interval = 1, |
|
123 |
chance = 1, |
|
124 |
action = function(pos, node, active_object_count, active_object_count_wider) |
ee5c6c
|
125 |
local meta = minetest.env:get_meta(pos) |
K |
126 |
local max_charge = 60000 -- Set maximum charge for the device here |
|
127 |
local max_charge_rate = 1000 -- Set maximum rate of charging |
|
128 |
local max_discharge_rate = 2000 -- Set maximum rate of discharging |
|
129 |
local eu_input = meta:get_int("LV_EU_input") |
|
130 |
local current_charge = meta:get_int("internal_EU_charge") -- Battery charge right now |
|
131 |
|
|
132 |
-- Power off automatically if no longer connected to a switching station |
|
133 |
technic.switching_station_timeout_count(pos, "LV") |
|
134 |
|
|
135 |
-- Charge/discharge the battery with the input EUs |
|
136 |
if eu_input >=0 then |
|
137 |
current_charge = math.min(current_charge+eu_input, max_charge) |
|
138 |
else |
|
139 |
current_charge = math.max(current_charge+eu_input, 0) |
|
140 |
end |
|
141 |
|
|
142 |
-- Charging/discharging tools here |
3bc6ca
|
143 |
current_charge = charge_tools(meta, current_charge, 1000) |
R |
144 |
current_charge = discharge_tools(meta, current_charge, max_charge, 1000) |
ee5c6c
|
145 |
|
K |
146 |
-- Set a demand (we allow batteries to charge on less than the demand though) |
|
147 |
meta:set_int("LV_EU_demand", math.min(max_charge_rate, max_charge-current_charge)) |
|
148 |
--print("BA:"..max_charge_rate.."|"..max_charge-current_charge.."|"..math.min(max_charge_rate, max_charge-current_charge)) |
|
149 |
|
|
150 |
-- Set how much we can supply |
|
151 |
meta:set_int("LV_EU_supply", math.min(max_discharge_rate, current_charge)) |
|
152 |
|
|
153 |
meta:set_int("internal_EU_charge", current_charge) |
|
154 |
--dprint("BA: input:"..eu_input.." supply="..meta:get_int("LV_EU_supply").." demand="..meta:get_int("LV_EU_demand").." current:"..current_charge) |
82cba9
|
155 |
|
8e03d7
|
156 |
-- Select node textures |
ee5c6c
|
157 |
local i=math.ceil((current_charge/max_charge)*8) |
8e03d7
|
158 |
if i > 8 then i = 8 end |
R |
159 |
local j = meta:get_float("last_side_shown") |
|
160 |
if i~=j then |
|
161 |
if i>0 then hacky_swap_node(pos,"technic:battery_box"..i) |
|
162 |
elseif i==0 then hacky_swap_node(pos,"technic:battery_box") end |
|
163 |
meta:set_float("last_side_shown",i) |
82cba9
|
164 |
end |
R |
165 |
|
ee5c6c
|
166 |
local load = math.floor(current_charge/max_charge * 100) |
8e03d7
|
167 |
meta:set_string("formspec", |
e23f87
|
168 |
battery_box_formspec.. |
8e03d7
|
169 |
"image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. |
R |
170 |
(load)..":technic_power_meter_fg.png]" |
|
171 |
) |
e23f87
|
172 |
|
ee5c6c
|
173 |
if eu_input == 0 then |
K |
174 |
meta:set_string("infotext", "LV Battery box: "..current_charge.."/"..max_charge.." (idle)") |
|
175 |
else |
|
176 |
meta:set_string("infotext", "LV Battery box: "..current_charge.."/"..max_charge) |
8e03d7
|
177 |
end |
82cba9
|
178 |
|
8e03d7
|
179 |
end |
R |
180 |
}) |
82cba9
|
181 |
|
8e03d7
|
182 |
-- Register as a battery type |
R |
183 |
-- Battery type machines function as power reservoirs and can both receive and give back power |
ee5c6c
|
184 |
technic.register_LV_machine("technic:battery_box","BA") |
8e03d7
|
185 |
for i=1,8,1 do |
ee5c6c
|
186 |
technic.register_LV_machine("technic:battery_box"..i,"BA") |
82cba9
|
187 |
end |
R |
188 |
|