Add support for fishing rods pulling Bedrock players (#1355)

Fishing rods pulling players is a clientside feature on Java. On Bedrock, a SetEntityMotionPacket is sent to the client. Therefore this PR implements the Java fishing rod pulling mechanics and sends it off to Bedrock, which sends MovePlayerPackets that are sent to the server.
This commit is contained in:
Camotoy 2020-10-02 15:44:46 -04:00 committed by GitHub
parent 772cb246f0
commit ba6f174058
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 3 deletions

View File

@ -30,8 +30,8 @@ import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import com.nukkitx.protocol.bedrock.data.entity.EntityEventType;
import com.nukkitx.protocol.bedrock.packet.EntityEventPacket;
import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket;
import com.nukkitx.protocol.bedrock.packet.SetEntityMotionPacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.PlayerEntity;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
@ -96,8 +96,20 @@ public class JavaEntityStatusTranslator extends PacketTranslator<ServerEntitySta
entityEventPacket.setType(EntityEventType.USE_ITEM);
break;
case FISHING_HOOK_PULL_PLAYER:
entityEventPacket.setType(EntityEventType.FISH_HOOK_TEASE); //TODO: CHECK
break;
// Player is pulled from a fishing rod
// The physics of this are clientside on Java
long pulledById = entity.getMetadata().getLong(EntityData.TARGET_EID);
if (session.getPlayerEntity().getGeyserId() == pulledById) {
Entity hookOwner = session.getEntityCache().getEntityByGeyserId(entity.getMetadata().getLong(EntityData.OWNER_EID));
if (hookOwner != null) {
// https://minecraft.gamepedia.com/Fishing_Rod#Hooking_mobs_and_other_entities
SetEntityMotionPacket motionPacket = new SetEntityMotionPacket();
motionPacket.setRuntimeEntityId(session.getPlayerEntity().getGeyserId());
motionPacket.setMotion(hookOwner.getPosition().sub(session.getPlayerEntity().getPosition()).mul(0.1f));
session.sendUpstreamPacket(motionPacket);
}
}
return;
case TAMEABLE_TAMING_FAILED:
entityEventPacket.setType(EntityEventType.TAME_FAILED);
break;