Paper/patches/server/0130-Cap-Entity-Collisions.patch
2021-12-01 10:03:46 -08:00

58 Zeilen
3.0 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 f383f30b9dd1a7c6cf69d342f99118beec70b206..47b717e8741bb2b8f3aa776dcdc73a3e7dbb5960 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 0041783c4cc05ce2730f15b4c8c58ff6f1a94f57..a1ca58317ed0c6a395503d00cff332b092c4d549 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -325,6 +325,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, i
public final org.spigotmc.ActivationRange.ActivationType activationType = org.spigotmc.ActivationRange.initializeEntityActivationType(this);
public final boolean defaultActivationState;
public long activatedTick = Integer.MIN_VALUE;
+ protected int numCollisions = 0; // Paper
public void inactiveTick() { }
// Spigot end
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 36aef3dbfe407ca6fa206bc3fc4390e5c2770aa3..e0fe53045da81fc9b2eac3b215d641cf0c722895 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -3227,8 +3227,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);
}