aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0991-Check-distance-in-entity-interactions.patch
blob: f8d61a567e419d30deadfc64378b4e673ab78092 (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] Check distance in entity interactions


diff --git a/src/main/java/net/minecraft/Util.java b/src/main/java/net/minecraft/Util.java
index 57223285860f61119b6cf348aa78e59384a04e22..ccfe9ef24dce9f34613692adb13738d3ad0e7aac 100644
--- a/src/main/java/net/minecraft/Util.java
+++ b/src/main/java/net/minecraft/Util.java
@@ -128,6 +128,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 - Check distance in entity interactions
     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 4f6a9c9a1a9fa0f98ee2c3bfdc4c5b3202c5cdd0..52ca53b4795981080476fa9425e01f2c804ae6b7 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -1469,7 +1469,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 - Check distance in entity interactions
                         LivingEntity entityliving = (LivingEntity) entity;
 
                         this.blockUsingShield(entityliving);
@@ -1593,6 +1593,14 @@ public abstract class LivingEntity extends Entity implements Attackable {
                         d0 = source.getSourcePosition().x() - this.getX();
                         d1 = source.getSourcePosition().z() - this.getZ();
                     }
+                    // Paper start - Check distance in entity interactions; see for loop in knockback method
+                    if (Math.abs(d0) > 200) {
+                        d0 = Math.random() - Math.random();
+                    }
+                    if (Math.abs(d1) > 200) {
+                        d1 = Math.random() - Math.random();
+                    }
+                    // Paper end - Check distance in entity interactions
 
                     this.knockback(0.4000000059604645D, d0, d1, entity1, entity1 == null ? io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.DAMAGE : io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.ENTITY_ATTACK); // CraftBukkit // Paper - knockback events
                     if (!flag) {
@@ -2428,7 +2436,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
                 this.hurtCurrentlyUsedShield((float) -event.getDamage(DamageModifier.BLOCKING));
                 Entity entity = damagesource.getDirectEntity();
 
-                if (!damagesource.is(DamageTypeTags.IS_PROJECTILE) && entity instanceof LivingEntity) { // Paper - Fix shield disable inconsistency
+                if (!damagesource.is(DamageTypeTags.IS_PROJECTILE) && entity instanceof LivingEntity && entity.distanceToSqr(this) <= (200.0D * 200.0D)) { // Paper - Fix shield disable inconsistency & Check distance in entity interactions
                     this.blockUsingShield((LivingEntity) entity);
                 }
             }
diff --git a/src/main/java/net/minecraft/world/entity/vehicle/AbstractBoat.java b/src/main/java/net/minecraft/world/entity/vehicle/AbstractBoat.java
index 3590f4bc1af829cdb6e0cfdc8fa6857197b9219e..1fdbef16cd29c8fc74578ac3328f985eca61088d 100644
--- a/src/main/java/net/minecraft/world/entity/vehicle/AbstractBoat.java
+++ b/src/main/java/net/minecraft/world/entity/vehicle/AbstractBoat.java
@@ -674,7 +674,7 @@ public abstract class AbstractBoat extends VehicleEntity implements Leashable {
             double d2 = (double) (this.getWaterLevelAbove() - this.getBbHeight()) + 0.101D;
 
             if (this.level().noCollision(this, this.getBoundingBox().move(0.0D, d2 - this.getY(), 0.0D))) {
-                this.setPos(this.getX(), d2, this.getZ());
+                this.move(MoverType.SELF, new Vec3(0.0D, d2 - this.getY(), 0.0D)); // Paper - Check distance in entity interactions // TODO Still needed??
                 this.setDeltaMovement(this.getDeltaMovement().multiply(1.0D, 0.0D, 1.0D));
                 this.lastYd = 0.0D;
             }