Change lighting fix method

This commit is contained in:
AJ Ferguson 2019-12-28 23:20:48 -09:00
parent c4658ecdae
commit 4153e98134
3 changed files with 12 additions and 18 deletions

View file

@ -67,7 +67,7 @@ public class JavaJoinGameTranslator extends PacketTranslator<ServerJoinGamePacke
session.getUpstream().sendPacket(chunkRadiusPacket);
if (DimensionUtils.javaToBedrock(packet.getDimension()) != entity.getDimension()) {
DimensionUtils.switchDimension(session, packet.getDimension());
DimensionUtils.switchDimension(session, packet.getDimension(), false);
}
}
}

View file

@ -26,13 +26,11 @@
package org.geysermc.connector.network.translators.java;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerRespawnPacket;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.packet.*;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.attribute.AttributeType;
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 JavaRespawnTranslator extends PacketTranslator<ServerRespawnPacket> {
@ -44,7 +42,8 @@ public class JavaRespawnTranslator extends PacketTranslator<ServerRespawnPacket>
return;
float maxHealth = entity.getAttributes().containsKey(AttributeType.MAX_HEALTH) ? entity.getAttributes().get(AttributeType.MAX_HEALTH).getValue() : 20f;
entity.getAttributes().put(AttributeType.HEALTH, AttributeType.HEALTH.getAttribute(maxHealth));
// Max health must be divisible by two in bedrock
entity.getAttributes().put(AttributeType.HEALTH, AttributeType.HEALTH.getAttribute(maxHealth, (maxHealth % 2 == 1 ? maxHealth + 1 : maxHealth)));
SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket();
playerGameTypePacket.setGamemode(packet.getGamemode().ordinal());
@ -52,23 +51,14 @@ public class JavaRespawnTranslator extends PacketTranslator<ServerRespawnPacket>
session.setGameMode(packet.getGamemode());
if (entity.getDimension() != DimensionUtils.javaToBedrock(packet.getDimension())) {
DimensionUtils.switchDimension(session, packet.getDimension());
DimensionUtils.switchDimension(session, packet.getDimension(), false);
} else {
// Handled in JavaPlayerPositionRotationTranslator
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);
int fakeDim = entity.getDimension() == 0 ? -1 : 0;
DimensionUtils.switchDimension(session, fakeDim, true);
DimensionUtils.switchDimension(session, packet.getDimension(), false);
}
}
}

View file

@ -6,7 +6,7 @@ import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession;
public class DimensionUtils {
public static void switchDimension(GeyserSession session, int javaDimension) {
public static void switchDimension(GeyserSession session, int javaDimension, boolean fake) {
int bedrockDimension = javaToBedrock(javaDimension);
Entity player = session.getPlayerEntity();
if (bedrockDimension == player.getDimension())
@ -28,6 +28,10 @@ public class DimensionUtils {
stopSoundPacket.setSoundName("");
session.getUpstream().sendPacket(stopSoundPacket);
if (fake) {
ChunkUtils.sendEmptyChunks(session, pos, 2, true);
}
session.setSpawned(false);
session.setSwitchingDimension(true);
}