From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: MrHua269 Date: Fri, 26 Jan 2024 10:58:48 +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 e91061b96701bc46f5a6ed8315eb6c8da8a74f3a..55d0ae641f1de570a293d1d6fe03da3ab2bba1c4 100644 --- a/src/main/java/me/earthme/luminol/LuminolConfig.java +++ b/src/main/java/me/earthme/luminol/LuminolConfig.java @@ -43,6 +43,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; @@ -165,6 +167,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 9bd6d4881280196a437161a9375ac8ee5e0f9231..18fdb265714584d4ee759d86cc8a10b13742e153 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,9 +1085,39 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource { } // 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();