Fixed loading distance in some Paper versions

This commit is contained in:
OmerBenGera 2024-05-24 14:54:34 +03:00
parent 7f504ee2d9
commit f22df7c611
11 changed files with 76 additions and 13 deletions

View File

@ -1,5 +1,7 @@
package com.bgsoftware.wildloaders.nms.v1_12_R1; package com.bgsoftware.wildloaders.nms.v1_12_R1;
import com.bgsoftware.common.reflection.ReflectField;
import com.bgsoftware.common.reflection.ReflectMethod;
import com.bgsoftware.wildloaders.handlers.NPCHandler; import com.bgsoftware.wildloaders.handlers.NPCHandler;
import com.bgsoftware.wildloaders.npc.DummyChannel; import com.bgsoftware.wildloaders.npc.DummyChannel;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
@ -38,6 +40,11 @@ import java.util.UUID;
public final class ChunkLoaderNPC extends EntityPlayer implements com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC { public final class ChunkLoaderNPC extends EntityPlayer implements com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC {
private static final ReflectMethod<Void> PLAYER_SET_VIEW_DISTANCE = new ReflectMethod<>(
EntityPlayer.class, "setViewDistance", int.class);
private static final ReflectField<Boolean> PLAYER_AFFECTS_SPAWNING = new ReflectField<>(
EntityPlayer.class, boolean.class, "affectsSpawning");
private final AxisAlignedBB boundingBox; private final AxisAlignedBB boundingBox;
private final AdvancementDataPlayer advancements; private final AdvancementDataPlayer advancements;
@ -53,8 +60,15 @@ public final class ChunkLoaderNPC extends EntityPlayer implements com.bgsoftware
this.advancements = new DummyPlayerAdvancements(server, this); this.advancements = new DummyPlayerAdvancements(server, this);
this.playerInteractManager.setGameMode(EnumGamemode.CREATIVE); this.playerInteractManager.setGameMode(EnumGamemode.CREATIVE);
fallDistance = 0.0F;
fauxSleeping = true; fauxSleeping = true;
if (PLAYER_SET_VIEW_DISTANCE.isValid())
PLAYER_SET_VIEW_DISTANCE.invoke(this, 0);
if (PLAYER_AFFECTS_SPAWNING.isValid())
PLAYER_AFFECTS_SPAWNING.set(this, true);
spawnIn(world); spawnIn(world);
setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());

View File

@ -40,6 +40,7 @@ import java.util.UUID;
public final class ChunkLoaderNPC extends EntityPlayer implements com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC { public final class ChunkLoaderNPC extends EntityPlayer implements com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC {
private final AxisAlignedBB boundingBox; private final AxisAlignedBB boundingBox;
private final AdvancementDataPlayer advancements; private final AdvancementDataPlayer advancements;
@ -57,9 +58,16 @@ public final class ChunkLoaderNPC extends EntityPlayer implements com.bgsoftware
this.advancements = new DummyPlayerAdvancements(server, this); this.advancements = new DummyPlayerAdvancements(server, this);
this.playerInteractManager.setGameMode(EnumGamemode.CREATIVE); this.playerInteractManager.setGameMode(EnumGamemode.CREATIVE);
clientViewDistance = 1;
fallDistance = 0.0F;
fauxSleeping = true; fauxSleeping = true;
clientViewDistance = 0;
try {
// Paper
affectsSpawning = true;
} catch (Throwable ignored) {
}
spawnIn(world); spawnIn(world);
setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());

View File

@ -56,9 +56,16 @@ public final class ChunkLoaderPlayer extends ServerPlayer {
this.advancements = new DummyPlayerAdvancements(minecraftServer, this); this.advancements = new DummyPlayerAdvancements(minecraftServer, this);
SET_GAMEMODE.invoke(this.gameMode, GameType.CREATIVE, null); SET_GAMEMODE.invoke(this.gameMode, GameType.CREATIVE, null);
clientViewDistance = 1;
fallDistance = 0.0F;
fauxSleeping = true; fauxSleeping = true;
clientViewDistance = 0;
try {
// Paper
affectsSpawning = true;
} catch (Throwable ignored) {
}
spawnIn(this.serverLevel); spawnIn(this.serverLevel);
moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());

View File

@ -58,9 +58,16 @@ public final class ChunkLoaderNPCImpl extends ServerPlayer implements ChunkLoade
this.advancements = new DummyPlayerAdvancements(minecraftServer, this); this.advancements = new DummyPlayerAdvancements(minecraftServer, this);
SET_GAMEMODE.invoke(this.gameMode, GameType.CREATIVE, null); SET_GAMEMODE.invoke(this.gameMode, GameType.CREATIVE, null);
clientViewDistance = 1;
fallDistance = 0.0F;
fauxSleeping = true; fauxSleeping = true;
clientViewDistance = 0;
try {
// Paper
affectsSpawning = true;
} catch (Throwable ignored) {
}
spawnIn(this.serverLevel); spawnIn(this.serverLevel);
moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());

View File

@ -60,9 +60,16 @@ public final class ChunkLoaderNPCImpl extends ServerPlayer implements ChunkLoade
this.advancements = new DummyPlayerAdvancements(minecraftServer, this); this.advancements = new DummyPlayerAdvancements(minecraftServer, this);
SET_GAMEMODE.invoke(this.gameMode, GameType.CREATIVE, null); SET_GAMEMODE.invoke(this.gameMode, GameType.CREATIVE, null);
clientViewDistance = 1;
fallDistance = 0.0F;
fauxSleeping = true; fauxSleeping = true;
clientViewDistance = 0;
try {
// Paper
affectsSpawning = true;
} catch (Throwable ignored) {
}
spawnIn(this.serverLevel); spawnIn(this.serverLevel);
moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());

View File

@ -60,9 +60,19 @@ public final class ChunkLoaderNPCImpl extends ServerPlayer implements ChunkLoade
this.advancements = new DummyPlayerAdvancements(minecraftServer, this); this.advancements = new DummyPlayerAdvancements(minecraftServer, this);
SET_GAMEMODE.invoke(this.gameMode, GameType.CREATIVE, null); SET_GAMEMODE.invoke(this.gameMode, GameType.CREATIVE, null);
clientViewDistance = 1;
fallDistance = 0.0F;
fauxSleeping = true; fauxSleeping = true;
clientViewDistance = 0;
try {
// Paper
setLoadViewDistance(2);
setTickViewDistance(2);
setSendViewDistance(2);
affectsSpawning = true;
} catch (Throwable ignored) {
}
spawnIn(this.serverLevel); spawnIn(this.serverLevel);
moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());

View File

@ -64,16 +64,19 @@ public final class ChunkLoaderNPCImpl extends ServerPlayer implements ChunkLoade
this.advancements = new DummyPlayerAdvancements(minecraftServer, this); this.advancements = new DummyPlayerAdvancements(minecraftServer, this);
SET_GAMEMODE.invoke(this.gameMode, GameType.CREATIVE, null); SET_GAMEMODE.invoke(this.gameMode, GameType.CREATIVE, null);
fallDistance = 0.0F;
fauxSleeping = true;
try { try {
setLoadViewDistance(2); setLoadViewDistance(2);
setTickViewDistance(2); setTickViewDistance(2);
setSendViewDistance(2); setSendViewDistance(2);
affectsSpawning = true;
} catch (Throwable ignored) { } catch (Throwable ignored) {
// Doesn't exist on Spigot // Doesn't exist on Spigot
} }
fauxSleeping = true;
spawnIn(this.serverLevel); spawnIn(this.serverLevel);
moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());

View File

@ -64,16 +64,19 @@ public final class ChunkLoaderNPCImpl extends ServerPlayer implements ChunkLoade
this.advancements = new DummyPlayerAdvancements(minecraftServer, this); this.advancements = new DummyPlayerAdvancements(minecraftServer, this);
SET_GAMEMODE.invoke(this.gameMode, GameType.CREATIVE, null); SET_GAMEMODE.invoke(this.gameMode, GameType.CREATIVE, null);
fallDistance = 0.0F;
fauxSleeping = true;
try { try {
setLoadViewDistance(2); setLoadViewDistance(2);
setTickViewDistance(2); setTickViewDistance(2);
setSendViewDistance(2); setSendViewDistance(2);
affectsSpawning = true;
} catch (Throwable ignored) { } catch (Throwable ignored) {
// Doesn't exist on Spigot // Doesn't exist on Spigot
} }
fauxSleeping = true;
spawnIn(this.serverLevel); spawnIn(this.serverLevel);
moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());

View File

@ -64,16 +64,19 @@ public final class ChunkLoaderNPCImpl extends ServerPlayer implements ChunkLoade
this.advancements = new DummyPlayerAdvancements(minecraftServer, this); this.advancements = new DummyPlayerAdvancements(minecraftServer, this);
SET_GAMEMODE.invoke(this.gameMode, GameType.CREATIVE, null); SET_GAMEMODE.invoke(this.gameMode, GameType.CREATIVE, null);
fallDistance = 0.0F;
fauxSleeping = true;
try { try {
setLoadViewDistance(2); setLoadViewDistance(2);
setTickViewDistance(2); setTickViewDistance(2);
setSendViewDistance(2); setSendViewDistance(2);
affectsSpawning = true;
} catch (Throwable ignored) { } catch (Throwable ignored) {
// Doesn't exist on Spigot // Doesn't exist on Spigot
} }
fauxSleeping = true;
spawnIn(this.serverLevel); spawnIn(this.serverLevel);
moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());

View File

@ -41,8 +41,8 @@ public final class ChunkLoaderNPC extends EntityPlayer implements com.bgsoftware
playerConnection = new DummyPlayerConnection(server, this); playerConnection = new DummyPlayerConnection(server, this);
playerInteractManager.setGameMode(EnumGamemode.CREATIVE); playerInteractManager.setGameMode(EnumGamemode.CREATIVE);
fallDistance = 0.0F;
fallDistance = 0.0F;
fauxSleeping = true; fauxSleeping = true;
spawnIn(world); spawnIn(world);

View File

@ -48,13 +48,14 @@ public final class ChunkLoaderNPC extends EntityPlayer implements com.bgsoftware
playerConnection = new DummyPlayerConnection(server, this); playerConnection = new DummyPlayerConnection(server, this);
playerInteractManager.setGameMode(WorldSettings.EnumGamemode.CREATIVE); playerInteractManager.setGameMode(WorldSettings.EnumGamemode.CREATIVE);
fallDistance = 0.0F;
fallDistance = 0.0F;
fauxSleeping = true; fauxSleeping = true;
try { try {
// Paper // Paper
affectsSpawning = true; affectsSpawning = true;
viewDistance = 0;
} catch (Throwable ignored) { } catch (Throwable ignored) {
} }