func (aabb AABB) CalculateXOffset(nearby AABB, deltaX float64) float64 {
	if aabb.max[1] <= nearby.min[1] || aabb.min[1] >= nearby.max[1] {
		return deltaX
	} else if aabb.max[2] <= nearby.min[2] || aabb.min[2] >= nearby.max[2] {
		return deltaX
	}
	if deltaX > 0 && aabb.max[0] <= nearby.min[0] {
		difference := nearby.min[0] - aabb.max[0]
		if difference < deltaX {
			deltaX = difference
		}
	}
	if deltaX < 0 && aabb.min[0] >= nearby.max[0] {
		difference := nearby.max[0] - aabb.min[0]
		if difference > deltaX {
			deltaX = difference
		}
	}
	return deltaX
}
CalculateXOffset calculates the offset on the X axis between two bounding boxes, returning a delta always
smaller than or equal to deltaX if deltaX is bigger than 0, or always bigger than or equal to deltaX if it
is smaller than 0.
package physics
import (
	"github.com/df-mc/dragonfly/server/block/cube"
	"github.com/go-gl/mathgl/mgl64"
)
type AABB struct {
	min, max mgl64.Vec3
}
func NewAABB(min, max mgl64.Vec3) AABB {
	return AABB{min: min, max: max}
}
func (aabb AABB) Grow(x float64) AABB {
	add := mgl64.Vec3{x, x, x}
	return AABB{min: aabb.min.Sub(add), max: aabb.max.Add(add)}
}
func (aabb AABB) GrowVec3(vec mgl64.Vec3) AABB {
	return AABB{min: aabb.min.Sub(vec), max: aabb.max.Add(vec)}
}
func (aabb AABB) Min() mgl64.Vec3 {
	return aabb.min
}
func (aabb AABB) Max() mgl64.Vec3 {
	return aabb.max
}
func (aabb AABB) Width() float64 {
	return aabb.max[0] - aabb.min[0]
}
func (aabb AABB) Length() float64 {
	return aabb.max[2] - aabb.min[2]
}
func (aabb AABB) Height() float64 {
	return aabb.max[1] - aabb.min[1]
}
func (aabb AABB) Extend(vec mgl64.Vec3) AABB {
	if vec[0] < 0 {
		aabb.min[0] += vec[0]
	} else if vec[0] > 0 {
		aabb.max[0] += vec[0]
	}
	if vec[1] < 0 {
		aabb.min[1] += vec[1]
	} else if vec[1] > 0 {
		aabb.max[1] += vec[1]
	}
	if vec[2] < 0 {
		aabb.min[2] += vec[2]
	} else if vec[2] > 0 {
		aabb.max[2] += vec[2]
	}
	return aabb
}
func (aabb AABB) ExtendTowards(f cube.Face, x float64) AABB {
	switch f {
	case cube.FaceDown:
		aabb.max[1] -= x
	case cube.FaceUp:
		aabb.min[1] += x
	case cube.FaceNorth:
		aabb.min[2] -= x
	case cube.FaceSouth:
		aabb.max[2] += x
	case cube.FaceWest:
		aabb.min[0] -= x
	case cube.FaceEast:
		aabb.max[0] += x
	}
	return aabb
}
func (aabb AABB) Stretch(a cube.Axis, x float64) AABB {
	switch a {
	case cube.Y:
		aabb.min[1] -= x
		aabb.max[1] += x
	case cube.Z:
		aabb.min[2] -= x
		aabb.max[2] += x
	case cube.X:
		aabb.min[0] -= x
		aabb.max[0] += x
	}
	return aabb
}
func (aabb AABB) Translate(vec mgl64.Vec3) AABB {
	return NewAABB(aabb.min.Add(vec), aabb.max.Add(vec))
}
func (aabb AABB) IntersectsWith(other AABB) bool {
	if other.max[0]-aabb.min[0] > 1e-5 && aabb.max[0]-other.min[0] > 1e-5 {
		if other.max[1]-aabb.min[1] > 1e-5 && aabb.max[1]-other.min[1] > 1e-5 {
			return other.max[2]-aabb.min[2] > 1e-5 && aabb.max[2]-other.min[2] > 1e-5
		}
	}
	return false
}
func AnyIntersections(boxes []AABB, search AABB) bool {
	for _, box := range boxes {
		if box.IntersectsWith(search) {
			return true
		}
	}
	return false
}
func (aabb AABB) Vec3Within(vec mgl64.Vec3) bool {
	if vec[0] <= aabb.min[0] || vec[0] >= aabb.max[0] {
		return false
	}
	if vec[2] <= aabb.min[2] || vec[2] >= aabb.max[2] {
		return false
	}
	return vec[1] > aabb.min[1] && vec[1] < aabb.max[1]
}
func (aabb AABB) Vec3WithinYZ(vec mgl64.Vec3) bool {
	if vec[2] <= aabb.min[2] || vec[2] >= aabb.max[2] {
		return false
	}
	return vec[1] > aabb.min[1] && vec[1] < aabb.max[1]
}
func (aabb AABB) Vec3WithinXZ(vec mgl64.Vec3) bool {
	if vec[0] <= aabb.min[0] || vec[0] >= aabb.max[0] {
		return false
	}
	return vec[2] > aabb.min[2] && vec[2] < aabb.max[2]
}
func (aabb AABB) Vec3WithinXY(vec mgl64.Vec3) bool {
	if vec[0] <= aabb.min[0] || vec[0] >= aabb.max[0] {
		return false
	}
	return vec[1] > aabb.min[1] && vec[1] < aabb.max[1]
}