Compare commits

..

2 Commits

Author SHA1 Message Date
M2ke4U
025f90a764 Rework and fix spector teleportation fix 2023-11-27 21:13:13 +08:00
M2ke4U
fc7212133f Try fixing folia spector teleportation 2023-11-26 21:24:46 +08:00

View File

@@ -0,0 +1,99 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: M2ke4U <79621885+MrHua269@users.noreply.github.com>
Date: Sun, 26 Nov 2023 21:23:06 +0800
Subject: [PATCH] Try fixing folia spector teleportation
diff --git a/src/main/java/me/earthme/luminol/LuminolConfig.java b/src/main/java/me/earthme/luminol/LuminolConfig.java
index d032786938db9725e1be72dae63a1387bcb69d79..08536bd5bbea3a9bb9d4c6212d361570c1d365bd 100644
--- a/src/main/java/me/earthme/luminol/LuminolConfig.java
+++ b/src/main/java/me/earthme/luminol/LuminolConfig.java
@@ -37,6 +37,7 @@ public class LuminolConfig {
public static boolean enableVoidTrading = false;
public static boolean allowIncorrectTripwireUpdating = false;
public static boolean useVanillaRandomSource = false;
+ public static boolean fixSpectorTeleportFolia = false;
public static RegionFileFormat regionFormatName = RegionFileFormat.ANVIL;
public static int regionFormatLinearCompressionLevel = 1;
@@ -130,6 +131,7 @@ public class LuminolConfig {
tpsColors = get("misc.tpsbar_range_colors", List.of(tpsColors),"The bar and text color of each tps ranges.The last is the color of initial bar's color").toArray(String[]::new);
pingColors = get("misc.tpsbar_ping_range_colors",List.of(pingColors),"As same as the tpsColors").toArray(String[]::new);
disableUsernameCheck = get("misc.disable_username_check",disableUsernameCheck,"Disable username check that can accept usernames with other characters(such as Chinese).Not recommended to use");
+ fixSpectorTeleportFolia = get("misc.fix_folia_spector_teleport",fixSpectorTeleportFolia);
if (tpsbarEnabled){
initTpsbar();
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index 97bfb92e52c3c5ef1cd22afe2b97c204eb45025a..710e87e388095f28af4983a04cb89ddb6be61986 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -18,6 +18,9 @@ import java.util.Optional;
import java.util.OptionalInt;
import java.util.Set;
import javax.annotation.Nullable;
+
+import io.papermc.paper.util.TickThread;
+import me.earthme.luminol.LuminolConfig;
import net.minecraft.BlockUtil;
import net.minecraft.ChatFormatting;
import net.minecraft.CrashReport;
@@ -835,18 +838,7 @@ public class ServerPlayer extends Player {
Entity entity = this.getCamera();
- if (entity != this) {
- if (entity.isAlive()) {
- this.absMoveTo(entity.getX(), entity.getY(), entity.getZ(), entity.getYRot(), entity.getXRot());
- this.serverLevel().getChunkSource().move(this);
- if (this.wantsToStopRiding()) {
- this.setCamera(this);
- }
- } else {
- this.setCamera(this);
- }
- }
-
+ //Luminol - move up
CriteriaTriggers.TICK.trigger(this);
if (this.levitationStartPos != null) {
CriteriaTriggers.LEVITATION.trigger(this, this.levitationStartPos, this.tickCount - this.levitationStartTime);
@@ -855,6 +847,38 @@ public class ServerPlayer extends Player {
this.trackStartFallingPosition();
this.trackEnteredOrExitedLavaOnVehicle();
this.advancements.flushDirty(this);
+
+ if (entity != this) {
+ if (entity.isAlive()) {
+ //Luminol start - Fix spector camera
+ if (TickThread.isTickThreadFor(entity) || !LuminolConfig.fixSpectorTeleportFolia){
+ this.absMoveTo(entity.getX(), entity.getY(), entity.getZ(), entity.getYRot(), entity.getXRot());
+ this.serverLevel().getChunkSource().move(this);
+ if (this.wantsToStopRiding()) {
+ this.setCamera(this);
+ }
+ }else{
+ this.teleportAsync(
+ ((ServerLevel) entity.level()),
+ entity.position,
+ entity.getYRot(),
+ entity.getXRot(),
+ null,
+ TeleportCause.SPECTATE,
+ Entity.TELEPORT_FLAG_LOAD_CHUNK | Entity.TELEPORT_FLAG_TELEPORT_PASSENGERS,
+ r -> {
+ this.serverLevel().getChunkSource().move(this);
+ if (this.wantsToStopRiding()) {
+ this.setCamera(this);
+ }
+ }
+ );
+ }
+ //Luminol end
+ } else {
+ this.setCamera(this);
+ }
+ }
}
public void doTick() {