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

Remove stripped movement method

This commit is contained in:
Samsuik
2025-01-25 23:30:30 +00:00
parent c8811412fe
commit 672477da5c
5 changed files with 154 additions and 180 deletions

View File

@@ -1,6 +1,6 @@
--- a/src/main/java/org/bukkit/World.java
+++ b/src/main/java/org/bukkit/World.java
@@ -205,6 +_,10 @@
@@ -206,6 +_,10 @@
return new Location(this, x, y, z);
}
// Paper end

View File

@@ -5,91 +5,24 @@ Subject: [PATCH] Optimise cannon entity movement
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index 2a617bd6d5d14cd69b149d6c5f82f8b2c3bc2d5d..8c3e0ca06f89e4d8c08d30272475cdeaca20b3ef 100644
index 2a617bd6d5d14cd69b149d6c5f82f8b2c3bc2d5d..d2f9708b9166a46adb5009bd6d927cd03f3f9820 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -1141,6 +1141,75 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
return this.moveStartZ;
}
// Paper end - detailed watchdog information
+ // Sakura start - optimise cannon entity movement; stripped back movement method
+ public final void moveStripped(MoverType movementType, Vec3 movement) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread("Cannot move an entity off-main");
+ if (this.noPhysics) {
+ this.setPos(this.getX() + movement.x, this.getY() + movement.y, this.getZ() + movement.z);
+ } else {
+ if (movementType == MoverType.PISTON) {
+ movement = this.limitPistonMovement(movement);
+ if (movement.equals(Vec3.ZERO)) {
+ return;
+ }
+ }
+
+ ProfilerFiller gameprofilerfiller = Profiler.get();
+ gameprofilerfiller.push("move");
+ if (this.stuckSpeedMultiplier.lengthSqr() > 1.0E-7D) {
+ movement = movement.multiply(this.stuckSpeedMultiplier);
+ this.stuckSpeedMultiplier = Vec3.ZERO;
+ this.setDeltaMovement(Vec3.ZERO);
+ }
+
+ Vec3 vec3d1 = this.sakura_collide(movement);
+ double d0 = vec3d1.lengthSqr();
+
+ if (d0 > 1.0E-7D || movement.lengthSqr() - d0 < 1.0E-7D) {
+ if (this.fallDistance != 0.0F && d0 >= 1.0D && !this.isFallingBlock) {
+ BlockHitResult clipResult = this.level().clip(new ClipContext(this.position(), this.position().add(vec3d1), ClipContext.Block.FALLDAMAGE_RESETTING, ClipContext.Fluid.WATER, this));
+ if (clipResult.getType() != HitResult.Type.MISS) {
+ this.resetFallDistance();
+ }
+ }
+
+ this.setPos(this.getX() + vec3d1.x, this.getY() + vec3d1.y, this.getZ() + vec3d1.z);
+ }
+
+ gameprofilerfiller.pop();
+ gameprofilerfiller.push("rest");
+ boolean movedX = !Mth.equal(movement.x, vec3d1.x);
+ boolean movedZ = !Mth.equal(movement.z, vec3d1.z);
+
+ this.horizontalCollision = movedX || movedZ;
+ this.verticalCollision = movement.y != vec3d1.y;
+ this.verticalCollisionBelow = this.verticalCollision && movement.y < 0.0D;
+
+ this.setOnGroundWithMovement(this.verticalCollisionBelow, this.horizontalCollision, vec3d1);
+ BlockPos blockPosBelow = this.getOnPosLegacy();
+ BlockState blockstate = this.level().getBlockState(blockPosBelow);
+
+ this.checkFallDamage(vec3d1.y, this.onGround(), blockstate, blockPosBelow);
+ if (this.isRemoved()) {
+ gameprofilerfiller.pop();
+ } else {
+ if (this.horizontalCollision) {
+ Vec3 vec3d2 = this.getDeltaMovement();
+ this.setDeltaMovement(movedX ? 0.0D : vec3d2.x, vec3d2.y, movedZ ? 0.0D : vec3d2.z);
+ }
+
+ Block block = blockstate.getBlock();
+ if (movement.y != vec3d1.y) { // remove y momentum
+ block.updateEntityMovementAfterFallOn(this.level(), this);
+ }
+
+ float f = this.getBlockSpeedFactor();
+ this.setDeltaMovement(this.getDeltaMovement().multiply((double) f, 1.0D, (double) f));
+ gameprofilerfiller.pop();
+ }
+ }
+ }
+ // Sakura end - optimise cannon entity movement; stripped back movement method
public void move(MoverType type, Vec3 movement) {
final Vec3 originalMovement = movement; // Paper - Expose pre-collision velocity
@@ -1488,6 +1557,107 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -1186,7 +1186,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
Vec3 vec3 = this.collide(movement);
double d = vec3.lengthSqr();
if (d > 1.0E-7 || movement.lengthSqr() - d < 1.0E-7) {
- if (this.fallDistance != 0.0F && d >= 1.0) {
+ if (this.fallDistance != 0.0F && d >= 1.0 && !this.isFallingBlock) { // Sakura - optimise cannon entity movement
BlockHitResult blockHitResult = this.level()
.clip(
new ClipContext(this.position(), this.position().add(vec3), ClipContext.Block.FALLDAMAGE_RESETTING, ClipContext.Fluid.WATER, this)
@@ -1488,6 +1488,131 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
return distance;
}
+ // Sakura start - optimise cannon entity movement
+ private Vec3 sakura_collide(Vec3 movement) {
+ protected final Vec3 sakura_collide(Vec3 movement) {
+ if (movement.x == 0.0 && movement.y == 0.0 && movement.z == 0.0) {
+ return movement;
+ }
@@ -116,7 +49,7 @@ index 2a617bd6d5d14cd69b149d6c5f82f8b2c3bc2d5d..8c3e0ca06f89e4d8c08d30272475cdea
+ } else {
+ bb = currBoundingBox.expandTowards(movement.x, movement.y, movement.z);
+ }
+ this.collectCollisions(bb, voxelList, bbList);
+ this.collectCollisions(bb, voxelList, bbList, ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.COLLISION_FLAG_CHECK_BORDER);
+ return ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.performCollisions(movement, currBoundingBox, voxelList, bbList);
+ }
+
@@ -155,11 +88,11 @@ index 2a617bd6d5d14cd69b149d6c5f82f8b2c3bc2d5d..8c3e0ca06f89e4d8c08d30272475cdea
+ return new Vec3(x, y, z);
+ }
+
+ private void collectCollisions(AABB collisionBox, List<VoxelShape> voxelList, List<AABB> bbList) {
+ private void collectCollisions(AABB collisionBox, List<VoxelShape> voxelList, List<AABB> bbList, int flags) {
+ // Copied from the collide method below
+ ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.getCollisionsForBlocksOrWorldBorder(
+ this.level, this, collisionBox, voxelList, bbList,
+ ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.COLLISION_FLAG_CHECK_BORDER | this.getExtraCollisionFlags(), null // Sakura - load chunks on movement
+ flags | this.getExtraCollisionFlags(), null // Sakura - load chunks on movement
+ );
+
+ ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.getEntityHardCollisions(
@@ -168,53 +101,85 @@ index 2a617bd6d5d14cd69b149d6c5f82f8b2c3bc2d5d..8c3e0ca06f89e4d8c08d30272475cdea
+ }
+
+ private double scanX(AABB currBoundingBox, double x, List<VoxelShape> voxelList, List<AABB> bbList) {
+ AABB scanBox = currBoundingBox.expandTowards(x, 0.0, 0.0);
+ this.collectCollisions(scanBox, voxelList, bbList);
+ AABB scanBox = cutBoundingBoxX(currBoundingBox, x);
+ this.collectCollisions(scanBox, voxelList, bbList, ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.COLLISION_FLAG_CHECK_BORDER);
+ x = ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.performAABBCollisionsX(currBoundingBox, x, bbList);
+ return ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.performVoxelCollisionsX(currBoundingBox, x, voxelList);
+ }
+
+ private double scanY(AABB currBoundingBox, double y, List<VoxelShape> voxelList, List<AABB> bbList) {
+ AABB scanBox = currBoundingBox.expandTowards(0.0, y, 0.0);
+ this.collectCollisions(scanBox, voxelList, bbList);
+ AABB scanBox = cutBoundingBoxY(currBoundingBox, y);
+ this.collectCollisions(scanBox, voxelList, bbList, 0);
+ y = ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.performAABBCollisionsY(currBoundingBox, y, bbList);
+ return ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.performVoxelCollisionsY(currBoundingBox, y, voxelList);
+ }
+
+ private double scanZ(AABB currBoundingBox, double z, List<VoxelShape> voxelList, List<AABB> bbList) {
+ AABB scanBox = currBoundingBox.expandTowards(0.0, 0.0, z);
+ this.collectCollisions(scanBox, voxelList, bbList);
+ AABB scanBox = cutBoundingBoxZ(currBoundingBox, z);
+ this.collectCollisions(scanBox, voxelList, bbList, ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.COLLISION_FLAG_CHECK_BORDER);
+ z = ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.performAABBCollisionsZ(currBoundingBox, z, bbList);
+ return ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.performVoxelCollisionsZ(currBoundingBox, z, voxelList);
+ }
+
+ private static AABB cutBoundingBoxX(AABB bb, double x) {
+ if (x > 0.0) {
+ return ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.cutRight(bb, x);
+ } else {
+ return ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.cutLeft(bb, x);
+ }
+ }
+
+ private static AABB cutBoundingBoxY(AABB bb, double y) {
+ if (y > 0.0) {
+ return ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.cutUpwards(bb, y);
+ } else {
+ return ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.cutDownwards(bb, y);
+ }
+ }
+
+ private static AABB cutBoundingBoxZ(AABB bb, double z) {
+ if (z > 0.0) {
+ return ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.cutForwards(bb, z);
+ } else {
+ return ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.cutBackwards(bb, z);
+ }
+ }
+ // Sakura end - optimise cannon entity movement
+
// Paper start - optimise collisions
protected Vec3 collide(Vec3 movement) {
final boolean xZero = movement.x == 0.0;
diff --git a/net/minecraft/world/entity/item/FallingBlockEntity.java b/net/minecraft/world/entity/item/FallingBlockEntity.java
index 1d9afcf995ee734f13803e26956439e5c3450f44..c6836ab9a2789520931d2119aeebeaf2179f27fa 100644
index 58baa1a72ccdc6557257aa2c9f652200cb9c4c70..af42bea9fb18bb0f6e576d4344cdee2cd0e9a4ef 100644
--- a/net/minecraft/world/entity/item/FallingBlockEntity.java
+++ b/net/minecraft/world/entity/item/FallingBlockEntity.java
@@ -213,7 +213,7 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti
Block block = this.blockState.getBlock();
this.time++;
this.applyGravity();
- this.move(MoverType.SELF, this.getDeltaMovement());
+ this.moveStripped(MoverType.SELF, this.getDeltaMovement()); // Sakura - optimise cannon entity movement
this.applyEffectsFromBlocks();
// Paper start - Configurable falling blocks height nerf
if (this.level().paperConfig().fixes.fallingBlockHeightNerf.test(v -> this.getY() > v)) {
@@ -119,6 +119,12 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti
return itemEntity;
}
// Sakura end - merge cannon entities
+ // Sakura start - optimise cannon entity movement
+ @Override
+ protected final Vec3 collide(Vec3 movement) {
+ return this.sakura_collide(movement);
+ }
+ // Sakura end - optimise cannon entity movement
public FallingBlockEntity(EntityType<? extends FallingBlockEntity> entityType, Level level) {
super(entityType, level);
diff --git a/net/minecraft/world/entity/item/PrimedTnt.java b/net/minecraft/world/entity/item/PrimedTnt.java
index c88fe6c244f6a88f1e42822dd0795187dcc3b655..2ee04093d7c8b61a48913bd4c929528e357aa971 100644
index cb972f9d619c7acc8bbed4cc18513ad4b97f19ed..d23193d3f11505cea428414487f891ab584ad071 100644
--- a/net/minecraft/world/entity/item/PrimedTnt.java
+++ b/net/minecraft/world/entity/item/PrimedTnt.java
@@ -148,7 +148,7 @@ public class PrimedTnt extends Entity implements TraceableEntity, me.samsuik.sak
// Sakura - remove max tnt per tick
this.handlePortal();
this.applyGravity();
- this.move(MoverType.SELF, this.getDeltaMovement());
+ this.moveStripped(MoverType.SELF, this.getDeltaMovement()); // Sakura - optimise cannon entity movement
this.applyEffectsFromBlocks();
// Paper start - Configurable TNT height nerf
if (this.level().paperConfig().fixes.tntEntityHeightNerf.test(v -> this.getY() > v)) {
@@ -80,6 +80,12 @@ public class PrimedTnt extends Entity implements TraceableEntity, me.samsuik.sak
this.mergeData.setCount(count); // Sakura - specialised explosions
}
// Sakura end - merge cannon entities
+ // Sakura start - optimise cannon entity movement
+ @Override
+ protected final net.minecraft.world.phys.Vec3 collide(net.minecraft.world.phys.Vec3 movement) {
+ return this.sakura_collide(movement);
+ }
+ // Sakura end - optimise cannon entity movement
public PrimedTnt(EntityType<? extends PrimedTnt> entityType, Level level) {
super(entityType, level);

View File

@@ -67,7 +67,7 @@ index 651a45b795818bd7b1364b95c52570fd99dd35e4..47c8ed946cb2ad81a4469daf60dabc40
if (xSmaller && z != 0.0) {
z = performAABBCollisionsZ(axisalignedbb, z, aabbs);
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index 8c3e0ca06f89e4d8c08d30272475cdeaca20b3ef..a6a47d9d0d8e475d936ce867cdbb8d597e71ff4e 100644
index d2f9708b9166a46adb5009bd6d927cd03f3f9820..a026047ed2ab4b9ab047c7d855914296a2c26c92 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -580,6 +580,13 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -93,48 +93,55 @@ index 8c3e0ca06f89e4d8c08d30272475cdeaca20b3ef..a6a47d9d0d8e475d936ce867cdbb8d59
AABB boundingBox = this.getBoundingBox();
AABB aabb = new AABB(boundingBox.minX, boundingBox.minY - 1.0E-6, boundingBox.minZ, boundingBox.maxX, boundingBox.minY, boundingBox.maxZ);
Optional<BlockPos> optional = this.level.findSupportingBlock(this, aabb);
@@ -1147,7 +1154,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
if (this.noPhysics) {
@@ -1158,7 +1165,10 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
this.setPos(this.getX() + movement.x, this.getY() + movement.y, this.getZ() + movement.z);
} else {
- if (movementType == MoverType.PISTON) {
+ if (movementType == MoverType.PISTON && this.physics.afterOrEqual(1_11_0)) { // Sakura - configure cannon physics
this.wasOnFire = this.isOnFire();
- if (type == MoverType.PISTON) {
+ // Sakura start - configure cannon physics
+ final me.samsuik.sakura.physics.PhysicsVersion physics = this.physics;
+ if (type == MoverType.PISTON && physics.afterOrEqual(1_11_0)) {
+ // Sakura end - configure cannon physics
this.activatedTick = Math.max(this.activatedTick, MinecraftServer.currentTick + 20); // Paper - EAR 2
this.activatedImmunityTick = Math.max(this.activatedImmunityTick, MinecraftServer.currentTick + 20); // Paper - EAR 2
movement = this.limitPistonMovement(movement);
if (movement.equals(Vec3.ZERO)) {
return;
@@ -1165,8 +1172,8 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
Vec3 vec3d1 = this.sakura_collide(movement);
double d0 = vec3d1.lengthSqr();
- if (d0 > 1.0E-7D || movement.lengthSqr() - d0 < 1.0E-7D) {
- if (this.fallDistance != 0.0F && d0 >= 1.0D && !this.isFallingBlock) {
+ if (d0 > 1.0E-7D || this.physics.afterOrEqual(1_21_2) && movement.lengthSqr() - d0 < 1.0E-7D || this.physics.before(1_14_0)) { // Sakura - configure cannon physics
+ if (this.fallDistance != 0.0F && d0 >= 1.0D && !this.isFallingBlock && this.physics.afterOrEqual(1_18_2)) { // Sakura - configure cannon physics
BlockHitResult clipResult = this.level().clip(new ClipContext(this.position(), this.position().add(vec3d1), ClipContext.Block.FALLDAMAGE_RESETTING, ClipContext.Fluid.WATER, this));
if (clipResult.getType() != HitResult.Type.MISS) {
this.resetFallDistance();
@@ -1195,6 +1202,11 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -1185,8 +1195,11 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
movement = this.maybeBackOffFromEdge(movement, type);
Vec3 vec3 = this.collide(movement);
double d = vec3.lengthSqr();
- if (d > 1.0E-7 || movement.lengthSqr() - d < 1.0E-7) {
- if (this.fallDistance != 0.0F && d >= 1.0 && !this.isFallingBlock) { // Sakura - optimise cannon entity movement
+
+ // Sakura start - configure cannon physics
+ if (d > 1.0E-7 || physics.afterOrEqual(1_21_2) && movement.lengthSqr() - d < 1.0E-7 || physics.before(1_14_0)) {
+ if (this.fallDistance != 0.0F && d >= 1.0 && !this.isFallingBlock && physics.afterOrEqual(1_18_2)) { // Sakura - optimise cannon entity movement
+ // Sakura end - configure cannon physics
BlockHitResult blockHitResult = this.level()
.clip(
new ClipContext(this.position(), this.position().add(vec3), ClipContext.Block.FALLDAMAGE_RESETTING, ClipContext.Fluid.WATER, this)
@@ -1227,6 +1240,12 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
} else {
if (this.horizontalCollision) {
Vec3 vec3d2 = this.getDeltaMovement();
Vec3 deltaMovement = this.getDeltaMovement();
+ // Sakura start - configure cannon physics
+ if (movedX && movedZ && this.physics.isWithin(1_14_0, 1_18_1)) {
+ movedX = false;
+ // SANITY: flag = movedX, flag1 = movedZ
+ if (flag && flag1 && physics.isWithin(1_14_0, 1_18_1)) {
+ flag = false;
+ }
+ // Sakura end - configure cannon physics
this.setDeltaMovement(movedX ? 0.0D : vec3d2.x, vec3d2.y, movedZ ? 0.0D : vec3d2.z);
this.setDeltaMovement(flag ? 0.0 : deltaMovement.x, deltaMovement.y, flag1 ? 0.0 : deltaMovement.z);
}
@@ -1586,7 +1598,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -1517,7 +1536,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
bb = currBoundingBox.expandTowards(movement.x, movement.y, movement.z);
}
this.collectCollisions(bb, voxelList, bbList);
this.collectCollisions(bb, voxelList, bbList, ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.COLLISION_FLAG_CHECK_BORDER);
- 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 - configure cannon physics
}
private Vec3 collideAxisScan(Vec3 movement, AABB currBoundingBox, List<VoxelShape> voxelList, List<AABB> bbList) {
@@ -1594,7 +1606,10 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -1525,7 +1544,10 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
double y = movement.y;
double z = movement.z;
@@ -146,7 +153,7 @@ index 8c3e0ca06f89e4d8c08d30272475cdeaca20b3ef..a6a47d9d0d8e475d936ce867cdbb8d59
if (y != 0.0) {
y = this.scanY(currBoundingBox, y, voxelList, bbList);
@@ -1692,7 +1707,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -1647,7 +1669,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.COLLISION_FLAG_CHECK_BORDER | this.getExtraCollisionFlags(), null // Sakura - load chunks on movement
);
potentialCollisionsBB.addAll(entityAABBs);
@@ -155,7 +162,7 @@ index 8c3e0ca06f89e4d8c08d30272475cdeaca20b3ef..a6a47d9d0d8e475d936ce867cdbb8d59
final boolean collidedX = collided.x != movement.x;
final boolean collidedY = collided.y != movement.y;
@@ -1851,9 +1866,17 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -1806,9 +1828,17 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
for (Entity.Movement movement : movements) {
Vec3 vec3 = movement.from();
Vec3 vec31 = movement.to();
@@ -177,13 +184,13 @@ index 8c3e0ca06f89e4d8c08d30272475cdeaca20b3ef..a6a47d9d0d8e475d936ce867cdbb8d59
return;
}
diff --git a/net/minecraft/world/entity/item/FallingBlockEntity.java b/net/minecraft/world/entity/item/FallingBlockEntity.java
index f525262a153919deeeb1e6df20009b78f9e8e601..6a2bb2d4fa2ff76f85648ea39c8f0abd9b4b7e95 100644
index af42bea9fb18bb0f6e576d4344cdee2cd0e9a4ef..10799fe7188f69c6eb56403ba0942a437139fb84 100644
--- a/net/minecraft/world/entity/item/FallingBlockEntity.java
+++ b/net/minecraft/world/entity/item/FallingBlockEntity.java
@@ -119,6 +119,43 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti
return itemEntity;
@@ -125,6 +125,43 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti
return this.sakura_collide(movement);
}
// Sakura end - merge cannon entities
// Sakura end - optimise cannon entity movement
+ // Sakura start - configure cannon physics
+ @Override
+ public final double distanceToSqr(Vec3 vector) {
@@ -224,7 +231,7 @@ index f525262a153919deeeb1e6df20009b78f9e8e601..6a2bb2d4fa2ff76f85648ea39c8f0abd
public FallingBlockEntity(EntityType<? extends FallingBlockEntity> entityType, Level level) {
super(entityType, level);
@@ -138,6 +175,10 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti
@@ -144,6 +181,10 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti
this.yo = y;
this.zo = z;
this.setStartPos(this.blockPosition());
@@ -235,7 +242,7 @@ index f525262a153919deeeb1e6df20009b78f9e8e601..6a2bb2d4fa2ff76f85648ea39c8f0abd
}
// Sakura start - falling block height parity api
@@ -158,7 +199,11 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti
@@ -164,7 +205,11 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti
: blockState
);
if (!CraftEventFactory.callEntityChangeBlockEvent(fallingBlockEntity, pos, blockState.getFluidState().createLegacyBlock())) return fallingBlockEntity; // CraftBukkit
@@ -248,7 +255,7 @@ index f525262a153919deeeb1e6df20009b78f9e8e601..6a2bb2d4fa2ff76f85648ea39c8f0abd
level.addFreshEntity(fallingBlockEntity);
return fallingBlockEntity;
}
@@ -202,7 +247,7 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti
@@ -208,7 +253,7 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti
@Override
protected double getDefaultGravity() {
@@ -257,57 +264,58 @@ index f525262a153919deeeb1e6df20009b78f9e8e601..6a2bb2d4fa2ff76f85648ea39c8f0abd
}
@Override
@@ -211,6 +256,11 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti
@@ -217,6 +262,12 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti
this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
} else {
Block block = this.blockState.getBlock();
+ // Sakura start - configure cannon physics
+ if (this.time == 0 && this.physics.before(1_18_2)) {
+ final me.samsuik.sakura.physics.PhysicsVersion physics = this.physics;
+ if (this.time == 0 && physics.before(1_18_2)) {
+ this.removeBlockOnFall(block);
+ }
+ // Sakura end - configure cannon physics
this.time++;
this.applyGravity();
this.moveStripped(MoverType.SELF, this.getDeltaMovement()); // Sakura - optimise cannon entity movement
@@ -225,8 +275,15 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti
this.move(MoverType.SELF, this.getDeltaMovement());
@@ -231,8 +282,15 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti
}
// Paper end - Configurable falling blocks height nerf
this.handlePortal();
+ // Sakura start - configure cannon physics
+ if (this.physics.before(1_12_0)) {
+ if (physics.before(1_12_0)) {
+ this.setDeltaMovement(this.getDeltaMovement().scale(0.98F));
+ }
if (this.level() instanceof ServerLevel serverLevel && (this.isAlive() || this.forceTickAfterTeleportToDuplicate)) {
- BlockPos blockPos = this.blockPosition();
+ // Patching the floating point issue on modern versions can break some cannons that rely on it.
+ // However, it makes sense for legacy versions pre-1.17 before the world height change.
+ BlockPos blockPos = this.physics.before(1_17_0) ? this.patchedBlockPosition() : this.blockPosition();
+ BlockPos blockPos = physics.before(1_17_0) ? this.patchedBlockPosition() : this.blockPosition();
+ // Sakura end - configure cannon physics
boolean flag = this.level().sakuraConfig().cannons.sand.concreteSolidifyInWater && this.blockState.getBlock() instanceof ConcretePowderBlock; // Sakura - configure concrete solidifying in water
boolean flag1 = flag && this.level().getFluidState(blockPos).is(FluidTags.WATER);
double d = this.getDeltaMovement().lengthSqr();
@@ -253,8 +310,11 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti
@@ -259,8 +317,11 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti
}
} else {
BlockState blockState = this.level().getBlockState(blockPos);
- this.setDeltaMovement(this.getDeltaMovement().multiply(0.7, -0.5, 0.7));
- if (!blockState.is(Blocks.MOVING_PISTON)) {
+ // Sakura start - configure cannon physics
+ double friction = this.physics.before(1_14_0) ? 0.7f : 0.7;
+ final double friction = physics.before(1_14_0) ? 0.7f : 0.7;
+ this.setDeltaMovement(this.getDeltaMovement().multiply(friction, -0.5, friction));
+ if (!blockState.is(Blocks.MOVING_PISTON) && (flag1 || !this.physics.isWithin(1_9_0, 1_12_0) || this.isAbleToStackOnBlock())) {
+ if (!blockState.is(Blocks.MOVING_PISTON) && (flag1 || !physics.isWithin(1_9_0, 1_12_0) || this.isAbleToStackOnBlock())) {
+ // Sakura end - configure cannon physics
if (!this.cancelDrop) {
boolean canBeReplaced = blockState.canBeReplaced(
new DirectionalPlaceContext(this.level(), blockPos, Direction.DOWN, ItemStack.EMPTY, Direction.UP)
@@ -326,7 +386,12 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti
@@ -332,7 +393,12 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti
}
}
- this.setDeltaMovement(this.getDeltaMovement().scale(0.98));
+ // Sakura start - configure cannon physics
+ if (this.physics.afterOrEqual(1_12_0)) {
+ double drag = this.physics.before(1_14_0) ? 0.98f : 0.98;
+ if (physics.afterOrEqual(1_12_0)) {
+ final double drag = physics.before(1_14_0) ? 0.98f : 0.98;
+ this.setDeltaMovement(this.getDeltaMovement().scale(drag));
+ }
+ // Sakura end - configure cannon physics
@@ -315,13 +323,13 @@ index f525262a153919deeeb1e6df20009b78f9e8e601..6a2bb2d4fa2ff76f85648ea39c8f0abd
}
diff --git a/net/minecraft/world/entity/item/PrimedTnt.java b/net/minecraft/world/entity/item/PrimedTnt.java
index 28fd804bcaf5e96c7c90881587c073cde94ae1d5..15f88b0b4e16db42955601ee2d28a0b693d88ace 100644
index d23193d3f11505cea428414487f891ab584ad071..ffd96218e2ee84aae7a008ef1b95f84d2a6b56b4 100644
--- a/net/minecraft/world/entity/item/PrimedTnt.java
+++ b/net/minecraft/world/entity/item/PrimedTnt.java
@@ -80,6 +80,22 @@ public class PrimedTnt extends Entity implements TraceableEntity, me.samsuik.sak
this.mergeData.setCount(count); // Sakura - specialised explosions
@@ -86,6 +86,22 @@ public class PrimedTnt extends Entity implements TraceableEntity, me.samsuik.sak
return this.sakura_collide(movement);
}
// Sakura end - merge cannon entities
// Sakura end - optimise cannon entity movement
+ // Sakura start - configure cannon physics
+ @Override
+ public final double getEyeY() {
@@ -341,7 +349,7 @@ index 28fd804bcaf5e96c7c90881587c073cde94ae1d5..15f88b0b4e16db42955601ee2d28a0b6
public PrimedTnt(EntityType<? extends PrimedTnt> entityType, Level level) {
super(entityType, level);
@@ -105,6 +121,13 @@ public class PrimedTnt extends Entity implements TraceableEntity, me.samsuik.sak
@@ -111,6 +127,13 @@ public class PrimedTnt extends Entity implements TraceableEntity, me.samsuik.sak
case Y -> this.setDeltaMovement(this.getDeltaMovement().multiply(0.0, 1.0, 0.0));
}
// Sakura end - configure cannon mechanics
@@ -355,7 +363,7 @@ index 28fd804bcaf5e96c7c90881587c073cde94ae1d5..15f88b0b4e16db42955601ee2d28a0b6
}
// Sakura start - optimise tnt fluid state
@@ -140,7 +163,7 @@ public class PrimedTnt extends Entity implements TraceableEntity, me.samsuik.sak
@@ -146,7 +169,7 @@ public class PrimedTnt extends Entity implements TraceableEntity, me.samsuik.sak
@Override
protected double getDefaultGravity() {
@@ -364,17 +372,18 @@ index 28fd804bcaf5e96c7c90881587c073cde94ae1d5..15f88b0b4e16db42955601ee2d28a0b6
}
@Override
@@ -156,14 +179,18 @@ public class PrimedTnt extends Entity implements TraceableEntity, me.samsuik.sak
@@ -162,14 +185,19 @@ public class PrimedTnt extends Entity implements TraceableEntity, me.samsuik.sak
return;
}
// Paper end - Configurable TNT height nerf
- this.setDeltaMovement(this.getDeltaMovement().scale(0.98));
+ // Sakura start - configure cannon physics
+ double drag = this.physics.before(1_14_0) ? 0.98f : 0.98;
+ final me.samsuik.sakura.physics.PhysicsVersion physics = this.physics;
+ final double drag = physics.before(1_14_0) ? 0.98f : 0.98;
+ this.setDeltaMovement(this.getDeltaMovement().scale(drag));
if (this.onGround()) {
- this.setDeltaMovement(this.getDeltaMovement().multiply(0.7, -0.5, 0.7));
+ double friction = this.physics.before(1_14_0) ? 0.7f : 0.7;
+ final double friction = physics.before(1_14_0) ? 0.7f : 0.7;
+ this.setDeltaMovement(this.getDeltaMovement().multiply(friction, -0.5, friction));
+ // Sakura end - configure cannon physics
}
@@ -382,11 +391,11 @@ index 28fd804bcaf5e96c7c90881587c073cde94ae1d5..15f88b0b4e16db42955601ee2d28a0b6
int i = this.getFuse() - 1;
this.setFuse(i);
- if (i <= 0) {
+ if (this.physics.before(1_9_0) ? (i < 0) : (i <= 0)) { // Sakura - configure cannon physics
+ if (physics.before(1_9_0) ? (i < 0) : (i <= 0)) { // Sakura - configure cannon physics
// CraftBukkit start - Need to reverse the order of the explosion and the entity death so we have a location for the event
//this.discard();
this.respawnEntity(); // Sakura - merge cannon entities
@@ -216,13 +243,14 @@ public class PrimedTnt extends Entity implements TraceableEntity, me.samsuik.sak
@@ -222,13 +250,14 @@ public class PrimedTnt extends Entity implements TraceableEntity, me.samsuik.sak
return;
}
// CraftBukkit end
@@ -402,7 +411,7 @@ index 28fd804bcaf5e96c7c90881587c073cde94ae1d5..15f88b0b4e16db42955601ee2d28a0b6
this.getZ(),
event.getRadius(), // CraftBukkit
event.getFire(), // CraftBukkit
@@ -314,7 +342,7 @@ public class PrimedTnt extends Entity implements TraceableEntity, me.samsuik.sak
@@ -320,7 +349,7 @@ public class PrimedTnt extends Entity implements TraceableEntity, me.samsuik.sak
// Paper start - Option to prevent TNT from moving in water
@Override
public boolean isPushedByFluid() {
@@ -909,7 +918,7 @@ index f14e84e67746208dd188525fb91ab30b190d332b..1d66e5848a7f1b3c5e6b70f2e3835166
}
diff --git a/net/minecraft/world/level/block/piston/PistonBaseBlock.java b/net/minecraft/world/level/block/piston/PistonBaseBlock.java
index 3d3a8879b7706b1a9dbfb818e694ac9988bb21ab..2b2a4eff85db43f6ae330f924cb3c75ca175f682 100644
index 2cf701ee91393800347cf44e06d6b6a6f4a99492..9aab4fc49357db20af346c227d8a566ebd3b1f69 100644
--- a/net/minecraft/world/level/block/piston/PistonBaseBlock.java
+++ b/net/minecraft/world/level/block/piston/PistonBaseBlock.java
@@ -145,6 +145,11 @@ public class PistonBaseBlock extends DirectionalBlock {

View File

@@ -5,7 +5,7 @@ Subject: [PATCH] Configurable left shooting and adjusting limits
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index 37d2ab5f3cfe10478e87d1649d072fe6b69fb914..f9b9d81cc60785488a7cf57caabb4a5fdd84ecae 100644
index 88a83d0b81fc65b4091c7f2c44820b4913356a2f..dd56f4e128793006c370514007755bdfb9d656d0 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -608,6 +608,46 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -13,7 +13,7 @@ index 37d2ab5f3cfe10478e87d1649d072fe6b69fb914..f9b9d81cc60785488a7cf57caabb4a5f
}
// Sakura end - entity travel distance limits
+ // Sakura start - configurable left shooting and adjusting limits
+ public final void limitLeftShooting() {
+ protected final void limitLeftShooting() {
+ Vec3 movement = this.getDeltaMovement();
+ int threshold = this.level.sakuraConfig().cannons.restrictions.leftShootingThreshold.or(-1);
+ if (threshold > 0 && (movement.x != 0.0 || movement.z != 0.0) && this.origin != null) {
@@ -30,7 +30,7 @@ index 37d2ab5f3cfe10478e87d1649d072fe6b69fb914..f9b9d81cc60785488a7cf57caabb4a5f
+ }
+ }
+
+ public final void limitAdjustMovement(AABB currBoundingBox, double dir, boolean xAdjust, List<VoxelShape> shapes) {
+ private 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;
@@ -55,7 +55,7 @@ index 37d2ab5f3cfe10478e87d1649d072fe6b69fb914..f9b9d81cc60785488a7cf57caabb4a5f
public Entity(EntityType<?> entityType, Level level) {
this.type = entityType;
@@ -1641,6 +1681,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -1579,6 +1619,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
if (xSmaller && z != 0.0) {
@@ -63,7 +63,7 @@ index 37d2ab5f3cfe10478e87d1649d072fe6b69fb914..f9b9d81cc60785488a7cf57caabb4a5f
z = this.scanZ(currBoundingBox, z, voxelList, bbList);
if (z != 0.0) {
currBoundingBox = ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.offsetZ(currBoundingBox, z);
@@ -1648,6 +1689,11 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -1586,6 +1627,11 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
if (x != 0.0) {
@@ -76,14 +76,14 @@ index 37d2ab5f3cfe10478e87d1649d072fe6b69fb914..f9b9d81cc60785488a7cf57caabb4a5f
if (x != 0.0) {
currBoundingBox = ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.offsetX(currBoundingBox, x);
diff --git a/net/minecraft/world/entity/item/FallingBlockEntity.java b/net/minecraft/world/entity/item/FallingBlockEntity.java
index d82e5184515c14a819b70c4d621cc6d93d120cc9..77656b3e8b80b07e9aa44a4d2c9bca468c52d26b 100644
index 10799fe7188f69c6eb56403ba0942a437139fb84..8ecc4a7b6f7bd997aecc85c5d0c12b0e8926a505 100644
--- a/net/minecraft/world/entity/item/FallingBlockEntity.java
+++ b/net/minecraft/world/entity/item/FallingBlockEntity.java
@@ -263,6 +263,7 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti
@@ -270,6 +270,7 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti
// Sakura end - configure cannon physics
this.time++;
this.applyGravity();
+ this.limitLeftShooting(); // Sakura - configurable left shooting and adjusting limits
this.moveStripped(MoverType.SELF, this.getDeltaMovement()); // Sakura - optimise cannon entity movement
this.move(MoverType.SELF, this.getDeltaMovement());
this.applyEffectsFromBlocks();
// Paper start - Configurable falling blocks height nerf

View File

@@ -5,10 +5,10 @@ Subject: [PATCH] Optimise check inside blocks and traverse blocks
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index f9b9d81cc60785488a7cf57caabb4a5fdd84ecae..17e5148f7fb273e6de3ab5f159cbfc5d4819eb9f 100644
index dd56f4e128793006c370514007755bdfb9d656d0..052cb99dd690f2ba6138d6a37bc7f3309c6c38bf 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -1930,6 +1930,11 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -1892,6 +1892,11 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
private void checkInsideBlocks(List<Entity.Movement> movements, Set<BlockState> blocksInside) {
if (this.isAffectedByBlocks()) {
LongSet set = this.visitedBlocks;
@@ -20,7 +20,7 @@ index f9b9d81cc60785488a7cf57caabb4a5fdd84ecae..17e5148f7fb273e6de3ab5f159cbfc5d
for (Entity.Movement movement : movements) {
Vec3 vec3 = movement.from();
@@ -1949,7 +1954,19 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -1911,7 +1916,19 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
return;
}