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:
Ursprung
f6ab70cabb
Commit
0ac89f4880
@ -82,6 +82,7 @@ public class Entity {
|
|||||||
|
|
||||||
this.valid = false;
|
this.valid = false;
|
||||||
this.movePending = false;
|
this.movePending = false;
|
||||||
|
this.dimension = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void spawnEntity(GeyserSession session) {
|
public void spawnEntity(GeyserSession session) {
|
||||||
@ -132,6 +133,7 @@ public class Entity {
|
|||||||
public void moveAbsolute(Vector3f position, Vector3f rotation) {
|
public void moveAbsolute(Vector3f position, Vector3f rotation) {
|
||||||
setPosition(position);
|
setPosition(position);
|
||||||
setRotation(rotation);
|
setRotation(rotation);
|
||||||
|
|
||||||
this.movePending = true;
|
this.movePending = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ import com.nukkitx.math.vector.Vector3f;
|
|||||||
import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket;
|
import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket;
|
||||||
import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
|
import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
|
||||||
import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket;
|
import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket;
|
||||||
|
import org.geysermc.api.ChatColor;
|
||||||
import org.geysermc.connector.entity.Entity;
|
import org.geysermc.connector.entity.Entity;
|
||||||
import org.geysermc.connector.entity.PlayerEntity;
|
import org.geysermc.connector.entity.PlayerEntity;
|
||||||
import org.geysermc.connector.entity.type.EntityType;
|
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;
|
import org.geysermc.connector.network.translators.block.BlockEntry;
|
||||||
|
|
||||||
public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPacket> {
|
public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPacket> {
|
||||||
|
|
||||||
@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()) return;
|
if (entity == null || !session.isSpawned()) return;
|
||||||
|
|
||||||
// can cause invalid moves when packet queue is not empty
|
|
||||||
if (!session.getUpstream().isInitialized()) {
|
if (!session.getUpstream().isInitialized()) {
|
||||||
MoveEntityAbsolutePacket moveEntityBack = new MoveEntityAbsolutePacket();
|
MoveEntityAbsolutePacket moveEntityBack = new MoveEntityAbsolutePacket();
|
||||||
moveEntityBack.setRuntimeEntityId(entity.getGeyserId());
|
moveEntityBack.setRuntimeEntityId(entity.getGeyserId());
|
||||||
@ -57,7 +58,7 @@ public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPack
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!isValidMove(session, packet.getMode(), entity.getPosition(), packet.getPosition())) {
|
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());
|
recalculatePosition(session, entity, entity.getPosition());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -102,7 +103,7 @@ public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPack
|
|||||||
zRange = -zRange;
|
zRange = -zRange;
|
||||||
|
|
||||||
if ((xRange + yRange + zRange) > 100) {
|
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);
|
" current position: " + currentPosition + ", new position: " + newPosition);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -122,7 +123,7 @@ public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPack
|
|||||||
movePlayerPacket.setRuntimeEntityId(entity.getGeyserId());
|
movePlayerPacket.setRuntimeEntityId(entity.getGeyserId());
|
||||||
movePlayerPacket.setPosition(entity.getPosition());
|
movePlayerPacket.setPosition(entity.getPosition());
|
||||||
movePlayerPacket.setRotation(entity.getBedrockRotation());
|
movePlayerPacket.setRotation(entity.getBedrockRotation());
|
||||||
movePlayerPacket.setMode(MovePlayerPacket.Mode.NORMAL);
|
movePlayerPacket.setMode(MovePlayerPacket.Mode.RESET);
|
||||||
movePlayerPacket.setOnGround(true);
|
movePlayerPacket.setOnGround(true);
|
||||||
entity.setMovePending(false);
|
entity.setMovePending(false);
|
||||||
session.getUpstream().sendPacket(movePlayerPacket);
|
session.getUpstream().sendPacket(movePlayerPacket);
|
||||||
|
@ -59,7 +59,6 @@ public class JavaJoinGameTranslator extends PacketTranslator<ServerJoinGamePacke
|
|||||||
session.getUpstream().sendPacket(entityDataPacket);
|
session.getUpstream().sendPacket(entityDataPacket);
|
||||||
|
|
||||||
session.setRenderDistance(packet.getViewDistance() + 1); // +1 to be sure it includes every chunk
|
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)
|
if (session.getRenderDistance() > 32) session.setRenderDistance(32); // <3 u ViaVersion but I don't like crashing clients x)
|
||||||
|
|
||||||
ChunkRadiusUpdatedPacket packet1 = new ChunkRadiusUpdatedPacket();
|
ChunkRadiusUpdatedPacket packet1 = new ChunkRadiusUpdatedPacket();
|
||||||
|
@ -26,7 +26,9 @@
|
|||||||
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.protocol.bedrock.packet.ChangeDimensionPacket;
|
||||||
import com.nukkitx.protocol.bedrock.packet.PlayStatusPacket;
|
import com.nukkitx.protocol.bedrock.packet.PlayStatusPacket;
|
||||||
|
import com.nukkitx.protocol.bedrock.packet.SetPlayerGameTypePacket;
|
||||||
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;
|
||||||
@ -39,10 +41,34 @@ public class JavaRespawnTranslator extends PacketTranslator<ServerRespawnPacket>
|
|||||||
if (entity == null)
|
if (entity == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (entity.getDimension() == packet.getDimension()) {
|
if (entity.getDimension() == getDimension(packet.getDimension()))
|
||||||
PlayStatusPacket playStatusPacket = new PlayStatusPacket();
|
return;
|
||||||
playStatusPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN);
|
|
||||||
session.getUpstream().sendPacket(playStatusPacket);
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren