-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix and update optimize minecart patch
- Loading branch information
1 parent
ff8529e
commit 662cf20
Showing
4 changed files
with
126 additions
and
119 deletions.
There are no files selected for viewing
115 changes: 0 additions & 115 deletions
115
patches/server/0043-Cache-minecart-vehicle-collision-results.patch
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com> | ||
Date: Sat, 6 Apr 2024 22:57:41 -0400 | ||
Subject: [PATCH] Optimize Minecart collisions | ||
|
||
Skip tick collisions to to prevent lag causing by massive stacked Minecart | ||
Useful for anarchy server. | ||
|
||
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 eb5bd5cfd131042e366872bf599a315d83dc732b..9bf74e76a2b2fef92bef37fbaee2171b7f7a357d 100644 | ||
--- a/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java | ||
+++ b/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java | ||
@@ -5,7 +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.Iterator; | ||
+ | ||
+import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import javax.annotation.Nullable; | ||
@@ -389,15 +390,15 @@ public abstract class AbstractMinecart extends VehicleEntity { | ||
this.level().getCraftServer().getPluginManager().callEvent(new org.bukkit.event.vehicle.VehicleMoveEvent(vehicle, from, to)); | ||
} | ||
// CraftBukkit end | ||
- if (this.getMinecartType() == AbstractMinecart.Type.RIDEABLE && this.getDeltaMovement().horizontalDistanceSqr() > 0.01D) { | ||
+ // Leaf start - Optimize Minecart collision handling | ||
+ // The logic below is used to get list of entities around Minecart | ||
+ // and handle behaviors for their collisions with each other | ||
+ if (!org.dreeam.leaf.config.modules.opt.OptimizeMinecart.enabled || this.tickCount % org.dreeam.leaf.config.modules.opt.OptimizeMinecart.skipTickCount == 0) { | ||
+ if (this.getMinecartType() == AbstractMinecart.Type.RIDEABLE && (org.dreeam.leaf.config.modules.opt.OptimizeMinecart.enabled || 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)); | ||
|
||
if (!list.isEmpty()) { | ||
- Iterator iterator = list.iterator(); | ||
- | ||
- while (iterator.hasNext()) { | ||
- Entity entity = (Entity) iterator.next(); | ||
- | ||
+ for (Entity entity : list) { | ||
if (!(entity instanceof Player) && !(entity instanceof IronGolem) && !(entity instanceof AbstractMinecart) && !this.isVehicle() && !entity.isPassenger()) { | ||
// CraftBukkit start | ||
VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent(vehicle, entity.getBukkitEntity()); | ||
@@ -424,11 +425,7 @@ public abstract class AbstractMinecart extends VehicleEntity { | ||
} | ||
} | ||
} else { | ||
- Iterator iterator1 = this.level().getEntities(this, this.getBoundingBox().inflate(0.20000000298023224D, 0.0D, 0.20000000298023224D)).iterator(); | ||
- | ||
- while (iterator1.hasNext()) { | ||
- Entity entity1 = (Entity) iterator1.next(); | ||
- | ||
+ for (Entity entity1 : this.level().getEntities(this, this.getBoundingBox().inflate(0.20000000298023224D, 0.0D, 0.20000000298023224D))) { | ||
if (!this.hasPassenger(entity1) && entity1.isPushable() && entity1 instanceof AbstractMinecart) { | ||
// CraftBukkit start | ||
VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent(vehicle, entity1.getBukkitEntity()); | ||
@@ -442,6 +439,8 @@ public abstract class AbstractMinecart extends VehicleEntity { | ||
} | ||
} | ||
} | ||
+ } | ||
+ // Leaf end | ||
|
||
this.updateInWaterStateAndDoFluidPushing(); | ||
if (this.isInLava()) { | ||
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java | ||
index ff05efe0b78defe3d25905b6a2984bdb646fcff3..820f5dc02f89a54fab00942a3eaa72f006b3bd89 100644 | ||
--- a/src/main/java/net/minecraft/world/level/Level.java | ||
+++ b/src/main/java/net/minecraft/world/level/Level.java | ||
@@ -1572,12 +1572,14 @@ public abstract class Level implements LevelAccessor, AutoCloseable { | ||
return this.getChunk(chunkX, chunkZ, ChunkStatus.FULL, false); | ||
} | ||
|
||
+ // Leaf start - Optimize predicate call | ||
@Override | ||
- public List<Entity> getEntities(@Nullable Entity except, AABB box, Predicate<? super Entity> predicate) { | ||
+ public List<Entity> getEntities(@Nullable Entity except, AABB box, @Nullable Predicate<? super Entity> predicate) { | ||
List<Entity> list = Lists.newArrayList(); | ||
- ((ServerLevel)this).getEntityLookup().getEntities(except, box, list, predicate); // Paper - optimise this call | ||
- return list; | ||
+ ((ServerLevel) this).getEntityLookup().getEntities(except, box, list, null); // Paper - optimise this call | ||
+ return predicate != null ? list.stream().filter(predicate).toList() : list; | ||
} | ||
+ // Leaf end | ||
|
||
@Override | ||
public <T extends Entity> List<T> getEntities(EntityTypeTest<Entity, T> filter, AABB box, Predicate<? super T> predicate) { | ||
diff --git a/src/main/java/org/dreeam/leaf/config/modules/opt/OptimizeMinecart.java b/src/main/java/org/dreeam/leaf/config/modules/opt/OptimizeMinecart.java | ||
new file mode 100644 | ||
index 0000000000000000000000000000000000000000..a891454eb9b83d50ef3e8914efbb013f88a6b3fd | ||
--- /dev/null | ||
+++ b/src/main/java/org/dreeam/leaf/config/modules/opt/OptimizeMinecart.java | ||
@@ -0,0 +1,28 @@ | ||
+package org.dreeam.leaf.config.modules.opt; | ||
+ | ||
+import org.dreeam.leaf.config.ConfigInfo; | ||
+import org.dreeam.leaf.config.EnumConfigCategory; | ||
+import org.dreeam.leaf.config.IConfigModule; | ||
+ | ||
+public class OptimizeMinecart implements IConfigModule { | ||
+ | ||
+ @Override | ||
+ public EnumConfigCategory getCategory() { | ||
+ return EnumConfigCategory.PERFORMANCE; | ||
+ } | ||
+ | ||
+ @Override | ||
+ public String getBaseName() { | ||
+ return "optimize_minecart"; | ||
+ } | ||
+ | ||
+ @ConfigInfo(baseName = "enabled", comments = """ | ||
+ Enable this feature to handle large amount of stacked Minecart better. | ||
+ By skipping tick collisions to reduce expense getting entities list | ||
+ and bukkit event calls, useful for the anarchy server. | ||
+ """) | ||
+ public static boolean enabled = false; | ||
+ | ||
+ @ConfigInfo(baseName = "skip-tick-count") | ||
+ public static int skipTickCount = 30; | ||
+} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters