3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-27 08:30:12 +01:00

Fix bugs when rapidly switching dimensions

Dieser Commit ist enthalten in:
AJ Ferguson 2020-02-05 19:21:09 -09:00
Ursprung 989312835f
Commit 13f198845c
7 geänderte Dateien mit 31 neuen und 29 gelöschten Zeilen

Datei anzeigen

@ -62,6 +62,7 @@ import org.geysermc.connector.utils.Toolbox;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
@Getter @Getter
public class GeyserSession implements Player { public class GeyserSession implements Player {
@ -98,8 +99,7 @@ public class GeyserSession implements Player {
@Setter @Setter
private GameMode gameMode = GameMode.SURVIVAL; private GameMode gameMode = GameMode.SURVIVAL;
@Setter private final AtomicInteger pendingDimSwitches = new AtomicInteger(0);
private boolean switchingDimension = false;
private boolean manyDimPackets = false; private boolean manyDimPackets = false;
private ServerRespawnPacket lastDimPacket = null; private ServerRespawnPacket lastDimPacket = null;
@ -127,6 +127,10 @@ public class GeyserSession implements Player {
public void connect(RemoteServer remoteServer) { public void connect(RemoteServer remoteServer) {
startGame(); startGame();
this.remoteServer = remoteServer; 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); ChunkUtils.sendEmptyChunks(this, playerEntity.getPosition().toInt(), 0, false);

Datei anzeigen

@ -107,12 +107,13 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
// Handled in BedrockInventoryTransactionTranslator // Handled in BedrockInventoryTransactionTranslator
break; break;
case DIMENSION_CHANGE_SUCCESS: case DIMENSION_CHANGE_SUCCESS:
session.setSwitchingDimension(false); if (session.getPendingDimSwitches().decrementAndGet() == 0) {
//sometimes the client doesn't feel like loading //sometimes the client doesn't feel like loading
PlayStatusPacket spawnPacket = new PlayStatusPacket(); PlayStatusPacket spawnPacket = new PlayStatusPacket();
spawnPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN); spawnPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN);
session.getUpstream().sendPacket(spawnPacket); session.getUpstream().sendPacket(spawnPacket);
entity.updateBedrockAttributes(session); entity.updateBedrockAttributes(session);
}
break; break;
} }
} }

Datei anzeigen

@ -42,7 +42,7 @@ public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPack
@Override @Override
public void translate(MovePlayerPacket packet, GeyserSession session) { public void translate(MovePlayerPacket packet, GeyserSession session) {
PlayerEntity entity = session.getPlayerEntity(); 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()) { if (!session.getUpstream().isInitialized()) {
MoveEntityAbsolutePacket moveEntityBack = new MoveEntityAbsolutePacket(); MoveEntityAbsolutePacket moveEntityBack = new MoveEntityAbsolutePacket();

Datei anzeigen

@ -38,11 +38,6 @@ public class BedrockPlayerInitializedTranslator extends PacketTranslator<SetLoca
if (!session.getUpstream().isInitialized()) { if (!session.getUpstream().isInitialized()) {
session.getUpstream().setInitialized(true); 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)) { for (PlayerEntity entity : session.getEntityCache().getEntitiesByType(PlayerEntity.class)) {
if (!entity.isValid()) { if (!entity.isValid()) {
// async skin loading // async skin loading

Datei anzeigen

@ -31,6 +31,7 @@ import com.nukkitx.protocol.bedrock.packet.*;
import org.geysermc.connector.entity.PlayerEntity; import org.geysermc.connector.entity.PlayerEntity;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.utils.ChunkUtils;
import org.geysermc.connector.utils.DimensionUtils; import org.geysermc.connector.utils.DimensionUtils;
public class JavaJoinGameTranslator extends PacketTranslator<ServerJoinGamePacket> { public class JavaJoinGameTranslator extends PacketTranslator<ServerJoinGamePacket> {
@ -67,7 +68,8 @@ public class JavaJoinGameTranslator extends PacketTranslator<ServerJoinGamePacke
session.getUpstream().sendPacket(chunkRadiusPacket); session.getUpstream().sendPacket(chunkRadiusPacket);
if (DimensionUtils.javaToBedrock(packet.getDimension()) != entity.getDimension()) { 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());
} }
} }
} }

Datei anzeigen

@ -51,14 +51,15 @@ public class JavaRespawnTranslator extends PacketTranslator<ServerRespawnPacket>
session.setGameMode(packet.getGamemode()); session.setGameMode(packet.getGamemode());
if (entity.getDimension() != DimensionUtils.javaToBedrock(packet.getDimension())) { if (entity.getDimension() != DimensionUtils.javaToBedrock(packet.getDimension())) {
DimensionUtils.switchDimension(session, packet.getDimension(), false); DimensionUtils.switchDimension(session, packet.getDimension());
} else {
if (session.isManyDimPackets()) { //reloading world
int fakeDim = entity.getDimension() == 0 ? -1 : 0;
DimensionUtils.switchDimension(session, fakeDim);
DimensionUtils.switchDimension(session, packet.getDimension());
} else { } else {
// Handled in JavaPlayerPositionRotationTranslator // Handled in JavaPlayerPositionRotationTranslator
session.setSpawned(false); 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);
} }
} }
} }

Datei anzeigen

@ -31,14 +31,18 @@ import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
public class DimensionUtils { 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); int bedrockDimension = javaToBedrock(javaDimension);
Entity player = session.getPlayerEntity(); Entity player = session.getPlayerEntity();
if (bedrockDimension == player.getDimension()) if (bedrockDimension == player.getDimension())
return; return;
Vector3i pos = Vector3i.from(0, Short.MAX_VALUE, 0);
session.getEntityCache().removeAllEntities(); 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 changeDimensionPacket = new ChangeDimensionPacket();
changeDimensionPacket.setDimension(bedrockDimension); changeDimensionPacket.setDimension(bedrockDimension);
@ -46,19 +50,14 @@ public class DimensionUtils {
changeDimensionPacket.setPosition(pos.toFloat()); changeDimensionPacket.setPosition(pos.toFloat());
session.getUpstream().sendPacket(changeDimensionPacket); session.getUpstream().sendPacket(changeDimensionPacket);
player.setDimension(bedrockDimension); player.setDimension(bedrockDimension);
player.setPosition(pos.toFloat());
session.setSpawned(false);
//let java server handle portal travel sound //let java server handle portal travel sound
StopSoundPacket stopSoundPacket = new StopSoundPacket(); StopSoundPacket stopSoundPacket = new StopSoundPacket();
stopSoundPacket.setStoppingAllSound(true); stopSoundPacket.setStoppingAllSound(true);
stopSoundPacket.setSoundName(""); stopSoundPacket.setSoundName("");
session.getUpstream().sendPacket(stopSoundPacket); session.getUpstream().sendPacket(stopSoundPacket);
if (fake) {
ChunkUtils.sendEmptyChunks(session, pos, 2, true);
}
session.setSpawned(false);
session.setSwitchingDimension(true);
} }
public static int javaToBedrock(int javaDimension) { public static int javaToBedrock(int javaDimension) {