81 lines
4.4 KiB
Diff
81 lines
4.4 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: MrHua269 <novau233@163.com>
|
|
Date: Fri, 26 Jan 2024 11:07:22 +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 875afb57c7f0c4e3d0bc752d86a8308147eee31a..7b478affcf01e4eca7a1c881e32fb0c3e7a9ee00 100644
|
|
--- a/src/main/java/me/earthme/luminol/LuminolConfig.java
|
|
+++ b/src/main/java/me/earthme/luminol/LuminolConfig.java
|
|
@@ -42,6 +42,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;
|
|
@@ -163,6 +165,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 8f019df26a9ad0dbb8e3ca96c9feddf1453074c5..82747dc7ab3d7d094c6e225be7898216c9e96b52 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;
|
|
@@ -1092,9 +1093,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();
|