扩充了形状工具类的方法
This commit is contained in:
parent
bb3097e68c
commit
21d37dd152
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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() { }
|
||||
}
|
||||
|
|
@ -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<VoxelShape> 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<VoxelShape> 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<VoxelShape> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user