This repository has been archived by the owner on May 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create AABBHelper, fix room spawn saving+lookup, add a RandSrc helper
- Loading branch information
1 parent
8992925
commit 7e0f6f8
Showing
6 changed files
with
79 additions
and
15 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
core-api/src/main/java/dev/compactmods/machines/api/util/AABBHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package dev.compactmods.machines.api.util; | ||
|
||
import net.minecraft.world.phys.AABB; | ||
import net.minecraft.world.phys.Vec3; | ||
|
||
public abstract class AABBHelper { | ||
|
||
public static Vec3 minCorner(AABB aabb) { | ||
return new Vec3(aabb.minX, aabb.minY, aabb.minZ); | ||
} | ||
|
||
public static Vec3 maxCorner(AABB aabb) { | ||
return new Vec3(aabb.maxX, aabb.maxY, aabb.maxZ); | ||
} | ||
|
||
public static AABB normalize(AABB source) { | ||
Vec3 offset = minCorner(source).reverse(); | ||
return source.move(offset); | ||
} | ||
|
||
public static AABB normalizeWithin(AABB source, AABB within) { | ||
Vec3 offset = minCorner(source).subtract(minCorner(within)).reverse(); | ||
return source.move(offset); | ||
} | ||
|
||
public static AABB alignFloor(AABB source, AABB within) { | ||
double targetY = within.minY; | ||
return alignFloor(source, targetY); | ||
} | ||
|
||
public static AABB alignFloor(AABB source, double targetY) { | ||
double offset = source.minY - targetY; | ||
return source.move(0, offset * -1, 0); | ||
} | ||
|
||
public static String toString(AABB aabb) { | ||
return "%s,%s,%s".formatted(aabb.getXsize(), aabb.getYsize(), aabb.getZsize()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
core/src/main/java/dev/compactmods/machines/util/RandomSourceUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package dev.compactmods.machines.util; | ||
|
||
import net.minecraft.util.Mth; | ||
import net.minecraft.util.RandomSource; | ||
import net.minecraft.world.phys.Vec3; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.joml.Math; | ||
|
||
import java.util.stream.Stream; | ||
|
||
public abstract class RandomSourceUtil { | ||
|
||
public static Stream<Vec3> randomVec3Stream(RandomSource source) { | ||
return Stream.generate(() -> randomVec3(source)); | ||
} | ||
|
||
@NotNull | ||
public static Vec3 randomVec3(RandomSource source) { | ||
return new Vec3(source.nextDouble(), source.nextDouble(), source.nextDouble()); | ||
} | ||
} |