mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 20:25:13 +00:00
Add mount edge case handling for dismount scenarios
- Player logout: Dismount from NPC mount before logout to prevent orphaned mount state (ServerTickHandler) - Teleportation: Dismount before cross-dimension teleport to prevent mount being left behind in old dimension (NoppesUtilPlayer) - Dead rider: Validate rider is alive, dismount dead/invalid riders to prevent stuck mount state (NPCMountUtil) - Role disable: Dismount rider when mount role is disabled to prevent mounted player on non-mount NPC (RoleMount)
This commit is contained in:
4 files changed
+31
-2
No files matched your search
@@ -123,8 +123,12 @@ public class NoppesUtilPlayer {
|
||||
}
|
||||
|
||||
public static void teleportPlayer(EntityPlayerMP player, double posX, double posY, double posZ, int dimension) {
|
||||
// Dismount from NPC mount before teleportation to prevent mount desync
|
||||
if (player.ridingEntity instanceof EntityNPCInterface) {
|
||||
player.mountEntity(null);
|
||||
}
|
||||
|
||||
if (player.dimension != dimension) {
|
||||
int dim = player.dimension;
|
||||
MinecraftServer server = MinecraftServer.getServer();
|
||||
WorldServer wor = server.worldServerForDimension(dimension);
|
||||
if (wor == null) {
|
||||
@@ -144,8 +148,12 @@ public class NoppesUtilPlayer {
|
||||
}
|
||||
|
||||
public static void teleportPlayer(EntityPlayerMP player, double posX, double posY, double posZ, float yaw, float pitch, int dimension) {
|
||||
// Dismount from NPC mount before teleportation to prevent mount desync
|
||||
if (player.ridingEntity instanceof EntityNPCInterface) {
|
||||
player.mountEntity(null);
|
||||
}
|
||||
|
||||
if (player.dimension != dimension) {
|
||||
int dim = player.dimension;
|
||||
MinecraftServer server = MinecraftServer.getServer();
|
||||
WorldServer wor = server.worldServerForDimension(dimension);
|
||||
if (wor == null) {
|
||||
|
||||
@@ -11,6 +11,7 @@ import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import noppes.npcs.client.AnalyticsTracking;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.controllers.data.action.ActionManager;
|
||||
|
||||
import java.net.InetAddress;
|
||||
@@ -68,6 +69,11 @@ public class ServerTickHandler {
|
||||
|
||||
@SubscribeEvent
|
||||
public void playerLogout(PlayerEvent.PlayerLoggedOutEvent event) {
|
||||
// Dismount player from NPC mount before logout to prevent orphaned mount state
|
||||
if (event.player.ridingEntity instanceof EntityNPCInterface) {
|
||||
event.player.mountEntity(null);
|
||||
}
|
||||
|
||||
PlayerData playerData = PlayerData.get(event.player);
|
||||
if (playerData != null) {
|
||||
playerData.onLogout();
|
||||
|
||||
@@ -192,6 +192,10 @@ public class RoleMount extends RoleInterface {
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
// Dismount any rider when mount role is disabled
|
||||
if (npc.riddenByEntity != null) {
|
||||
npc.riddenByEntity.mountEntity(null);
|
||||
}
|
||||
npc.ais.returnToStart = storedReturnToStart;
|
||||
}
|
||||
|
||||
|
||||
@@ -177,6 +177,17 @@ public final class NPCMountUtil {
|
||||
|
||||
RoleMount mount = (RoleMount) npc.roleInterface;
|
||||
Entity currentRider = npc.riddenByEntity;
|
||||
|
||||
// Validate rider is alive and valid - dismount dead/invalid riders
|
||||
if (currentRider != null && !currentRider.isEntityAlive()) {
|
||||
currentRider.mountEntity(null);
|
||||
stabilizeDismountedRider(currentRider);
|
||||
haltMountedMotion(npc, state);
|
||||
applyUnriddenFlightDescent(npc, state, mount);
|
||||
currentRider = null;
|
||||
}
|
||||
|
||||
// Only allow EntityPlayer as riders
|
||||
if (currentRider != null && !(currentRider instanceof EntityPlayer)) {
|
||||
Entity dismount = currentRider;
|
||||
dismount.mountEntity(null);
|
||||
|
||||
Reference in new issue
Block a user