Files
LuminolMC/patches/server/0048-Teleport-async-if-the-entity-was-moving-to-another-r.patch
2024-02-06 04:51:04 +00:00

82 lines
4.5 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Tue, 6 Feb 2024 04:17:43 +0000
Subject: [PATCH] Teleport async if the entity was moving to another region
diff --git a/src/main/java/me/earthme/luminol/LuminolConfig.java b/src/main/java/me/earthme/luminol/LuminolConfig.java
index ec372d91ed60534ecbe0d2b28ba3b9abda800683..3f560bd27c5a43c5681b50492e04290dda51f37e 100644
--- a/src/main/java/me/earthme/luminol/LuminolConfig.java
+++ b/src/main/java/me/earthme/luminol/LuminolConfig.java
@@ -40,6 +40,8 @@ public class LuminolConfig {
public static boolean enableVoidTrading = false;
public static boolean allowIncorrectTripwireUpdating = false;
public static boolean useVanillaRandomSource = false;
+ public static boolean fixLargePosMoving = false;
+ public static boolean warnOnLargeMovingDetected = true;
public static RegionFileFormat regionFormatName = RegionFileFormat.ANVIL;
public static int regionFormatLinearCompressionLevel = 1;
@@ -159,6 +161,8 @@ public class LuminolConfig {
enableVoidTrading = get("fixes.enable_void_trading",enableVoidTrading);
allowIncorrectTripwireUpdating = get("fixes.allow_incorrect_trip_wire_updaing",allowIncorrectTripwireUpdating);
useVanillaRandomSource = get("fixes.use_vanilla_random_source",useVanillaRandomSource,"RNG feature related");
+ fixLargePosMoving = get("fixes.fix_large_pos_moving", fixLargePosMoving,"Fix an entity moving issue on folia which is not fixed yet");
+ warnOnLargeMovingDetected = get("fixes.warn_on_large_pos_moving",warnOnLargeMovingDetected);
regionFormatName = RegionFileFormat.fromString(get("save.region-format.format", regionFormatName.name()));
if (regionFormatName.equals(RegionFileFormat.INVALID)) {
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index b1a17c730939f39ba81209a368c215c236f203b0..ea7fe58bd68895dedeed2df1a7f1276d7fe5b70d 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -7,6 +7,7 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.common.collect.UnmodifiableIterator;
import com.mojang.logging.LogUtils;
+import io.papermc.paper.util.TickThread;
import it.unimi.dsi.fastutil.objects.Object2DoubleArrayMap;
import it.unimi.dsi.fastutil.objects.Object2DoubleMap;
import java.util.Arrays;
@@ -1084,10 +1085,40 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
}
// 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
io.papermc.paper.util.TickThread.ensureTickThread("Cannot move an entity off-main");
+ //Luminol start - Fix high position moving
+ if (LuminolConfig.fixLargePosMoving && TickThread.isTickThread()){ //Except the threads because it may be called by the chunk system worker thread
+ if (this.preventMoving){
+ return;
+ }
+
+ var finalPosition = movement.add(this.position);
+ if (!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 (LuminolConfig.warnOnLargeMovingDetected){
+ MinecraftServer.LOGGER.warn("Entity {} with entityId {} has tried moving to another region!",this.type.getCategory().getName(),this.getId());
+ }
+ return;
+ }
+ }
+ //Luminol end
synchronized (this.posLock) {
this.moveStartX = this.getX();
this.moveStartY = this.getY();