11package de .srendi .advancedperipherals .common .util ;
22
33import net .minecraft .core .BlockPos ;
4+ import net .minecraft .util .Mth ;
45import net .minecraft .world .level .Level ;
56import net .minecraft .world .level .block .state .BlockState ;
67import net .minecraft .world .phys .Vec3 ;
@@ -18,18 +19,23 @@ public static void traverseBlocks(Level world, Vec3 center, double radius, BiCon
1819
1920 public static void traverseBlocks (Level world , Vec3 center , double radius , BiConsumer <BlockState , Vec3 > consumer , boolean relativePosition ) {
2021 final double x = center .x , y = center .y , z = center .z ;
21- for (int oX = (int ) (x - radius ); oX <= (int ) (x + radius ); oX ++) {
22- for (int oY = (int ) (y - radius ); oY <= (int ) (y + radius ); oY ++) {
23- for (int oZ = (int ) (z - radius ); oZ <= (int ) (z + radius ); oZ ++) {
24- BlockPos subPos = new BlockPos (oX , oY , oZ );
25- BlockState blockState = world .getBlockState (subPos );
26- if (!blockState .isAir ()) {
27- if (relativePosition ) {
28- consumer .accept (blockState , new Vec3 (oX + 0.5 - center .x , oY + 0.5 - center .y , oZ + 0.5 - center .z ));
29- } else {
30- consumer .accept (blockState , new Vec3 (oX , oY , oZ ));
31- }
22+ final int minX = Mth .floor (x - radius ), maxX = Mth .floor (x + radius );
23+ final int minY = Mth .floor (y - radius ), maxY = Mth .floor (y + radius );
24+ final int minZ = Mth .floor (z - radius ), maxZ = Mth .floor (z + radius );
25+ final BlockPos .MutableBlockPos subPos = new BlockPos .MutableBlockPos ();
26+ for (int oX = minX ; oX <= maxX ; oX ++) {
27+ for (int oY = minY ; oY <= maxY ; oY ++) {
28+ for (int oZ = minZ ; oZ <= maxZ ; oZ ++) {
29+ BlockState blockState = world .getBlockState (subPos .set (oX , oY , oZ ));
30+ if (blockState .isAir ()) {
31+ continue ;
3232 }
33+ consumer .accept (
34+ blockState ,
35+ relativePosition
36+ ? new Vec3 (oX + 0.5 - x , oY + 0.5 - y , oZ + 0.5 - z )
37+ : new Vec3 (oX , oY , oZ )
38+ );
3339 }
3440 }
3541 }
0 commit comments