mirror of
https://github.com/GTNewHorizons/GTNHLib.git
synced 2026-10-26 14:24:10 +00:00
Backport BlockPos#getAllInBox (#49)
* Backport BlockPos#getAllInBox * Rename params and add javadoc * Mention that range is inclusive
This commit is contained in:
1 parent
2895735d5f
commit
5157c9c6ad
7 files changed
+81
-15
No files matched your search
@@ -1,12 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
if ! git diff --name-only HEAD HEAD~1 | grep -qF 'build.gradle'; then
|
||||
new_version="$(date +%s)"
|
||||
sed --in-place "s!^//version:.*!//version: $new_version!g" build.gradle
|
||||
git add build.gradle
|
||||
git commit -m "[ci skip] update build script version to $new_version"
|
||||
git push
|
||||
printf 'Updated buildscript version to %s\n' "$new_version"
|
||||
else
|
||||
printf 'Ignored buildscript version update: no changes detected\n'
|
||||
fi
|
||||
+7
-1
@@ -26,7 +26,13 @@ whitelist.json
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
src/main/resources/mixins.*.json
|
||||
src/main/resources/mixins.*([!.]).json
|
||||
*.bat
|
||||
*.DS_Store
|
||||
!gradlew.bat
|
||||
.factorypath
|
||||
addon.local.gradle
|
||||
addon.local.gradle.kts
|
||||
addon.late.local.gradle
|
||||
addon.late.local.gradle.kts
|
||||
layout.json
|
||||
Vendored
BIN
Binary file not shown.
+1
-1
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
@@ -84,7 +86,8 @@ done
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
|
||||
' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
Vendored
+2
@@ -13,6 +13,8 @@
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.gtnewhorizon.gtnhlib.blockpos;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.world.ChunkPosition;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import org.joml.Vector3i;
|
||||
|
||||
import com.google.common.collect.AbstractIterator;
|
||||
import com.gtnewhorizon.gtnhlib.util.CoordinatePacker;
|
||||
|
||||
public class BlockPos extends Vector3i implements IMutableBlockPos {
|
||||
@@ -67,4 +70,68 @@ public class BlockPos extends Vector3i implements IMutableBlockPos {
|
||||
CoordinatePacker.unpack(packedPos, this);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterable of all BlockPos objects within the specified box. The range is inclusive.
|
||||
*
|
||||
* @param from the starting BlockPos of the box
|
||||
* @param to the ending BlockPos of the box
|
||||
* @return an iterable of all BlockPos objects within the box
|
||||
*/
|
||||
public static Iterable<BlockPos> getAllInBox(BlockPos from, BlockPos to) {
|
||||
return getAllInBox(
|
||||
Math.min(from.getX(), to.getX()),
|
||||
Math.min(from.getY(), to.getY()),
|
||||
Math.min(from.getZ(), to.getZ()),
|
||||
Math.max(from.getX(), to.getX()),
|
||||
Math.max(from.getY(), to.getY()),
|
||||
Math.max(from.getZ(), to.getZ()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterable of BlockPos objects representing all positions within the specified box. The range is
|
||||
* inclusive.
|
||||
*
|
||||
* @param xMin The minimum x-coordinate of the box.
|
||||
* @param yMin The minimum y-coordinate of the box.
|
||||
* @param zMin The minimum z-coordinate of the box.
|
||||
* @param xMax The maximum x-coordinate of the box.
|
||||
* @param yMax The maximum y-coordinate of the box.
|
||||
* @param zMax The maximum z-coordinate of the box.
|
||||
* @return An iterable of BlockPos objects representing all positions within the specified box.
|
||||
*/
|
||||
public static Iterable<BlockPos> getAllInBox(final int xMin, final int yMin, final int zMin, final int xMax,
|
||||
final int yMax, final int zMax) {
|
||||
return new Iterable<>() {
|
||||
|
||||
public Iterator<BlockPos> iterator() {
|
||||
return new AbstractIterator<>() {
|
||||
|
||||
private BlockPos pos;
|
||||
|
||||
protected BlockPos computeNext() {
|
||||
if (this.pos == null) {
|
||||
this.pos = new BlockPos(xMin, yMin, zMin);
|
||||
return this.pos;
|
||||
} else if (this.pos.x == xMax && this.pos.y == yMax && this.pos.z == zMax) {
|
||||
return this.endOfData();
|
||||
} else {
|
||||
if (this.pos.x < xMax) {
|
||||
++this.pos.x;
|
||||
} else if (this.pos.y < yMax) {
|
||||
this.pos.x = xMin;
|
||||
++this.pos.y;
|
||||
} else if (this.pos.z < zMax) {
|
||||
this.pos.x = xMin;
|
||||
this.pos.y = yMin;
|
||||
++this.pos.z;
|
||||
}
|
||||
|
||||
return this.pos;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user