From 8755725d51d08ad28e5ca99b2bc19b4abc339b07 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Mon, 21 Nov 2022 15:15:48 +0100 Subject: [PATCH] AABBBlock shift and clone methods --- .../pandacube/lib/paper/util/AABBBlock.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/util/AABBBlock.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/util/AABBBlock.java index f1cf405..4c00797 100644 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/util/AABBBlock.java +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/util/AABBBlock.java @@ -17,13 +17,21 @@ import fr.pandacube.lib.util.RandomUtil; * Represent the littelest cuboid selection of blocks that contains the bounding box * passed to the constructor. */ -public class AABBBlock implements Iterable { +public class AABBBlock implements Iterable, Cloneable { public final Vector pos1, pos2; private final Vector center; private final long volume; + + private AABBBlock(AABBBlock original, int shiftX, int shiftY, int shiftZ) { + Vector shiftVect = new Vector(shiftX, shiftY, shiftZ); + pos1 = original.pos1.clone().add(shiftVect); + pos2 = original.pos2.clone().add(shiftVect); + center = original.center.clone().add(shiftVect); + volume = original.volume; + } public AABBBlock(Vector p1, Vector p2) { this(p1.getBlockX(), p1.getBlockY(), p1.getBlockZ(), p2.getBlockX(), p2.getBlockY(), p2.getBlockZ()); @@ -55,7 +63,17 @@ public class AABBBlock implements Iterable { volume = (long) Math.abs(p2x_ - p1x_) * Math.abs(p2x_ - p1x_) * Math.abs(p2x_ - p1x_); } - + + public AABBBlock shift(int x, int y, int z) { + return new AABBBlock(this, x, y, z); + } + + @SuppressWarnings("MethodDoesntCallSuperMethod") + @Override + public AABBBlock clone() throws CloneNotSupportedException { + return new AABBBlock(this, 0, 0, 0); + } + public boolean overlaps(Entity e) { return overlaps(e.getBoundingBox()); }