aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/1001-Improve-boat-collision-performance.patch
blob: 32c6ddbca3e421d2c33f99451f45604a22ebd021 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
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 2cd0a4dc4f0baa08bd7f5a053303bb63733f0bab..0bd367235f80c1f0d319a6aa5130d82ad82d895c 100644
--- a/src/main/java/net/minecraft/Util.java
+++ b/src/main/java/net/minecraft/Util.java
@@ -125,6 +125,7 @@ public class Util {
         .filter(fileSystemProvider -> fileSystemProvider.getScheme().equalsIgnoreCase("jar"))
         .findFirst()
         .orElseThrow(() -> new IllegalStateException("No jar file system provider found"));
+    public static final double COLLISION_EPSILON = 1.0E-7; // Paper - Improve boat collision performance
     private static Consumer<String> 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 322de978f5738433e6064f9210893dcfbc701b91..7614b06669485ae565764f3e5e543300ff711b21 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -1459,7 +1459,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
                 if (!source.is(DamageTypeTags.IS_PROJECTILE)) {
                     Entity entity = source.getDirectEntity();
 
-                    if (entity instanceof LivingEntity) {
+                    if (entity instanceof LivingEntity && entity.distanceToSqr(this) <= (200.0D * 200.0D)) { // Paper - Improve boat collision performance
                         LivingEntity entityliving = (LivingEntity) entity;
 
                         this.blockUsingShield(entityliving);
@@ -1559,11 +1559,12 @@ public abstract class LivingEntity extends Entity implements Attackable {
                 }
 
                 if (entity1 != null && !source.is(DamageTypeTags.NO_KNOCKBACK)) {
-                    double d0 = entity1.getX() - this.getX();
+                    final boolean far = entity1.distanceToSqr(this) > (200.0 * 200.0); // Paper - Improve boat collision performance
+                    double d0 = far ? (Math.random() - Math.random()) : entity1.getX() - this.getX(); // Paper - Improve boat collision performance
 
                     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 - Improve boat collision performance
                         d0 = (Math.random() - Math.random()) * 0.01D;
                     }
 
@@ -2340,7 +2341,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
                 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 - Improve boat collision performance
                     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 549202706396fee91c23f6e34f7faa7672e4b03f..b068cff9b5aa457d65b679529956e8210296d799 100644
--- a/src/main/java/net/minecraft/world/entity/vehicle/Boat.java
+++ b/src/main/java/net/minecraft/world/entity/vehicle/Boat.java
@@ -686,7 +686,7 @@ public class Boat extends VehicleEntity implements VariantHolder<Boat.Type> {
         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.move(MoverType.SELF, new Vec3(0.0, ((double) (this.getWaterLevelAbove() - this.getBbHeight()) + 0.101D) - this.getY(), 0.0)); // Paper - Improve boat collision performance
             this.setDeltaMovement(this.getDeltaMovement().multiply(1.0D, 0.0D, 1.0D));
             this.lastYd = 0.0D;
             this.status = Boat.Status.IN_WATER;