Skip to content

Commit

Permalink
Make cache minecart collision configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreeam-qwq committed Oct 15, 2023
1 parent cb51f2c commit 7c1e327
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <[email protected]>
Date: Wed, 23 Aug 2023 14:21:16 -0400
Subject: [PATCH] Cache minecart vehicle collide results
Subject: [PATCH] Cache minecart vehicle collision results

Co-authored-by: MrHua269 <[email protected]>

Cache minecart vehicle collide results to prevent lag causing by massive stacked minecart
Cache minecart vehicle collision 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 faf449dfb4f95a300796db46833f3b6a51cb961b..67f93b1d915f709364125ae6db3e1148b31ae575 100644
index faf449dfb4f95a300796db46833f3b6a51cb961b..847bf9edd3f3dbd5c9fd4de4973ac066bbcc1f45 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;
Expand All @@ -24,7 +24,7 @@ index faf449dfb4f95a300796db46833f3b6a51cb961b..67f93b1d915f709364125ae6db3e1148
return this.flipped ? this.getDirection().getOpposite().getClockWise() : this.getDirection().getClockWise();
}

+ // Leaf start - Cache minecart vehicle collide results
+ // Leaf start - Cache minecart vehicle collision results
+ private List<Entity> lastCollideCache = new ArrayList<>();
+ private List<Entity> lastCollideCache2 = new ArrayList<>();
+
Expand All @@ -46,10 +46,10 @@ index faf449dfb4f95a300796db46833f3b6a51cb961b..67f93b1d915f709364125ae6db3e1148
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 (org.dreeam.leaf.LeafConfig.cacheMinecartCollision) this.checkAndUpdateCache(); // Leaf - Cache minecart vehicle collision 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
+ List<Entity> list = org.dreeam.leaf.LeafConfig.cacheMinecartCollision ? this.lastCollideCache : this.level().getEntities((Entity) this, this.getBoundingBox().inflate(0.20000000298023224D, 0.0D, 0.20000000298023224D), EntitySelector.pushableBy(this));; // Leaf - Cache minecart vehicle collcollisionide results

if (!list.isEmpty()) {
Iterator iterator = list.iterator();
Expand All @@ -58,7 +58,27 @@ index faf449dfb4f95a300796db46833f3b6a51cb961b..67f93b1d915f709364125ae6db3e1148
}
} else {
- Iterator iterator1 = this.level().getEntities(this, this.getBoundingBox().inflate(0.20000000298023224D, 0.0D, 0.20000000298023224D)).iterator();
+ Iterator iterator1 = this.lastCollideCache2.iterator(); // Leaf - Cache minecart vehicle collide results
+ Iterator iterator1 = org.dreeam.leaf.LeafConfig.cacheMinecartCollision ? this.lastCollideCache2.iterator() : this.level().getEntities(this, this.getBoundingBox().inflate(0.20000000298023224D, 0.0D, 0.20000000298023224D)).iterator();; // Leaf - Cache minecart vehicle collision results

while (iterator1.hasNext()) {
Entity entity1 = (Entity) iterator1.next();
diff --git a/src/main/java/org/dreeam/leaf/LeafConfig.java b/src/main/java/org/dreeam/leaf/LeafConfig.java
index 839b4dba682b67f4ea291717d45d973c84cd3612..2253c44a8532fbc984d97a0067267580788d5d5f 100644
--- a/src/main/java/org/dreeam/leaf/LeafConfig.java
+++ b/src/main/java/org/dreeam/leaf/LeafConfig.java
@@ -188,6 +188,7 @@ public class LeafConfig {
public static boolean asyncPathfinding = false;
public static int asyncPathfindingMaxThreads = 0;
public static int asyncPathfindingKeepalive = 60;
+ public static boolean cacheMinecartCollision = false;
private static void performance() {
useSpigotItemMergingMechanism = getBoolean("performance.use-spigot-item-merging-mechanism", useSpigotItemMergingMechanism);
asyncPathfinding = getBoolean("performance.async-pathfinding.enable", asyncPathfinding);
@@ -201,6 +202,7 @@ public class LeafConfig {
asyncPathfindingMaxThreads = 0;
else
Bukkit.getLogger().log(Level.INFO, "Using " + asyncPathfindingMaxThreads + " threads for Async Pathfinding");
+ cacheMinecartCollision = getBoolean("performance.cache-minecart-collision", cacheMinecartCollision);
}

public static boolean jadeProtocol = false;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Subject: [PATCH] Faster Random for xaeroMapServerID generation


diff --git a/src/main/java/org/dreeam/leaf/LeafConfig.java b/src/main/java/org/dreeam/leaf/LeafConfig.java
index 839b4dba682b67f4ea291717d45d973c84cd3612..3935afc36528c1d9bb2d38e60e98999cb8301be4 100644
index 2253c44a8532fbc984d97a0067267580788d5d5f..3b2ed47f3ad717817afbd7d24f0d926a7396337e 100644
--- a/src/main/java/org/dreeam/leaf/LeafConfig.java
+++ b/src/main/java/org/dreeam/leaf/LeafConfig.java
@@ -1,7 +1,7 @@
Expand All @@ -17,7 +17,7 @@ index 839b4dba682b67f4ea291717d45d973c84cd3612..3935afc36528c1d9bb2d38e60e98999c
import net.minecraft.server.MinecraftServer;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
@@ -206,7 +206,7 @@ public class LeafConfig {
@@ -208,7 +208,7 @@ public class LeafConfig {
public static boolean jadeProtocol = false;
public static boolean appleskinProtocol = false;
public static boolean xaeroMapProtocol = false;
Expand Down

0 comments on commit 7c1e327

Please sign in to comment.