From 21d37dd152a9857ac93712bb505d5bfe42ff2b9a Mon Sep 17 00:00:00 2001 From: 3944Realms Date: Tue, 14 Oct 2025 17:38:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=A9=E5=85=85=E4=BA=86=E5=BD=A2=E7=8A=B6?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E7=B1=BB=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 2 +- .../lib39/util/shape/Quaternions.java | 22 +++++++++++ .../lib39/util/shape/ShapeUtil.java | 39 ++++++++++++++++++- 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 src/main/java/top/r3944realms/lib39/util/shape/Quaternions.java diff --git a/gradle.properties b/gradle.properties index 9c3af22..f77ca19 100644 --- a/gradle.properties +++ b/gradle.properties @@ -33,7 +33,7 @@ mod_name=3944Realms 's Lib Mod # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=MIT # The mod version. See https://semver.org/ -mod_version=0.0.3 +mod_version=0.0.5 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/src/main/java/top/r3944realms/lib39/util/shape/Quaternions.java b/src/main/java/top/r3944realms/lib39/util/shape/Quaternions.java new file mode 100644 index 0000000..e9c1fd7 --- /dev/null +++ b/src/main/java/top/r3944realms/lib39/util/shape/Quaternions.java @@ -0,0 +1,22 @@ +package top.r3944realms.lib39.util.shape; + + +import com.mojang.math.Axis; +import org.joml.Quaternionf; + +public final class Quaternions { + public static final Quaternionf XP_90 = Axis.XP.rotationDegrees(90); + public static final Quaternionf XP_180 = Axis.XP.rotationDegrees(180); + public static final Quaternionf XN_90 = Axis.XN.rotationDegrees(90); + + public static final Quaternionf YP_90 = Axis.YP.rotationDegrees(90); + public static final Quaternionf YN_90 = Axis.YN.rotationDegrees(90); + + public static final Quaternionf ZP_90 = Axis.ZP.rotationDegrees(90); + public static final Quaternionf ZP_180 = Axis.ZP.rotationDegrees(180); + public static final Quaternionf ZN_90 = Axis.ZN.rotationDegrees(90); + + + + private Quaternions() { } +} \ No newline at end of file diff --git a/src/main/java/top/r3944realms/lib39/util/shape/ShapeUtil.java b/src/main/java/top/r3944realms/lib39/util/shape/ShapeUtil.java index 1022001..9629b85 100644 --- a/src/main/java/top/r3944realms/lib39/util/shape/ShapeUtil.java +++ b/src/main/java/top/r3944realms/lib39/util/shape/ShapeUtil.java @@ -2,12 +2,49 @@ package top.r3944realms.lib39.util.shape; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; public class ShapeUtil { /** * 创建基于像素的碰撞箱(将像素坐标转换为方块坐标) */ - public static VoxelShape createPixelBasedShape(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) { + public static @NotNull VoxelShape createPixelBasedShape(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) { return Shapes.box(minX / 16.0d, minY / 16.0d, minZ / 16.0d, maxX / 16.0d, maxY / 16.0d, maxZ / 16.0d); } + public static @NotNull VoxelShape rotateVoxelShapeClockwise(@NotNull VoxelShape in) { + final List generatedShapes = new ArrayList<>(); + in.forAllBoxes((arg0, arg1, arg2, arg3, arg4, arg5) -> { + VoxelShape shape = Shapes.box(1.0 - arg5, arg1, arg0, 1.0 - arg2, arg4, arg3); + generatedShapes.add(shape); + }); + return getVoxelShape(generatedShapes); + } + public static VoxelShape RotateVoxelShapeXAxis(VoxelShape in) { + final List generatedShapes = new ArrayList<>(); + in.forAllBoxes((arg0, arg1, arg2, arg3, arg4, arg5) -> { + VoxelShape shape = Shapes.box(arg0, 1.0 - arg5, arg1, arg3, 1.0 - arg2, arg4); + generatedShapes.add(shape); + }); + return getVoxelShape(generatedShapes); + } + + @NotNull + private static VoxelShape getVoxelShape(List generatedShapes) { + if (generatedShapes.isEmpty()) { + return Shapes.block(); + } else { + VoxelShape out = generatedShapes.get(0); + + for(int i = 1; i < generatedShapes.size(); ++i) { + VoxelShape shape = generatedShapes.get(i); + out = Shapes.or(out, shape); + } + + out.optimize(); + return out; + } + } }