9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2025-12-28 19:29:07 +00:00

Clean up movement related patches

This commit is contained in:
Samsuik
2024-10-05 13:23:03 +01:00
parent f156073704
commit dbe198bb6d
6 changed files with 87 additions and 62 deletions

View File

@@ -5,7 +5,7 @@ Subject: [PATCH] Optimise cannon entity movement
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index a636c0331b6c963224727eaaed9c09d29ba9d2d7..b8b86de79c276b89ff5d4f9469c3456104dcc00e 100644
index a636c0331b6c963224727eaaed9c09d29ba9d2d7..ccbe81eb8df2406554c34e771b16855136db111c 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -1166,6 +1166,93 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -33,7 +33,7 @@ index a636c0331b6c963224727eaaed9c09d29ba9d2d7..b8b86de79c276b89ff5d4f9469c34561
+ }
+
+ // collideScan for optimised large movements
+ Vec3 vec3d1 = this.collideScan(movement);
+ Vec3 vec3d1 = this.sakura_collide(movement);
+ double d0 = vec3d1.lengthSqr();
+
+ if (d0 > 1.0E-7D) {
@@ -102,31 +102,43 @@ index a636c0331b6c963224727eaaed9c09d29ba9d2d7..b8b86de79c276b89ff5d4f9469c34561
public void move(MoverType movementType, Vec3 movement) {
final Vec3 originalMovement = movement; // Paper - Expose pre-collision velocity
@@ -1510,6 +1597,95 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -1510,6 +1597,104 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
return offsetFactor;
}
+ // Sakura start - optimise cannon entity movement
+ private Vec3 collideScan(Vec3 movement) {
+ private Vec3 sakura_collide(Vec3 movement) {
+ if (movement.x == 0.0 && movement.y == 0.0 && movement.z == 0.0) {
+ return movement;
+ }
+
+ boolean scan = movement.lengthSqr() >= 12.0;
+ List<VoxelShape> potentialCollisionsVoxel = new it.unimi.dsi.fastutil.objects.ObjectArrayList<>(0);
+ List<AABB> potentialCollisionsBB = new it.unimi.dsi.fastutil.objects.ObjectArrayList<>(4);
+ List<VoxelShape> potentialCollisionsVoxel = new it.unimi.dsi.fastutil.objects.ObjectArrayList<>(1);
+ AABB currBoundingBox = getBoundingBox();
+ AABB currBoundingBox = this.getBoundingBox();
+
+ if (scan) {
+ return this.scanAndCollide(movement, currBoundingBox, potentialCollisionsVoxel, potentialCollisionsBB);
+ if (movement.lengthSqr() >= 12.0) { // axis scan on large movement
+ return this.collideAxisScan(movement, currBoundingBox, potentialCollisionsVoxel, potentialCollisionsBB);
+ } else {
+ AABB bb = currBoundingBox.expandTowards(movement.x, movement.y, movement.z);
+ this.collectCollisions(bb, potentialCollisionsVoxel, potentialCollisionsBB);
+ return ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.performCollisions(movement, currBoundingBox, potentialCollisionsVoxel, potentialCollisionsBB);
+ return this.collideCube(movement, currBoundingBox, potentialCollisionsVoxel, potentialCollisionsBB);
+ }
+ }
+
+ private Vec3 scanAndCollide(Vec3 movement, AABB currBoundingBox, List<VoxelShape> voxelList, List<AABB> bbList) {
+ private Vec3 collideCube(Vec3 movement, AABB currBoundingBox, List<VoxelShape> voxelList, List<AABB> bbList) {
+ final AABB bb;
+ if (movement.x() == 0.0 && movement.z() == 0.0) {
+ if (movement.y > 0.0) {
+ bb = ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.cutUpwards(currBoundingBox, movement.y);
+ } else {
+ bb = ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.cutDownwards(currBoundingBox, movement.y);
+ }
+ } else {
+ bb = currBoundingBox.expandTowards(movement.x, movement.y, movement.z);
+ }
+ this.collectCollisions(bb, voxelList, bbList);
+ return ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.performCollisions(movement, currBoundingBox, voxelList, bbList);
+ }
+
+ private Vec3 collideAxisScan(Vec3 movement, AABB currBoundingBox, List<VoxelShape> voxelList, List<AABB> bbList) {
+ double x = movement.x;
+ double y = movement.y;
+ double z = movement.z;
@@ -135,7 +147,6 @@ index a636c0331b6c963224727eaaed9c09d29ba9d2d7..b8b86de79c276b89ff5d4f9469c34561
+
+ if (y != 0.0) {
+ y = this.scanY(currBoundingBox, y, voxelList, bbList);
+
+ if (y != 0.0) {
+ currBoundingBox = ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.offsetY(currBoundingBox, y);
+ }
@@ -143,7 +154,6 @@ index a636c0331b6c963224727eaaed9c09d29ba9d2d7..b8b86de79c276b89ff5d4f9469c34561
+
+ if (xSmaller && z != 0.0) {
+ z = this.scanZ(currBoundingBox, z, voxelList, bbList);
+
+ if (z != 0.0) {
+ currBoundingBox = ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.offsetZ(currBoundingBox, z);
+ }
@@ -151,7 +161,6 @@ index a636c0331b6c963224727eaaed9c09d29ba9d2d7..b8b86de79c276b89ff5d4f9469c34561
+
+ if (x != 0.0) {
+ x = this.scanX(currBoundingBox, x, voxelList, bbList);
+
+ if (x != 0.0) {
+ currBoundingBox = ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.offsetX(currBoundingBox, x);
+ }

View File

@@ -5,7 +5,7 @@ Subject: [PATCH] Entity pushed by fluid API
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index b8b86de79c276b89ff5d4f9469c3456104dcc00e..18f3aaa704a9f04aa5bac468f2e5963538629f64 100644
index ccbe81eb8df2406554c34e771b16855136db111c..33027663cd43f2a56b9cf09f280a277149aad427 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -603,6 +603,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -16,7 +16,7 @@ index b8b86de79c276b89ff5d4f9469c3456104dcc00e..18f3aaa704a9f04aa5bac468f2e59635
public Entity(EntityType<?> type, Level world) {
this.id = Entity.ENTITY_COUNTER.incrementAndGet();
@@ -4171,7 +4172,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -4180,7 +4181,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
public boolean isPushedByFluid() {

View File

@@ -5,10 +5,10 @@ Subject: [PATCH] Optimise TNT fluid state
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 18f3aaa704a9f04aa5bac468f2e5963538629f64..6131a99836b721f468d21df00c8d0f2bcb7feda9 100644
index 33027663cd43f2a56b9cf09f280a277149aad427..c1c1737bc7f57b7112567fe22a31c964cf4d10f7 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -2153,7 +2153,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -2162,7 +2162,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
return this.isInWater() || flag;
}

View File

@@ -106,7 +106,7 @@ index a5d13c6b0d8765e4a65b43f5835fd907738e1da4..19f0d8cf94a60b66cead3c129ded69fc
protected int getExplosionCount() {
if (this.cause.getMergeEntityData().getMergeLevel() == MergeLevel.NONE) {
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 6131a99836b721f468d21df00c8d0f2bcb7feda9..4a899864f460c80bbc6d5d6849e0421c2e392495 100644
index c1c1737bc7f57b7112567fe22a31c964cf4d10f7..ba94f23803adc9b83e46a7ed936e178064a42e71 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -384,7 +384,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -151,7 +151,7 @@ index 6131a99836b721f468d21df00c8d0f2bcb7feda9..4a899864f460c80bbc6d5d6849e0421c
if (movement.equals(Vec3.ZERO)) {
return;
@@ -1191,10 +1198,10 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
Vec3 vec3d1 = this.collideScan(movement);
Vec3 vec3d1 = this.sakura_collide(movement);
double d0 = vec3d1.lengthSqr();
- if (d0 > 1.0E-7D) {
@@ -208,16 +208,16 @@ index 6131a99836b721f468d21df00c8d0f2bcb7feda9..4a899864f460c80bbc6d5d6849e0421c
this.setDeltaMovement(flag ? 0.0D : vec3d2.x, vec3d2.y, flag1 ? 0.0D : vec3d2.z);
}
@@ -1614,7 +1631,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
} else {
AABB bb = currBoundingBox.expandTowards(movement.x, movement.y, movement.z);
this.collectCollisions(bb, potentialCollisionsVoxel, potentialCollisionsBB);
- return ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.performCollisions(movement, currBoundingBox, potentialCollisionsVoxel, potentialCollisionsBB);
+ return ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.performCollisions(movement, currBoundingBox, potentialCollisionsVoxel, potentialCollisionsBB, this.physics); // Sakura - physics version api
@@ -1627,7 +1644,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
bb = currBoundingBox.expandTowards(movement.x, movement.y, movement.z);
}
this.collectCollisions(bb, voxelList, bbList);
- return ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.performCollisions(movement, currBoundingBox, voxelList, bbList);
+ return ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.performCollisions(movement, currBoundingBox, voxelList, bbList, this.physics); // Sakura - physics version api
}
@@ -1623,7 +1640,10 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
private Vec3 collideAxisScan(Vec3 movement, AABB currBoundingBox, List<VoxelShape> voxelList, List<AABB> bbList) {
@@ -1635,7 +1652,10 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
double y = movement.y;
double z = movement.z;
@@ -229,7 +229,7 @@ index 6131a99836b721f468d21df00c8d0f2bcb7feda9..4a899864f460c80bbc6d5d6849e0421c
if (y != 0.0) {
y = this.scanY(currBoundingBox, y, voxelList, bbList);
@@ -1739,7 +1759,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -1748,7 +1768,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
return movement;
}
@@ -238,7 +238,7 @@ index 6131a99836b721f468d21df00c8d0f2bcb7feda9..4a899864f460c80bbc6d5d6849e0421c
if (stepHeight > 0.0
&& (onGround || (limitedMoveVector.y != movement.y && movement.y < 0.0))
@@ -1890,8 +1910,11 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -1899,8 +1919,11 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
protected void checkInsideBlocks() {
AABB axisalignedbb = this.getBoundingBox();

View File

@@ -5,10 +5,10 @@ Subject: [PATCH] Optimise check inside blocks and fluids
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index eb90625e5a4b843877ba2f7b2510ba1c26d861ce..8237ed9645ccebc274d3e7bbb16444126638c7a2 100644
index 6591dc7d43c0f2086328c8704b130ccca8e097cc..1a873b14ccf65a62ed5f6fe41e281bda1a799636 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -1924,18 +1924,37 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -1933,18 +1933,37 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
BlockPos blockposition1 = BlockPos.containing(axisalignedbb.maxX - offset, axisalignedbb.maxY - offset, axisalignedbb.maxZ - offset);
// Sakura end - physics version api
@@ -50,7 +50,7 @@ index eb90625e5a4b843877ba2f7b2510ba1c26d861ce..8237ed9645ccebc274d3e7bbb1644412
try {
iblockdata.entityInside(this.level(), blockposition_mutableblockposition, this);
@@ -4714,7 +4733,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -4723,7 +4742,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
public boolean updateFluidHeightAndDoFluidPushing(TagKey<Fluid> tag, double speed) {
@@ -59,7 +59,7 @@ index eb90625e5a4b843877ba2f7b2510ba1c26d861ce..8237ed9645ccebc274d3e7bbb1644412
return false;
} else {
AABB axisalignedbb = this.getBoundingBox().deflate(0.001D);
@@ -4731,11 +4750,30 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -4740,11 +4759,30 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
int k1 = 0;
BlockPos.MutableBlockPos blockposition_mutableblockposition = new BlockPos.MutableBlockPos();

View File

@@ -5,10 +5,10 @@ Subject: [PATCH] Configurable left shooting and adjusting limits
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 2e902a96d335abe849a2519fdc94844346046dc3..1912b9b1410073711ca85ed1703886a2d0e72f2b 100644
index 11c91e62ad71fbe8b22e417c6d942c8d0849a863..2201bd3639482ec0e6f01b4f991bb4abfb5b9da6 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -632,6 +632,24 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -632,6 +632,46 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
return Math.max(x, z) >= this.travelDistanceLimit;
}
// Sakura end - entity travel distance limits
@@ -29,36 +29,52 @@ index 2e902a96d335abe849a2519fdc94844346046dc3..1912b9b1410073711ca85ed1703886a2
+ }
+ }
+ }
+
+ public final void limitAdjustMovement(AABB currBoundingBox, double dir, boolean xAdjust, List<VoxelShape> shapes) {
+ int adjustDistance = this.level.sakuraConfig().cannons.restrictions.maxAdjustDistance.or(-1);
+ if (adjustDistance > 0 && Math.abs(dir) > adjustDistance) {
+ double minX = Double.NEGATIVE_INFINITY;
+ double minZ = Double.NEGATIVE_INFINITY;
+ double maxX = Double.POSITIVE_INFINITY;
+ double maxZ = Double.POSITIVE_INFINITY;
+ if (xAdjust) { // limit x adjust
+ minX = Math.floor(currBoundingBox.minX) - adjustDistance;
+ maxX = Math.floor(currBoundingBox.maxX) + adjustDistance + 1;
+ } else { // limit z adjust
+ minZ = Math.floor(currBoundingBox.minZ) - adjustDistance;
+ maxZ = Math.floor(currBoundingBox.maxZ) + adjustDistance + 1;
+ }
+ VoxelShape safeSpace = Shapes.box(
+ minX, Double.NEGATIVE_INFINITY, minZ,
+ maxX, Double.POSITIVE_INFINITY, maxZ
+ );
+ shapes.add(Shapes.join(Shapes.INFINITY, safeSpace, BooleanOp.ONLY_FIRST));
+ }
+ }
+ // Sakura end - configurable left shooting and adjusting limits
public Entity(EntityType<?> type, Level world) {
this.id = Entity.ENTITY_COUNTER.incrementAndGet();
@@ -1666,6 +1684,25 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
boolean xSmaller = this.physics == null || this.physics.afterOrEqual(1_14_0) ? Math.abs(x) < Math.abs(z)
: this.physics.isLegacy() && Math.abs(x) > Math.abs(z);
// Sakura end - physics version api
+ // Sakura start - configurable left shooting and adjusting limits
+ // NOTE: If scanAndCollide is made redundant by paper move this logic into CollisionUtil.
+ // This is being after xSmaller is intentional, we do not want to change the adjust direction.
+ int adjustDistance = this.level.sakuraConfig().cannons.restrictions.maxAdjustDistance.or(-1);
+ if (adjustDistance > 0) {
+ if (xSmaller) { // adjust z -> x
+ if (Math.abs(z) > adjustDistance) {
+ // limit z adjust and remove momentum to replicate it hitting a block
+ this.setDeltaMovement(this.getDeltaMovement().multiply(1.0, 1.0, 0.0));
+ z = Math.floor(this.getZ() + Math.copySign(adjustDistance, z)) - this.getZ() + 0.5;
+ }
+ } else { // adjust x -> z
+ if (Math.abs(x) > adjustDistance) {
+ this.setDeltaMovement(this.getDeltaMovement().multiply(0.0, 1.0, 1.0));
+ x = Math.floor(this.getX() + Math.copySign(adjustDistance, x)) - this.getX() + 0.5;
+ }
+ }
+ }
+ // Sakura end - configurable left shooting and adjusting limits
@@ -1687,6 +1727,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
if (y != 0.0) {
y = this.scanY(currBoundingBox, y, voxelList, bbList);
if (xSmaller && z != 0.0) {
+ this.limitAdjustMovement(currBoundingBox, z, false, voxelList); // Sakura - configurable left shooting and adjusting limits
z = this.scanZ(currBoundingBox, z, voxelList, bbList);
if (z != 0.0) {
currBoundingBox = ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.offsetZ(currBoundingBox, z);
@@ -1694,6 +1735,11 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
if (x != 0.0) {
+ // Sakura start - configurable left shooting and adjusting limits
+ if (!xSmaller) {
+ this.limitAdjustMovement(currBoundingBox, x, true, voxelList);
+ }
+ // Sakura end - configurable left shooting and adjusting limits
x = this.scanX(currBoundingBox, x, voxelList, bbList);
if (x != 0.0) {
currBoundingBox = ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.offsetX(currBoundingBox, x);
diff --git a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
index 87a5e151895c7fac32afc3b44088e5e75856dcd7..d722542fd1295669208946daa839c12cdf6886a9 100644
--- a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java