commit | author | age
|
ee0765
|
1 |
-- The electric generator. |
S |
2 |
-- A simple device to get started on the electric machines. |
|
3 |
-- Inefficient and expensive in fuel (200EU per tick) |
|
4 |
-- Also only allows for LV machinery to run. |
|
5 |
|
|
6 |
minetest.register_alias("generator", "technic:generator") |
|
7 |
minetest.register_alias("generator", "technic:generator_active") |
|
8 |
|
|
9 |
minetest.register_craft({ |
|
10 |
output = 'technic:generator', |
|
11 |
recipe = { |
|
12 |
{'default:stone', 'default:stone', 'default:stone'}, |
|
13 |
{'default:stone', '', 'default:stone'}, |
|
14 |
{'default:stone', 'default:copper_ingot', 'default:stone'}, |
|
15 |
} |
|
16 |
}) |
|
17 |
|
|
18 |
local generator_formspec = |
|
19 |
"invsize[8,9;]".. |
|
20 |
"label[0,0;Generator]".. |
|
21 |
"list[current_name;src;3,1;1,1;]".. |
|
22 |
"image[4,1;1,1;default_furnace_fire_bg.png]".. |
|
23 |
"list[current_player;main;0,5;8,4;]" |
|
24 |
|
|
25 |
|
|
26 |
minetest.register_node("technic:generator", { |
|
27 |
description = "Electric Generator", |
|
28 |
tiles = {"technic_generator_top.png", "technic_machine_bottom.png", "technic_generator_side.png", |
|
29 |
"technic_generator_side.png", "technic_generator_side.png", "technic_generator_front.png"}, |
|
30 |
paramtype2 = "facedir", |
|
31 |
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2}, |
|
32 |
legacy_facedir_simple = true, |
|
33 |
sounds = default.node_sound_wood_defaults(), |
|
34 |
on_construct = function(pos) |
|
35 |
local meta = minetest.get_meta(pos) |
|
36 |
meta:set_string("infotext", "Electric Generator") |
|
37 |
meta:set_int("LV_EU_supply", 0) |
|
38 |
-- Signal to the switching station that this device burns some |
|
39 |
-- sort of fuel and needs special handling |
|
40 |
meta:set_int("LV_EU_from_fuel", 1) |
|
41 |
meta:set_int("burn_time", 0) |
|
42 |
meta:set_string("formspec", generator_formspec) |
|
43 |
local inv = meta:get_inventory() |
|
44 |
inv:set_size("src", 1) |
|
45 |
end, |
|
46 |
can_dig = function(pos,player) |
|
47 |
local meta = minetest.get_meta(pos); |
|
48 |
local inv = meta:get_inventory() |
|
49 |
if not inv:is_empty("src") then |
|
50 |
minetest.chat_send_player(player:get_player_name(), |
|
51 |
"Machine cannot be removed because it is not empty"); |
|
52 |
return false |
|
53 |
else |
|
54 |
return true |
|
55 |
end |
|
56 |
end, |
|
57 |
}) |
|
58 |
|
|
59 |
minetest.register_node("technic:generator_active", { |
|
60 |
description = "Electric Generator", |
|
61 |
tiles = {"technic_generator_top.png", "technic_machine_bottom.png", |
|
62 |
"technic_generator_side.png", "technic_generator_side.png", |
|
63 |
"technic_generator_side.png", "technic_generator_front_active.png"}, |
|
64 |
paramtype2 = "facedir", |
|
65 |
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, |
|
66 |
not_in_creative_inventory=1}, |
|
67 |
legacy_facedir_simple = true, |
|
68 |
sounds = default.node_sound_wood_defaults(), |
|
69 |
drop = "technic:generator", |
|
70 |
can_dig = function(pos,player) |
|
71 |
local meta = minetest.get_meta(pos); |
|
72 |
local inv = meta:get_inventory() |
|
73 |
if not inv:is_empty("src") then |
|
74 |
minetest.chat_send_player(player:get_player_name(), |
|
75 |
"Machine cannot be removed because it is not empty"); |
|
76 |
return false |
|
77 |
else |
|
78 |
return true |
|
79 |
end |
|
80 |
end, |
|
81 |
}) |
|
82 |
|
|
83 |
minetest.register_abm({ |
|
84 |
nodenames = {"technic:generator", "technic:generator_active"}, |
|
85 |
interval = 1, |
|
86 |
chance = 1, |
|
87 |
action = function(pos, node, active_object_count, active_object_count_wider) |
|
88 |
local meta = minetest.get_meta(pos) |
|
89 |
local burn_time = meta:get_int("burn_time") |
|
90 |
local burn_totaltime = meta:get_int("burn_totaltime") |
|
91 |
|
|
92 |
-- If more to burn and the energy produced was used: produce some more |
|
93 |
if burn_time > 0 then |
|
94 |
meta:set_int("LV_EU_supply", 200) -- Give 200EUs |
|
95 |
burn_time = burn_time - 1 |
|
96 |
meta:set_int("burn_time", burn_time) |
|
97 |
end |
|
98 |
|
|
99 |
-- Burn another piece of fuel |
|
100 |
if burn_time == 0 then |
|
101 |
local inv = meta:get_inventory() |
|
102 |
if not inv:is_empty("src") then |
|
103 |
local fuellist = inv:get_list("src") |
|
104 |
fuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist}) |
|
105 |
if not fuel or fuel.time == 0 then |
|
106 |
meta:set_string("infotext", "Generator out of fuel") |
|
107 |
hacky_swap_node(pos, "technic:generator") |
|
108 |
return |
|
109 |
end |
|
110 |
meta:set_int("burn_time", fuel.time) |
|
111 |
meta:set_int("burn_totaltime", fuel.time) |
|
112 |
|
|
113 |
|
|
114 |
local stack = inv:get_stack("src", 1) |
|
115 |
stack:take_item() |
|
116 |
inv:set_stack("src", 1, stack) |
|
117 |
hacky_swap_node(pos, "technic:generator_active") |
|
118 |
meta:set_int("LV_EU_supply", 200) -- Give 200EUs |
|
119 |
else |
|
120 |
hacky_swap_node(pos, "technic:generator") |
|
121 |
meta:set_int("LV_EU_supply", 0) |
|
122 |
end |
|
123 |
end |
|
124 |
|
|
125 |
local percent = math.floor((burn_time / burn_totaltime) * 100) |
|
126 |
meta:set_string("infotext", "Electric Generator ("..percent.."%)") |
|
127 |
meta:set_string("formspec", |
|
128 |
"size[8,9]".. |
|
129 |
"label[0,0;Generator]".. |
|
130 |
"list[current_name;src;3,1;1,1;]".. |
|
131 |
"image[4,1;1,1;default_furnace_fire_bg.png^[lowpart:".. |
|
132 |
(percent)..":default_furnace_fire_fg.png]".. |
|
133 |
"list[current_player;main;0,5;8,4;]") |
|
134 |
end |
|
135 |
}) |
|
136 |
|
|
137 |
technic.register_machine("LV", "technic:generator", technic.producer) |
|
138 |
technic.register_machine("LV", "technic:generator_active", technic.producer) |
|
139 |
|