From 74861ac60190c76e847dc0a929a6374742727a14 Mon Sep 17 00:00:00 2001
From: daoge_cmd <3523206925@qq.com>
Date: Sun, 2 Feb 2025 22:03:56 +0800
Subject: [PATCH 01/12] feat: init work
---
.../java/org/allaymc/api/math/MathUtils.java | 58 ++++++++++++++-----
.../allaymc/api/math/location/Location3d.java | 7 +++
2 files changed, 52 insertions(+), 13 deletions(-)
diff --git a/api/src/main/java/org/allaymc/api/math/MathUtils.java b/api/src/main/java/org/allaymc/api/math/MathUtils.java
index f48822c8c..1275af28d 100644
--- a/api/src/main/java/org/allaymc/api/math/MathUtils.java
+++ b/api/src/main/java/org/allaymc/api/math/MathUtils.java
@@ -3,6 +3,7 @@
import org.allaymc.api.math.location.Location3dc;
import org.allaymc.api.math.location.Location3fc;
import org.joml.*;
+import org.joml.primitives.AABBd;
import org.joml.primitives.AABBf;
import java.lang.Math;
@@ -16,11 +17,11 @@
*/
public final class MathUtils {
- private static final float[] SIN_LOOK_UP_TABLE = new float[65536];
+ private static final double[] SIN_LOOK_UP_TABLE = new double[65536];
static {
for (int i = 0; i < 65536; i++) {
- SIN_LOOK_UP_TABLE[i] = (float) Math.sin(i * Math.PI * 2.0D / 65536.0d);
+ SIN_LOOK_UP_TABLE[i] = Math.sin(i * Math.PI * 2.0D / 65536.0d);
}
}
@@ -145,8 +146,8 @@ public static Vector3i ceil(Vector3fc vector3f) {
*
* @return the centered vector.
*/
- public static Vector3f center(Vector3ic vector3i) {
- return new Vector3f(vector3i.x() + 0.5f, vector3i.y() + 0.5f, vector3i.z() + 0.5f);
+ public static Vector3d center(Vector3ic vector3i) {
+ return new Vector3d(vector3i.x() + 0.5, vector3i.y() + 0.5, vector3i.z() + 0.5);
}
/**
@@ -203,7 +204,7 @@ public static double fastDoubleInverseSqrt(double x) {
*
* @return {@code true} if the value is in the range, otherwise {@code false}.
*/
- public static boolean isInRange(float l, float value, float r) {
+ public static boolean isInRange(double l, double value, double r) {
return l <= value && value <= r;
}
@@ -215,13 +216,13 @@ public static boolean isInRange(float l, float value, float r) {
*
* @return the direction vector.
*/
- public static Vector3f getDirectionVector(double yaw, double pitch) {
+ public static Vector3d getDirectionVector(double yaw, double pitch) {
var pitch0 = toRadians(pitch + 90);
var yaw0 = toRadians(yaw + 90);
var x = sin(pitch0) * cos(yaw0);
var z = sin(pitch0) * sin(yaw0);
var y = cos(pitch0);
- return new Vector3f((float) x, (float) y, (float) z).normalize();
+ return new Vector3d(x, y, z).normalize();
}
/**
@@ -231,7 +232,7 @@ public static Vector3f getDirectionVector(double yaw, double pitch) {
*
* @return the yaw.
*/
- public static double getYawFromVector(Vector3fc vector) {
+ public static double getYawFromVector(Vector3dc vector) {
double length = vector.x() * vector.x() + vector.z() * vector.z();
// Prevent NAN
if (length == 0) {
@@ -248,7 +249,7 @@ public static double getYawFromVector(Vector3fc vector) {
*
* @return the pitch.
*/
- public static double getPitchFromVector(Vector3fc vector) {
+ public static double getPitchFromVector(Vector3dc vector) {
double length =
vector.x() * vector.x() +
vector.z() * vector.z() +
@@ -268,7 +269,7 @@ public static double getPitchFromVector(Vector3fc vector) {
*
* @return the sin value.
*/
- public static float fastSin(float radian) {
+ public static double fastSin(float radian) {
return SIN_LOOK_UP_TABLE[((int) (radian * 10430.378F) & 0xFFFF)];
}
@@ -279,7 +280,7 @@ public static float fastSin(float radian) {
*
* @return the sin value.
*/
- public static float fastSin(double radian) {
+ public static double fastSin(double radian) {
return SIN_LOOK_UP_TABLE[((int) (radian * 10430.378F) & 0xFFFF)];
}
@@ -290,7 +291,7 @@ public static float fastSin(double radian) {
*
* @return the cos value.
*/
- public static float fastCos(float radian) {
+ public static double fastCos(float radian) {
return SIN_LOOK_UP_TABLE[((int) (radian * 10430.378F + 16384.0F) & 0xFFFF)];
}
@@ -301,7 +302,7 @@ public static float fastCos(float radian) {
*
* @return the cos value.
*/
- public static float fastCos(double radian) {
+ public static double fastCos(double radian) {
return SIN_LOOK_UP_TABLE[((int) (radian * 10430.378F + 16384.0F) & 0xFFFF)];
}
@@ -364,6 +365,19 @@ public static Vector3f normalizeIfNotZero(Vector3f v) {
return v.lengthSquared() > 0 ? v.normalize(v) : v;
}
+ /**
+ * Normalize the vector if it is not zero.
+ *
+ * If the vector is zero, it can't be normalized, otherwise a vector with three NaN values will be produced.
+ *
+ * @param v the vector.
+ *
+ * @return the normalized vector.
+ */
+ public static Vector3d normalizeIfNotZero(Vector3d v) {
+ return v.lengthSquared() > 0 ? v.normalize(v) : v;
+ }
+
/**
* Grow an AABB by a certain amount.
*
@@ -381,4 +395,22 @@ public static AABBf grow(AABBf aabb, float growth) {
aabb.maxZ += growth;
return aabb;
}
+
+ /**
+ * Grow an AABB by a certain amount.
+ *
+ * @param aabb the AABB to grow.
+ * @param growth the amount to grow by.
+ *
+ * @return the grown AABB.
+ */
+ public static AABBd grow(AABBd aabb, double growth) {
+ aabb.minX -= growth;
+ aabb.minY -= growth;
+ aabb.minZ -= growth;
+ aabb.maxX += growth;
+ aabb.maxY += growth;
+ aabb.maxZ += growth;
+ return aabb;
+ }
}
diff --git a/api/src/main/java/org/allaymc/api/math/location/Location3d.java b/api/src/main/java/org/allaymc/api/math/location/Location3d.java
index f5e0b4ad1..2c305b99e 100644
--- a/api/src/main/java/org/allaymc/api/math/location/Location3d.java
+++ b/api/src/main/java/org/allaymc/api/math/location/Location3d.java
@@ -30,6 +30,13 @@ public Location3d(Location3dc l) {
this.headYaw = l.headYaw();
}
+ public Location3d(Location3ic l) {
+ super(l.x(), l.y(), l.z(), l.dimension());
+ this.pitch = l.pitch();
+ this.yaw = l.yaw();
+ this.headYaw = l.headYaw();
+ }
+
public Location3d(double x, double y, double z, Dimension dimension) {
super(x, y, z, dimension);
}
From 2bd71c634e38e5e8949e66d4fab439e2772feafd Mon Sep 17 00:00:00 2001
From: daoge_cmd <3523206925@qq.com>
Date: Tue, 4 Feb 2025 05:34:18 +0800
Subject: [PATCH 02/12] feat: complete most of the things
---
.../block/component/data/BlockStateData.java | 28 ++-
.../org/allaymc/api/block/data/BlockFace.java | 26 +--
.../api/client/storage/PlayerData.java | 2 +-
.../allaymc/api/command/CommandSender.java | 4 +-
.../allaymc/api/command/NPCCommandSender.java | 4 +-
.../args/CachedFilterSelectorArgument.java | 6 +-
.../args/CachedSimpleSelectorArgument.java | 8 +-
.../selector/args/SelectorArgument.java | 8 +-
.../entity/component/EntityBaseComponent.java | 112 +++++-----
.../player/EntityPlayerBaseComponent.java | 16 +-
.../api/entity/initinfo/EntityInitInfo.java | 22 +-
.../api/entity/interfaces/EntityPlayer.java | 4 +-
.../event/entity/EntityFallEvent.java | 4 +-
.../event/entity/EntityMoveEvent.java | 8 +-
.../event/entity/EntityTeleportEvent.java | 10 +-
.../event/player/PlayerMoveEvent.java | 8 +-
.../java/org/allaymc/api/math/MathUtils.java | 10 +
.../allaymc/api/math/position/Position3d.java | 5 +
.../api/math/voxelshape/VoxelShape.java | 192 +++++++++---------
.../java/org/allaymc/api/world/Dimension.java | 166 +++++++--------
.../java/org/allaymc/api/world/Explosion.java | 156 +++++++-------
.../java/org/allaymc/api/world/WorldPool.java | 14 --
.../allaymc/api/world/chunk/ChunkLoader.java | 4 +-
.../world/service/EntityPhysicsService.java | 8 +-
.../allaymc/api/world/service/HasAABB.java | 6 +-
.../org/allaymc/server/AABBTreeJMHTest.java | 42 ++--
.../java/org/allaymc/server/AllayServer.java | 8 +-
.../component/BlockBaseComponentImpl.java | 4 +-
.../BlockJukeboxBaseComponentImpl.java | 4 +-
.../BlockLiquidBaseComponentImpl.java | 6 +-
.../component/BlockTntBaseComponentImpl.java | 6 +-
.../BlockWetSpongeBaseComponentImpl.java | 3 +-
...ockEntityContainerHolderComponentImpl.java | 10 +-
.../BlockEntityJukeboxBaseComponentImpl.java | 10 +-
.../BlockEntityFurnaceBaseComponentImpl.java | 12 +-
.../server/command/ProxyCommandSender.java | 6 +-
.../command/defaults/ExecuteCommand.java | 16 +-
.../server/command/defaults/FillCommand.java | 6 +-
.../command/defaults/GameTestCommand.java | 22 +-
.../command/defaults/SetBlockCommand.java | 4 +-
.../defaults/SetWorldSpawnCommand.java | 4 +-
.../command/defaults/SpawnPointCommand.java | 6 +-
.../command/defaults/StructureCommand.java | 8 +-
.../command/defaults/SummonCommand.java | 8 +-
.../command/defaults/TeleportCommand.java | 20 +-
.../server/command/defaults/WorldCommand.java | 4 +-
.../selector/AllayEntitySelectorAPI.java | 8 +-
.../server/command/selector/ParseUtils.java | 20 ++
.../server/command/selector/args/C.java | 4 +-
.../server/command/selector/args/DX.java | 4 +-
.../server/command/selector/args/DY.java | 4 +-
.../server/command/selector/args/DZ.java | 4 +-
.../server/command/selector/args/L.java | 4 +-
.../server/command/selector/args/LM.java | 4 +-
.../server/command/selector/args/M.java | 4 +-
.../server/command/selector/args/Name.java | 4 +-
.../server/command/selector/args/R.java | 4 +-
.../server/command/selector/args/RM.java | 4 +-
.../server/command/selector/args/RX.java | 4 +-
.../server/command/selector/args/RXM.java | 4 +-
.../server/command/selector/args/RY.java | 4 +-
.../server/command/selector/args/RYM.java | 4 +-
.../server/command/selector/args/Scores.java | 4 +-
.../server/command/selector/args/Tag.java | 4 +-
.../server/command/selector/args/Type.java | 4 +-
.../server/command/selector/args/X.java | 6 +-
.../server/command/selector/args/Y.java | 6 +-
.../server/command/selector/args/Z.java | 6 +-
.../server/command/tree/node/PosNode.java | 8 +-
.../server/datastruct/aabb/AABBTree.java | 30 +--
.../aabb/AABBTreeHeuristicFunction.java | 4 +-
.../server/datastruct/aabb/AABBTreeNode.java | 8 +-
.../server/datastruct/aabb/AABBUtils.java | 24 +--
.../aabb/AreaAABBHeuristicFunction.java | 6 +-
.../component/EntityBaseComponentImpl.java | 115 +++++------
.../EntityContainerHolderComponentImpl.java | 18 +-
.../component/EntityDamageComponentImpl.java | 2 +-
.../EntityFallingBlockBaseComponentImpl.java | 16 +-
.../EntityItemBaseComponentImpl.java | 14 +-
.../EntityPickableBaseComponentImpl.java | 4 +-
.../component/EntityTntBaseComponentImpl.java | 16 +-
.../EntityXpOrbBaseComponentImpl.java | 8 +-
.../component/event/CEntityFallEvent.java | 2 +-
.../component/event/CPlayerMoveEvent.java | 4 +-
.../player/EntityPlayerBaseComponentImpl.java | 56 ++---
.../EntityPlayerNetworkComponentImpl.java | 4 +-
.../ItemSpawnEggBaseComponentImpl.java | 13 +-
.../ItemChorusFruitBaseComponentImpl.java | 4 +-
.../ingame/PlayerActionPacketProcessor.java | 6 +-
.../PlayerAuthInputPacketProcessor.java | 9 +-
.../org/allaymc/server/world/AllayWorld.java | 8 +-
.../service/AllayEntityPhysicsService.java | 108 +++++-----
.../allaymc/api/block/data/BlockFaceTest.java | 14 +-
.../api/math/voxelshape/VoxelShapeTest.java | 98 ++++-----
.../server/block/BlockStateDataTest.java | 12 +-
.../server/command/CommandTreeTest.java | 20 +-
.../command/selector/ParseUtilsTest.java | 11 +
.../datastruct/aabbtree/AABBTreeTest.java | 92 ++++-----
.../datastruct/aabbtree/TestEntity.java | 24 +--
.../entity/type/AllayEntityTypeTest.java | 4 +-
.../server/world/service/TestChunkLoader.java | 6 +-
101 files changed, 972 insertions(+), 950 deletions(-)
diff --git a/api/src/main/java/org/allaymc/api/block/component/data/BlockStateData.java b/api/src/main/java/org/allaymc/api/block/component/data/BlockStateData.java
index 160f237e5..23327543d 100644
--- a/api/src/main/java/org/allaymc/api/block/component/data/BlockStateData.java
+++ b/api/src/main/java/org/allaymc/api/block/component/data/BlockStateData.java
@@ -10,9 +10,9 @@
import lombok.ToString;
import lombok.experimental.Accessors;
import org.allaymc.api.math.voxelshape.VoxelShape;
-import org.joml.Vector3fc;
+import org.joml.Vector3dc;
import org.joml.Vector3ic;
-import org.joml.primitives.AABBf;
+import org.joml.primitives.AABBd;
import java.awt.*;
@@ -36,18 +36,16 @@ public class BlockStateData {
protected static Gson SERIALIZER = new GsonBuilder()
.registerTypeAdapter(VoxelShape.class, (JsonDeserializer