aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/utils/Boxes.java
blob: c50d9bcf6ba7b7ed33a75c4a935d3e221641b04a (plain)
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
package de.hysky.skyblocker.utils;

import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction.Axis;
import net.minecraft.util.math.Vec3d;

public class Boxes {
    /**
     * Returns the vector of the min pos of this box.
     * @deprecated Use {@link Box#getMinPos()} instead.
     */
    @Deprecated(since = "1.22")
    public static Vec3d getMinVec(Box box) {
        return box.getMinPos();
    }

    /**
     * Returns the vector of the max pos of this box.
     * @deprecated Use {@link Box#getMaxPos()} instead.
     */
    @Deprecated(since = "1.22")
    public static Vec3d getMaxVec(Box box) {
        return box.getMaxPos();
    }

    /** Returns the vector of the side lengths of this box. **/
    public static Vec3d getLengthVec(Box box) {
        return new Vec3d(box.getLengthX(), box.getLengthY(), box.getLengthZ());
    }

    /** Offsets this box so that minX, minY and minZ are all zero. **/
    public static Box moveToZero(Box box) {
        return box.offset(box.getMinPos().negate());
    }

    /** Returns the distance between to oppisite corners of the box. **/
    public static double getCornerLength(Box box) {
        return box.getMinPos().distanceTo(box.getMaxPos());
    }

    /** Returns the length of an axis in the box. **/
    public static double getAxisLength(Box box, Axis axis) {
        return box.getMax(axis) - box.getMin(axis);
    }

    /** Returns a box with each axis multiplied by the amount specified. **/
    public static Box multiply(Box box, double amount) {
        return multiply(box, amount, amount, amount);
    }

    /** Returns a box with each axis multiplied by the amount specified. **/
    public static Box multiply(Box box, double x, double y, double z) {
        return box.expand(
                getAxisLength(box, Axis.X) * (x - 1) / 2d,
                getAxisLength(box, Axis.Y) * (y - 1) / 2d,
                getAxisLength(box, Axis.Z) * (z - 1) / 2d);
    }
}