PaperMC/paper-server/patches/features/0014-Check-distance-in-entity-interactions.patch

69 lines
4.6 KiB
Diff
Raw Normal View History

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
Rewrite chunk system (#8177) Patch documentation to come Issues with the old system that are fixed now: - World generation does not scale with cpu cores effectively. - Relies on the main thread for scheduling and maintaining chunk state, dropping chunk load/generate rates at lower tps. - Unreliable prioritisation of chunk gen/load calls that block the main thread. - Shutdown logic is utterly unreliable, as it has to wait for all chunks to unload - is it guaranteed that the chunk system is in a state on shutdown that it can reliably do this? Watchdog shutdown also typically failed due to thread checks, which is now resolved. - Saving of data is not unified (i.e can save chunk data without saving entity data, poses problems for desync if shutdown is really abnormal. - Entities are not loaded with chunks. This caused quite a bit of headache for Chunk#getEntities API, but now the new chunk system loads entities with chunks so that they are ready whenever the chunk loads in. Effectively brings the behavior back to 1.16 era, but still storing entities in their own separate regionfiles. The above list is not complete. The patch documentation will complete it. New chunk system hard relies on starlight and dataconverter, and most importantly the new concurrent utilities in ConcurrentUtil. Some of the old async chunk i/o interface (i.e the old file io thread reroutes _some_ calls to the new file io thread) is kept for plugin compat reasons. It will be removed in the next major version of minecraft. The old legacy chunk system patches have been moved to the removed folder in case we need them again.
2022-09-26 10:02:51 +02:00
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Mon, 2 Aug 2021 10:10:40 +0200
Subject: [PATCH] Check distance in entity interactions
2024-12-16 10:43:57 +01:00
diff --git a/net/minecraft/Util.java b/net/minecraft/Util.java
2024-12-16 18:24:34 +01:00
index ae1d53cefb9cede1c93cb8b22122a4a2d2d9a40c..80a7a85e1a03a1ca406259207e1ae3b909b3284f 100644
2024-12-16 10:43:57 +01:00
--- a/net/minecraft/Util.java
+++ b/net/minecraft/Util.java
@@ -130,6 +130,7 @@ public class Util {
.findFirst()
.orElseThrow(() -> new IllegalStateException("No jar file system provider found"));
2024-12-16 10:43:57 +01:00
private static Consumer<String> thePauser = string -> {};
+ public static final double COLLISION_EPSILON = 1.0E-7; // Paper - Check distance in entity interactions
2024-12-16 10:43:57 +01:00
public static <K, V> Collector<Entry<? extends K, ? extends V>, ?, Map<K, V>> toMap() {
return Collectors.toMap(Entry::getKey, Entry::getValue);
diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java
2024-12-19 22:12:09 +01:00
index 9bf5addb07f40cc50e80a46c0ee7944e938620fb..635e6e49483194c43b0ab47b5e1bacfe84613c3a 100644
2024-12-16 10:43:57 +01:00
--- a/net/minecraft/world/entity/LivingEntity.java
+++ b/net/minecraft/world/entity/LivingEntity.java
2024-12-16 15:17:46 +01:00
@@ -1385,7 +1385,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
2024-12-16 10:43:57 +01:00
this.hurtCurrentlyUsedShield(amount);
f1 = amount;
amount = 0.0F;
- if (!damageSource.is(DamageTypeTags.IS_PROJECTILE) && damageSource.getDirectEntity() instanceof LivingEntity livingEntity) {
+ if (!damageSource.is(DamageTypeTags.IS_PROJECTILE) && damageSource.getDirectEntity() instanceof LivingEntity livingEntity && livingEntity.distanceToSqr(this) <= (200.0D * 200.0D)) { // Paper - Check distance in entity interactions
this.blockUsingShield(livingEntity);
}
2022-12-07 21:16:54 +01:00
2024-12-16 15:17:46 +01:00
@@ -1470,6 +1470,14 @@ public abstract class LivingEntity extends Entity implements Attackable {
2024-12-16 10:43:57 +01:00
d = damageSource.getSourcePosition().x() - this.getX();
d1 = damageSource.getSourcePosition().z() - this.getZ();
}
+ // Paper start - Check distance in entity interactions; see for loop in knockback method
2024-12-16 10:43:57 +01:00
+ if (Math.abs(d) > 200) {
+ d = Math.random() - Math.random();
+ }
+ if (Math.abs(d1) > 200) {
2024-07-04 12:34:11 +02:00
+ d1 = Math.random() - Math.random();
+ }
+ // Paper end - Check distance in entity interactions
2024-12-16 10:43:57 +01:00
this.knockback(0.4F, d, d1, damageSource.getDirectEntity(), damageSource.getDirectEntity() == null ? io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.DAMAGE : io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.ENTITY_ATTACK); // CraftBukkit // Paper - knockback events
if (!flag) {
2024-12-19 22:12:09 +01:00
@@ -2342,7 +2350,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
this.hurtCurrentlyUsedShield((float) -event.getDamage(DamageModifier.BLOCKING));
2024-12-16 10:43:57 +01:00
Entity entity = damageSource.getDirectEntity();
2024-12-16 10:43:57 +01:00
- 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);
}
}
2024-12-16 10:43:57 +01:00
diff --git a/net/minecraft/world/entity/vehicle/AbstractBoat.java b/net/minecraft/world/entity/vehicle/AbstractBoat.java
index 3bdb3b0984d0fee21b2c094e1d4c1f917ab68f92..54a4bf2f7df87b4a694187ade81ba158f83f0246 100644
2024-12-16 10:43:57 +01:00
--- a/net/minecraft/world/entity/vehicle/AbstractBoat.java
+++ b/net/minecraft/world/entity/vehicle/AbstractBoat.java
@@ -638,7 +638,7 @@ public abstract class AbstractBoat extends VehicleEntity implements Leashable {
2024-12-16 10:43:57 +01:00
this.waterLevel = this.getY(1.0);
double d2 = this.getWaterLevelAbove() - this.getBbHeight() + 0.101;
if (this.level().noCollision(this, this.getBoundingBox().move(0.0, d2 - this.getY(), 0.0))) {
2024-07-04 12:34:11 +02:00
- this.setPos(this.getX(), d2, this.getZ());
2024-10-24 23:03:27 +02:00
+ this.move(MoverType.SELF, new Vec3(0.0D, d2 - this.getY(), 0.0D)); // Paper - Check distance in entity interactions // TODO Still needed??
2024-12-16 10:43:57 +01:00
this.setDeltaMovement(this.getDeltaMovement().multiply(1.0, 0.0, 1.0));
this.lastYd = 0.0;
2024-07-04 12:34:11 +02:00
}