-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit.lua
786 lines (734 loc) · 26.7 KB
/
init.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
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
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
local page_start
local page_end
local message_index
phonics = {
a={name="a", length=.4, gain=1, is_letter=1},
_a={name="_a", length=.5, gain=1, is_letter=0},
ar={name="ar", length=.93, gain=1, is_letter=0},
au={name="au", length=.52, gain=1, is_letter=0},
b={name="b", length=.35, gain=1, is_letter=1},
c={name="c", length=.3, gain=1, is_letter=1},
ch={name="ch", length=.17, gain=1, is_letter=0},
d={name="d", length=.77, gain=1, is_letter=1},
e={name="e", length=.65, gain=1, is_letter=1},
_e={name="_e", length=.64, gain=1, is_letter=0},
er={name="er", length=.65, gain=1, is_letter=0},
f={name="f", length=.7, gain=1, is_letter=1},
g={name="g", length=.14, gain=1, is_letter=1},
h={name="h", length=.48, gain=1, is_letter=1},
i={name="i", length=.65, gain=1, is_letter=1},
_i={name="_i", length=.45, gain=1, is_letter=0},
ing={name="ing", length=.67, gain=1, is_letter=0},
j={name="j", length=.20, gain=1, is_letter=1},
k={name="k", length=.3, gain=1, is_letter=1},
l={name="l", length=.65, gain=1, is_letter=1},
m={name="m", length=.65, gain=1, is_letter=1},
n={name="n", length=.65, gain=1, is_letter=1},
o={name="o", length=.65, gain=1, is_letter=1},
_o={name="_o", length=.65, gain=1, is_letter=0},
_oo={name="_oo", length=.65, gain=1, is_letter=0},
oo={name="oo", length=.65, gain=1, is_letter=0},
ou={name="ou", length=.6, gain=1, is_letter=0},
p={name="p", length=.35, gain=1, is_letter=1},
q={name="q", length=.15, gain=1, is_letter=1},
r={name="r", length=.65, gain=1, is_letter=1},
s={name="s", length=.65, gain=1, is_letter=1},
sh={name="sh", length=.65, gain=1, is_letter=0},
t={name="t", length=.3, gain=1, is_letter=1},
th={name="th", length=.18, gain=1, is_letter=0},
u={name="u", length=.65, gain=1, is_letter=1},
_u={name="_u", length=.92, gain=1, is_letter=0},
v={name="v", length=.65, gain=1, is_letter=1},
w={name="w", length=.45, gain=1, is_letter=1},
--wh={name="wh", length=.23, gain=1, is_letter=0},
x={name="x", length=.6, gain=1, is_letter=1},
y={name="y", length=.84, gain=1, is_letter=1},
z={name="z", length=.65, gain=1, is_letter=1}
}
two_char_phonics = {
ar= {name="ar"},
au= {name="au"},
ch= {name="ch"},
er= {name="er"},
oo= {name="oo"},
ou= {name="ou"},
sh= {name="sh"},
th= {name="th"},
--wh= {name="wh"}
}
three_char_phonics = {
ing= {name="ing"}
}
local words = {
cat={spellings={ {c},{a},{t} } }
}
for key,value in pairs(phonics) do
minetest.register_node("phonics:"..key, {
description = key,
tiles = {"phonics_"..key..".jpg"},
is_ground_content = true,
groups = {cracky=3, choppy=3},
sounds = default.node_sound_stone_defaults(),
on_punch = function(pos, node, puncher)
-- minetest.chat_send_all("phonic.on_punch:" .. pos.x ..">" )
hit_with = puncher:get_wielded_item()
wear=hit_with:get_wear()
if wear == 0 then
activate_node({pos, key, phonics[key].length})
end
end,
})
minetest.register_node("phonics:"..key.."_active", {
description = key.."_active",
tiles = {"phonics_"..key.."_active.png"},
light_source = 20,
is_ground_content = true,
groups = {cracky=3, choppy=3, not_in_creative_inventory=1},
sounds = default.node_sound_stone_defaults(),
})
if phonics[key].is_letter ==1 then
minetest.register_node("phonics:0"..key, {
description = "Silent "..key,
tiles = {"phonics_0"..key..".png"},
is_ground_content = true,
groups = {cracky=3, choppy=3},
sounds = default.node_sound_stone_defaults(),
})
end
end
minetest.register_node("phonics:question_mark", {
description = "Question Mark",
tiles = {
"question_mark.png",},
is_ground_content = true,
paramtype = "light",
paramtype2 = "facedir",
groups = {cracky=3},
sounds = default.node_sound_stone_defaults(),
-- on_punch = function(pos, node, puncher)
-- end
})
minetest.register_node("phonics:exclamation_point", {
description = "Exclamation Point",
tiles = {
"exclamation_point.png",},
is_ground_content = true,
paramtype = "light",
paramtype2 = "facedir",
groups = {cracky=3},
sounds = default.node_sound_stone_defaults(),
-- on_punch = function(pos, node, puncher)
-- end
})
minetest.register_node("phonics:period", {
description = "Period",
tiles = {
"period.png",},
is_ground_content = true,
paramtype = "light",
paramtype2 = "facedir",
groups = {cracky=3},
sounds = default.node_sound_stone_defaults(),
-- on_punch = function(pos, node, puncher)
-- end
})
minetest.register_node("phonics:SayWord", {
description = "say word",
tiles = {
"white.jpg",
"white.jpg",
"SpeakingMouth64.png",
"SpeakingMouth64.png",
"SpeakingMouth64.png",
"SpeakingMouth64.png",},
is_ground_content = true,
paramtype = "light",
paramtype2 = "facedir",
groups = {cracky=3},
sounds = default.node_sound_stone_defaults(),
on_punch = function(pos, node, puncher)
sound_out_word(pos, "x", 1)
sound_out_word(pos, "x", -1)
sound_out_word(pos, "z", 1)
sound_out_word(pos, "z", -1)
end
})
minetest.register_node("phonics:PaperStart", {
description = "Paper Start",
tiles = {
"white.jpg",
"white.jpg",
"nicubunu_Scroll.png",
"nicubunu_Scroll.png",
"nicubunu_Scroll.png",
"nicubunu_Scroll.png",},
is_ground_content = true,
paramtype = "light",
paramtype2 = "facedir",
groups = {cracky=3},
sounds = default.node_sound_stone_defaults(),
after_place_node = function(pos)
get_page_start_loc(pos)
end,
on_punch = function(pos, node, puncher)
clear_page(pos)
end--[[,
on_dig = function(pos_dig,node)
replace_page(pos_dig, "x", 1, "air")
replace_page(pos_dig, "x", -1, "air")
replace_page(pos_dig, "z", 1, "air")
replace_page(pos_dig, "z", -1, "air")
replace_column(pos_dig, "air")
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
local player = digger:get_player_name()
local itemstack = ItemStack("phonics:PaperStart")
local inv = minetest.get_inventory({type = "player", name = player})
if inv and inv:room_for_item("main", itemstack) then
inv:add_item("main", itemstack)
else
-- If the player's inventory is full, spawn the item on the ground
minetest.add_item(pos, itemstack)
end
end]]
})
function clear_page(pos)
local clear_pos = {} --needed this because the node being passed to revertnode was incremented (must have been by reference
clear_pos.x = pos.x
clear_pos.y = pos.y
clear_pos.z = pos.z
replace_page(clear_pos, "x", 1, "phonics:BlankPaper")
replace_page(clear_pos, "x", -1, "phonics:BlankPaper")
replace_page(clear_pos, "z", 1, "phonics:BlankPaper")
replace_page(clear_pos, "z", -1, "phonics:BlankPaper")
replace_column(clear_pos, "phonics:BlankPaper")
page_start = pos
page_end = pos
end
minetest.register_node("phonics:PaperFinish", {
description = "Paper Finish",
tiles = {
"white.jpg",
"white.jpg",
"finish_line_flag_pin_th.png",
"finish_line_flag_pin_th.png",
"finish_line_flag_pin_th.png",
"finish_line_flag_pin_th.png",},
is_ground_content = true,
paramtype = "light",
paramtype2 = "facedir",
groups = {cracky=3},
sounds = default.node_sound_stone_defaults(),
after_place_node = function(pos)
blank_page(pos)
end
})
minetest.register_node("phonics:BlankPaper", {
description = "Blank Paper",
tiles = {
"white.jpg",
"white.jpg",
"white.jpg",
"white.jpg",
"white.jpg",
"white.jpg",},
is_ground_content = true,
paramtype = "light",
paramtype2 = "facedir",
groups = {cracky=3},
sounds = default.node_sound_stone_defaults(),
})
function split(str, pat)
local t = {} -- NOTE: use {n = 0} in Lua-5.0
local fpat = "(.-)" .. pat
local last_end = 1
local s, e, cap = str:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(t,cap)
end
last_end = e+1
s, e, cap = str:find(fpat, last_end)
end
if last_end <= #str then
cap = str:sub(last_end)
table.insert(t, cap)
end
return t
end
local play_sound = function(list, soundname)
local gain = 1.0
local handler = minetest.sound_play("phonics_"..soundname, {gain=gain})
end
function revertnode(parms)
local pos3 = parms[1]
local node3= parms[2]
minetest.env:remove_node(pos3,{name="phonics:"..node3.."_active"})
minetest.env:place_node(pos3,{name="phonics:"..node3})
end
function activate_node(anparms)
local pos2 = anparms[1]
local nodename = anparms[2]
local duration = anparms[3]
minetest.env:remove_node(pos2,{name="phonics:"..nodename})
minetest.env:place_node(pos2,{name="phonics:"..nodename.."_active"})
play_sound(phonics, nodename)
local np = {} --needed this because the node being passed to revertnode was incremented (must have been by reference
np.x = pos2.x
np.y = pos2.y
np.z = pos2.z
minetest.after(duration, revertnode, {np, nodename})
end
function sound_out_word(pos1, axis, direction)
local cumulative_delay = 0
local mpos = {} --needed this because the node being passed to revertnode was incremented (must have been by reference
mpos.x = pos1.x
mpos.y = pos1.y
mpos.z = pos1.z
--see if there are any sounds next to mouth on this axis. (or if there is a BlankPage before it.) If not, do nothing.
local test_pos = {}
test_pos.x = pos1.x
test_pos.y = pos1.y
test_pos.z = pos1.z
if axis == "x" then
test_pos.x=test_pos.x+direction
end
if axis == "z" then
test_pos.z=test_pos.z+direction
end
local test_nodename = minetest.env:get_node(test_pos).name
local test_nodenamearray = split(test_nodename, ":")
local test_nodename_prefix = test_nodenamearray[1]
local test_nodename_suffix = test_nodenamearray[2]
--see if blank page before it
if axis == "x" then
test_pos.x=test_pos.x-(direction*2)
end
if axis == "z" then
test_pos.z=test_pos.z-(direction*2)
end
local b4_nodename = minetest.env:get_node(test_pos).name
if b4_nodename ~="phonics:BlankPaper" then
if test_nodename_prefix ~="phonics" or test_nodename_suffix == "BlankPaper" or test_nodename_suffix =="PaperStart" then
return
end
end
local row_count = 1
repeat --go to next row 1 time
repeat --continue sounding on this row until you reach blank paper or a non phonics node
if axis == "x" then
mpos.x=mpos.x+direction
end
if axis == "z" then
mpos.z=mpos.z+direction
end
local nodename = minetest.env:get_node(mpos).name
local nodenamearray = split(nodename, ":")
local nodename_prefix = nodenamearray[1]
local nodename_suffix = nodenamearray[2]
local delay = phonics[nodename_suffix]
if delay ~=nil and nodename_prefix =="phonics" then
local lpos = {} --needed this because the node being passed to revertnode was incremented (must have been by reference
lpos.x = mpos.x
lpos.y = mpos.y
lpos.z = mpos.z
minetest.after(cumulative_delay, activate_node, {lpos, nodename_suffix, phonics[nodename_suffix].length})
cumulative_delay = cumulative_delay + phonics[nodename_suffix].length
end
until nodename_prefix ~="phonics" or nodename_suffix == "BlankPaper"
--if I will find a BlankPaper in this row, then dont look in next row
local find_blank_pos = {} --needed this because the node being passed to revertnode was incremented (must have been by reference
find_blank_pos.x = mpos.x
find_blank_pos.y = mpos.y
find_blank_pos.z = mpos.z
repeat
--is this node BlankPaper?
local find_blank_nodename = minetest.env:get_node(find_blank_pos).name
local find_blank_nodenamearray = split(find_blank_nodename, ":")
local find_blank_nodename_prefix = find_blank_nodenamearray[1]
local find_blank_nodename_suffix = find_blank_nodenamearray[2]
if find_blank_nodename_suffix == "BlankPaper" then
return
end
--if not, increment pointer and repeat search
if axis == "x" then
find_blank_pos.x=find_blank_pos.x+direction
end
if axis == "z" then
find_blank_pos.z=find_blank_pos.z+direction
end
until find_blank_nodename_prefix ~="phonics"--prefix not phonics
--we're not done, so search next row for more phonics to sound out
local new_row_pos = {} --needed this because the node being passed to revertnode was incremented (must have been by reference
new_row_pos.x = mpos.x
new_row_pos.y = mpos.y
new_row_pos.z = mpos.z
new_row_pos.y=new_row_pos.y-1
if nodename_suffix == "BlankPaper" then
return
end
repeat --go to the beginning of the new row
if axis == "x" then
new_row_pos.x=new_row_pos.x-direction
end
if axis == "z" then
new_row_pos.z=new_row_pos.z-direction
end
local new_row_nodename = minetest.env:get_node(new_row_pos).name
local new_row_nodenamearray = split(new_row_nodename, ":")
local new_row_nodename_prefix = new_row_nodenamearray[1]
local new_row_nodename_suffix = new_row_nodenamearray[2]
mpos.x = new_row_pos.x
mpos.y = new_row_pos.y
mpos.z = new_row_pos.z
until new_row_nodename_prefix ~="phonics"
row_count= row_count +1
until row_count >2 or nodename_suffix == "BlankPaper"
end
function write_message_to_page(message)
local start_page_pos = {} --needed this because the node being passed to revertnode was incremented (must have been by reference
start_page_pos.x = page_start.x
start_page_pos.y = page_start.y
start_page_pos.z = page_start.z
local start_message_pos = {} --needed this because the node being passed to revertnode was incremented (must have been by reference
start_message_pos.x = page_start.x
start_message_pos.y = page_start.y
start_message_pos.z = page_start.z
write_message_to_page_on_axis(start_message_pos, "x", 1, message)
write_message_to_page_on_axis(start_message_pos, "x", -1, message)
write_message_to_page_on_axis(start_message_pos, "z", 1, message)
write_message_to_page_on_axis(start_message_pos, "z", -1, message)
end
function write_message_to_page_on_axis(pos, axis, direction,message)
local page_position = {} --needed this because the node being passed to revertnode was incremented (must have been by reference
page_position.x = pos.x
page_position.y = pos.y
page_position.z = pos.z
message_index = 1
--if the first node after the PageStart node is not a phonic, skip everything.
local first_position = {}
first_position.x = pos.x
first_position.y = pos.y
first_position.z = pos.z
if axis=="x" then
first_position.x = first_position.x +direction
end
if axis=="z" then
first_position.z = first_position.z +direction
end
local first_nodename = minetest.env:get_node(first_position).name
local firstnamearray = split(first_nodename, ":")
local firstname_prefix = firstnamearray[1]
if firstname_prefix == "phonics" then --we have phonics on this axis
repeat
local current_nodename = minetest.env:get_node(page_position).name
local nodenamearray = split(current_nodename, ":")
local nodename_prefix = nodenamearray[1]
local nodename_suffix = nodenamearray[2]
write_page_row(page_position, axis, direction,message)
page_position.y = page_position.y-1
until nodename_prefix ~="phonics" or message_index > string.len(message)
end
end
function write_page_row(pos, axis, direction, message)
local replace_pointer = {} --needed this because the node being passed to revertnode was incremented (must have been by reference
replace_pointer.x = pos.x
replace_pointer.y = pos.y
replace_pointer.z = pos.z
local nodename = minetest.env:get_node(replace_pointer).name
if nodename=="phonics:PaperStart" then
if axis == "x" then
replace_pointer.x=replace_pointer.x+direction
new_nodename ="phonics:SayWord"
minetest.env:add_node(replace_pointer, {name=new_nodename})
replace_pointer.x=replace_pointer.x+direction
end
if axis == "z" then
replace_pointer.z=replace_pointer.z+direction
new_nodename ="phonics:SayWord"
minetest.env:add_node(replace_pointer, {name=new_nodename})
replace_pointer.z=replace_pointer.z+direction
end
end
--1get me node at current location
--2if node prefix is phonics then replace node with next phonic in the message
--3(and have some code behind the scenes automatically bump the message_index)
--4increment the replace pointer
--5repeat 1-4 until node prefix at current location is not phonics
repeat
local nodename = minetest.env:get_node(replace_pointer).name
local nodenamearray = split(nodename, ":")
local nodename_prefix = nodenamearray[1]
local nodename_suffix = nodenamearray[2]
if nodename_prefix =="phonics" then
if new_nodename =="phonics:BlankPaper" then
--if we had a space between words then inject sayword block into stream
new_nodename ="phonics:SayWord"
minetest.env:add_node(replace_pointer, {name=new_nodename})
else
new_nodename = get_next_phonic_in_message(message)
if minetest.registered_nodes[new_nodename] then
minetest.env:add_node(replace_pointer, {name=new_nodename}) --*******************************************
end
end
if minetest.registered_nodes[new_nodename] then
if axis == "x" then
replace_pointer.x=replace_pointer.x+direction
end
if axis == "z" then
replace_pointer.z=replace_pointer.z+direction
end
end
end
until nodename_prefix ~="phonics" or message_index > string.len(message)
end
function get_next_phonic_in_message(message)
--and have some code behind the scenes automatically bump the message_index
string.len(message)
if message_index <= string.len(message) then
local current_char_in_message = string.sub(message,message_index,message_index)
phonic_builder = current_char_in_message
--if currentchar=" " then just set cpim to blankPaper and skip all the char business"
if current_char_in_message==" " then
current_phonic_in_message = "phonics:BlankPaper"
elseif current_char_in_message=="." then
current_phonic_in_message = "phonics:period"
elseif current_char_in_message=="?" then
current_phonic_in_message = "phonics:question_mark"
elseif current_char_in_message=="!" then
current_phonic_in_message = "phonics:exclamation_point"
else
if current_char_in_message == "0" or current_char_in_message == "_" then
message_index = message_index +1
current_char_in_message = string.sub(message,message_index,message_index)
phonic_builder = phonic_builder..current_char_in_message
end
char_after_current_char = string.sub(message,message_index+1,message_index+1)
third_char = string.sub(message,message_index+2,message_index+2)
two_chars = current_char_in_message..char_after_current_char
three_chars = two_chars..third_char
--minetest.log("x", "phonic_builder: "..phonic_builder)
--minetest.log("x", "phonic_builder 1st char: "..string.sub(phonic_builder,1,1))
--minetest.log("x", "two_chars: "..two_chars)
--check to see if this is a 2 character phonic. But only if it doesn't begin with an "_" or if it is _oo.
--this is because the only two character phonic that can use the "_" prefix is the "_oo" phonic.
if (two_char_phonics[two_chars] ~= nil and string.sub(phonic_builder,1,1) ~= "_" and string.sub(phonic_builder,1,1) ~= "0") or (two_chars == "oo" and string.sub(phonic_builder,1,1) ~= "0") then
phonic_builder = phonic_builder..char_after_current_char
message_index = message_index +1
end
if (three_char_phonics[three_chars] ~= nil and string.sub(phonic_builder,1,1) ~= "_" and string.sub(phonic_builder,1,1) ~= "0")then
phonic_builder = phonic_builder..string.sub(message,message_index+1,message_index+2)
message_index = message_index +2
end
current_phonic_in_message = "phonics:"..phonic_builder
end
message_index = message_index +1
else
current_phonic_in_message = "phonics:BlankPaper"
end
return current_phonic_in_message
end
function replace_page(pos, axis, direction,new_nodename)
local replace_row_pos = {} --needed this because the node being passed to revertnode was incremented (must have been by reference
replace_row_pos.x = pos.x
replace_row_pos.y = pos.y
replace_row_pos.z = pos.z
repeat
local current_nodename = minetest.env:get_node(replace_row_pos).name
local nodenamearray = split(current_nodename, ":")
local nodename_prefix = nodenamearray[1]
local nodename_suffix = nodenamearray[2]
replace_page_row(replace_row_pos, axis, direction,new_nodename)
replace_row_pos.y = replace_row_pos.y-1
until nodename_prefix ~="phonics"
end
function replace_column(pos, new_nodename)
replace_column_pos= pos
repeat
local current_nodename = minetest.env:get_node(replace_column_pos).name
local nodenamearray = split(current_nodename, ":")
local nodename_prefix = nodenamearray[1]
local nodename_suffix = nodenamearray[2]
if nodename_prefix =="phonics" then
if new_nodename =="air" then
minetest.env:add_node(replace_column_pos, {name=new_nodename})
end
if new_nodename =="phonics:BlankPaper" and current_nodename ~="phonics:PaperStart" then
minetest.env:add_node(replace_column_pos, {name=new_nodename})
end
end
replace_column_pos.y = replace_column_pos.y-1
until nodename_prefix ~="phonics"
end
function replace_page_row(pos, axis, direction, new_nodename)
local replace_pointer = {} --needed this because the node being passed to revertnode was incremented (must have been by reference
replace_pointer.x = pos.x
replace_pointer.y = pos.y
replace_pointer.z = pos.z
repeat
if axis == "x" then
replace_pointer.x=replace_pointer.x+direction
end
if axis == "z" then
replace_pointer.z=replace_pointer.z+direction
end
local nodename = minetest.env:get_node(replace_pointer).name
local nodenamearray = split(nodename, ":")
local nodename_prefix = nodenamearray[1]
local nodename_suffix = nodenamearray[2]
if nodename_prefix =="phonics" then
minetest.env:add_node(replace_pointer, {name=new_nodename})
end
until nodename_prefix ~="phonics"
end
function get_page_start_loc(pos)
page_start = pos
end
function blank_page(pos)
page_end = pos
if page_start ~= nil and math.abs(page_start.x-page_end.x) <20 and math.abs(page_start.y-page_end.y) <20 and math.abs(page_start.z-page_end.z) <20 then
if page_end.y <= page_start.y then --if the page end block was placed at or below page start block
if page_end.x == page_start.x then
buildwall(page_start.z, pos.z, page_start.y, pos.y, "x", pos.x, "phonics:BlankPaper")
end
if page_end.z == page_start.z then
buildwall(page_start.x, pos.x, page_start.y, pos.y, "z", pos.z, "phonics:BlankPaper")
end
end
end
end
function buildwall(hstart, hend, ystart, yend, haxis, haxis_fixed, nodename)
repeat
buildrow(hstart, hend, ystart, haxis, haxis_fixed, nodename)
ystart = ystart -1
until ystart < yend
end
function buildrow(hstart, hend, y, haxis, haxis_fixed, nodename)
local hpos = math.min(hstart, hend)
local hmax = math.max(hstart, hend)
local current_pos={}
current_pos.y = y
repeat
if haxis =="x" then
current_pos.z = hpos
current_pos.x = haxis_fixed
end
if haxis =="z" then
current_pos.x = hpos
current_pos.z = haxis_fixed
end
if minetest.env:get_node(current_pos).name ~= "phonics:PaperStart" then --leave paperstart node there.
minetest.env:add_node(current_pos, {name=nodename})
end
hpos = hpos +1
until hpos> hmax
end
minetest.register_chatcommand("w", {
params = "<message>",
description = "Write phonics message on a page",
privs = {shout=true},
func = function(name, param)
if page_start == nil or page_end == nil then minetest.chat_send_player(name, "You need to create a page first") return end
write_message(string.lower(param))
end, })
function write_message(param)
write_message_to_page(param)
end
--turn the phonics nodes into ores:
-- Function to generate the phonics nodes underground
phonics_scarcity = tonumber(minetest.settings:get("phonics_scarcity")) or 350
if phonics_scarcity >0 then
-- Register nodes based on the phonics data
for key, value in pairs(phonics) do
-- Generate the nodes underground using the register_ore function
minetest.register_ore({
ore_type = "scatter",
ore = "phonics:" .. key,
wherein = "default:stone",
clust_scarcity = phonics_scarcity,
clust_num_ores = 1,
clust_size = 1,
y_min = -31000, -- Adjust these values for your desired depth range
y_max = 100,
})
if phonics[key].is_letter ==1 then
minetest.register_ore({
ore_type = "scatter",
ore = "phonics:0" .. key,
wherein = "default:stone",
clust_scarcity = phonics_scarcity,
clust_num_ores = 1,
clust_size = 1,
y_min = -31000, -- Adjust these values for your desired depth range
y_max = 100,
})
end
end
minetest.register_ore({
ore_type = "scatter",
ore = "phonics:SayWord",
wherein = "default:stone",
clust_scarcity = phonics_scarcity,
clust_num_ores = 1,
clust_size = 1,
y_min = -31000, -- Adjust these values for your desired depth range
y_max = 100,
})
minetest.register_ore({
ore_type = "scatter",
ore = "phonics:PaperStart",
wherein = "default:stone",
clust_scarcity = phonics_scarcity,
clust_num_ores = 1,
clust_size = 1,
y_min = -31000, -- Adjust these values for your desired depth range
y_max = 100,
})
minetest.register_ore({
ore_type = "scatter",
ore = "phonics:PaperFinish",
wherein = "default:stone",
clust_scarcity = phonics_scarcity,
clust_num_ores = 1,
clust_size = 1,
y_min = -31000, -- Adjust these values for your desired depth range
y_max = 100,
})
minetest.register_ore({
ore_type = "scatter",
ore = "phonics:period",
wherein = "default:stone",
clust_scarcity = phonics_scarcity,
clust_num_ores = 1,
clust_size = 1,
y_min = -31000, -- Adjust these values for your desired depth range
y_max = 100,
})
minetest.register_ore({
ore_type = "scatter",
ore = "phonics:exclamation_point",
wherein = "default:stone",
clust_scarcity = phonics_scarcity,
clust_num_ores = 1,
clust_size = 1,
y_min = -31000, -- Adjust these values for your desired depth range
y_max = 100,
})
minetest.register_ore({
ore_type = "scatter",
ore = "phonics:question_mark",
wherein = "default:stone",
clust_scarcity = phonics_scarcity,
clust_num_ores = 1,
clust_size = 1,
y_min = -31000, -- Adjust these values for your desired depth range
y_max = 100,
})
end
local dpath = minetest.get_modpath("phonics") .. "/"
dofile(dpath .. "crafting.lua")
print("Phonics Mod Loaded!")
--minetest.env:punch_node(pos)
--minetest.env:dig_node(pos)
--http://minetest.net/forum/viewtopic.php?id=2602
--https://c9.io/lkjoel/minetest-modder/workspace/parseme.txt