-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdna_cultivator.lua
282 lines (233 loc) · 9.93 KB
/
dna_cultivator.lua
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
--------------------
-- DNA Cultivator --
--------------------
------ Ver 2.0 -----
-----------------------
-- Initial Functions --
-----------------------
paleotest.dna_cultivator = {}
local dna_cultivator = paleotest.dna_cultivator
dna_cultivator.recipes = {}
function dna_cultivator.register_recipe(input, output)
dna_cultivator.recipes[input] = output
end
--------------
-- Formspec --
--------------
local dna_cultivator_fs = "formspec_version[3]" .. "size[12.75,8.5]" ..
"background[-1.25,-1.25;15,10;paleotest_machine_formspec.png]" ..
"image[5.6,0.5;1.5,1.5;paleotest_progress_bar.png^[transformR270]]" ..
"list[current_player;main;1.5,3;8,4;]" ..
"list[context;input;4,0.75;1,1;]" ..
"list[context;output;7.75,0.75;1,1;]" ..
"listring[current_player;main]" ..
"listring[context;input]" ..
"listring[current_player;main]" ..
"listring[context;output]" ..
"listring[current_player;main]"
local function get_active_dna_cultivator_fs(item_percent)
local form = {
"formspec_version[3]", "size[12.75,8.5]",
"background[-1.25,-1.25;15,10;paleotest_machine_formspec.png]",
"image[5.6,0.5;1.5,1.5;paleotest_progress_bar.png^[lowpart:" ..
(item_percent) ..
":paleotest_progress_bar_full.png^[transformR270]]",
"list[current_player;main;1.5,3;8,4;]",
"list[context;input;4,0.75;1,1;]",
"list[context;output;7.75,0.75;1,1;]", "listring[current_player;main]",
"listring[context;input]", "listring[current_player;main]",
"listring[context;output]", "listring[current_player;main]"
}
return table.concat(form, "")
end
local function update_formspec(progress, goal, meta)
local formspec
if progress > 0 and progress <= goal then
local item_percent = math.floor(progress / goal * 100)
formspec = get_active_dna_cultivator_fs(item_percent)
else
formspec = dna_cultivator_fs
end
meta:set_string("formspec", formspec)
end
---------------
-- Cultivate --
---------------
local function cultivate(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local input_item = inv:get_stack("input", 1)
local output_item = dna_cultivator.recipes[input_item:get_name()]
input_item:set_count(1)
if not dna_cultivator.recipes[input_item:get_name()] or
not inv:room_for_item("output", output_item) then
minetest.get_node_timer(pos):stop()
update_formspec(0, 3, meta)
else
inv:remove_item("input", input_item)
inv:add_item("output", output_item)
end
end
----------
-- Node --
----------
minetest.register_node("paleotest:dna_cultivator", {
description = "DNA Cultivator",
tiles = {
"paleotest_dna_cultivator_top.png",
"paleotest_dna_cultivator_bottom.png",
"paleotest_dna_cultivator_side.png",
"paleotest_dna_cultivator_side.png",
"paleotest_dna_cultivator_side.png", "paleotest_dna_cultivator_side.png"
},
paramtype2 = "facedir",
groups = {cracky = 2, tubedevice = 1, tubedevice_receiver = 1},
legacy_facedir_simple = true,
is_ground_content = false,
sounds = default.node_sound_stone_defaults(),
drawtype = "node",
can_dig = function(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return inv:is_empty("input") and inv:is_empty("output")
end,
on_timer = function(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local stack = meta:get_inventory():get_stack("input", 1)
if not dna_cultivator.recipes[stack:get_name()] then return false end
local output_item = dna_cultivator.recipes[stack:get_name()]
local cultivating_time = meta:get_int("cultivating_time") or 0
cultivating_time = cultivating_time + 1
if cultivating_time % 15 == 0 then cultivate(pos) end
update_formspec(cultivating_time % 15, 15, meta)
meta:set_int("cultivating_time", cultivating_time)
if not inv:room_for_item("output", output_item) then return false end
if not stack:is_empty() then
return true
else
meta:set_int("cultivating_time", 0)
update_formspec(0, 3, meta)
return false
end
end,
allow_metadata_inventory_put = function(pos, listname, _, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
if listname == "input" then
return dna_cultivator.recipes[stack:get_name()] and
stack:get_count() or 0
end
return 0
end,
allow_metadata_inventory_move = function() return 0 end,
allow_metadata_inventory_take = function(pos, _, _, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
return stack:get_count()
end,
on_metadata_inventory_put = function(pos)
local meta, timer = minetest.get_meta(pos), minetest.get_node_timer(pos)
local inv = meta:get_inventory()
local stack = inv:get_stack("input", 1)
local output_item = dna_cultivator.recipes[stack:get_name()]
local cultivating_time = meta:get_int("cultivating_time") or 0
if not dna_cultivator.recipes[stack:get_name()] then
timer:stop()
meta:set_string("formspec", dna_cultivator_fs)
return
end
if not inv:room_for_item("output", output_item) then
timer:stop()
return
else
if cultivating_time < 1 then update_formspec(0, 3, meta) end
timer:start(1)
end
end,
on_metadata_inventory_take = function(pos)
local meta, timer = minetest.get_meta(pos), minetest.get_node_timer(pos)
local inv = meta:get_inventory()
local stack = inv:get_stack("input", 1)
local cultivating_time = meta:get_int("cultivating_time") or 0
if not dna_cultivator.recipes[stack:get_name()] then
timer:stop()
meta:set_string("formspec", dna_cultivator_fs)
if cultivating_time > 0 then
meta:set_int("cultivating_time", 0)
end
return
end
timer:stop()
if cultivating_time < 1 then update_formspec(0, 3, meta) end
timer:start(1)
end,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", dna_cultivator_fs)
local inv = meta:get_inventory()
inv:set_size("input", 1)
inv:set_size("output", 1)
end,
on_blast = function(pos)
local drops = {}
default.get_inventory_drops(pos, "input", drops)
default.get_inventory_drops(pos, "output", drops)
table.insert(drops, "paleotest:dna_cultivator")
minetest.remove_node(pos)
return drops
end
})
-------------------------
-- Recipe Registration --
-------------------------
-- Plants --
dna_cultivator.register_recipe("paleotest:metasequoia_sapling_petrified",
"paleotest:metasequoia_sapling")
dna_cultivator.register_recipe("paleotest:fossilized_cycad_seeds",
"paleotest:seeds_cycad")
dna_cultivator.register_recipe("paleotest:fossilized_horsetail_spores",
"paleotest:seeds_horsetail")
-- Aquatic Reptiles --
dna_cultivator.register_recipe("paleotest:dna_dunkleosteus",
"paleotest:sac_dunkleosteus")
dna_cultivator.register_recipe("paleotest:dna_plesiosaurus",
"paleotest:sac_plesiosaurus")
dna_cultivator.register_recipe("paleotest:dna_mosasaurus",
"paleotest:sac_mosasaurus")
-- Mammals --
dna_cultivator.register_recipe("paleotest:dna_dire_wolf",
"paleotest:syringe_dire_wolf")
dna_cultivator.register_recipe("paleotest:dna_elasmotherium",
"paleotest:syringe_elasmotherium")
dna_cultivator.register_recipe("paleotest:dna_mammoth",
"paleotest:syringe_mammoth")
dna_cultivator.register_recipe("paleotest:dna_procoptodon",
"paleotest:syringe_procoptodon")
dna_cultivator.register_recipe("paleotest:dna_smilodon",
"paleotest:syringe_smilodon")
dna_cultivator.register_recipe("paleotest:dna_thylacoleo",
"paleotest:syringe_thylacoleo")
-- Dinosaurs and Terrestrial Reptiles --
dna_cultivator.register_recipe("paleotest:dna_brachiosaurus",
"paleotest:egg_brachiosaurus")
dna_cultivator.register_recipe("paleotest:dna_carnotaurus",
"paleotest:egg_carnotaurus")
dna_cultivator.register_recipe("paleotest:dna_pteranodon",
"paleotest:egg_pteranodon")
dna_cultivator.register_recipe("paleotest:dna_quetzalcoatlus",
"paleotest:egg_quetzalcoatlus")
dna_cultivator.register_recipe("paleotest:dna_sarcosuchus",
"paleotest:egg_sarcosuchus")
dna_cultivator.register_recipe("paleotest:dna_spinosaurus",
"paleotest:egg_spinosaurus")
dna_cultivator.register_recipe("paleotest:dna_stegosaurus",
"paleotest:egg_stegosaurus")
dna_cultivator.register_recipe("paleotest:dna_triceratops",
"paleotest:egg_triceratops")
dna_cultivator.register_recipe("paleotest:dna_tyrannosaurus",
"paleotest:egg_tyrannosaurus")
dna_cultivator.register_recipe("paleotest:dna_velociraptor",
"paleotest:egg_velociraptor")