Files
LuminolMC/patches/server/0049-Teleport-async-if-the-entity-was-moving-to-another-r.patch
2024-01-27 14:38:04 +00:00

81 lines
4.4 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Sat, 27 Jan 2024 13:43: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 6626961d57fff6475ec82da57941d8dad6455bc6..a535ab9432010b15dfb07f206d15c285d1f76597 100644
--- a/src/main/java/me/earthme/luminol/LuminolConfig.java
+++ b/src/main/java/me/earthme/luminol/LuminolConfig.java
@@ -41,6 +41,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;
@@ -161,6 +163,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 4cdb0e62a3027ae292e1d818e1a06a47496676af..235f96fd0f2c74356f986017f514d2805f88ef46 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;
@@ -1094,9 +1095,39 @@ 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) {
// 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();