-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcocoa.lua
More file actions
703 lines (646 loc) · 19.8 KB
/
cocoa.lua
File metadata and controls
703 lines (646 loc) · 19.8 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
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
--[[
X Farming. Extends Luanti farming mod with new plants, crops and ice fishing.
Copyright (C) 2025 SaKeL
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to juraj.vajda@gmail.com
--]]
local S = core.get_translator(core.get_current_modname())
-- how often node timers for plants will tick, +/- some random value
local function tick(pos)
core.get_node_timer(pos):start(math.random(332, 572))
end
-- how often a growth failure tick is retried (e.g. too dark)
local function tick_again(pos)
core.get_node_timer(pos):start(math.random(80, 160))
end
function x_farming.grow_cocoa_plant(pos, elapsed)
local node = core.get_node(pos)
local name = node.name
local def = core.registered_nodes[name]
if not def.next_plant then
-- disable timer for fully grown plant
return
end
-- check if on jungletree
local direction = core.facedir_to_dir(node.param2)
local below_pos = vector.add(pos, direction)
local below = core.get_node(below_pos)
if below.name ~= 'default:jungletree' and below.name ~= 'x_farming:jungle_tree' then
tick_again(pos)
return
end
-- check light
local light = core.get_node_light(pos)
if not light or light < def.minlight or light > def.maxlight then
tick_again(pos)
return
end
-- grow
core.swap_node(pos, { name = def.next_plant, param2 = node.param2 })
-- new timer needed?
if core.registered_nodes[def.next_plant].next_plant then
tick(pos)
end
end
function x_farming.place_cocoa_bean(itemstack, placer, pointed_thing)
local pt = pointed_thing
-- check if pointing at a node
if not pt then
return itemstack
end
if pt.type ~= 'node' then
return itemstack
end
local under = core.get_node(pt.under)
local above = core.get_node(pt.above)
local udef = core.registered_nodes[under.name]
if udef and udef.on_rightclick
and not (placer and placer:is_player()
and placer:get_player_control().sneak)
then
return udef.on_rightclick(pt.under, under, placer, itemstack, pointed_thing) or itemstack
end
local player_name = placer and placer:get_player_name() or ''
if core.is_protected(pt.under, player_name) then
core.record_protection_violation(pt.under, player_name)
return
end
if core.is_protected(pt.above, player_name) then
core.record_protection_violation(pt.above, player_name)
return
end
-- return if any of the nodes is not registered
if not core.registered_nodes[under.name] then
return itemstack
end
if not core.registered_nodes[above.name] then
return itemstack
end
-- check if NOT pointing at the top/below of the node
if pt.above.y == pt.under.y - 1
or pt.above.y == pt.under.y + 1
then
return itemstack
end
-- check if you can replace the node above the pointed node
if not core.registered_nodes[above.name].buildable_to then
return itemstack
end
-- check if pointing at soil
if under.name ~= 'default:jungletree' and under.name ~= 'x_farming:jungle_tree' then
return itemstack
end
local direction = vector.direction(pt.above, pt.under)
local new_param2 = core.dir_to_facedir(direction)
-- add the node and remove 1 item from the itemstack
core.set_node(pt.above, { name = 'x_farming:cocoa_1', param2 = new_param2 })
tick(pt.above)
if not core.is_creative_enabled(player_name) then
itemstack:take_item()
end
return itemstack
end
-- COCOA
core.register_craftitem('x_farming:cocoa_bean', {
description = S('Cocoa bean') .. ' (' .. S('plant on jungle tree trunk') .. ')'
.. '\n' .. S('Compost chance') .. ': 65%',
short_description = S('Cocoa bean'),
tiles = { 'x_farming_cocoa_bean.png' },
inventory_image = 'x_farming_cocoa_bean.png',
wield_image = 'x_farming_cocoa_bean.png',
groups = { compost = 65 },
on_place = x_farming.place_cocoa_bean,
})
-- 1
core.register_node('x_farming:cocoa_1', {
description = S('Cocoa') .. ' 1',
short_description = S('Cocoa') .. ' 1',
drawtype = 'nodebox',
tiles = {
'x_farming_cocoa_top_1.png',
'x_farming_cocoa_bottom_1.png',
'x_farming_cocoa_right_1.png',
'x_farming_cocoa_left_1.png',
'x_farming_cocoa_front_1.png',
'x_farming_cocoa_front_1.png'
},
use_texture_alpha = 'clip',
paramtype = 'light',
sunlight_propagates = true,
wield_scale = { x = 2, y = 2, z = 2 },
on_rotate = function(pos, node, user, mode, new_param2)
return false
end,
paramtype2 = 'facedir',
is_ground_content = false,
drop = {
items = {
{ items = { 'x_farming:cocoa_bean' }, rarity = 3 },
}
},
node_box = {
type = 'fixed',
fixed = {
{ -0.125, -0.0625, 0.1875, 0.125, 0.25, 0.4375 }, -- fruit
{ 0, 0.25, 0.3125, 0, 0.375, 0.375 }, -- stem_1
{ 0, 0.375, 0.4375, 0, 0.4375, 0.5 }, -- stem_2
{ 0, 0.3125, 0.375, 0, 0.4375, 0.4375 }, -- stem_3
}
},
collision_box = {
type = 'fixed',
fixed = {
{ -0.125, -0.0625, 0.1875, 0.125, 0.5, 0.5 },
},
},
selection_box = {
type = 'fixed',
fixed = {
{ -0.125, -0.0625, 0.1875, 0.125, 0.5, 0.5 },
},
},
groups = {
-- MTG
choppy = 3,
flammable = 2,
plant = 1,
cocoa = 1,
-- MCL
handy = 1,
axey = 1,
dig_by_water = 1,
destroy_by_lava_flow = 1,
dig_by_piston = 1,
attached_node_facedir = 1,
-- ALL
not_in_creative_inventory = 1,
},
_mcl_blast_resistance = 3,
_mcl_hardness = 0.2,
sounds = x_farming.node_sound_wood_defaults(),
next_plant = 'x_farming:cocoa_2',
on_timer = x_farming.grow_cocoa_plant,
minlight = 13,
maxlight = 15,
})
-- 2
core.register_node('x_farming:cocoa_2', {
description = S('Cocoa') .. ' 2',
short_description = S('Cocoa') .. ' 2',
drawtype = 'nodebox',
tiles = {
'x_farming_cocoa_top_2.png',
'x_farming_cocoa_bottom_2.png',
'x_farming_cocoa_right_2.png',
'x_farming_cocoa_left_2.png',
'x_farming_cocoa_front_2.png',
'x_farming_cocoa_front_2.png'
},
use_texture_alpha = 'clip',
paramtype = 'light',
sunlight_propagates = true,
wield_scale = { x = 1.5, y = 1.5, z = 1.5 },
on_rotate = function(pos, node, user, mode, new_param2)
return false
end,
paramtype2 = 'facedir',
is_ground_content = false,
drop = {
items = {
{ items = { 'x_farming:cocoa_bean' }, rarity = 2 },
}
},
node_box = {
type = 'fixed',
fixed = {
{ -0.1875, -0.1875, 0.0625, 0.1875, 0.25, 0.4375 }, -- fruit
{ 0, 0.25, 0.25, 0, 0.375, 0.375 }, -- stem_1
{ 0, 0.375, 0.375, 0, 0.5, 0.5 }, -- stem_2
{ 0, 0.375, 0.3125, 0, 0.4375, 0.375 }, -- stem_3
}
},
collision_box = {
type = 'fixed',
fixed = {
{ -0.1875, -0.1875, 0.0625, 0.1875, 0.5, 0.5 },
},
},
selection_box = {
type = 'fixed',
fixed = {
{ -0.1875, -0.1875, 0.0625, 0.1875, 0.5, 0.5 },
},
},
groups = {
-- MTG
choppy = 3,
flammable = 2,
plant = 1,
cocoa = 2,
-- MCL
handy = 1,
axey = 1,
dig_by_water = 1,
destroy_by_lava_flow = 1,
dig_by_piston = 1,
attached_node_facedir = 1,
-- ALL
not_in_creative_inventory = 1,
},
_mcl_blast_resistance = 3,
_mcl_hardness = 0.2,
sounds = x_farming.node_sound_wood_defaults(),
next_plant = 'x_farming:cocoa_3',
on_timer = x_farming.grow_cocoa_plant,
minlight = 13,
maxlight = 15
})
-- 3
core.register_node('x_farming:cocoa_3', {
description = S('Cocoa') .. ' 3',
short_description = S('Cocoa') .. ' 3',
drawtype = 'nodebox',
tiles = {
'x_farming_cocoa_top_3.png',
'x_farming_cocoa_bottom_3.png',
'x_farming_cocoa_right_3.png',
'x_farming_cocoa_left_3.png',
'x_farming_cocoa_front_3.png',
'x_farming_cocoa_front_3.png'
},
use_texture_alpha = 'clip',
paramtype = 'light',
sunlight_propagates = true,
wield_scale = { x = 1.5, y = 1.5, z = 1.5 },
on_rotate = function(pos, node, user, mode, new_param2)
return false
end,
paramtype2 = 'facedir',
is_ground_content = false,
drop = {
items = {
{ items = { 'x_farming:cocoa_bean' }, rarity = 1 },
{ items = { 'x_farming:cocoa_bean' }, rarity = 2 },
}
},
node_box = {
type = 'fixed',
fixed = {
{ -0.25, -0.3125, -0.0625, 0.25, 0.25, 0.4375 },
{ -0.0624999, 0.25, 0.25, 0.0625, 0.375, 0.4375 },
{ -0.0625, 0.375, 0.375, 0.0625, 0.5, 0.5 },
{ -0.0624999, 0.375, 0.3125, 0.0625, 0.4375, 0.375 },
}
},
collision_box = {
type = 'fixed',
fixed = {
{ -0.25, -0.3125, -0.0625, 0.25, 0.5, 0.5 },
},
},
selection_box = {
type = 'fixed',
fixed = {
{ -0.25, -0.3125, -0.0625, 0.25, 0.5, 0.5 },
},
},
groups = {
-- MTG
choppy = 3,
flammable = 2,
plant = 1,
leafdecay = 3,
leafdecay_drop = 1,
cocoa = 3,
-- MCL
handy = 1,
axey = 1,
dig_by_water = 1,
destroy_by_lava_flow = 1,
dig_by_piston = 1,
attached_node_facedir = 1,
-- ALL
not_in_creative_inventory = 1,
},
_mcl_blast_resistance = 3,
_mcl_hardness = 0.2,
sounds = x_farming.node_sound_wood_defaults(),
minlight = 13,
maxlight = 15
})
-- replacement LBM for pre-nodetimer plants
core.register_lbm({
name = 'x_farming:start_nodetimer_cocoa',
nodenames = {
'x_farming:cocoa_1',
'x_farming:cocoa_2'
},
action = function(pos, node)
tick_again(pos)
end,
})
core.register_node('x_farming:jungle_with_cocoa_sapling', {
description = S('Jungle Tree with Cocoa Sapling') .. '\n' .. S('Compost chance') .. ': 30%',
short_description = S('Jungle Tree with Cocoa Sapling'),
drawtype = 'plantlike',
tiles = { 'x_farming_junglesapling.png' },
inventory_image = 'x_farming_junglesapling.png',
wield_image = 'x_farming_junglesapling.png',
paramtype = 'light',
sunlight_propagates = true,
walkable = false,
on_timer = x_farming.grow_jungle_tree,
selection_box = {
type = 'fixed',
fixed = { -4 / 16, -0.5, -4 / 16, 4 / 16, 7 / 16, 4 / 16 }
},
groups = {
-- MTG
snappy = 2,
flammable = 2,
-- MCL
plant = 1,
non_mycelium_plant = 1,
deco_block = 1,
dig_by_water = 1,
dig_by_piston = 1,
destroy_by_lava_flow = 1,
compostability = 30,
-- ALL
dig_immediate = 3,
attached_node = 1,
sapling = 1,
},
_mcl_blast_resistance = 0,
_mcl_hardness = 0,
sounds = x_farming.node_sound_leaves_defaults(),
on_construct = function(pos)
core.get_node_timer(pos):start(math.random(300, 1500))
end,
on_place = function(itemstack, placer, pointed_thing)
itemstack = x_farming.sapling_on_place(itemstack, placer, pointed_thing,
'x_farming:jungle_with_cocoa_sapling',
-- minp, maxp to be checked, relative to sapling pos
{ x = -3, y = -5, z = -3 },
{ x = 3, y = 31, z = 3 },
-- maximum interval of interior volume check
4)
return itemstack
end,
})
-- trunk
core.register_node('x_farming:jungle_tree', {
description = S('Jungle Tree'),
short_description = S('Jungle Tree'),
tiles = { 'x_farming_jungle_tree_top.png', 'x_farming_jungle_tree_top.png', 'x_farming_jungle_tree.png' },
paramtype2 = 'facedir',
is_ground_content = false,
groups = {
-- MTG
choppy = 2,
oddly_breakable_by_hand = 1,
-- MCL
handy = 1,
axey = 1,
building_block = 1,
material_wood = 1,
fire_encouragement = 5,
fire_flammability = 5,
-- ALL
tree = 1,
flammable = 2,
},
_mcl_blast_resistance = 2,
_mcl_hardness = 2,
sounds = x_farming.node_sound_wood_defaults(),
on_place = core.rotate_node
})
-- leaves
core.register_node('x_farming:jungle_leaves', {
description = S('Jungle Tree Leaves') .. '\n' .. S('Compost chance') .. ': 30%',
short_description = S('Jungle Tree Leaves'),
drawtype = 'allfaces_optional',
waving = 1,
tiles = { 'x_farming_jungleleaves.png' },
special_tiles = { 'x_farming_jungleleaves.png' },
paramtype = 'light',
is_ground_content = false,
groups = {
-- MTG
snappy = 3,
leafdecay = 3,
-- MCL
handy = 1,
hoey = 1,
shearsy = 1,
swordy = 1,
dig_by_piston = 1,
fire_encouragement = 30,
fire_flammability = 60,
deco_block = 1,
compostability = 30,
-- ALL
flammable = 2,
leaves = 1,
},
_mcl_shears_drop = true,
_mcl_blast_resistance = 0.2,
_mcl_hardness = 0.2,
_mcl_silk_touch_drop = true,
drop = {
max_items = 1,
items = {
{
-- player will get sapling with 1/20 chance
items = { 'x_farming:jungle_with_cocoa_sapling' },
rarity = 20,
},
{
-- player will get leaves only if he get no saplings,
-- this is because max_items is 1
items = { 'x_farming:jungle_leaves' },
}
}
},
sounds = x_farming.node_sound_leaves_defaults(),
after_place_node = x_farming.after_place_leaves,
})
-- leafdecay
x_farming.register_leafdecay({
trunks = { 'x_farming:jungle_tree' },
leaves = {
'x_farming:cocoa_3',
'x_farming:jungle_leaves'
},
radius = 2,
})
-- planks
core.register_node('x_farming:jungle_wood', {
description = S('Jungle Wood Planks'),
short_description = S('Jungle Wood Planks'),
paramtype2 = 'facedir',
place_param2 = 0,
tiles = { 'x_farming_jungle_wood.png' },
is_ground_content = false,
groups = {
-- MTG
choppy = 2,
oddly_breakable_by_hand = 2,
-- Everness
everness_wood = 1,
-- MCL
handy = 1,
axey = 1,
building_block = 1,
material_wood = 1,
fire_encouragement = 5,
fire_flammability = 20,
-- ALL
flammable = 3,
wood = 1,
},
_mcl_blast_resistance = 3,
_mcl_hardness = 2,
sounds = x_farming.node_sound_wood_defaults(),
})
-- Cookie
local cookie_def = {
description = S('Cookie') .. '\n' .. S('Compost chance') .. ': 85%\n'
.. core.colorize(x_farming.colors.brown, S('Hunger') .. ': 2'),
inventory_image = 'x_farming_cookie.png',
groups = {
hunger_amount = 2,
-- MTG
compost = 85,
-- MCL
food = 2,
eatable = 2,
compostability = 85
},
on_use = function(itemstack, user, pointed_thing)
local hunger_amount = core.get_item_group(itemstack:get_name(), "hunger_amount") or 0
if hunger_amount == 0 then
return itemstack
end
return core.item_eat(hunger_amount)(itemstack, user, pointed_thing)
end,
}
if core.get_modpath('farming') then
cookie_def.on_use = core.item_eat(2)
end
if core.get_modpath('mcl_farming') then
cookie_def.on_place = core.item_eat(2)
cookie_def.on_secondary_use = core.item_eat(2)
end
core.register_craftitem('x_farming:cookie', cookie_def)
-- Chocolate
local chocolate_def = {
description = S('Chocolate') .. '\n' .. S('Compost chance') .. ': 65%\n'
.. core.colorize(x_farming.colors.brown, S('Hunger') .. ': 3'),
inventory_image = 'x_farming_chocolate.png',
groups = {
-- MTG
compost = 65,
-- MCL
food = 2,
eatable = 2,
compostability = 65,
hunger_amount = 3
},
on_use = function(itemstack, user, pointed_thing)
local hunger_amount = core.get_item_group(itemstack:get_name(), "hunger_amount") or 0
if hunger_amount == 0 then
return itemstack
end
return core.item_eat(hunger_amount)(itemstack, user, pointed_thing)
end,
}
if core.get_modpath('farming') then
chocolate_def.on_use = core.item_eat(3)
end
if core.get_modpath('mcl_farming') then
chocolate_def.on_place = core.item_eat(3)
chocolate_def.on_secondary_use = core.item_eat(3)
end
core.register_craftitem('x_farming:chocolate', chocolate_def)
-- Stairs
if core.global_exists('stairs') and core.get_modpath('stairs') then
stairs.register_stair_and_slab(
'jungle_wood',
'x_farming:jungle_wood',
{ choppy = 2, oddly_breakable_by_hand = 2, flammable = 2 },
{ 'x_farming_jungle_wood.png' },
'Jungle Wooden Stair',
'Jungle Wooden Slab',
x_farming.node_sound_wood_defaults(),
false
)
end
if core.get_modpath('mcl_stairs') then
mcl_stairs.register_stair_and_slab(
'x_farming_jungle_wood',
'x_farming:jungle_wood',
{ handy = 1, axey = 1, building_block = 1, material_wood = 1, fire_encouragement = 5, fire_flammability = 20, flammable = 3, wood = 1, },
{ 'x_farming_jungle_wood.png' },
S('Jungle Wooden Stair'),
S('Jungle Wooden Slab'),
x_farming.node_sound_wood_defaults(),
6,
2,
S('Double Jungle Wooden Slab'),
nil
)
end
-- Crate
x_farming.register_crate('crate_cocoa_bean_3', {
description = S('Cocoa Bean Crate'),
short_description = S('Cocoa Bean Crate'),
tiles = { 'x_farming_crate_cocoa_bean_3.png' },
_custom = {
crate_item = 'x_farming:cocoa_bean'
}
})
core.register_on_mods_loaded(function()
local deco_place_on = {}
local deco_biomes = {}
local deco_fill_ratio = 0.025
-- MTG
if core.get_modpath('default') then
table.insert(deco_place_on, 'default:dirt_with_rainforest_litter')
table.insert(deco_biomes, 'rainforest')
end
-- Everness
if core.get_modpath('everness') then
table.insert(deco_place_on, 'everness:dirt_with_grass_1')
table.insert(deco_biomes, 'everness:bamboo_forest')
deco_fill_ratio = deco_fill_ratio / 20
end
-- MCL
if core.get_modpath('mcl_core') then
table.insert(deco_place_on, 'mcl_core:dirt_with_grass')
table.insert(deco_biomes, 'Jungle')
end
if next(deco_place_on) and next(deco_biomes) then
core.register_decoration({
name = 'x_farming:jungle_tree',
deco_type = 'schematic',
place_on = deco_place_on,
sidelen = 80,
fill_ratio = deco_fill_ratio,
biomes = deco_biomes,
y_max = 31000,
y_min = 1,
schematic = core.get_modpath('x_farming') .. '/schematics/x_farming_jungle_tree_with_cocoa.mts',
flags = 'place_center_x, place_center_z',
rotation = '0',
})
end
end)