From 78f2057049312b8a34570546d7a1525e24807e09 Mon Sep 17 00:00:00 2001 From: Axionize <154778082+Axionize@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:53:20 -0500 Subject: [PATCH] Rename and fix initing array filled size pointer --- .../datatypes/ComplexCollisionBox.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/ac/grim/grimac/utils/collisions/datatypes/ComplexCollisionBox.java b/src/main/java/ac/grim/grimac/utils/collisions/datatypes/ComplexCollisionBox.java index 226c363b3c..6e4794d758 100644 --- a/src/main/java/ac/grim/grimac/utils/collisions/datatypes/ComplexCollisionBox.java +++ b/src/main/java/ac/grim/grimac/utils/collisions/datatypes/ComplexCollisionBox.java @@ -8,7 +8,7 @@ public class ComplexCollisionBox implements CollisionBox { // Most complex shape is the Modern MC Cauldron which is made up of 15 boxes public static int DEFAULT_MAX_COLLISION_BOX_SIZE = 15; // increase if we somehow have a shape made of more than 15 parts. private final SimpleCollisionBox[] boxes; - int maxLength = 0; + int currentLength = 0; public ComplexCollisionBox(SimpleCollisionBox... boxes) { this(DEFAULT_MAX_COLLISION_BOX_SIZE, boxes); @@ -19,15 +19,15 @@ public ComplexCollisionBox(int maxIndex) { } public ComplexCollisionBox(int maxIndex, SimpleCollisionBox... boxes) { + this.currentLength = Math.min(maxIndex, boxes.length); this.boxes = new SimpleCollisionBox[maxIndex]; - System.arraycopy(boxes, 0, this.boxes, 0, Math.min(maxIndex, boxes.length)); - maxLength = boxes.length; + System.arraycopy(boxes, 0, this.boxes, 0, this.currentLength); } public boolean add(SimpleCollisionBox collisionBox) { - boxes[maxLength] = collisionBox; - maxLength++; - return maxLength <= boxes.length; + boxes[currentLength] = collisionBox; + currentLength++; + return currentLength <= boxes.length; } @Override @@ -38,7 +38,7 @@ public CollisionBox union(SimpleCollisionBox other) { @Override public boolean isCollided(SimpleCollisionBox other) { - for (int i = 0; i < maxLength; i++) { + for (int i = 0; i < currentLength; i++) { if (boxes[i].isCollided(other)) return true; } return false; @@ -46,7 +46,7 @@ public boolean isCollided(SimpleCollisionBox other) { @Override public boolean isIntersected(SimpleCollisionBox other) { - for (int i = 0; i < maxLength; i++) { + for (int i = 0; i < currentLength; i++) { if (boxes[i].isIntersected(other)) return true; } return false; @@ -59,7 +59,7 @@ public CollisionBox copy() { @Override public CollisionBox offset(double x, double y, double z) { - for (int i = 0; i < maxLength; i++) { + for (int i = 0; i < currentLength; i++) { boxes[i].offset(x, y ,z); } return this; @@ -67,18 +67,18 @@ public CollisionBox offset(double x, double y, double z) { @Override public void downCast(List list) { - list.addAll(Arrays.asList(boxes).subList(0, maxLength)); + list.addAll(Arrays.asList(boxes).subList(0, currentLength)); } @Override public int downCast(SimpleCollisionBox[] list) { - System.arraycopy(boxes, 0, list, 0, maxLength); - return maxLength; + System.arraycopy(boxes, 0, list, 0, currentLength); + return currentLength; } @Override public boolean isNull() { - for (int i = 0; i < maxLength; i++) { + for (int i = 0; i < currentLength; i++) { if (!boxes[i].isNull()) return false; } return true;