|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package org.geysermc.connector.network.translators.java.entity; |
|
|
|
import org.geysermc.connector.entity.Entity; |
|
import org.geysermc.connector.entity.ItemEntity; |
|
import org.geysermc.connector.entity.living.animal.horse.AbstractHorseEntity; |
|
import org.geysermc.connector.network.session.GeyserSession; |
|
import org.geysermc.connector.network.translators.PacketTranslator; |
|
import org.geysermc.connector.network.translators.Translator; |
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityVelocityPacket; |
|
import com.nukkitx.math.vector.Vector3f; |
|
import com.nukkitx.protocol.bedrock.packet.SetEntityMotionPacket; |
|
|
|
@Translator(packet = ServerEntityVelocityPacket.class) |
|
public class JavaEntityVelocityTranslator extends PacketTranslator<ServerEntityVelocityPacket> { |
|
|
|
@Override |
|
public void translate(GeyserSession session, ServerEntityVelocityPacket packet) { |
|
Entity entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId()); |
|
if (packet.getEntityId() == session.getPlayerEntity().getEntityId()) { |
|
entity = session.getPlayerEntity(); |
|
} |
|
if (entity == null) return; |
|
|
|
entity.setMotion(Vector3f.from(packet.getMotionX(), packet.getMotionY(), packet.getMotionZ())); |
|
|
|
if (entity == session.getRidingVehicleEntity() && entity instanceof AbstractHorseEntity) { |
|
|
|
|
|
return; |
|
} |
|
|
|
if (entity instanceof ItemEntity) { |
|
|
|
|
|
return; |
|
} |
|
|
|
SetEntityMotionPacket entityMotionPacket = new SetEntityMotionPacket(); |
|
entityMotionPacket.setRuntimeEntityId(entity.getGeyserId()); |
|
entityMotionPacket.setMotion(entity.getMotion()); |
|
|
|
session.sendUpstreamPacket(entityMotionPacket); |
|
} |
|
} |
|
|