mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-29 03:49:21 +00:00
Cache minecart vehicle collide results to prevent lag causing by massive stacked minecart
Co-Authored-By: M2ke4U <79621885+mrhua269@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: MrHua269 <wangxyper@163.com>
|
||||
Date: Wed, 23 Aug 2023 14:21:16 -0400
|
||||
Subject: [PATCH] Cache minecart vehicle collide results
|
||||
|
||||
Co-authored-by: MrHua269 <wangxyper@163.com>
|
||||
|
||||
Cache minecart vehicle collide results to prevent lag causing by massive stacked minecart
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java b/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java
|
||||
index c9b7b12470afac45b0132858407aacb8f91aac68..615897305063c2daf42ec1ea3a7deb853b2852f7 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java
|
||||
@@ -5,6 +5,8 @@ import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.UnmodifiableIterator;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
+
|
||||
+import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -335,6 +337,21 @@ public abstract class AbstractMinecart extends Entity {
|
||||
return this.flipped ? this.getDirection().getOpposite().getClockWise() : this.getDirection().getClockWise();
|
||||
}
|
||||
|
||||
+ // Leaf start - Cache minecart vehicle collide results
|
||||
+ private List<Entity> lastCollideCache = new ArrayList<>();
|
||||
+ private List<Entity> lastCollideCache2 = new ArrayList<>();
|
||||
+
|
||||
+ private void checkAndUpdateCache() {
|
||||
+ if (this.getId() + this.tickCount % 5 == 0) {
|
||||
+ if (this.getMinecartType() == AbstractMinecart.Type.RIDEABLE && this.getDeltaMovement().horizontalDistanceSqr() > 0.01D) {
|
||||
+ this.lastCollideCache = this.level().getEntities((Entity) this, this.getBoundingBox().inflate(0.20000000298023224D, 0.0D, 0.20000000298023224D), EntitySelector.pushableBy(this));
|
||||
+ } else {
|
||||
+ this.lastCollideCache2 = this.level().getEntities(this, this.getBoundingBox().inflate(0.20000000298023224D, 0.0D, 0.20000000298023224D));
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ // Leaf end
|
||||
+
|
||||
@Override
|
||||
public void tick() {
|
||||
// Purpur start
|
||||
@@ -439,8 +456,9 @@ public abstract class AbstractMinecart extends Entity {
|
||||
this.level().getCraftServer().getPluginManager().callEvent(new org.bukkit.event.vehicle.VehicleMoveEvent(vehicle, from, to));
|
||||
}
|
||||
// CraftBukkit end
|
||||
+ this.checkAndUpdateCache(); // Leaf - Cache minecart vehicle collide results
|
||||
if (this.getMinecartType() == AbstractMinecart.Type.RIDEABLE && this.getDeltaMovement().horizontalDistanceSqr() > 0.01D) {
|
||||
- List<Entity> list = this.level().getEntities((Entity) this, this.getBoundingBox().inflate(0.20000000298023224D, 0.0D, 0.20000000298023224D), EntitySelector.pushableBy(this));
|
||||
+ List<Entity> list = this.lastCollideCache; // Leaf - Cache minecart vehicle collide results
|
||||
|
||||
if (!list.isEmpty()) {
|
||||
for (int l = 0; l < list.size(); ++l) {
|
||||
@@ -472,7 +490,7 @@ public abstract class AbstractMinecart extends Entity {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
- Iterator iterator = this.level().getEntities(this, this.getBoundingBox().inflate(0.20000000298023224D, 0.0D, 0.20000000298023224D)).iterator();
|
||||
+ Iterator iterator = this.lastCollideCache2.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
Entity entity1 = (Entity) iterator.next();
|
||||
Reference in New Issue
Block a user