-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
CuboidTag.java
1809 lines (1614 loc) · 69.3 KB
/
CuboidTag.java
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
package com.denizenscript.denizen.objects;
import com.denizenscript.denizen.objects.notable.NotableManager;
import com.denizenscript.denizen.utilities.Utilities;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizen.utilities.depends.Depends;
import com.denizenscript.denizencore.objects.*;
import com.denizenscript.denizen.Settings;
import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.nms.interfaces.BlockData;
import com.denizenscript.denizen.nms.interfaces.BlockHelper;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.core.ListTag;
import com.denizenscript.denizencore.objects.notable.Notable;
import com.denizenscript.denizencore.objects.notable.Note;
import com.denizenscript.denizencore.tags.Attribute;
import com.denizenscript.denizencore.tags.TagContext;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class CuboidTag implements ObjectTag, Cloneable, Notable, Adjustable {
// <--[language]
// @name CuboidTag
// @group Object System
// @description
// A CuboidTag represents a cuboidal region in the world.
//
// The word 'cuboid' means a less strict cube.
// Basically: a "cuboid" is to a 3D "cube" what a "rectangle" is to a 2D "square".
//
// One 'cuboid' consists of two points: the low point and a high point.
// a CuboidTag can contain as many cuboids within itself as needed (this allows forming more complex shapes from a single CuboidTag).
//
// For format info, see <@link language cu@>
//
// -->
// <--[language]
// @name cu@
// @group Object Fetcher System
// @description
// cu@ refers to the 'object identifier' of a CuboidTag. The 'cu@' is notation for Denizen's Object
// Fetcher. The constructor for a CuboidTag is <x>,<y>,<z>,<world>|...
// For example, 'cu@1,2,3,space|4,5,6,space'.
//
// For general info, see <@link language CuboidTag>
//
// -->
// Cloning
@Override
public CuboidTag clone() throws CloneNotSupportedException {
CuboidTag cuboid = (CuboidTag) super.clone();
cuboid.pairs = new ArrayList<>(pairs.size());
for (LocationPair pair : pairs) {
cuboid.pairs.add(new LocationPair(pair.point_1.clone(), pair.point_2.clone()));
}
cuboid.filter = new ArrayList<>(filter);
return cuboid;
}
/////////////////////
// STATIC METHODS
/////////////////
public static List<CuboidTag> getNotableCuboidsContaining(Location location) {
List<CuboidTag> cuboids = new ArrayList<>();
for (CuboidTag cuboid : NotableManager.getAllType(CuboidTag.class)) {
if (cuboid.isInsideCuboid(location)) {
cuboids.add(cuboid);
}
}
return cuboids;
}
//////////////////
// OBJECT FETCHER
////////////////
public static CuboidTag valueOf(String string) {
return valueOf(string, null);
}
final static Pattern cuboid_by_saved = Pattern.compile("(cu@)?(.+)");
@Fetchable("cu")
public static CuboidTag valueOf(String string, TagContext context) {
if (string == null) {
return null;
}
////////
// Match location formats
// Split values
ListTag positions = ListTag.valueOf(string.replace("cu@", ""));
// If there's a | and the first two points look like locations, assume it's a valid location-list constructor.
if (positions.size() > 1
&& LocationTag.matches(positions.get(0))
&& LocationTag.matches(positions.get(1))) {
if (positions.size() % 2 != 0) {
if (context == null || context.debug) {
Debug.echoError("valueOf CuboidTag returning null (Uneven number of locations): '" + string + "'.");
}
return null;
}
// Form a cuboid to add to
CuboidTag toReturn = new CuboidTag();
// Add to the cuboid
for (int i = 0; i < positions.size(); i += 2) {
LocationTag pos_1 = LocationTag.valueOf(positions.get(i));
LocationTag pos_2 = LocationTag.valueOf(positions.get(i + 1));
// Must be valid locations
if (pos_1 == null || pos_2 == null) {
if (context == null || context.debug) {
Debug.echoError("valueOf in CuboidTag returning null (null locations): '" + string + "'.");
}
return null;
}
// Must have worlds
if (pos_1.getWorldName() == null || pos_2.getWorldName() == null) {
if (context == null || context.debug) {
Debug.echoError("valueOf in CuboidTag returning null (null worlds): '" + string + "'.");
}
return null;
}
toReturn.addPair(pos_1, pos_2);
}
// Ensure validity and return the created cuboid
if (toReturn.pairs.size() > 0) {
return toReturn;
}
}
////////
// Match @object format for Notable CuboidTags
Matcher m;
m = cuboid_by_saved.matcher(string);
if (m.matches() && NotableManager.isType(m.group(2), CuboidTag.class)) {
return (CuboidTag) NotableManager.getSavedObject(m.group(2));
}
if (context == null || context.debug) {
Debug.echoError("valueOf CuboidTag returning null: " + string);
}
return null;
}
// The regex below: optional-"|" + "<#.#>," x3 + <text> + "|" + "<#.#>," x3 + <text> -- repeating
final static Pattern cuboidLocations =
Pattern.compile("(\\|?([-\\d\\.]+,){3}[\\w\\s]+\\|([-\\d\\.]+,){3}[\\w\\s]+)+",
Pattern.CASE_INSENSITIVE);
public static boolean matches(String string) {
// Starts with cu@? Assume match.
if (CoreUtilities.toLowerCase(string).startsWith("cu@")) {
return true;
}
Matcher m;
// Check for named cuboid: cu@notable_cuboid
m = cuboid_by_saved.matcher(string);
if (m.matches() && NotableManager.isType(m.group(2), CuboidTag.class)) {
return true;
}
// Check for standard cuboid format: cu@x,y,z,world|x,y,z,world|...
m = cuboidLocations.matcher(string.replace("cu@", ""));
return m.matches();
}
///////////////
// LocationPairs
/////////////
public static class LocationPair {
public LocationTag low;
public LocationTag high;
LocationTag point_1;
LocationTag point_2;
int x_distance;
int y_distance;
int z_distance;
public LocationPair(LocationTag point_1, LocationTag point_2) {
this.point_1 = point_1;
this.point_2 = point_2;
regenerate();
}
public void changePoint(int number, LocationTag point) {
if (number == 1) {
this.point_1 = point;
}
else if (number == 2) {
this.point_2 = point;
}
regenerate();
}
public void regenerate() {
World world = point_1.getWorld();
// Find the low and high locations based on the points
// specified
int x_high = (point_1.getBlockX() >= point_2.getBlockX()
? point_1.getBlockX() : point_2.getBlockX());
int x_low = (point_1.getBlockX() <= point_2.getBlockX()
? point_1.getBlockX() : point_2.getBlockX());
int y_high = (point_1.getBlockY() >= point_2.getBlockY()
? point_1.getBlockY() : point_2.getBlockY());
int y_low = (point_1.getBlockY() <= point_2.getBlockY()
? point_1.getBlockY() : point_2.getBlockY());
int z_high = (point_1.getBlockZ() >= point_2.getBlockZ()
? point_1.getBlockZ() : point_2.getBlockZ());
int z_low = (point_1.getBlockZ() <= point_2.getBlockZ()
? point_1.getBlockZ() : point_2.getBlockZ());
// Specify defining locations to the pair
low = new LocationTag(world, x_low, y_low, z_low);
high = new LocationTag(world, x_high, y_high, z_high);
generateDistances();
}
public void generateDistances() {
x_distance = high.getBlockX() - low.getBlockX();
y_distance = high.getBlockY() - low.getBlockY();
z_distance = high.getBlockZ() - low.getBlockZ();
}
}
///////////////////
// Constructors/Instance Methods
//////////////////
// Location Pairs (low, high) that make up the CuboidTag
public List<LocationPair> pairs = new ArrayList<>();
// Only put MaterialTags in filter.
ArrayList<ObjectTag> filter = new ArrayList<>();
/**
* Construct the cuboid without adding pairs
* ONLY use this if addPair will be called immediately after!
*/
public CuboidTag() {
}
public CuboidTag(Location point_1, Location point_2) {
addPair(point_1, point_2);
}
public void addPair(Location point_1, Location point_2) {
if (point_1.getWorld() != point_2.getWorld()) {
Debug.echoError("Tried to make cross-world cuboid!");
return;
}
if (pairs.size() > 0 && point_1.getWorld() != getWorld()) {
Debug.echoError("Tried to make cross-world cuboid set!");
return;
}
// Make a new pair
LocationPair pair = new LocationPair(new LocationTag(point_1), new LocationTag(point_2));
// Add it to the Cuboid pairs list
pairs.add(pair);
}
public boolean isInsideCuboid(Location location) {
for (LocationPair pair : pairs) {
if (!location.getWorld().equals(pair.low.getWorld())) {
continue;
}
if (!Utilities.isBetween(pair.low.getBlockX(), pair.high.getBlockX() + 1, location.getBlockX())) {
continue;
}
if (!Utilities.isBetween(pair.low.getBlockY(), pair.high.getBlockY() + 1, location.getBlockY())) {
continue;
}
if (Utilities.isBetween(pair.low.getBlockZ(), pair.high.getBlockZ() + 1, location.getBlockZ())) {
return true;
}
}
// Does not match any of the pairs
return false;
}
public CuboidTag addBlocksToFilter(List<MaterialTag> addl) {
filter.addAll(addl);
return this;
}
public CuboidTag removeBlocksFromFilter(List<MaterialTag> addl) {
filter.removeAll(addl);
return this;
}
public CuboidTag removeFilter() {
filter.clear();
return this;
}
public CuboidTag setAsFilter(List<MaterialTag> list) {
filter.clear();
filter.addAll(list);
return this;
}
public ListTag getShell() {
int max = Settings.blockTagsMaxBlocks();
int index = 0;
ListTag list = new ListTag();
for (LocationPair pair : pairs) {
LocationTag low = pair.low;
LocationTag high = pair.high;
int y_distance = pair.y_distance;
int z_distance = pair.z_distance;
int x_distance = pair.x_distance;
for (int x = 0; x < x_distance; x++) {
for (int y = 0; y < y_distance; y++) {
list.addObject(new LocationTag(low.getWorld(), low.getBlockX() + x, low.getBlockY() + y, low.getBlockZ()));
list.addObject(new LocationTag(low.getWorld(), low.getBlockX() + x, low.getBlockY() + y, high.getBlockZ()));
index++;
if (index > max) {
return list;
}
}
for (int z = 0; z < z_distance; z++) {
list.addObject(new LocationTag(low.getWorld(), low.getBlockX() + x, low.getBlockY(), low.getBlockZ() + z));
list.addObject(new LocationTag(low.getWorld(), low.getBlockX() + x, high.getBlockY(), low.getBlockZ() + z));
index++;
if (index > max) {
return list;
}
}
}
for (int y = 0; y < y_distance; y++) {
for (int z = 0; z < z_distance; z++) {
list.addObject(new LocationTag(low.getWorld(), low.getBlockX(), low.getBlockY() + y, low.getBlockZ() + z));
list.addObject(new LocationTag(low.getWorld(), high.getBlockX(), low.getBlockY() + y, low.getBlockZ() + z));
index++;
if (index > max) {
return list;
}
}
}
}
return list;
}
public ListTag getOutline() {
// +-----2
// /| /|
// +-----+ |
// | +---|-+
// |/ |/
// 1-----+
int max = Settings.blockTagsMaxBlocks();
int index = 0;
ListTag list = new ListTag();
for (LocationPair pair : pairs) {
LocationTag loc_1 = pair.low;
LocationTag loc_2 = pair.high;
int y_distance = pair.y_distance;
int z_distance = pair.z_distance;
int x_distance = pair.x_distance;
for (int y = loc_1.getBlockY(); y < loc_1.getBlockY() + y_distance; y++) {
list.addObject(new LocationTag(loc_1.getWorld(),
loc_1.getBlockX(),
y,
loc_1.getBlockZ()));
list.addObject(new LocationTag(loc_1.getWorld(),
loc_2.getBlockX(),
y,
loc_2.getBlockZ()));
list.addObject(new LocationTag(loc_1.getWorld(),
loc_1.getBlockX(),
y,
loc_2.getBlockZ()));
list.addObject(new LocationTag(loc_1.getWorld(),
loc_2.getBlockX(),
y,
loc_1.getBlockZ()));
index++;
if (index > max) {
return list;
}
}
for (int x = loc_1.getBlockX(); x < loc_1.getBlockX() + x_distance; x++) {
list.addObject(new LocationTag(loc_1.getWorld(),
x,
loc_1.getBlockY(),
loc_1.getBlockZ()));
list.addObject(new LocationTag(loc_1.getWorld(),
x,
loc_1.getBlockY(),
loc_2.getBlockZ()));
list.addObject(new LocationTag(loc_1.getWorld(),
x,
loc_2.getBlockY(),
loc_2.getBlockZ()));
list.addObject(new LocationTag(loc_1.getWorld(),
x,
loc_2.getBlockY(),
loc_1.getBlockZ()));
index++;
if (index > max) {
return list;
}
}
for (int z = loc_1.getBlockZ(); z < loc_1.getBlockZ() + z_distance; z++) {
list.addObject(new LocationTag(loc_1.getWorld(),
loc_1.getBlockX(),
loc_1.getBlockY(),
z));
list.addObject(new LocationTag(loc_1.getWorld(),
loc_2.getBlockX(),
loc_2.getBlockY(),
z));
list.addObject(new LocationTag(loc_1.getWorld(),
loc_1.getBlockX(),
loc_2.getBlockY(),
z));
list.addObject(new LocationTag(loc_1.getWorld(),
loc_2.getBlockX(),
loc_1.getBlockY(),
z));
index++;
if (index > max) {
return list;
}
}
list.add(pair.high.identify());
}
return list;
}
public ListTag getBlocks(Attribute attribute) {
return getBlocks(null, attribute);
}
private boolean matchesMaterialList(Location loc, List<MaterialTag> materials, Attribute attribute) {
if (materials == null) {
return true;
}
MaterialTag mat = new MaterialTag(new LocationTag(loc).getBlockForTag(attribute));
for (MaterialTag material : materials) {
if (mat.equals(material) || mat.getMaterial() == material.getMaterial()) {
return true;
}
}
return false;
}
public ListTag getBlocks(List<MaterialTag> materials, Attribute attribute) {
List<LocationTag> locs = getBlocks_internal(materials, attribute);
ListTag list = new ListTag();
for (LocationTag loc : locs) {
list.add(loc.identify());
}
return list;
}
public List<LocationTag> getBlocks_internal(List<MaterialTag> materials, Attribute attribute) {
int max = Settings.blockTagsMaxBlocks();
LocationTag loc;
List<LocationTag> list = new ArrayList<>();
int index = 0;
for (LocationPair pair : pairs) {
LocationTag loc_1 = pair.low;
int y_distance = pair.y_distance;
int z_distance = pair.z_distance;
int x_distance = pair.x_distance;
for (int x = 0; x != x_distance + 1; x++) {
for (int y = 0; y != y_distance + 1; y++) {
for (int z = 0; z != z_distance + 1; z++) {
loc = new LocationTag(loc_1.clone().add(x, y, z));
if (loc.getY() < 0 || loc.getY() > 255) {
continue;
}
if (!filter.isEmpty()) { // TODO: Should 'filter' exist?
// Check filter
for (ObjectTag material : filter) {
if (((MaterialTag) material).matchesBlock(loc.getBlockForTag(attribute))) {
if (matchesMaterialList(loc, materials, attribute)) {
list.add(loc);
}
}
}
}
else {
if (matchesMaterialList(loc, materials, attribute)) {
list.add(loc);
}
}
index++;
if (index > max) {
return list;
}
}
}
}
}
return list;
}
public void setBlocks_internal(List<BlockData> materials) {
LocationTag loc;
int index = 0;
for (LocationPair pair : pairs) {
LocationTag loc_1 = pair.low;
int y_distance = pair.y_distance;
int z_distance = pair.z_distance;
int x_distance = pair.x_distance;
for (int x = 0; x != x_distance + 1; x++) {
for (int y = 0; y != y_distance + 1; y++) {
for (int z = 0; z != z_distance + 1; z++) {
if (loc_1.getY() + y >= 0 && loc_1.getY() + y < 256) {
materials.get(index).setBlock(loc_1.clone().add(x, y, z).getBlock(), false);
}
index++;
}
}
}
}
}
public BlockData getBlockAt(double nX, double nY, double nZ, List<BlockData> materials) {
LocationTag loc;
int index = 0;
// TODO: calculate rather than cheat
for (LocationPair pair : pairs) {
LocationTag loc_1 = pair.low;
int y_distance = pair.y_distance;
int z_distance = pair.z_distance;
int x_distance = pair.x_distance;
for (int x = 0; x != x_distance + 1; x++) {
for (int y = 0; y != y_distance + 1; y++) {
for (int z = 0; z != z_distance + 1; z++) {
if (x == nX && nY == y && z == nZ) {
return materials.get(index);
}
index++;
}
}
}
}
return null;
}
public List<LocationTag> getBlockLocationsUnfiltered() {
int max = Settings.blockTagsMaxBlocks();
LocationTag loc;
List<LocationTag> list = new ArrayList<>();
int index = 0;
for (LocationPair pair : pairs) {
LocationTag loc_1 = pair.low;
int y_distance = pair.y_distance;
int z_distance = pair.z_distance;
int x_distance = pair.x_distance;
for (int x = 0; x != x_distance + 1; x++) {
for (int z = 0; z != z_distance + 1; z++) {
for (int y = 0; y != y_distance + 1; y++) {
loc = new LocationTag(loc_1.clone().add(x, y, z));
list.add(loc);
index++;
if (index > max) {
return list;
}
}
}
}
}
return list;
}
public List<LocationTag> getBlockLocations(Attribute attribute) {
int max = Settings.blockTagsMaxBlocks();
LocationTag loc;
List<LocationTag> list = new ArrayList<>();
int index = 0;
for (LocationPair pair : pairs) {
LocationTag loc_1 = pair.low;
int y_distance = pair.y_distance;
int z_distance = pair.z_distance;
int x_distance = pair.x_distance;
for (int x = 0; x != x_distance + 1; x++) {
for (int z = 0; z != z_distance + 1; z++) {
for (int y = 0; y != y_distance + 1; y++) {
loc = new LocationTag(loc_1.clone().add(x, y, z));
if (!filter.isEmpty()) {
// Check filter
for (ObjectTag material : filter) {
if (loc.getBlockTypeForTag(attribute).name().equalsIgnoreCase(((MaterialTag) material).getMaterial().name())) {
list.add(loc);
}
}
}
else {
list.add(loc);
}
index++;
if (index > max) {
return list;
}
}
}
}
}
return list;
}
public ListTag getSpawnableBlocks(Attribute attribute) {
return getSpawnableBlocks(null, attribute);
}
/**
* Returns a ListTag of LocationTags with 2 vertical blocks of air
* that are safe for players and similar entities to spawn in,
* but ignoring blocks in midair
*
* @return The ListTag
*/
public ListTag getSpawnableBlocks(List<MaterialTag> mats, Attribute attribute) {
int max = Settings.blockTagsMaxBlocks();
LocationTag loc;
ListTag list = new ListTag();
int index = 0;
BlockHelper blockHelper = NMSHandler.getBlockHelper();
for (LocationPair pair : pairs) {
LocationTag loc_1 = pair.low;
int y_distance = pair.y_distance;
int z_distance = pair.z_distance;
int x_distance = pair.x_distance;
for (int x = 0; x != x_distance + 1; x++) {
for (int y = 0; y != y_distance + 1; y++) {
for (int z = 0; z != z_distance + 1; z++) {
loc = new LocationTag(loc_1.clone()
.add(x, y, z));
if (blockHelper.isSafeBlock(loc.getBlockTypeForTag(attribute))
&& blockHelper.isSafeBlock(new LocationTag(loc.clone().add(0, 1, 0)).getBlockTypeForTag(attribute))
&& new LocationTag(loc.clone().add(0, -1, 0)).getBlockTypeForTag(attribute).isSolid()
&& matchesMaterialList(loc.clone().add(0, -1, 0), mats, attribute)) {
// Get the center of the block, so the entity won't suffocate
// inside the edges for a couple of seconds
loc.add(0.5, 0, 0.5);
list.add(loc.identify());
}
index++;
if (index > max) {
return list;
}
}
}
}
}
return list;
}
public World getWorld() {
if (pairs.size() == 0) {
return null;
}
return pairs.get(0).high.getWorld();
}
public LocationTag getHigh(int index) {
if (index < 0) {
return null;
}
if (index >= pairs.size()) {
return null;
}
return pairs.get(index).high;
}
public LocationTag getLow(int index) {
if (index < 0) {
return null;
}
if (index >= pairs.size()) {
return null;
}
return pairs.get(index).low;
}
///////////////////
// Notable
///////////////////
@Override
public boolean isUnique() {
return NotableManager.isSaved(this);
}
@Override
@Note("Cuboids")
public String getSaveObject() {
return identifyFull().substring(3);
}
@Override
public void makeUnique(String id) {
NotableManager.saveAs(this, id);
}
@Override
public void forget() {
NotableManager.remove(this);
}
/////////////////////
// ObjectTag
////////////////////
String prefix = "Cuboid";
@Override
public String getObjectType() {
return "cuboid";
}
@Override
public String getPrefix() {
return prefix;
}
@Override
public CuboidTag setPrefix(String prefix) {
this.prefix = prefix;
return this;
}
@Override
public String debuggable() {
if (isUnique()) {
return "cu@" + NotableManager.getSavedId(this) + " <GR>(" + identifyFull() + ")";
}
else {
return identifyFull();
}
}
@Override
public String identify() {
if (isUnique()) {
return "cu@" + NotableManager.getSavedId(this);
}
else {
return identifyFull();
}
}
@Override
public String identifySimple() {
return identify();
}
public String identifyFull() {
StringBuilder sb = new StringBuilder();
sb.append("cu@");
for (LocationPair pair : pairs) {
if (pair.low.getWorld() == null || pair.high.getWorld() == null) {
Debug.echoError("Null world for cuboid, returning invalid identity!");
return "cu@null";
}
sb.append(pair.low.getBlockX()).append(',').append(pair.low.getBlockY())
.append(',').append(pair.low.getBlockZ()).append(',').append(pair.low.getWorld().getName())
.append('|').append(pair.high.getBlockX()).append(',').append(pair.high.getBlockY())
.append(',').append(pair.high.getBlockZ()).append(',').append(pair.high.getWorld().getName()).append('|');
}
return sb.toString().substring(0, sb.toString().length() - 1);
}
@Override
public String toString() {
return identify();
}
/////////////////////
// ObjectTag Tag Management
/////////////////////
public static void registerTags() {
// <--[tag]
// @attribute <CuboidTag.blocks[<material>|...]>
// @returns ListTag(LocationTag)
// @description
// Returns each block location within the CuboidTag.
// Optionally, specify a list of materials to only return locations
// with that block type.
// -->
registerTag("blocks", new TagRunnable() {
@Override
public String run(Attribute attribute, ObjectTag object) {
if (attribute.hasContext(1)) {
return new ListTag(((CuboidTag) object).getBlocks(ListTag.valueOf(attribute.getContext(1)).filter(MaterialTag.class, attribute.context), attribute))
.getAttribute(attribute.fulfill(1));
}
else {
return new ListTag(((CuboidTag) object).getBlocks(attribute))
.getAttribute(attribute.fulfill(1));
}
}
});
registerTag("get_blocks", registeredTags.get("blocks"));
// <--[tag]
// @attribute <CuboidTag.members_size>
// @returns ElementTag(Number)
// @description
// Returns the number of cuboids defined in the CuboidTag.
// -->
registerTag("members_size", new TagRunnable() {
@Override
public String run(Attribute attribute, ObjectTag object) {
return new ElementTag(((CuboidTag) object).pairs.size())
.getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <CuboidTag.spawnable_blocks[<Material>|...]>
// @returns ListTag(LocationTag)
// @description
// Returns each LocationTag within the CuboidTag that is
// safe for players or similar entities to spawn in.
// Optionally, specify a list of materials to only return locations
// with that block type.
// -->
registerTag("spawnable_blocks", new TagRunnable() {
@Override
public String run(Attribute attribute, ObjectTag object) {
if (attribute.hasContext(1)) {
return new ListTag(((CuboidTag) object).getSpawnableBlocks(ListTag.valueOf(attribute.getContext(1)).filter(MaterialTag.class, attribute.context), attribute))
.getAttribute(attribute.fulfill(1));
}
else {
return new ListTag(((CuboidTag) object).getSpawnableBlocks(attribute))
.getAttribute(attribute.fulfill(1));
}
}
});
registerTag("get_spawnable_blocks", registeredTags.get("spawnable_blocks"));
// <--[tag]
// @attribute <CuboidTag.shell>
// @returns ListTag(LocationTag)
// @description
// Returns each block location on the shell of the CuboidTag.
// -->
registerTag("shell", new TagRunnable() {
@Override
public String run(Attribute attribute, ObjectTag object) {
return ((CuboidTag) object).getShell()
.getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <CuboidTag.outline>
// @returns ListTag(LocationTag)
// @description
// Returns each block location on the outline of the CuboidTag.
// -->
registerTag("outline", new TagRunnable() {
@Override
public String run(Attribute attribute, ObjectTag object) {
return ((CuboidTag) object).getOutline()
.getAttribute(attribute.fulfill(1));
}
});
registerTag("get_outline", registeredTags.get("outline"));
// <--[tag]
// @attribute <CuboidTag.filter>
// @returns ListTag(LocationTag)
// @description
// Returns the block locations from the CuboidTag's filter.
// -->
registerTag("filter", new TagRunnable() {
@Override
public String run(Attribute attribute, ObjectTag object) {
return new ListTag(((CuboidTag) object).filter)
.getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <CuboidTag.intersects[<cuboid>]>
// @returns ElementTag(Boolean)
// @description
// Returns whether this cuboid and another intersect.
// -->
registerTag("intersects", new TagRunnable() {
@Override
public String run(Attribute attribute, ObjectTag object) {
if (!attribute.hasContext(1)) {
Debug.echoError("The tag CuboidTag.intersects[...] must have a value.");
return null;
}
CuboidTag cub2 = CuboidTag.valueOf(attribute.getContext(1));
if (cub2 != null) {
boolean intersects = false;
whole_loop:
for (LocationPair pair : ((CuboidTag) object).pairs) {
for (LocationPair pair2 : cub2.pairs) {
if (!pair.low.getWorld().getName().equalsIgnoreCase(pair2.low.getWorld().getName())) {
return new ElementTag("false").getAttribute(attribute.fulfill(1));
}
if (pair2.low.getX() <= pair.high.getX()
&& pair2.low.getY() <= pair.high.getY()
&& pair2.low.getZ() <= pair.high.getZ()
&& pair2.high.getX() >= pair.low.getX()