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

Fix chunk view position bugs on some servers

Dieser Commit ist enthalten in:
AJ Ferguson 2020-03-05 16:26:36 -09:00
Ursprung 223e94a31d
Commit eaf45ff6f7
6 geänderte Dateien mit 31 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -38,6 +38,7 @@ import com.github.steveice10.packetlib.tcp.TcpSessionFactory;
import com.nukkitx.math.GenericMath; import com.nukkitx.math.GenericMath;
import com.nukkitx.math.TrigMath; import com.nukkitx.math.TrigMath;
import com.nukkitx.math.vector.Vector2f; import com.nukkitx.math.vector.Vector2f;
import com.nukkitx.math.vector.Vector2i;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.math.vector.Vector3i; import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.nbt.tag.CompoundTag; import com.nukkitx.nbt.tag.CompoundTag;
@ -96,6 +97,8 @@ public class GeyserSession implements CommandSender {
private DataCache<Packet> javaPacketCache; private DataCache<Packet> javaPacketCache;
@Setter
private Vector2i lastChunkPosition = null;
private int renderDistance; private int renderDistance;
private boolean loggedIn; private boolean loggedIn;

Datei anzeigen

@ -38,6 +38,7 @@ import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.entity.type.EntityType;
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;
public class JavaPlayerPositionRotationTranslator extends PacketTranslator<ServerPlayerPositionRotationPacket> { public class JavaPlayerPositionRotationTranslator extends PacketTranslator<ServerPlayerPositionRotationPacket> {
@ -84,6 +85,8 @@ public class JavaPlayerPositionRotationTranslator extends PacketTranslator<Serve
ClientTeleportConfirmPacket teleportConfirmPacket = new ClientTeleportConfirmPacket(packet.getTeleportId()); ClientTeleportConfirmPacket teleportConfirmPacket = new ClientTeleportConfirmPacket(packet.getTeleportId());
session.getDownstream().getSession().send(teleportConfirmPacket); session.getDownstream().getSession().send(teleportConfirmPacket);
ChunkUtils.updateChunkPosition(session, pos.toInt());
session.getConnector().getLogger().info("Spawned player at " + packet.getX() + " " + packet.getY() + " " + packet.getZ()); session.getConnector().getLogger().info("Spawned player at " + packet.getX() + " " + packet.getY() + " " + packet.getZ());
return; return;
} }

Datei anzeigen

@ -43,6 +43,10 @@ public class JavaChunkDataTranslator extends PacketTranslator<ServerChunkDataPac
@Override @Override
public void translate(ServerChunkDataPacket packet, GeyserSession session) { public void translate(ServerChunkDataPacket packet, GeyserSession session) {
if (session.isSpawned()) {
ChunkUtils.updateChunkPosition(session, session.getPlayerEntity().getPosition().toInt());
}
// Not sure if this is safe or not, however without this the client usually times out // Not sure if this is safe or not, however without this the client usually times out
GeyserConnector.getInstance().getGeneralThreadPool().execute(() -> { GeyserConnector.getInstance().getGeneralThreadPool().execute(() -> {
try { try {

Datei anzeigen

@ -27,17 +27,16 @@ package org.geysermc.connector.network.translators.java.world;
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateViewPositionPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateViewPositionPacket;
import com.nukkitx.math.vector.Vector3i; import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.protocol.bedrock.packet.NetworkChunkPublisherUpdatePacket;
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;
public class JavaUpdateViewPositionTranslator extends PacketTranslator<ServerUpdateViewPositionPacket> { public class JavaUpdateViewPositionTranslator extends PacketTranslator<ServerUpdateViewPositionPacket> {
@Override @Override
public void translate(ServerUpdateViewPositionPacket packet, GeyserSession session) { public void translate(ServerUpdateViewPositionPacket packet, GeyserSession session) {
NetworkChunkPublisherUpdatePacket chunkPublisherUpdatePacket = new NetworkChunkPublisherUpdatePacket(); if (!session.isSpawned() && session.getLastChunkPosition() == null) {
chunkPublisherUpdatePacket.setPosition(Vector3i.from(packet.getChunkX() << 4, 0, packet.getChunkZ() << 4)); ChunkUtils.updateChunkPosition(session, Vector3i.from(packet.getChunkX() << 4, 64, packet.getChunkZ() << 4));
chunkPublisherUpdatePacket.setRadius(session.getRenderDistance() << 4); }
session.getUpstream().sendPacket(chunkPublisherUpdatePacket);
} }
} }

Datei anzeigen

@ -29,8 +29,10 @@ import com.github.steveice10.mc.protocol.data.game.chunk.Chunk;
import com.github.steveice10.mc.protocol.data.game.chunk.Column; import com.github.steveice10.mc.protocol.data.game.chunk.Column;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
import com.github.steveice10.mc.protocol.data.game.world.block.BlockState; import com.github.steveice10.mc.protocol.data.game.world.block.BlockState;
import com.nukkitx.math.vector.Vector2i;
import com.nukkitx.math.vector.Vector3i; import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket; import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket;
import com.nukkitx.protocol.bedrock.packet.NetworkChunkPublisherUpdatePacket;
import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket; import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.TranslatorsInit; import org.geysermc.connector.network.translators.TranslatorsInit;
@ -74,6 +76,20 @@ public class ChunkUtils {
return chunkData; return chunkData;
} }
public static void updateChunkPosition(GeyserSession session, Vector3i position) {
Vector2i chunkPos = session.getLastChunkPosition();
Vector2i newChunkPos = Vector2i.from(position.getX() >> 4, position.getZ() >> 4);
if (chunkPos == null || !chunkPos.equals(newChunkPos)) {
NetworkChunkPublisherUpdatePacket chunkPublisherUpdatePacket = new NetworkChunkPublisherUpdatePacket();
chunkPublisherUpdatePacket.setPosition(position);
chunkPublisherUpdatePacket.setRadius(session.getRenderDistance() << 4);
session.getUpstream().sendPacket(chunkPublisherUpdatePacket);
session.setLastChunkPosition(newChunkPos);
}
}
public static void updateBlock(GeyserSession session, BlockState blockState, Position position) { public static void updateBlock(GeyserSession session, BlockState blockState, Position position) {
Vector3i pos = Vector3i.from(position.getX(), position.getY(), position.getZ()); Vector3i pos = Vector3i.from(position.getX(), position.getY(), position.getZ());
updateBlock(session, blockState, pos); updateBlock(session, blockState, pos);

Datei anzeigen

@ -52,6 +52,7 @@ public class DimensionUtils {
player.setDimension(bedrockDimension); player.setDimension(bedrockDimension);
player.setPosition(pos.toFloat()); player.setPosition(pos.toFloat());
session.setSpawned(false); session.setSpawned(false);
session.setLastChunkPosition(null);
//let java server handle portal travel sound //let java server handle portal travel sound
StopSoundPacket stopSoundPacket = new StopSoundPacket(); StopSoundPacket stopSoundPacket = new StopSoundPacket();