forked from minetest-mods/nether
-
Notifications
You must be signed in to change notification settings - Fork 0
/
portal_api.lua
2389 lines (2011 loc) · 102 KB
/
portal_api.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
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--[[
Portal API for Minetest
See portal_api.txt for documentation
--
Copyright (C) 2020 Treer
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
]]--
-- setting DEBUG_IGNORE_MODSTORAGE true prevents portals from knowing where other
-- portals are, forcing find_realm_anchorpos() etc. to be executed every time.
local DEBUG_IGNORE_MODSTORAGE = false
nether.registered_portals = {}
nether.registered_portals_count = 0
-- Exposes a list of node names that are used as frame nodes by registered portals
nether.is_frame_node = {}
-- gives the colour values in nether_portals_palette.png that are used by the wormhole colorfacedir
-- hardware colouring.
nether.portals_palette = {
[0] = {r = 128, g = 0, b = 128, asString = "#800080"}, -- traditional/magenta
[1] = {r = 0, g = 0, b = 0, asString = "#000000"}, -- black
[2] = {r = 19, g = 19, b = 255, asString = "#1313FF"}, -- blue
[3] = {r = 55, g = 168, b = 0, asString = "#37A800"}, -- green
[4] = {r = 141, g = 237, b = 255, asString = "#8DEDFF"}, -- cyan
[5] = {r = 221, g = 0, b = 0, asString = "#DD0000"}, -- red
[6] = {r = 255, g = 240, b = 0, asString = "#FFF000"}, -- yellow
[7] = {r = 255, g = 255, b = 255, asString = "#FFFFFF"} -- white
}
if minetest.get_mod_storage == nil then
error(nether.modname .. " does not support Minetest versions earlier than 0.4.16", 0)
end
local S = nether.get_translator
nether.portal_destination_not_found_message =
S("Mysterious forces prevented you from opening that portal. Please try another location")
--[[
Positions
=========
p1 & p2 p1 and p2 is the system used by earlier versions of the nether mod, which the portal_api
is forwards and backwards compatible with.
p1 is the bottom/west/south corner of the portal, and p2 is the opposite corner, together
they define the bounding volume for the portal.
The value of p1 and p2 is kept in the metadata of every node in the portal
WormholePos The location of the node that a portal's target is set to, and a player is teleported
to. It can also be used to test whether a portal is active.
AnchorPos Introduced by the portal_api. Coordinates for portals are normally given in terms of
the AnchorPos. The AnchorPos does not change with portal orientation - portals rotate
around the AnchorPos. Ideally an AnchorPos would be near the bottom center of a portal
shape, but this is not the case with PortalShape_Traditional to keep comptaibility with
earlier versions of the nether mod.
Usually an orientation is required with an AnchorPos.
Orientation is yaw, either 0 or 90, 0 meaning a portal that faces north/south - i.e. obsidian
running east/west.
TimerPos The portal_api replaces ABMs with a single node timer per portal, and the TimerPos is the
node in which that timer is located. Extra metadata is also kept in the TimerPos node.
Portal shapes
=============
For the PortalShape_Traditional implementation, p1, p2, anchorPos, wormholdPos and TimerPos are defined
as follows:
.
+--------+--------+--------+--------+
| | Frame | |
| | | | p2 |
+--------+--------+--------+--------+
| | | |
| | | |
+--------+ + +--------+
| | Wormhole | |
| | | |
+--------+ + +--------+
| |Wormhole | |
| | Pos | |
+--------+--------+--------+--------+
AnchorPos|TimerPos| | |
| p1 | | | |
+--------+--------+--------+--------+
+X/East or +Z/North ----->
A better location for AnchorPos would be directly under WormholePos, as it's more centered
and you don't need to know the portal's orientation to find AnchorPos from the WormholePos
or vice-versa, however AnchorPos is in the bottom/south/west-corner to keep compatibility
with earlier versions of nether mod (which only records portal corners p1 & p2 in the node
metadata).
]]
local facedir_up, facedir_north, facedir_south, facedir_east, facedir_west, facedir_down = 0, 4, 8, 12, 16, 20
local __ = {name = "air", prob = 0}
local AA = {name = "air", prob = 255, force_place = true}
local ON = {name = "default:obsidian", facedir = facedir_north + 0, prob = 255, force_place = true}
local ON2 = {name = "default:obsidian", facedir = facedir_north + 1, prob = 255, force_place = true}
local ON3 = {name = "default:obsidian", facedir = facedir_north + 2, prob = 255, force_place = true}
local ON4 = {name = "default:obsidian", facedir = facedir_north + 3, prob = 255, force_place = true}
local OS = {name = "default:obsidian", facedir = facedir_south, prob = 255, force_place = true}
local OE = {name = "default:obsidian", facedir = facedir_east, prob = 255, force_place = true}
local OW = {name = "default:obsidian", facedir = facedir_west, prob = 255, force_place = true}
local OU = {name = "default:obsidian", facedir = facedir_up + 0, prob = 255, force_place = true}
local OU2 = {name = "default:obsidian", facedir = facedir_up + 1, prob = 255, force_place = true}
local OU3 = {name = "default:obsidian", facedir = facedir_up + 2, prob = 255, force_place = true}
local OU4 = {name = "default:obsidian", facedir = facedir_up + 3, prob = 255, force_place = true}
local OD = {name = "default:obsidian", facedir = facedir_down, prob = 255, force_place = true}
-- facedirNodeList is a list of node references which should have their facedir value copied into
-- param2 before placing a schematic. The facedir values will only be copied when the portal's frame
-- node has a paramtype2 of "facedir" or "colorfacedir".
-- Having schematics provide this list avoids needing to check every node in the schematic volume.
local facedirNodeList = {ON, ON2, ON3, ON4, OS, OE, OW, OU, OU2, OU3, OU4, OD}
-- This object defines a portal's shape, segregating the shape logic code from portal behaviour code.
-- You can create a new "PortalShape" definition object which implements the same
-- functions if you wish to register a custom shaped portal in register_portal(). Examples of other
-- shapes follow after PortalShape_Traditional.
-- Since it's symmetric, this PortalShape definition has only implemented orientations of 0 and 90
nether.PortalShape_Traditional = {
name = "Traditional",
size = vector.new(4, 5, 1), -- size of the portal, and not necessarily the size of the schematic,
-- which may clear area around the portal.
is_horizontal = false, -- whether the wormhole is a vertical or horizontal surface
diagram_image = {
image = "nether_book_diagram_traditional.png", -- The diagram to be shown in the Book of Portals
width = 142,
height = 305
},
-- returns the coords for minetest.place_schematic() that will place the schematic on the anchorPos
get_schematicPos_from_anchorPos = function(anchorPos, orientation)
assert(orientation, "no orientation passed")
if orientation == 0 then
return {x = anchorPos.x, y = anchorPos.y, z = anchorPos.z - 2}
else
return {x = anchorPos.x - 2, y = anchorPos.y, z = anchorPos.z }
end
end,
get_wormholePos_from_anchorPos = function(anchorPos, orientation)
assert(orientation, "no orientation passed")
if orientation == 0 then
return {x = anchorPos.x + 1, y = anchorPos.y + 1, z = anchorPos.z }
else
return {x = anchorPos.x, y = anchorPos.y + 1, z = anchorPos.z + 1}
end
end,
get_anchorPos_from_wormholePos = function(wormholePos, orientation)
assert(orientation, "no orientation passed")
if orientation == 0 then
return {x = wormholePos.x - 1, y = wormholePos.y - 1, z = wormholePos.z }
else
return {x = wormholePos.x, y = wormholePos.y - 1, z = wormholePos.z - 1}
end
end,
-- p1 and p2 are used to keep maps compatible with earlier versions of this mod.
-- p1 is the bottom/west/south corner of the portal, and p2 is the opposite corner, together
-- they define the bounding volume for the portal.
get_p1_and_p2_from_anchorPos = function(self, anchorPos, orientation)
assert(orientation, "no orientation passed")
assert(self ~= nil and self.name == nether.PortalShape_Traditional.name, "Must pass self as first argument, or use shape:func() instead of shape.func()")
local p1 = anchorPos -- PortalShape_Traditional puts the anchorPos at p1 for backwards&forwards compatibility
local p2
if orientation == 0 then
p2 = {x = p1.x + self.size.x - 1, y = p1.y + self.size.y - 1, z = p1.z }
else
p2 = {x = p1.x, y = p1.y + self.size.y - 1, z = p1.z + self.size.x - 1}
end
return p1, p2
end,
get_anchorPos_and_orientation_from_p1_and_p2 = function(p1, p2)
if p1.z == p2.z then
return p1, 0
elseif p1.x == p2.x then
return p1, 90
else
-- this KISS implementation will break you've made a 3D PortalShape definition
minetest.log("error", "get_anchorPos_and_orientation_from_p1_and_p2 failed on p1=" .. minetest.pos_to_string(p1) .. " p2=" .. minetest.pos_to_string(p2))
end
end,
-- returns true if function was applied to all frame nodes
apply_func_to_frame_nodes = function(anchorPos, orientation, func)
-- a 4x5 portal is small enough that hardcoded positions is simpler that procedural code
local shortCircuited
if orientation == 0 then
-- use short-circuiting of boolean evaluation to allow func() to cause an abort by returning true
shortCircuited =
func({x = anchorPos.x + 0, y = anchorPos.y, z = anchorPos.z}) or
func({x = anchorPos.x + 1, y = anchorPos.y, z = anchorPos.z}) or
func({x = anchorPos.x + 2, y = anchorPos.y, z = anchorPos.z}) or
func({x = anchorPos.x + 3, y = anchorPos.y, z = anchorPos.z}) or
func({x = anchorPos.x + 0, y = anchorPos.y + 4, z = anchorPos.z}) or
func({x = anchorPos.x + 1, y = anchorPos.y + 4, z = anchorPos.z}) or
func({x = anchorPos.x + 2, y = anchorPos.y + 4, z = anchorPos.z}) or
func({x = anchorPos.x + 3, y = anchorPos.y + 4, z = anchorPos.z}) or
func({x = anchorPos.x, y = anchorPos.y + 1, z = anchorPos.z}) or
func({x = anchorPos.x, y = anchorPos.y + 2, z = anchorPos.z}) or
func({x = anchorPos.x, y = anchorPos.y + 3, z = anchorPos.z}) or
func({x = anchorPos.x + 3, y = anchorPos.y + 1, z = anchorPos.z}) or
func({x = anchorPos.x + 3, y = anchorPos.y + 2, z = anchorPos.z}) or
func({x = anchorPos.x + 3, y = anchorPos.y + 3, z = anchorPos.z})
else
shortCircuited =
func({x = anchorPos.x, y = anchorPos.y, z = anchorPos.z + 0}) or
func({x = anchorPos.x, y = anchorPos.y, z = anchorPos.z + 1}) or
func({x = anchorPos.x, y = anchorPos.y, z = anchorPos.z + 2}) or
func({x = anchorPos.x, y = anchorPos.y, z = anchorPos.z + 3}) or
func({x = anchorPos.x, y = anchorPos.y + 4, z = anchorPos.z + 0}) or
func({x = anchorPos.x, y = anchorPos.y + 4, z = anchorPos.z + 1}) or
func({x = anchorPos.x, y = anchorPos.y + 4, z = anchorPos.z + 2}) or
func({x = anchorPos.x, y = anchorPos.y + 4, z = anchorPos.z + 3}) or
func({x = anchorPos.x, y = anchorPos.y + 1, z = anchorPos.z }) or
func({x = anchorPos.x, y = anchorPos.y + 2, z = anchorPos.z }) or
func({x = anchorPos.x, y = anchorPos.y + 3, z = anchorPos.z }) or
func({x = anchorPos.x, y = anchorPos.y + 1, z = anchorPos.z + 3}) or
func({x = anchorPos.x, y = anchorPos.y + 2, z = anchorPos.z + 3}) or
func({x = anchorPos.x, y = anchorPos.y + 3, z = anchorPos.z + 3})
end
return not shortCircuited
end,
-- returns true if function was applied to all wormhole nodes
apply_func_to_wormhole_nodes = function(anchorPos, orientation, func)
local shortCircuited
if orientation == 0 then
local wormholePos = {x = anchorPos.x + 1, y = anchorPos.y + 1, z = anchorPos.z}
-- use short-circuiting of boolean evaluation to allow func() to cause an abort by returning true
shortCircuited =
func({x = wormholePos.x + 0, y = wormholePos.y + 0, z = wormholePos.z}) or
func({x = wormholePos.x + 1, y = wormholePos.y + 0, z = wormholePos.z}) or
func({x = wormholePos.x + 0, y = wormholePos.y + 1, z = wormholePos.z}) or
func({x = wormholePos.x + 1, y = wormholePos.y + 1, z = wormholePos.z}) or
func({x = wormholePos.x + 0, y = wormholePos.y + 2, z = wormholePos.z}) or
func({x = wormholePos.x + 1, y = wormholePos.y + 2, z = wormholePos.z})
else
local wormholePos = {x = anchorPos.x, y = anchorPos.y + 1, z = anchorPos.z + 1}
shortCircuited =
func({x = wormholePos.x, y = wormholePos.y + 0, z = wormholePos.z + 0}) or
func({x = wormholePos.x, y = wormholePos.y + 0, z = wormholePos.z + 1}) or
func({x = wormholePos.x, y = wormholePos.y + 1, z = wormholePos.z + 0}) or
func({x = wormholePos.x, y = wormholePos.y + 1, z = wormholePos.z + 1}) or
func({x = wormholePos.x, y = wormholePos.y + 2, z = wormholePos.z + 0}) or
func({x = wormholePos.x, y = wormholePos.y + 2, z = wormholePos.z + 1})
end
return not shortCircuited
end,
-- Check for whether the portal is blocked in, and if so then provide a safe way
-- on one side for the player to step out of the portal. Suggest including a roof
-- incase the portal was blocked with lava flowing from above.
-- If portal can appear in mid-air then can also check for that and add a platform.
disable_portal_trap = function(anchorPos, orientation)
assert(orientation, "no orientation passed")
-- Not implemented yet. It may not need to be implemented because if you
-- wait in a portal long enough you teleport again. So a trap portal would have to link
-- to one of two blocked-in portals which link to each other - which is possible, but
-- quite extreme.
end,
schematic = {
size = {x = 4, y = 5, z = 5},
data = { -- note that data is upside down
__,__,__,__,
AA,AA,AA,AA,
AA,AA,AA,AA,
AA,AA,AA,AA,
AA,AA,AA,AA,
__,__,__,__,
AA,AA,AA,AA,
AA,AA,AA,AA,
AA,AA,AA,AA,
AA,AA,AA,AA,
ON,OW,OE,ON2,
OU,AA,AA,OU,
OU,AA,AA,OU,
OU,AA,AA,OU,
ON4,OE,OW,ON3,
__,__,__,__,
AA,AA,AA,AA,
AA,AA,AA,AA,
AA,AA,AA,AA,
AA,AA,AA,AA,
__,__,__,__,
AA,AA,AA,AA,
AA,AA,AA,AA,
AA,AA,AA,AA,
AA,AA,AA,AA,
},
facedirNodes = facedirNodeList
}
} -- End of PortalShape_Traditional class
-- Example alternative PortalShape
nether.PortalShape_Circular = {
name = "Circular",
size = vector.new(7, 7, 1), -- size of the portal, and not necessarily the size of the schematic,
-- which may clear area around the portal.
is_horizontal = false, -- whether the wormhole is a vertical or horizontal surface
diagram_image = {
image = "nether_book_diagram_circular.png", -- The diagram to be shown in the Book of Portals
width = 149,
height = 243
},
-- returns the coords for minetest.place_schematic() that will place the schematic on the anchorPos
get_schematicPos_from_anchorPos = function(anchorPos, orientation)
assert(orientation, "no orientation passed")
if orientation == 0 then
return {x = anchorPos.x - 3, y = anchorPos.y, z = anchorPos.z - 3}
else
return {x = anchorPos.x - 3, y = anchorPos.y, z = anchorPos.z - 3 }
end
end,
get_wormholePos_from_anchorPos = function(anchorPos, orientation)
-- wormholePos is the node above anchorPos
return {x = anchorPos.x, y = anchorPos.y + 1, z = anchorPos.z}
end,
get_anchorPos_from_wormholePos = function(wormholePos, orientation)
-- wormholePos is the node above anchorPos
return {x = wormholePos.x, y = wormholePos.y - 1, z = wormholePos.z}
end,
-- p1 and p2 are used to keep maps compatible with earlier versions of this mod.
-- p1 is the bottom/west/south corner of the portal, and p2 is the opposite corner, together
-- they define the bounding volume for the portal.
get_p1_and_p2_from_anchorPos = function(self, anchorPos, orientation)
assert(orientation, "no orientation passed")
assert(self ~= nil and self.name == nether.PortalShape_Circular.name, "Must pass self as first argument, or use shape:func() instead of shape.func()")
local p1
local p2
if orientation == 0 then
p1 = {x = anchorPos.x - 3, y = anchorPos.y, z = anchorPos.z }
p2 = {x = p1.x + self.size.x - 1, y = p1.y + self.size.y - 1, z = p1.z }
else
p1 = {x = anchorPos.x, y = anchorPos.y, z = anchorPos.z - 3 }
p2 = {x = p1.x, y = p1.y + self.size.y - 1, z = p1.z + self.size.x - 1}
end
return p1, p2
end,
get_anchorPos_and_orientation_from_p1_and_p2 = function(p1, p2)
if p1.z == p2.z then
return {x= p1.x + 3, y = p1.y, z = p1.z }, 0
elseif p1.x == p2.x then
return {x= p1.x, y = p1.y, z = p1.z + 3}, 90
end
end,
apply_func_to_frame_nodes = function(anchorPos, orientation, func)
local shortCircuited
if orientation == 0 then
-- use short-circuiting of boolean evaluation to allow func() to cause an abort by returning true
shortCircuited =
func({x = anchorPos.x + 0, y = anchorPos.y + 0, z = anchorPos.z}) or
func({x = anchorPos.x + 1, y = anchorPos.y + 0, z = anchorPos.z}) or func({x = anchorPos.x - 1, y = anchorPos.y + 0, z = anchorPos.z}) or
func({x = anchorPos.x + 2, y = anchorPos.y + 1, z = anchorPos.z}) or func({x = anchorPos.x - 2, y = anchorPos.y + 1, z = anchorPos.z}) or
func({x = anchorPos.x + 3, y = anchorPos.y + 2, z = anchorPos.z}) or func({x = anchorPos.x - 3, y = anchorPos.y + 2, z = anchorPos.z}) or
func({x = anchorPos.x + 3, y = anchorPos.y + 3, z = anchorPos.z}) or func({x = anchorPos.x - 3, y = anchorPos.y + 3, z = anchorPos.z}) or
func({x = anchorPos.x + 3, y = anchorPos.y + 4, z = anchorPos.z}) or func({x = anchorPos.x - 3, y = anchorPos.y + 4, z = anchorPos.z}) or
func({x = anchorPos.x + 2, y = anchorPos.y + 5, z = anchorPos.z}) or func({x = anchorPos.x - 2, y = anchorPos.y + 5, z = anchorPos.z}) or
func({x = anchorPos.x + 1, y = anchorPos.y + 6, z = anchorPos.z}) or func({x = anchorPos.x - 1, y = anchorPos.y + 6, z = anchorPos.z}) or
func({x = anchorPos.x + 0, y = anchorPos.y + 6, z = anchorPos.z})
else
shortCircuited =
func({x = anchorPos.x, y = anchorPos.y + 0, z = anchorPos.z + 0}) or
func({x = anchorPos.x, y = anchorPos.y + 0, z = anchorPos.z + 1}) or func({x = anchorPos.x, y = anchorPos.y + 0, z = anchorPos.z - 1}) or
func({x = anchorPos.x, y = anchorPos.y + 1, z = anchorPos.z + 2}) or func({x = anchorPos.x, y = anchorPos.y + 1, z = anchorPos.z - 2}) or
func({x = anchorPos.x, y = anchorPos.y + 2, z = anchorPos.z + 3}) or func({x = anchorPos.x, y = anchorPos.y + 2, z = anchorPos.z - 3}) or
func({x = anchorPos.x, y = anchorPos.y + 3, z = anchorPos.z + 3}) or func({x = anchorPos.x, y = anchorPos.y + 3, z = anchorPos.z - 3}) or
func({x = anchorPos.x, y = anchorPos.y + 4, z = anchorPos.z + 3}) or func({x = anchorPos.x, y = anchorPos.y + 4, z = anchorPos.z - 3}) or
func({x = anchorPos.x, y = anchorPos.y + 5, z = anchorPos.z + 2}) or func({x = anchorPos.x, y = anchorPos.y + 5, z = anchorPos.z - 2}) or
func({x = anchorPos.x, y = anchorPos.y + 6, z = anchorPos.z + 1}) or func({x = anchorPos.x, y = anchorPos.y + 6, z = anchorPos.z - 1}) or
func({x = anchorPos.x, y = anchorPos.y + 6, z = anchorPos.z + 0})
end
return not shortCircuited
end,
-- returns true if function was applied to all wormhole nodes
apply_func_to_wormhole_nodes = function(anchorPos, orientation, func)
local xRange = 2
local zRange = 0
if orientation ~= 0 then
xRange = 0
zRange = 2
end
local xEdge, yEdge, zEdge
local pos = {}
for x = -xRange, xRange do
pos.x = anchorPos.x + x
xEdge = x == -xRange or x == xRange
for z = -zRange, zRange do
zEdge = z == -zRange or z == zRange
pos.z = anchorPos.z + z
for y = 1, 5 do
yEdge = y == 1 or y == 5
if not (yEdge and xEdge and zEdge) then
pos.y = anchorPos.y + y
if func(pos) then
-- func() caused an abort by returning true
return false
end
end
end
end
end
return true
end,
-- Check for whether the portal is blocked in, and if so then provide a safe way
-- on one side for the player to step out of the portal. Suggest including a roof
-- incase the portal was blocked with lava flowing from above.
-- If portal can appear in mid-air then can also check for that and add a platform.
disable_portal_trap = function(anchorPos, orientation)
assert(orientation, "no orientation passed")
-- Not implemented.
end,
schematic = {
size = {x = 7, y = 7, z = 7},
data = { -- note that data is upside down
__,__,__,__,__,__,__,
__,__,__,__,__,__,__,
__,__,AA,AA,AA,__,__,
__,__,AA,AA,AA,__,__,
__,__,AA,AA,AA,__,__,
__,__,__,__,__,__,__,
__,__,__,__,__,__,__,
__,__,__,__,__,__,__,
__,AA,AA,AA,AA,AA,__,
__,AA,AA,AA,AA,AA,__,
__,AA,AA,AA,AA,AA,__,
__,AA,AA,AA,AA,AA,__,
__,AA,AA,AA,AA,AA,__,
__,__,__,__,__,__,__,
__,__,__,__,__,__,__,
__,AA,AA,AA,AA,AA,__,
AA,AA,AA,AA,AA,AA,AA,
AA,AA,AA,AA,AA,AA,AA,
AA,AA,AA,AA,AA,AA,AA,
__,AA,AA,AA,AA,AA,__,
__,__,AA,AA,AA,__,__,
__,__,OW,OW,OW,__,__,
__,ON,AA,AA,AA,ON2,__,
OU,AA,AA,AA,AA,AA,OD,
OU,AA,AA,AA,AA,AA,OD,
OU,AA,AA,AA,AA,AA,OD,
__,ON4,AA,AA,AA,ON3,__,
__,__,OE,OE,OE,__,__,
__,__,__,__,__,__,__,
__,AA,AA,AA,AA,AA,__,
AA,AA,AA,AA,AA,AA,AA,
AA,AA,AA,AA,AA,AA,AA,
AA,AA,AA,AA,AA,AA,AA,
__,AA,AA,AA,AA,AA,__,
__,__,AA,AA,AA,__,__,
__,__,__,__,__,__,__,
__,AA,AA,AA,AA,AA,__,
__,AA,AA,AA,AA,AA,__,
__,AA,AA,AA,AA,AA,__,
__,AA,AA,AA,AA,AA,__,
__,AA,AA,AA,AA,AA,__,
__,__,__,__,__,__,__,
__,__,__,__,__,__,__,
__,__,__,__,__,__,__,
__,__,AA,AA,AA,__,__,
__,__,AA,AA,AA,__,__,
__,__,AA,AA,AA,__,__,
__,__,__,__,__,__,__,
__,__,__,__,__,__,__,
},
facedirNodes = facedirNodeList
}
} -- End of PortalShape_Circular class
-- Example alternative PortalShape
-- This platform shape is symmetrical around the y-axis, so the orientation value never matters.
nether.PortalShape_Platform = {
name = "Platform",
size = vector.new(5, 2, 5), -- size of the portal, and not necessarily the size of the schematic,
-- which may clear area around the portal.
is_horizontal = true, -- whether the wormhole is a vertical or horizontal surface
diagram_image = {
image = "nether_book_diagram_platform.png", -- The diagram to be shown in the Book of Portals
width = 200,
height = 130
},
-- returns the coords for minetest.place_schematic() that will place the schematic on the anchorPos
get_schematicPos_from_anchorPos = function(anchorPos, orientation)
return {x = anchorPos.x - 2, y = anchorPos.y, z = anchorPos.z - 2}
end,
get_wormholePos_from_anchorPos = function(anchorPos, orientation)
-- wormholePos is the node above anchorPos
return {x = anchorPos.x, y = anchorPos.y + 1, z = anchorPos.z}
end,
get_anchorPos_from_wormholePos = function(wormholePos, orientation)
-- wormholePos is the node above anchorPos
return {x = wormholePos.x, y = wormholePos.y - 1, z = wormholePos.z}
end,
-- p1 and p2 are used to keep maps compatible with earlier versions of this mod.
-- p1 is the bottom/west/south corner of the portal, and p2 is the opposite corner, together
-- they define the bounding volume for the portal.
get_p1_and_p2_from_anchorPos = function(self, anchorPos, orientation)
assert(self ~= nil and self.name == nether.PortalShape_Platform.name, "Must pass self as first argument, or use shape:func() instead of shape.func()")
local p1 = {x = anchorPos.x - 2, y = anchorPos.y, z = anchorPos.z - 2}
local p2 = {x = anchorPos.x + 2, y = anchorPos.y + 1, z = anchorPos.z + 2}
return p1, p2
end,
get_anchorPos_and_orientation_from_p1_and_p2 = function(p1, p2)
return {x= p1.x + 2, y = p1.y, z = p1.z + 2}, 0
end,
apply_func_to_frame_nodes = function(anchorPos, orientation, func)
local shortCircuited
local yPlus1 = anchorPos.y + 1
-- use short-circuiting of boolean evaluation to allow func() to cause an abort by returning true
shortCircuited =
func({x = anchorPos.x - 2, y = yPlus1, z = anchorPos.z - 1}) or func({x = anchorPos.x + 2, y = yPlus1, z = anchorPos.z - 1}) or
func({x = anchorPos.x - 2, y = yPlus1, z = anchorPos.z }) or func({x = anchorPos.x + 2, y = yPlus1, z = anchorPos.z }) or
func({x = anchorPos.x - 2, y = yPlus1, z = anchorPos.z + 1}) or func({x = anchorPos.x + 2, y = yPlus1, z = anchorPos.z + 1}) or
func({x = anchorPos.x - 1, y = yPlus1, z = anchorPos.z - 2}) or func({x = anchorPos.x - 1, y = yPlus1, z = anchorPos.z + 2}) or
func({x = anchorPos.x , y = yPlus1, z = anchorPos.z - 2}) or func({x = anchorPos.x , y = yPlus1, z = anchorPos.z + 2}) or
func({x = anchorPos.x + 1, y = yPlus1, z = anchorPos.z - 2}) or func({x = anchorPos.x + 1, y = yPlus1, z = anchorPos.z + 2}) or
func({x = anchorPos.x - 1, y = anchorPos.y, z = anchorPos.z - 1}) or
func({x = anchorPos.x - 1, y = anchorPos.y, z = anchorPos.z }) or
func({x = anchorPos.x - 1, y = anchorPos.y, z = anchorPos.z + 1}) or
func({x = anchorPos.x , y = anchorPos.y, z = anchorPos.z - 1}) or
func({x = anchorPos.x , y = anchorPos.y, z = anchorPos.z }) or
func({x = anchorPos.x , y = anchorPos.y, z = anchorPos.z + 1}) or
func({x = anchorPos.x + 1, y = anchorPos.y, z = anchorPos.z - 1}) or
func({x = anchorPos.x + 1, y = anchorPos.y, z = anchorPos.z }) or
func({x = anchorPos.x + 1, y = anchorPos.y, z = anchorPos.z + 1})
return not shortCircuited
end,
-- returns true if function was applied to all wormhole nodes
apply_func_to_wormhole_nodes = function(anchorPos, orientation, func)
local shortCircuited
local yPlus1 = anchorPos.y + 1
-- use short-circuiting of boolean evaluation to allow func() to cause an abort by returning true
shortCircuited =
func({x = anchorPos.x - 1, y = yPlus1, z = anchorPos.z - 1}) or
func({x = anchorPos.x - 1, y = yPlus1, z = anchorPos.z }) or
func({x = anchorPos.x - 1, y = yPlus1, z = anchorPos.z + 1}) or
func({x = anchorPos.x , y = yPlus1, z = anchorPos.z - 1}) or
func({x = anchorPos.x , y = yPlus1, z = anchorPos.z }) or
func({x = anchorPos.x , y = yPlus1, z = anchorPos.z + 1}) or
func({x = anchorPos.x + 1, y = yPlus1, z = anchorPos.z - 1}) or
func({x = anchorPos.x + 1, y = yPlus1, z = anchorPos.z }) or
func({x = anchorPos.x + 1, y = yPlus1, z = anchorPos.z + 1})
return not shortCircuited
end,
-- Check for suffocation
disable_portal_trap = function(anchorPos, orientation)
-- Not implemented.
end,
schematic = {
size = {x = 5, y = 5, z = 5},
data = { -- note that data is upside down
__,__,__,__,__,
OU4,OW,OW,OW,OU3,
__,AA,AA,AA,__,
__,AA,AA,AA,__,
__,__,__,__,__,
__,OU4,OW,OU3,__,
ON,AA,AA,AA,OS,
AA,AA,AA,AA,AA,
AA,AA,AA,AA,AA,
__,AA,AA,AA,__,
__,ON,OD,OS,__,
ON,AA,AA,AA,OS,
AA,AA,AA,AA,AA,
AA,AA,AA,AA,AA,
__,AA,AA,AA,__,
__,OU,OE,OU2,__,
ON,AA,AA,AA,OS,
AA,AA,AA,AA,AA,
AA,AA,AA,AA,AA,
__,AA,AA,AA,__,
__,__,__,__,__,
OU,OE,OE,OE,OU2,
__,AA,AA,AA,__,
__,AA,AA,AA,__,
__,__,__,__,__,
},
facedirNodes = facedirNodeList
}
} -- End of PortalShape_Platform class
--====================================================--
--======== End of PortalShape implementations ========--
--====================================================--
-- Portal implementation functions --
-- =============================== --
local debugf = nether.debug
local ignition_item_name
local mod_storage = minetest.get_mod_storage()
local meseconsAvailable = minetest.get_modpath("mesecon") ~= nil and minetest.global_exists("mesecon")
local book_added_as_treasure = false
local function get_timerPos_from_p1_and_p2(p1, p2)
-- Pick a frame node for the portal's timer.
--
-- The timer event will need to know the portal definition, which can be determined by
-- what the portal frame is made from, so the timer node should be on the frame.
-- The timer event will also need to know its portal orientation, but unless someone
-- makes a cubic portal shape, orientation can be determined from p1 and p2 in the node's
-- metadata (frame nodes don't have orientation set in param2 like wormhole nodes do).
--
-- We shouldn't pick p1 or p2 as it's possible for two orthogonal portals to share
-- the same p1, etc. - or at least it was - there's code to try to stop that now.
--
-- I'll pick the bottom center node of the portal, since that works for rectangular portals
-- and if someone want to make a circular portal then that positon will still likely be part
-- of the frame.
return {
x = math.floor((p1.x + p2.x) / 2),
y = p1.y,
z = math.floor((p1.z + p2.z) / 2),
}
end
-- orientation is the yaw rotation degrees passed to place_schematic: 0, 90, 180, or 270
-- color is a value from 0 to 7 corresponding to the color of pixels in nether_portals_palette.png
-- portal_is_horizontal is a bool indicating whether the portal lies flat or stands vertically
local function get_colorfacedir_from_color_and_orientation(color, orientation, portal_is_horizontal)
assert(orientation, "no orientation passed")
local axis_direction, rotation
local dir = math.floor((orientation % 360) / 90 + 0.5)
-- if the portal is vertical then node axis direction will be +Y (up) and portal orientation
-- will set the node's rotation.
-- if the portal is horizontal then the node axis direction reflects the yaw orientation and
-- the node's rotation will be whatever's needed to keep the texture horizontal (either 0 or 1)
if portal_is_horizontal then
if dir == 0 then axis_direction = 1 end -- North
if dir == 1 then axis_direction = 3 end -- East
if dir == 2 then axis_direction = 2 end -- South
if dir == 3 then axis_direction = 4 end -- West
rotation = math.floor(axis_direction / 2); -- a rotation is only needed if axis_direction is east or west
else
axis_direction = 0 -- 0 is up, or +Y
rotation = dir
end
-- wormhole nodes have a paramtype2 of colorfacedir, which means the
-- high 3 bits are palette, followed by 3 direction bits and 2 rotation bits.
-- We set the palette bits and rotation
return rotation + axis_direction * 4 + color * 32
end
local function get_orientation_from_colorfacedir(param2)
local axis_direction = 0
-- Strip off the top 6 bits to leave the 2 rotation bits, unfortunately MT lua has no bitwise '&'
-- (high 3 bits are palette, followed by 3 direction bits then 2 rotation bits)
if param2 >= 128 then param2 = param2 - 128 end
if param2 >= 64 then param2 = param2 - 64 end
if param2 >= 32 then param2 = param2 - 32 end
if param2 >= 16 then param2 = param2 - 16; axis_direction = axis_direction + 4 end
if param2 >= 8 then param2 = param2 - 8; axis_direction = axis_direction + 2 end
if param2 >= 4 then param2 = param2 - 4; axis_direction = axis_direction + 1 end
-- if the portal is vertical then node axis direction will be +Y (up) and portal orientation
-- will set the node's rotation.
-- if the portal is horizontal then the node axis direction reflects the yaw orientation and
-- the node's rotation will be whatever's needed to keep the texture horizontal (either 0 or 1)
if axis_direction == 0 or axis_direction == 5 then
-- portal is vertical
return param2 * 90
else
if axis_direction == 1 then return 0 end
if axis_direction == 3 then return 90 end
if axis_direction == 2 then return 180 end
if axis_direction == 4 then return 270 end
end
end
-- We want wormhole nodes to only emit mesecon energy orthogonally to the
-- wormhole surface so that the wormhole will not send power to the frame,
-- this allows the portal frame to listen for mesecon energy from external switches/wires etc.
function get_mesecon_emission_rules_from_colorfacedir(param2)
local axis_direction = 0
-- Strip off the top 6 bits to leave the 2 rotation bits, unfortunately MT lua has no bitwise '&'
-- (high 3 bits are palette, followed by 3 direction bits then 2 rotation bits)
if param2 >= 128 then param2 = param2 - 128 end
if param2 >= 64 then param2 = param2 - 64 end
if param2 >= 32 then param2 = param2 - 32 end
if param2 >= 16 then param2 = param2 - 16; axis_direction = axis_direction + 4 end
if param2 >= 8 then param2 = param2 - 8; axis_direction = axis_direction + 2 end
if param2 >= 4 then param2 = param2 - 4; axis_direction = axis_direction + 1 end
-- if the portal is vertical then node axis_direction will be +Y (up) and node rotation
-- will reflect the portal's yaw orientation.
-- If the portal is horizontal then the node axis direction reflects the yaw orientation and
-- the node's rotation will be whatever's needed to keep the texture horizontal (either 0 or 1)
local rules
if axis_direction == 0 or axis_direction == 5 then
-- portal is vertical
rules = {{x = 0, y = 0, z = 1}, {x = 0, y = 0, z = -1}}
if param2 % 2 ~= 0 then
rules = mesecon.rotate_rules_right(rules)
end
else
-- portal is horizontal, only emit up
rules = {{x = 0, y = 1, z = 0}}
end
return rules
end
nether.get_mesecon_emission_rules_from_colorfacedir = get_mesecon_emission_rules_from_colorfacedir -- make the function available to nodes.lua
-- Combining frame_node_name, p1, and p2 will always be enough to uniquely identify a portal_definition
-- WITHOUT needing to inspect the world. register_portal() will enforce this.
-- This function does not require the portal to be in a loaded chunk.
-- Returns nil if no portal_definition matches the arguments
local function get_portal_definition(frame_node_name, p1, p2)
local size = vector.add(vector.subtract(p2, p1), 1)
local rotated_size = {x = size.z, y = size.y, z = size.x}
for _, portal_def in pairs(nether.registered_portals) do
if portal_def.frame_node_name == frame_node_name then
if vector.equals(size, portal_def.shape.size) or vector.equals(rotated_size, portal_def.shape.size) then
return portal_def
end
end
end
return nil
end
-- Returns a list of all portal_definitions with a frame made of frame_node_name.
-- Ideally no two portal types will be built from the same frame material so this call might be enough
-- to uniquely identify a portal_definition without needing to inspect the world, HOWEVER we shouldn't
-- cramp anyone's style and prohibit non-nether use of obsidian to make portals, so it returns a list.
-- If the list contains more than one item then routines like ignite_portal() will have to search twice
-- for a portal and take twice the CPU.
local function list_portal_definitions_for_frame_node(frame_node_name)
local result = {}
for _, portal_def in pairs(nether.registered_portals) do
if portal_def.frame_node_name == frame_node_name then table.insert(result, portal_def) end
end
return result
end
-- Add portal information to mod storage, so new portals may find existing portals near the target location.
-- Do this whenever a portal is created or changes its ignition state
local function store_portal_location_info(portal_name, anchorPos, orientation, ignited)
if not DEBUG_IGNORE_MODSTORAGE then
local key = minetest.pos_to_string(anchorPos) .. " is " .. portal_name
debugf("Adding/updating portal in mod_storage: " .. key)
mod_storage:set_string(
key,
minetest.serialize({orientation = orientation, active = ignited})
)
end
end
-- Remove portal information from mod storage.
-- Do this if a portal frame is destroyed such that it cannot be ignited anymore.
local function remove_portal_location_info(portal_name, anchorPos)
if not DEBUG_IGNORE_MODSTORAGE then
local key = minetest.pos_to_string(anchorPos) .. " is " .. portal_name
debugf("Removing portal from mod_storage: " .. key)
mod_storage:set_string(key, "")
end
end
-- Returns a table of the nearest portals to anchorPos indexed by distance, based on mod_storage
-- data.
-- Only portals in the same realm as the anchorPos will be returned, even if y_factor is 0.
-- WARNING: Portals are not checked, and inactive portals especially may have been damaged without
-- being removed from the mod_storage data. Check these portals still exist before using them, and
-- invoke remove_portal_location_info() on any found to no longer exist.
--
-- A y_factor of 0 means y does not affect the distance_limit, a y_factor of 1 means y is included,
-- and a y_factor of 2 would squash the search-sphere by a factor of 2 on the y-axis, etc.
-- Pass a nil or negative distance_limit to indicate no distance limit
local function list_closest_portals(portal_definition, anchorPos, distance_limit, y_factor)
local result = {}
if not DEBUG_IGNORE_MODSTORAGE then
local isRealm = portal_definition.is_within_realm(anchorPos)
if distance_limit == nil then distance_limit = -1 end
if y_factor == nil then y_factor = 1 end
for key, value in pairs(mod_storage:to_table().fields) do
local closingBrace = key:find(")", 6, true)
if closingBrace ~= nil then
local found_anchorPos = minetest.string_to_pos(key:sub(0, closingBrace))
if found_anchorPos ~= nil and portal_definition.is_within_realm(found_anchorPos) == isRealm then
local found_name = key:sub(closingBrace + 5)
if found_name == portal_definition.name then
local x = anchorPos.x - found_anchorPos.x
local y = anchorPos.y - found_anchorPos.y
local z = anchorPos.z - found_anchorPos.z
local distance = math.hypot(y * y_factor, math.hypot(x, z))
if distance <= distance_limit or distance_limit < 0 then
local info = minetest.deserialize(value) or {}
debugf("found %s listed at distance %.2f (within %.2f) from dest %s, found: %s orientation %s", found_name, distance, distance_limit, anchorPos, found_anchorPos, info.orientation)
info.anchorPos = found_anchorPos
info.distance = distance
result[distance] = info
end
end
end
end
end
end
return result
end
-- the timerNode is used to keep the metadata as that node already needs to be known any time a portal is stopped or run
-- see also ambient_sound_stop()
function ambient_sound_play(portal_definition, soundPos, timerNodeMeta)
if portal_definition.sounds.ambient ~= nil then
local soundLength = portal_definition.sounds.ambient.length
if soundLength == nil then soundLength = 3 end
local lastPlayed = timerNodeMeta:get_int("ambient_sound_last_played")
-- Using "os.time() % soundLength == 0" is lightweight but means delayed starts, so trying a stored lastPlayed
if os.time() >= lastPlayed + soundLength then
local soundHandle = minetest.sound_play(portal_definition.sounds.ambient, {pos = soundPos, max_hear_distance = 8})
if timerNodeMeta ~= nil then
timerNodeMeta:set_int("ambient_sound_handle", soundHandle)
timerNodeMeta:set_int("ambient_sound_last_played", os.time())
end
end
end
end
-- the timerNode is used to keep the metadata as that node already needs to be known any time a portal is stopped or run
-- see also ambient_sound_play()
function ambient_sound_stop(timerNodeMeta)
if timerNodeMeta ~= nil then
local soundHandle = timerNodeMeta:get_int("ambient_sound_handle")
minetest.sound_fade(soundHandle, -3, 0)
-- clear the metadata
timerNodeMeta:set_string("ambient_sound_handle", "")
timerNodeMeta:set_string("ambient_sound_last_played", "")
end
end
-- WARNING - this is invoked by on_destruct, so you can't assume there's an accesible node at pos
-- Returns true if a portal was found to extinguish
function extinguish_portal(pos, node_name, frame_was_destroyed)
-- mesecons seems to invoke action_off() 6 times every time you place a block?
debugf("extinguish_portal %s %s", pos, node_name)
local meta = minetest.get_meta(pos)
local p1 = minetest.string_to_pos(meta:get_string("p1"))
local p2 = minetest.string_to_pos(meta:get_string("p2"))
local target = minetest.string_to_pos(meta:get_string("target"))
if p1 == nil or p2 == nil then
debugf(" no active portal found to extinguish")
return false
end
local portal_definition = get_portal_definition(node_name, p1, p2)
if portal_definition == nil then
minetest.log("error", "extinguish_portal() invoked on " .. node_name .. " but no registered portal is constructed from " .. node_name)
return false -- no portal frames are made from this type of node
end
if portal_definition.sounds.extinguish ~= nil then
minetest.sound_play(portal_definition.sounds.extinguish, {pos = p1})
end
-- stop timer and ambient sound
local timerPos = get_timerPos_from_p1_and_p2(p1, p2)
minetest.get_node_timer(timerPos):stop()
ambient_sound_stop(minetest.get_meta(timerPos))
-- update the ignition state in the portal location info
local anchorPos, orientation = portal_definition.shape.get_anchorPos_and_orientation_from_p1_and_p2(p1, p2)
if frame_was_destroyed then
remove_portal_location_info(portal_definition.name, anchorPos)
else
store_portal_location_info(portal_definition.name, anchorPos, orientation, false)
end
local frame_node_name = portal_definition.frame_node_name
local wormhole_node_name = portal_definition.wormhole_node_name
for x = p1.x, p2.x do
for y = p1.y, p2.y do
for z = p1.z, p2.z do
local clearPos = {x = x, y = y, z = z}
local nn = minetest.get_node(clearPos).name
if nn == frame_node_name or nn == wormhole_node_name then
if nn == wormhole_node_name then
minetest.remove_node(clearPos)
if meseconsAvailable then mesecon.receptor_off(clearPos) end
end
local m = minetest.get_meta(clearPos)
m:set_string("p1", "")
m:set_string("p2", "")
m:set_string("target", "")
m:set_string("portal_type", "")
end
end
end
end
if target ~= nil then
debugf(" attempting to also extinguish target with wormholePos %s", target)
extinguish_portal(target, node_name)
end
if portal_definition.on_extinguish ~= nil then
portal_definition.on_extinguish(portal_definition, anchorPos, orientation)
end
return true