PaperMC/patches/server/0126-Cap-Entity-Collisions.patch
2022-06-02 21:26:56 -07:00

57 lines
2.9 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sun, 22 Jan 2017 18:07:56 -0500
Subject: [PATCH] Cap Entity Collisions
Limit a single entity to colliding a max of configurable times per tick.
This will alleviate issues where living entities are hoarded in 1x1 pens
This is not tied to the maxEntityCramming rule. Cramming will still apply
just as it does in Vanilla, but entity pushing logic will be capped.
You can set this to 0 to disable collisions.
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
index cfe37643eea0fbff097ecf770977f9fefd94dece..9a3940e93e87a0b2b17d4a35bd71f0a40a139cea 100644
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -370,4 +370,10 @@ public class PaperWorldConfig {
log("Treasure Maps will return already discovered locations");
}
}
+
+ public int maxCollisionsPerEntity = 8;
+ private void maxEntityCollision() {
+ maxCollisionsPerEntity = getInt( "max-entity-collisions", this.spigotConfig.getInt("max-entity-collisions", this.maxCollisionsPerEntity, false) );
+ log( "Max Entity Collisions: " + maxCollisionsPerEntity );
+ }
}
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 74a5b29ee48964aef9587939ecb3a66f52f658b5..336f6209089d3f076bfdd332bfc80d69509ca209 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -317,6 +317,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
public void inactiveTick() { }
// Spigot end
// Paper start
+ protected int numCollisions = 0; // Paper
@javax.annotation.Nullable
private org.bukkit.util.Vector origin;
@javax.annotation.Nullable
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 27ba3a28c18b0af18eb20a7441f361a46700a4bd..a7e09145160f9c26b19a8d61564bf9c04e2616b1 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -3228,8 +3228,11 @@ public abstract class LivingEntity extends Entity {
}
}
- for (j = 0; j < list.size(); ++j) {
+ this.numCollisions = Math.max(0, this.numCollisions - this.level.paperConfig.maxCollisionsPerEntity); // Paper
+ for (j = 0; j < list.size() && this.numCollisions < this.level.paperConfig.maxCollisionsPerEntity; ++j) { // Paper
Entity entity = (Entity) list.get(j);
+ entity.numCollisions++; // Paper
+ this.numCollisions++; // Paper
this.doPush(entity);
}