-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathelectric_composter.lua
More file actions
236 lines (209 loc) · 5.92 KB
/
electric_composter.lua
File metadata and controls
236 lines (209 loc) · 5.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
------------------------
-- Electric Composter --
------------------------
------- Ver 1.0 --------
-----------------------
-- Initial Functions --
-----------------------
local S = composting.translator;
composting.electric_composter = appliances.appliance:new(
{
node_name_inactive = "composting:electric_composter",
node_name_active = "composting:electric_composter_active",
node_description = S("Electric Composter"),
node_help = S("Accelerate composting process of biomaterial."),
usage_stack = 0,
have_usage = false,
sounds = {
running = {
sound = "composting_electric_composter_running",
sound_param = {max_hear_distance = 16, gain = 1},
repeat_timer = 4,
},
},
})
local electric_composter = composting.electric_composter
electric_composter:item_data_register(
{
["tube_item"] = {
},
["techage_item"] = {
},
["minecart_item"] = {
},
})
electric_composter:power_data_register(
{
["no_power"] = {
disable = {}
},
["LV_power"] = {
demand = 100,
run_speed = 1,
disable = {"no_power"}
},
["power_generators_electric_power"] = {
demand = 100,
run_speed = 1,
disable = {"no_power"}
},
["elepower_power"] = {
demand = 8,
run_speed = 1,
disable = {"no_power"}
},
["techage_electric_power"] = {
demand = 40,
run_speed = 1,
disable = {"no_power"}
},
["factory_power"] = {
demand = 5,
run_speed = 1,
disable = {"no_power"}
},
})
electric_composter.node_help = S("Connect to power (@1).", electric_composter:get_power_help()).."\n"..electric_composter.node_help
--------------
-- Formspec --
--------------
---------------
-- Callbacks --
---------------
local compost_per_clod = composting.settings.clod_cost
local electric_composter_time = composting.settings.electric_composter_time
local function input_on_done(self, timer_step, output)
local compost = timer_step.meta:get_int("compost")
compost = compost + timer_step.use_input.amount
if compost>=compost_per_clod then
timer_step.meta:set_int("compost", compost-compost_per_clod)
return {"composting:compost_clod"}
end
timer_step.meta:set_int("compost", compost)
return {""}
end
function electric_composter:recipe_aviable_input(inventory)
local input_stack = inventory:get_stack(self.input_stack, 1)
local input_def = input_stack:get_definition()
if input_def._compost then
local input = {
inputs = 1,
outputs = {"composting:compost_clod"},
on_done = input_on_done,
production_time = input_def._compost.amount*electric_composter_time,
amount = input_def._compost.amount,
}
return input, nil
end
return nil, nil
end
function electric_composter:recipe_inventory_can_put(pos, listname, index, stack, player)
local input_def = stack:get_definition()
if input_def._compost then
return stack:get_count()
end
return 0
end
function electric_composter:recipe_inventory_can_take(pos, listname, index, stack, player_name)
if player_name then
if minetest.is_protected(pos, player_name) then
return 0
end
end
local count = stack:get_count();
local meta = minetest.get_meta(pos);
if (listname==self.input_stack) then
if count>0 then
local production_time = meta:get_int("production_time")
if (production_time>0) then
return count-1
end
end
end
return count
end
----------
-- Node --
----------
local node_sounds = nil
if minetest.get_modpath("default") then
node_sounds = default.node_sound_metal_defaults();
end
if minetest.get_modpath("hades_sounds") then
node_sounds = hades_sounds.node_sound_metal_defaults();
end
if minetest.get_modpath("sounds") then
node_sounds = sounds.node_metal();
end
-- node box {x=0, y=0, z=0}
local node_box = {
type = "fixed",
fixed = {
{-0.4375,-0.375,-0.4375,0.4375,0.25,0.4375},
{-0.4375,0.375,-0.4375,0.4375,0.5,0.4375},
{-0.375,-0.5,-0.375,0.375,-0.375,0.375},
{-0.375,0.25,-0.375,0.375,0.375,0.375},
{-0.5,-0.1875,-0.1875,-0.4375,0.1875,0.1875},
{0.4375,-0.1875,-0.1875,0.5,0.1875,0.1875},
{-0.0625,-0.0625,0.4375,0.0625,0.0625,0.5},
},
}
local node_def = {
paramtype = "light",
paramtype2 = "facedir",
groups = {cracky = 2},
legacy_facedir_simple = true,
is_ground_content = false,
sounds = node_sounds,
drawtype = "mesh",
mesh = "composting_electric_composter.obj",
use_texture_alpha = "blend",
collision_box = node_box,
selection_box = node_box,
}
local node_inactive = {
tiles = {
"composting_electric_composter_body.png",
"composting_electric_composter_body2.png",
"composting_electric_composter_power.png",
"composting_electric_composter_tube.png",
},
}
local node_active = {
tiles = {
{
image = "composting_electric_composter_body_active.png",
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 2
}
},
"composting_electric_composter_body2.png",
"composting_electric_composter_power.png",
"composting_electric_composter_tube.png",
},
}
electric_composter:register_nodes(node_def, node_inactive, node_active)
-------------------------
-- Recipe Registration --
-------------------------
--[[
appliances.register_craft_type("composting_electric_composter", {
description = S("Composting"),
icon = "composting_composting_craft_type_icon.png",
width = 1,
height = 1,
})
electric_composter:recipe_register_input(
"",
{
inputs = 1,
outputs = {"composting:compost_clod"},
consumption_time = 76,
consumption_step_size = 1,
});
electric_composter:register_recipes("composting_electric_composter", "composting_electric_composter_usage")
)
--]]