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

Implement dimension changing and debugize 'moved too quickly' messages

Dieser Commit ist enthalten in:
RednedEpic 2019-10-15 21:47:28 -05:00 committet von RednedEpic
Ursprung f6ab70cabb
Commit 0ac89f4880
4 geänderte Dateien mit 37 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -82,6 +82,7 @@ public class Entity {
this.valid = false;
this.movePending = false;
this.dimension = 0;
}
public void spawnEntity(GeyserSession session) {
@ -132,6 +133,7 @@ public class Entity {
public void moveAbsolute(Vector3f position, Vector3f rotation) {
setPosition(position);
setRotation(rotation);
this.movePending = true;
}

Datei anzeigen

@ -31,6 +31,7 @@ import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket;
import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket;
import org.geysermc.api.ChatColor;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.PlayerEntity;
import org.geysermc.connector.entity.type.EntityType;
@ -39,12 +40,12 @@ import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.block.BlockEntry;
public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPacket> {
@Override
public void translate(MovePlayerPacket packet, GeyserSession session) {
PlayerEntity entity = session.getPlayerEntity();
if (entity == null || !session.isSpawned()) return;
// can cause invalid moves when packet queue is not empty
if (!session.getUpstream().isInitialized()) {
MoveEntityAbsolutePacket moveEntityBack = new MoveEntityAbsolutePacket();
moveEntityBack.setRuntimeEntityId(entity.getGeyserId());
@ -57,7 +58,7 @@ public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPack
}
if (!isValidMove(session, packet.getMode(), entity.getPosition(), packet.getPosition())) {
session.getConnector().getLogger().info("Recalculating position...");
session.getConnector().getLogger().debug("Recalculating position...");
recalculatePosition(session, entity, entity.getPosition());
return;
}
@ -102,7 +103,7 @@ public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPack
zRange = -zRange;
if ((xRange + yRange + zRange) > 100) {
session.getConnector().getLogger().warning(session.getName() + " moved too quickly." +
session.getConnector().getLogger().debug(ChatColor.RED + session.getName() + " moved too quickly." +
" current position: " + currentPosition + ", new position: " + newPosition);
return false;
@ -122,7 +123,7 @@ public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPack
movePlayerPacket.setRuntimeEntityId(entity.getGeyserId());
movePlayerPacket.setPosition(entity.getPosition());
movePlayerPacket.setRotation(entity.getBedrockRotation());
movePlayerPacket.setMode(MovePlayerPacket.Mode.NORMAL);
movePlayerPacket.setMode(MovePlayerPacket.Mode.RESET);
movePlayerPacket.setOnGround(true);
entity.setMovePending(false);
session.getUpstream().sendPacket(movePlayerPacket);

Datei anzeigen

@ -59,7 +59,6 @@ public class JavaJoinGameTranslator extends PacketTranslator<ServerJoinGamePacke
session.getUpstream().sendPacket(entityDataPacket);
session.setRenderDistance(packet.getViewDistance() + 1); // +1 to be sure it includes every chunk
System.out.println(session.getRenderDistance());
if (session.getRenderDistance() > 32) session.setRenderDistance(32); // <3 u ViaVersion but I don't like crashing clients x)
ChunkRadiusUpdatedPacket packet1 = new ChunkRadiusUpdatedPacket();

Datei anzeigen

@ -26,7 +26,9 @@
package org.geysermc.connector.network.translators.java;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerRespawnPacket;
import com.nukkitx.protocol.bedrock.packet.ChangeDimensionPacket;
import com.nukkitx.protocol.bedrock.packet.PlayStatusPacket;
import com.nukkitx.protocol.bedrock.packet.SetPlayerGameTypePacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
@ -39,10 +41,34 @@ public class JavaRespawnTranslator extends PacketTranslator<ServerRespawnPacket>
if (entity == null)
return;
if (entity.getDimension() == packet.getDimension()) {
if (entity.getDimension() == getDimension(packet.getDimension()))
return;
entity.setDimension(getDimension(packet.getDimension()));
ChangeDimensionPacket changeDimensionPacket = new ChangeDimensionPacket();
changeDimensionPacket.setDimension(getDimension(packet.getDimension()));
changeDimensionPacket.setRespawn(false);
changeDimensionPacket.setPosition(entity.getPosition());
session.getUpstream().sendPacket(changeDimensionPacket);
SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket();
playerGameTypePacket.setGamemode(packet.getGamemode().ordinal());
session.getUpstream().sendPacket(playerGameTypePacket);
PlayStatusPacket playStatusPacket = new PlayStatusPacket();
playStatusPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN);
session.getUpstream().sendPacket(playStatusPacket);
}
private int getDimension(int javaDimension) {
switch (javaDimension) {
case -1:
return 1;
case 1:
return 2;
}
return javaDimension;
}
}