3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-03 14:50:19 +01:00

Fix lighting when reloading world

Dieser Commit ist enthalten in:
AJ Ferguson 2019-12-28 18:17:00 -09:00
Ursprung b2f86ec20b
Commit 782feed641
3 geänderte Dateien mit 30 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -128,7 +128,7 @@ public class GeyserSession implements Player {
startGame(); startGame();
this.remoteServer = remoteServer; this.remoteServer = remoteServer;
ChunkUtils.sendEmptyChunks(this, playerEntity.getPosition().toInt(), 5); ChunkUtils.sendEmptyChunks(this, playerEntity.getPosition().toInt(), 0, false);
BiomeDefinitionListPacket biomePacket = new BiomeDefinitionListPacket(); BiomeDefinitionListPacket biomePacket = new BiomeDefinitionListPacket();
biomePacket.setTag(CompoundTag.EMPTY); biomePacket.setTag(CompoundTag.EMPTY);

Datei anzeigen

@ -26,10 +26,12 @@
package org.geysermc.connector.network.translators.java; package org.geysermc.connector.network.translators.java;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerRespawnPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.ServerRespawnPacket;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.packet.*; import com.nukkitx.protocol.bedrock.packet.*;
import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.Entity;
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 JavaRespawnTranslator extends PacketTranslator<ServerRespawnPacket> { public class JavaRespawnTranslator extends PacketTranslator<ServerRespawnPacket> {
@ -48,12 +50,22 @@ public class JavaRespawnTranslator extends PacketTranslator<ServerRespawnPacket>
if (entity.getDimension() != DimensionUtils.javaToBedrock(packet.getDimension())) { if (entity.getDimension() != DimensionUtils.javaToBedrock(packet.getDimension())) {
DimensionUtils.switchDimension(session, packet.getDimension()); DimensionUtils.switchDimension(session, packet.getDimension());
} else { } else {
if (session.isManyDimPackets()) { //reloading world
session.getEntityCache().removeAllEntities();
//TODO: fix lighting bug
}
// Handled in JavaPlayerPositionRotationTranslator // Handled in JavaPlayerPositionRotationTranslator
session.setSpawned(false); session.setSpawned(false);
if (session.isManyDimPackets()) { //reloading world
session.getEntityCache().removeAllEntities();
//lighting fix
ChunkUtils.sendEmptyChunks(session, entity.getPosition().toInt(), session.getRenderDistance(), false);
Vector3f tempPos = Vector3f.from(entity.getPosition().getX() > 0 ? -5000 : 5000, 0, 0);
MovePlayerPacket movePlayerPacket = new MovePlayerPacket();
movePlayerPacket.setRuntimeEntityId(entity.getGeyserId());
movePlayerPacket.setPosition(tempPos);
movePlayerPacket.setRotation(Vector3f.ZERO);
movePlayerPacket.setMode(MovePlayerPacket.Mode.NORMAL);
movePlayerPacket.setOnGround(true);
session.getUpstream().sendPacket(movePlayerPacket);
ChunkUtils.sendEmptyChunks(session, tempPos.toInt(), 5, true);
}
} }
} }
} }

Datei anzeigen

@ -73,16 +73,16 @@ public class ChunkUtils {
session.getUpstream().sendPacket(waterPacket); session.getUpstream().sendPacket(waterPacket);
} }
public static void sendEmptyChunks(GeyserSession session, Vector3i position, int radius) { public static void sendEmptyChunks(GeyserSession session, Vector3i position, int radius, boolean forceUpdate) {
int chunkX = position.getX() >> 4; int chunkX = position.getX() >> 4;
int chunkZ = position.getZ() >> 4; int chunkZ = position.getZ() >> 4;
NetworkChunkPublisherUpdatePacket chunkPublisherUpdatePacket = new NetworkChunkPublisherUpdatePacket(); NetworkChunkPublisherUpdatePacket chunkPublisherUpdatePacket = new NetworkChunkPublisherUpdatePacket();
chunkPublisherUpdatePacket.setPosition(position); chunkPublisherUpdatePacket.setPosition(position);
chunkPublisherUpdatePacket.setRadius(radius << 4); chunkPublisherUpdatePacket.setRadius(radius + 1 << 4);
session.getUpstream().sendPacket(chunkPublisherUpdatePacket); session.getUpstream().sendPacket(chunkPublisherUpdatePacket);
session.setLastChunkPosition(null); session.setLastChunkPosition(null);
for (int x = -radius; x < radius; x++) { for (int x = -radius; x <= radius; x++) {
for (int z = -radius; z < radius; z++) { for (int z = -radius; z <= radius; z++) {
LevelChunkPacket data = new LevelChunkPacket(); LevelChunkPacket data = new LevelChunkPacket();
data.setChunkX(chunkX + x); data.setChunkX(chunkX + x);
data.setChunkZ(chunkZ + z); data.setChunkZ(chunkZ + z);
@ -90,6 +90,15 @@ public class ChunkUtils {
data.setData(TranslatorsInit.EMPTY_LEVEL_CHUNK_DATA); data.setData(TranslatorsInit.EMPTY_LEVEL_CHUNK_DATA);
data.setCachingEnabled(false); data.setCachingEnabled(false);
session.getUpstream().sendPacket(data); session.getUpstream().sendPacket(data);
if (forceUpdate) {
Vector3i pos = Vector3i.from(chunkX + x << 4, 80, chunkZ + z << 4);
UpdateBlockPacket blockPacket = new UpdateBlockPacket();
blockPacket.setBlockPosition(pos);
blockPacket.setDataLayer(1);
blockPacket.setRuntimeId(1);
session.getUpstream().sendPacket(blockPacket);
}
} }
} }
} }