forked from GeyserMC/Geyser
Fix bugs when rapidly switching dimensions
This commit is contained in:
parent
989312835f
commit
13f198845c
7 changed files with 31 additions and 29 deletions
|
@ -62,6 +62,7 @@ import org.geysermc.connector.utils.Toolbox;
|
|||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@Getter
|
||||
public class GeyserSession implements Player {
|
||||
|
@ -98,8 +99,7 @@ public class GeyserSession implements Player {
|
|||
@Setter
|
||||
private GameMode gameMode = GameMode.SURVIVAL;
|
||||
|
||||
@Setter
|
||||
private boolean switchingDimension = false;
|
||||
private final AtomicInteger pendingDimSwitches = new AtomicInteger(0);
|
||||
private boolean manyDimPackets = false;
|
||||
private ServerRespawnPacket lastDimPacket = null;
|
||||
|
||||
|
@ -127,6 +127,10 @@ public class GeyserSession implements Player {
|
|||
public void connect(RemoteServer remoteServer) {
|
||||
startGame();
|
||||
this.remoteServer = remoteServer;
|
||||
if (!(connector.getConfig().getRemote().getAuthType().hashCode() == "online".hashCode())) {
|
||||
connector.getLogger().info("Attempting to login using offline mode... authentication is disabled.");
|
||||
authenticate(authenticationData.getName());
|
||||
}
|
||||
|
||||
ChunkUtils.sendEmptyChunks(this, playerEntity.getPosition().toInt(), 0, false);
|
||||
|
||||
|
|
|
@ -107,12 +107,13 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
|||
// Handled in BedrockInventoryTransactionTranslator
|
||||
break;
|
||||
case DIMENSION_CHANGE_SUCCESS:
|
||||
session.setSwitchingDimension(false);
|
||||
//sometimes the client doesn't feel like loading
|
||||
PlayStatusPacket spawnPacket = new PlayStatusPacket();
|
||||
spawnPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN);
|
||||
session.getUpstream().sendPacket(spawnPacket);
|
||||
entity.updateBedrockAttributes(session);
|
||||
if (session.getPendingDimSwitches().decrementAndGet() == 0) {
|
||||
//sometimes the client doesn't feel like loading
|
||||
PlayStatusPacket spawnPacket = new PlayStatusPacket();
|
||||
spawnPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN);
|
||||
session.getUpstream().sendPacket(spawnPacket);
|
||||
entity.updateBedrockAttributes(session);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPack
|
|||
@Override
|
||||
public void translate(MovePlayerPacket packet, GeyserSession session) {
|
||||
PlayerEntity entity = session.getPlayerEntity();
|
||||
if (entity == null || !session.isSpawned() || session.isSwitchingDimension()) return;
|
||||
if (entity == null || !session.isSpawned() || session.getPendingDimSwitches().get() > 0) return;
|
||||
|
||||
if (!session.getUpstream().isInitialized()) {
|
||||
MoveEntityAbsolutePacket moveEntityBack = new MoveEntityAbsolutePacket();
|
||||
|
|
|
@ -38,11 +38,6 @@ public class BedrockPlayerInitializedTranslator extends PacketTranslator<SetLoca
|
|||
if (!session.getUpstream().isInitialized()) {
|
||||
session.getUpstream().setInitialized(true);
|
||||
|
||||
if (!(session.getConnector().getConfig().getRemote().getAuthType().hashCode() == "online".hashCode())) {
|
||||
session.getConnector().getLogger().info("Attempting to login using offline mode... authentication is disabled.");
|
||||
session.authenticate(session.getAuthenticationData().getName());
|
||||
}
|
||||
|
||||
for (PlayerEntity entity : session.getEntityCache().getEntitiesByType(PlayerEntity.class)) {
|
||||
if (!entity.isValid()) {
|
||||
// async skin loading
|
||||
|
|
|
@ -31,6 +31,7 @@ import com.nukkitx.protocol.bedrock.packet.*;
|
|||
import org.geysermc.connector.entity.PlayerEntity;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||
import org.geysermc.connector.utils.ChunkUtils;
|
||||
import org.geysermc.connector.utils.DimensionUtils;
|
||||
|
||||
public class JavaJoinGameTranslator extends PacketTranslator<ServerJoinGamePacket> {
|
||||
|
@ -67,7 +68,8 @@ public class JavaJoinGameTranslator extends PacketTranslator<ServerJoinGamePacke
|
|||
session.getUpstream().sendPacket(chunkRadiusPacket);
|
||||
|
||||
if (DimensionUtils.javaToBedrock(packet.getDimension()) != entity.getDimension()) {
|
||||
DimensionUtils.switchDimension(session, packet.getDimension(), false);
|
||||
ChunkUtils.sendEmptyChunks(session, entity.getPosition().toInt(), 3, true);
|
||||
DimensionUtils.switchDimension(session, packet.getDimension());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,14 +51,15 @@ public class JavaRespawnTranslator extends PacketTranslator<ServerRespawnPacket>
|
|||
session.setGameMode(packet.getGamemode());
|
||||
|
||||
if (entity.getDimension() != DimensionUtils.javaToBedrock(packet.getDimension())) {
|
||||
DimensionUtils.switchDimension(session, packet.getDimension(), false);
|
||||
DimensionUtils.switchDimension(session, packet.getDimension());
|
||||
} else {
|
||||
// Handled in JavaPlayerPositionRotationTranslator
|
||||
session.setSpawned(false);
|
||||
if (session.isManyDimPackets()) { //reloading world
|
||||
int fakeDim = entity.getDimension() == 0 ? -1 : 0;
|
||||
DimensionUtils.switchDimension(session, fakeDim, true);
|
||||
DimensionUtils.switchDimension(session, packet.getDimension(), false);
|
||||
DimensionUtils.switchDimension(session, fakeDim);
|
||||
DimensionUtils.switchDimension(session, packet.getDimension());
|
||||
} else {
|
||||
// Handled in JavaPlayerPositionRotationTranslator
|
||||
session.setSpawned(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,14 +31,18 @@ import org.geysermc.connector.entity.Entity;
|
|||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
|
||||
public class DimensionUtils {
|
||||
public static void switchDimension(GeyserSession session, int javaDimension, boolean fake) {
|
||||
public static void switchDimension(GeyserSession session, int javaDimension) {
|
||||
int bedrockDimension = javaToBedrock(javaDimension);
|
||||
Entity player = session.getPlayerEntity();
|
||||
if (bedrockDimension == player.getDimension())
|
||||
return;
|
||||
Vector3i pos = Vector3i.from(0, Short.MAX_VALUE, 0);
|
||||
|
||||
session.getEntityCache().removeAllEntities();
|
||||
if (session.getPendingDimSwitches().getAndIncrement() > 0) {
|
||||
ChunkUtils.sendEmptyChunks(session, player.getPosition().toInt(), 3, true);
|
||||
}
|
||||
|
||||
Vector3i pos = Vector3i.from(0, Short.MAX_VALUE, 0);
|
||||
|
||||
ChangeDimensionPacket changeDimensionPacket = new ChangeDimensionPacket();
|
||||
changeDimensionPacket.setDimension(bedrockDimension);
|
||||
|
@ -46,19 +50,14 @@ public class DimensionUtils {
|
|||
changeDimensionPacket.setPosition(pos.toFloat());
|
||||
session.getUpstream().sendPacket(changeDimensionPacket);
|
||||
player.setDimension(bedrockDimension);
|
||||
player.setPosition(pos.toFloat());
|
||||
session.setSpawned(false);
|
||||
|
||||
//let java server handle portal travel sound
|
||||
StopSoundPacket stopSoundPacket = new StopSoundPacket();
|
||||
stopSoundPacket.setStoppingAllSound(true);
|
||||
stopSoundPacket.setSoundName("");
|
||||
session.getUpstream().sendPacket(stopSoundPacket);
|
||||
|
||||
if (fake) {
|
||||
ChunkUtils.sendEmptyChunks(session, pos, 2, true);
|
||||
}
|
||||
|
||||
session.setSpawned(false);
|
||||
session.setSwitchingDimension(true);
|
||||
}
|
||||
|
||||
public static int javaToBedrock(int javaDimension) {
|
||||
|
|
Loading…
Reference in a new issue