mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-30 20:29:14 +00:00
Fix movement on legacy physics versions
This commit is contained in:
@@ -5,33 +5,65 @@ Subject: [PATCH] Configure cannon physics by version
|
||||
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/util/CollisionUtil.java b/src/main/java/io/papermc/paper/util/CollisionUtil.java
|
||||
index 19086bbfdf3a015eafec5ca868c8d2451f554ef0..a40dcbde87860fd6d3b60d0b9e2d5e63e18e69b7 100644
|
||||
index 19086bbfdf3a015eafec5ca868c8d2451f554ef0..510d722fffd4bdcee2db42aefa662c49563ffa81 100644
|
||||
--- a/src/main/java/io/papermc/paper/util/CollisionUtil.java
|
||||
+++ b/src/main/java/io/papermc/paper/util/CollisionUtil.java
|
||||
@@ -1495,6 +1495,14 @@ public final class CollisionUtil {
|
||||
public static Vec3 performCollisions(final Vec3 moveVector, AABB axisalignedbb,
|
||||
final List<VoxelShape> voxels,
|
||||
final List<AABB> aabbs) {
|
||||
+ // Sakura start
|
||||
+ return performCollisions(moveVector, axisalignedbb, voxels, aabbs, null);
|
||||
@@ -1457,7 +1457,15 @@ public final class CollisionUtil {
|
||||
return new Vec3(x, y, z);
|
||||
}
|
||||
|
||||
+ // Sakura start - physics version api
|
||||
public static Vec3 performAABBCollisions(final Vec3 moveVector, AABB axisalignedbb, final List<AABB> potentialCollisions) {
|
||||
+ return performAABBCollisions(moveVector, axisalignedbb, potentialCollisions, null);
|
||||
+ }
|
||||
+ public static Vec3 performCollisions(final Vec3 moveVector, AABB axisalignedbb,
|
||||
+ final List<VoxelShape> voxels,
|
||||
+ final List<AABB> aabbs,
|
||||
+ final me.samsuik.sakura.physics.PhysicsVersion physics) {
|
||||
+ // Sakura end
|
||||
if (voxels.isEmpty()) {
|
||||
// fast track only AABBs
|
||||
return performAABBCollisions(moveVector, axisalignedbb, aabbs);
|
||||
@@ -1512,7 +1520,10 @@ public final class CollisionUtil {
|
||||
+ public static Vec3 performAABBCollisions(final Vec3 moveVector,
|
||||
+ AABB axisalignedbb,
|
||||
+ final List<AABB> potentialCollisions,
|
||||
+ final me.samsuik.sakura.physics.PhysicsVersion physics) {
|
||||
+ // Sakura end - physics version api
|
||||
double x = moveVector.x;
|
||||
double y = moveVector.y;
|
||||
double z = moveVector.z;
|
||||
@@ -1469,7 +1477,10 @@ public final class CollisionUtil {
|
||||
}
|
||||
}
|
||||
|
||||
- final boolean xSmaller = Math.abs(x) < Math.abs(z);
|
||||
+ // Sakura start - physics version api
|
||||
+ final boolean xSmaller = physics == null || physics.afterOrEqual(1_14_0) ? Math.abs(x) < Math.abs(z)
|
||||
+ : physics.is(1_7_0) && Math.abs(x) > Math.abs(z);
|
||||
+ // Sakura end
|
||||
+ : physics.isLegacy() && Math.abs(x) > Math.abs(z);
|
||||
+ // Sakura end - physics version api
|
||||
|
||||
if (xSmaller && z != 0.0) {
|
||||
z = performAABBCollisionsZ(axisalignedbb, z, potentialCollisions);
|
||||
@@ -1495,9 +1506,17 @@ public final class CollisionUtil {
|
||||
public static Vec3 performCollisions(final Vec3 moveVector, AABB axisalignedbb,
|
||||
final List<VoxelShape> voxels,
|
||||
final List<AABB> aabbs) {
|
||||
+ // Sakura start - physics version api
|
||||
+ return performCollisions(moveVector, axisalignedbb, voxels, aabbs, null);
|
||||
+ }
|
||||
+ public static Vec3 performCollisions(final Vec3 moveVector, AABB axisalignedbb,
|
||||
+ final List<VoxelShape> voxels,
|
||||
+ final List<AABB> aabbs,
|
||||
+ final me.samsuik.sakura.physics.PhysicsVersion physics) {
|
||||
if (voxels.isEmpty()) {
|
||||
// fast track only AABBs
|
||||
- return performAABBCollisions(moveVector, axisalignedbb, aabbs);
|
||||
+ return performAABBCollisions(moveVector, axisalignedbb, aabbs, physics);
|
||||
+ // Sakura end - physics version api
|
||||
}
|
||||
|
||||
double x = moveVector.x;
|
||||
@@ -1512,7 +1531,10 @@ public final class CollisionUtil {
|
||||
}
|
||||
}
|
||||
|
||||
- final boolean xSmaller = Math.abs(x) < Math.abs(z);
|
||||
+ // Sakura start - physics version api
|
||||
+ final boolean xSmaller = physics == null || physics.afterOrEqual(1_14_0) ? Math.abs(x) < Math.abs(z)
|
||||
+ : physics.isLegacy() && Math.abs(x) > Math.abs(z);
|
||||
+ // Sakura end - physics version api
|
||||
|
||||
if (xSmaller && z != 0.0) {
|
||||
z = performAABBCollisionsZ(axisalignedbb, z, aabbs);
|
||||
@@ -87,7 +119,7 @@ index cecc88aa129e201ebe85f7ca9cfd73bc25f2f902..78b08a9557e9fd98251714dce9ba1180
|
||||
x /= distance;
|
||||
y /= distance;
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
||||
index e682b52c6f295506f25223950e73188ed5eb4e1a..4c8ef097735020642811decc2e9122dd6373d2df 100644
|
||||
index e682b52c6f295506f25223950e73188ed5eb4e1a..c596f553bfce8db067c3a3df2f366878fd97376a 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
||||
@@ -380,7 +380,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
|
||||
@@ -190,6 +222,15 @@ index e682b52c6f295506f25223950e73188ed5eb4e1a..4c8ef097735020642811decc2e9122dd
|
||||
this.setDeltaMovement(flag ? 0.0D : vec3d2.x, vec3d2.y, flag1 ? 0.0D : vec3d2.z);
|
||||
}
|
||||
|
||||
@@ -1720,7 +1739,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
|
||||
} else {
|
||||
final AABB bb = currBoundingBox.expandTowards(movement.x, movement.y, movement.z);
|
||||
collectCollisions(bb, potentialCollisionsVoxel, potentialCollisionsBB);
|
||||
- return io.papermc.paper.util.CollisionUtil.performCollisions(movement, currBoundingBox, potentialCollisionsVoxel, potentialCollisionsBB);
|
||||
+ return io.papermc.paper.util.CollisionUtil.performCollisions(movement, currBoundingBox, potentialCollisionsVoxel, potentialCollisionsBB, this.physics); // Sakura - physics version api
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1729,7 +1748,10 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
|
||||
double y = movement.y;
|
||||
double z = movement.z;
|
||||
@@ -197,8 +238,8 @@ index e682b52c6f295506f25223950e73188ed5eb4e1a..4c8ef097735020642811decc2e9122dd
|
||||
- final boolean xSmaller = Math.abs(x) < Math.abs(z);
|
||||
+ // Sakura start - physics version api
|
||||
+ final boolean xSmaller = this.physics == null || this.physics.afterOrEqual(1_14_0) ? Math.abs(x) < Math.abs(z)
|
||||
+ : this.physics.is(1_7_0) && Math.abs(x) > Math.abs(z);
|
||||
+ // Sakura end
|
||||
+ : this.physics.isLegacy() && Math.abs(x) > Math.abs(z);
|
||||
+ // Sakura end - physics version api
|
||||
|
||||
if (y != 0.0) {
|
||||
y = scanY(currBoundingBox, y, voxelList, bbList);
|
||||
|
||||
@@ -5,10 +5,10 @@ Subject: [PATCH] Treat all collidable blocks as full while moving fast
|
||||
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/util/CollisionUtil.java b/src/main/java/io/papermc/paper/util/CollisionUtil.java
|
||||
index a40dcbde87860fd6d3b60d0b9e2d5e63e18e69b7..d0bab6610a0ea8d3e6ba69034a25f4096dc00940 100644
|
||||
index 510d722fffd4bdcee2db42aefa662c49563ffa81..37b6d16f0b1e000eb4082a530c7f713482d25a1d 100644
|
||||
--- a/src/main/java/io/papermc/paper/util/CollisionUtil.java
|
||||
+++ b/src/main/java/io/papermc/paper/util/CollisionUtil.java
|
||||
@@ -1581,6 +1581,7 @@ public final class CollisionUtil {
|
||||
@@ -1592,6 +1592,7 @@ public final class CollisionUtil {
|
||||
public static final int COLLISION_FLAG_CHECK_BORDER = 1 << 2;
|
||||
public static final int COLLISION_FLAG_CHECK_ONLY = 1 << 3;
|
||||
public static final int COLLISION_FLAG_ADD_TICKET = 1 << 4; // Sakura
|
||||
@@ -16,7 +16,7 @@ index a40dcbde87860fd6d3b60d0b9e2d5e63e18e69b7..d0bab6610a0ea8d3e6ba69034a25f409
|
||||
|
||||
public static boolean getCollisionsForBlocksOrWorldBorder(final Level world, final Entity entity, final AABB aabb,
|
||||
final List<VoxelShape> intoVoxel, final List<AABB> intoAABB,
|
||||
@@ -1632,6 +1633,7 @@ public final class CollisionUtil {
|
||||
@@ -1643,6 +1644,7 @@ public final class CollisionUtil {
|
||||
|
||||
final boolean loadChunks = (collisionFlags & COLLISION_FLAG_LOAD_CHUNKS) != 0;
|
||||
final boolean addTicket = (collisionFlags & COLLISION_FLAG_ADD_TICKET) != 0; // Sakura
|
||||
@@ -24,7 +24,7 @@ index a40dcbde87860fd6d3b60d0b9e2d5e63e18e69b7..d0bab6610a0ea8d3e6ba69034a25f409
|
||||
final ServerChunkCache chunkSource = (ServerChunkCache)world.getChunkSource();
|
||||
|
||||
for (int currChunkZ = minChunkZ; currChunkZ <= maxChunkZ; ++currChunkZ) {
|
||||
@@ -1673,7 +1675,7 @@ public final class CollisionUtil {
|
||||
@@ -1684,7 +1686,7 @@ public final class CollisionUtil {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ index a40dcbde87860fd6d3b60d0b9e2d5e63e18e69b7..d0bab6610a0ea8d3e6ba69034a25f409
|
||||
final int sectionAdjust = !hasSpecial ? 1 : 0;
|
||||
|
||||
final PalettedContainer<BlockState> blocks = section.states;
|
||||
@@ -1707,12 +1709,20 @@ public final class CollisionUtil {
|
||||
@@ -1718,12 +1720,20 @@ public final class CollisionUtil {
|
||||
}
|
||||
|
||||
if (edgeCount == 0 || ((edgeCount != 1 || blockData.hasLargeCollisionShape()) && (edgeCount != 2 || blockData.getBlock() == Blocks.MOVING_PISTON))) {
|
||||
@@ -59,7 +59,7 @@ index a40dcbde87860fd6d3b60d0b9e2d5e63e18e69b7..d0bab6610a0ea8d3e6ba69034a25f409
|
||||
AABB singleAABB = blockCollision.getSingleAABBRepresentation();
|
||||
if (singleAABB != null) {
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
||||
index d0a70a1035aa7b24879b16d6e85adb834685fb1e..192416a406feb5892862848ed30d395dae665a8e 100644
|
||||
index c596f553bfce8db067c3a3df2f366878fd97376a..6baf325f6b985944b6edc13c4e18fb8f0a27910f 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
||||
@@ -581,6 +581,14 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
|
||||
|
||||
Reference in New Issue
Block a user