From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Mon, 2 Aug 2021 10:10:40 +0200 Subject: [PATCH] Improve boat collision performance diff --git a/src/main/java/net/minecraft/Util.java b/src/main/java/net/minecraft/Util.java index a8772417eb54e1a52c490b75b470a502a480f925..c072819c1ebc772f524649c6c2f8b48d919bf805 100644 --- a/src/main/java/net/minecraft/Util.java +++ b/src/main/java/net/minecraft/Util.java @@ -85,6 +85,7 @@ public class Util { }).findFirst().orElseThrow(() -> { return new IllegalStateException("No jar file system provider found"); }); + public static final double COLLISION_EPSILON = 1.0E-7; // Paper private static Consumer thePauser = (message) -> { }; diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java index 1f35368f9f44c578be76d66a85da937f497df655..d64e946a3228b871fb8a9703a8631008078e4bec 100644 --- a/src/main/java/net/minecraft/world/entity/LivingEntity.java +++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java @@ -1318,7 +1318,7 @@ public abstract class LivingEntity extends Entity { if (!source.isProjectile()) { Entity entity = source.getDirectEntity(); - if (entity instanceof LivingEntity) { + if (entity instanceof LivingEntity && entity.distanceToSqr(this) <= (200.0D * 200.0D)) { // Paper this.blockUsingShield((LivingEntity) entity); } } @@ -1426,11 +1426,12 @@ public abstract class LivingEntity extends Entity { } if (entity1 != null) { - double d0 = entity1.getX() - this.getX(); + final boolean far = entity1.distanceToSqr(this) > (200.0 * 200.0); // Paper + double d0 = far ? (Math.random() - Math.random()) : entity1.getX() - this.getX(); // Paper double d1; - for (d1 = entity1.getZ() - this.getZ(); d0 * d0 + d1 * d1 < 1.0E-4D; d1 = (Math.random() - Math.random()) * 0.01D) { + for (d1 = far ? Math.random() - Math.random() : entity1.getZ() - this.getZ(); d0 * d0 + d1 * d1 < 1.0E-4D; d1 = (Math.random() - Math.random()) * 0.01D) { // Paper d0 = (Math.random() - Math.random()) * 0.01D; } @@ -2109,7 +2110,7 @@ public abstract class LivingEntity extends Entity { this.hurtCurrentlyUsedShield((float) -event.getDamage(DamageModifier.BLOCKING)); Entity entity = damagesource.getDirectEntity(); - if (entity instanceof LivingEntity) { + if (entity instanceof LivingEntity && entity.distanceToSqr(this) <= (200.0D * 200.0D)) { // Paper this.blockUsingShield((LivingEntity) entity); } } diff --git a/src/main/java/net/minecraft/world/entity/vehicle/Boat.java b/src/main/java/net/minecraft/world/entity/vehicle/Boat.java index a8f37fab9c8020e884bf029145d03e3be57b7f2b..0dbc85c450797d7384e641f80e1b1f8c56fd14fc 100644 --- a/src/main/java/net/minecraft/world/entity/vehicle/Boat.java +++ b/src/main/java/net/minecraft/world/entity/vehicle/Boat.java @@ -686,8 +686,8 @@ public class Boat extends Entity { this.invFriction = 0.05F; if (this.oldStatus == Boat.Status.IN_AIR && this.status != Boat.Status.IN_AIR && this.status != Boat.Status.ON_LAND) { this.waterLevel = this.getY(1.0D); - this.setPos(this.getX(), (double) (this.getWaterLevelAbove() - this.getBbHeight()) + 0.101D, this.getZ()); - this.setDeltaMovement(this.getDeltaMovement().multiply(1.0D, 0.0D, 1.0D)); + this.move(MoverType.SELF, new Vec3(0.0, ((double) (this.getWaterLevelAbove() - this.getBbHeight()) + 0.101D) - this.getY(), 0.0)); // Paper + this.setDeltaMovement(this.getDeltaMovement().multiply(1.0D, 0.0D, 1.0D)); // Paper this.lastYd = 0.0D; this.status = Boat.Status.IN_WATER; } else {