Implement player movement

This commit is contained in:
RednedEpic 2019-09-13 19:37:06 -05:00 committed by RednedEpic
parent 03bf12ee65
commit a69aa8ebdb
3 changed files with 31 additions and 1 deletions

View file

@ -121,7 +121,8 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
return true;
}
return false;
return translateAndDefault(packet);
}
@Override

View file

@ -65,6 +65,7 @@ import com.nukkitx.nbt.tag.CompoundTag;
import com.nukkitx.protocol.bedrock.packet.AnimatePacket;
import com.nukkitx.protocol.bedrock.packet.CommandRequestPacket;
import com.nukkitx.protocol.bedrock.packet.MobEquipmentPacket;
import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
import com.nukkitx.protocol.bedrock.packet.PlayerActionPacket;
import com.nukkitx.protocol.bedrock.packet.TextPacket;
import lombok.Getter;
@ -72,6 +73,7 @@ import org.geysermc.connector.network.translators.bedrock.BedrockActionTranslato
import org.geysermc.connector.network.translators.bedrock.BedrockAnimateTranslator;
import org.geysermc.connector.network.translators.bedrock.BedrockCommandRequestTranslator;
import org.geysermc.connector.network.translators.bedrock.BedrockMobEquipmentTranslator;
import org.geysermc.connector.network.translators.bedrock.BedrockMovePlayerTranslator;
import org.geysermc.connector.network.translators.bedrock.BedrockTextTranslator;
import org.geysermc.connector.network.translators.inventory.GenericInventoryTranslator;
import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
@ -182,6 +184,7 @@ public class TranslatorsInit {
Registry.registerBedrock(TextPacket.class, new BedrockTextTranslator());
Registry.registerBedrock(MobEquipmentPacket.class, new BedrockMobEquipmentTranslator());
Registry.registerBedrock(PlayerActionPacket.class, new BedrockActionTranslator());
Registry.registerBedrock(MovePlayerPacket.class, new BedrockMovePlayerTranslator());
itemTranslator = new ItemTranslator();

View file

@ -0,0 +1,26 @@
package org.geysermc.connector.network.translators.bedrock;
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionRotationPacket;
import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPacket> {
@Override
public void translate(MovePlayerPacket packet, GeyserSession session) {
Entity entity = session.getPlayerEntity();
if (entity == null)
return;
// TODO: Implement collision support
ClientPlayerPositionRotationPacket playerPositionRotationPacket = new ClientPlayerPositionRotationPacket(
packet.isOnGround(), packet.getPosition().getX(), Math.ceil((packet.getPosition().getY() - EntityType.PLAYER.getOffset()) * 2) / 2,
packet.getPosition().getZ(), packet.getRotation().getY(), packet.getRotation().getX());
entity.moveAbsolute(packet.getPosition(), packet.getRotation());
session.getDownstream().getSession().send(playerPositionRotationPacket);
}
}