Files
LuminolMC/patches/server/0019-Teleport-async-if-entity-was-moving-to-another-regio.patch
2024-08-07 14:35:13 +08:00

89 lines
4.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Wed, 7 Feb 2024 06:34:15 +0000
Subject: [PATCH] Teleport async if entity was moving to another region at once
diff --git a/src/main/java/me/earthme/luminol/config/modules/fixes/FoliaEntityMovingFixConfig.java b/src/main/java/me/earthme/luminol/config/modules/fixes/FoliaEntityMovingFixConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..0e51d465db3554ac80d00c6b85cc1f013f3949ba
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/config/modules/fixes/FoliaEntityMovingFixConfig.java
@@ -0,0 +1,28 @@
+package me.earthme.luminol.config.modules.fixes;
+
+import me.earthme.luminol.config.ConfigInfo;
+import me.earthme.luminol.config.EnumConfigCategory;
+import me.earthme.luminol.config.IConfigModule;
+
+public class FoliaEntityMovingFixConfig implements IConfigModule {
+ @ConfigInfo(baseName = "enabled", comments =
+ """
+ A simple fix of a issue on folia\s
+ (Some times the entity would\s
+ have a large moment that cross the\s
+ different tick regions and it would\s
+ make the server crashed) but sometimes it might doesn't work""")
+ public static boolean enabled = false;
+ @ConfigInfo(baseName = "warn_on_detected")
+ public static boolean warnOnDetected = true;
+
+ @Override
+ public EnumConfigCategory getCategory() {
+ return EnumConfigCategory.FIXES;
+ }
+
+ @Override
+ public String getBaseName() {
+ return "folia.fix_high_velocity_issue";
+ }
+}
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index a949998d40e5113db87f887f8c80067218dd33b3..6f6ae49cf8918e00e4469f0e5fa4a03aa25d19d4 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -1123,6 +1123,10 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
// Paper end - detailed watchdog information
+ //Luminol start - Fix large pos moving
+ private volatile boolean preventMoving = false;
+ //Luminol end
+
public void move(MoverType movementType, Vec3 movement) {
final Vec3 originalMovement = movement; // Paper - Expose pre-collision velocity
// Paper start - detailed watchdog information
@@ -1133,6 +1137,32 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
this.moveStartZ = this.getZ();
this.moveVector = movement;
}
+ //Luminol start - Fix high position moving
+ if (me.earthme.luminol.config.modules.fixes.FoliaEntityMovingFixConfig.enabled && ca.spottedleaf.moonrise.common.util.TickThread.isTickThread()){ //Except the threads because it may be called by the chunk system worker thread
+ var finalPosition = movement.add(this.position);
+ if (this.preventMoving || Double.isNaN(finalPosition.x) || Double.isNaN(finalPosition.y) || Double.isNaN(finalPosition.z)){
+ return;
+ }
+
+ if (!ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(((ServerLevel) this.level),finalPosition)){
+ this.preventMoving = true;
+ this.teleportAsync(
+ (ServerLevel) this.level(),
+ finalPosition,
+ this.getYRot(), this.getXRot(),
+ null, PlayerTeleportEvent.TeleportCause.UNKNOWN,
+ Entity.TELEPORT_FLAG_LOAD_CHUNK | Entity.TELEPORT_FLAG_TELEPORT_PASSENGERS,
+ result -> {
+ this.preventMoving = false;
+ }
+ );
+ if (me.earthme.luminol.config.modules.fixes.FoliaEntityMovingFixConfig.warnOnDetected){
+ MinecraftServer.LOGGER.warn("Entity {} with entityId {} has tried moving to another region!",this.type.getCategory().getName(),this.getId());
+ }
+ return;
+ }
+ }
+ //Luminol end
try {
// Paper end - detailed watchdog information
if (this.noPhysics) {