Fix/implement entity interaction and fix sprinting

This commit is contained in:
RednedEpic 2019-10-16 15:32:53 -05:00 committed by RednedEpic
parent 7571df9903
commit d548647367
5 changed files with 36 additions and 31 deletions

View file

@ -151,6 +151,7 @@ public class TranslatorsInit {
Registry.registerBedrock(MovePlayerPacket.class, new BedrockMovePlayerTranslator());
Registry.registerBedrock(PlayerActionPacket.class, new BedrockActionTranslator());
Registry.registerBedrock(SetLocalPlayerAsInitializedPacket.class, new BedrockPlayerInitializedTranslator());
Registry.registerBedrock(InteractPacket.class, new BedrockInteractTranslator());
Registry.registerBedrock(TextPacket.class, new BedrockTextTranslator());
itemTranslator = new ItemTranslator();

View file

@ -43,7 +43,7 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
@Override
public void translate(PlayerActionPacket packet, GeyserSession session) {
Entity entity = session.getPlayerEntity();
Entity entity = session.getEntityCache().getEntityByGeyserId(packet.getRuntimeEntityId());
if (entity == null)
return;
@ -57,32 +57,31 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
break;
case START_GLIDE:
case STOP_GLIDE:
ClientPlayerStatePacket glidePacket = new ClientPlayerStatePacket((int) session.getPlayerEntity().getGeyserId(), PlayerState.START_ELYTRA_FLYING);
ClientPlayerStatePacket glidePacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_ELYTRA_FLYING);
session.getDownstream().getSession().send(glidePacket);
break;
case START_SNEAK:
ClientPlayerStatePacket startSneakPacket = new ClientPlayerStatePacket((int) session.getPlayerEntity().getGeyserId(), PlayerState.START_SNEAKING);
ClientPlayerStatePacket startSneakPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_SNEAKING);
session.getDownstream().getSession().send(startSneakPacket);
break;
case STOP_SNEAK:
ClientPlayerStatePacket stopSneakPacket = new ClientPlayerStatePacket((int) session.getPlayerEntity().getGeyserId(), PlayerState.STOP_SNEAKING);
ClientPlayerStatePacket stopSneakPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.STOP_SNEAKING);
session.getDownstream().getSession().send(stopSneakPacket);
break;
// Apparently the code below breaks sprinting...
case START_SPRINT:
// ClientPlayerStatePacket startSprintPacket = new ClientPlayerStatePacket((int) session.getPlayerEntity().getGeyserId(), PlayerState.START_SPRINTING);
// session.getDownstream().getSession().send(startSprintPacket);
ClientPlayerStatePacket startSprintPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_SPRINTING);
session.getDownstream().getSession().send(startSprintPacket);
break;
case STOP_SPRINT:
// ClientPlayerStatePacket stopSprintPacket = new ClientPlayerStatePacket((int) session.getPlayerEntity().getGeyserId(), PlayerState.STOP_SPRINTING);
// session.getDownstream().getSession().send(stopSprintPacket);
ClientPlayerStatePacket stopSprintPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.STOP_SPRINTING);
session.getDownstream().getSession().send(stopSprintPacket);
break;
case DROP_ITEM:
ClientPlayerActionPacket dropItemPacket = new ClientPlayerActionPacket(PlayerAction.DROP_ITEM, position, BlockFace.values()[packet.getFace()]);
session.getDownstream().getSession().send(dropItemPacket);
break;
case STOP_SLEEP:
ClientPlayerStatePacket stopSleepingPacket = new ClientPlayerStatePacket((int) session.getPlayerEntity().getGeyserId(), PlayerState.LEAVE_BED);
ClientPlayerStatePacket stopSleepingPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.LEAVE_BED);
session.getDownstream().getSession().send(stopSleepingPacket);
break;
case BLOCK_INTERACT:

View file

@ -39,6 +39,7 @@ public class BedrockAnimateTranslator extends PacketTranslator<AnimatePacket> {
case SWING_ARM:
ClientPlayerSwingArmPacket swingArmPacket = new ClientPlayerSwingArmPacket(Hand.MAIN_HAND);
session.getDownstream().getSession().send(swingArmPacket);
break;
}
}
}

View file

@ -30,6 +30,8 @@ import com.github.steveice10.mc.protocol.data.game.entity.player.InteractAction;
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerInteractEntityPacket;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.packet.InteractPacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.PlayerEntity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
@ -37,18 +39,21 @@ public class BedrockInteractTranslator extends PacketTranslator<InteractPacket>
@Override
public void translate(InteractPacket packet, GeyserSession session) {
Vector3f vector = packet.getMousePosition();
InteractAction action;
Entity entity = session.getEntityCache().getEntityByGeyserId(packet.getRuntimeEntityId());
if (entity == null)
return;
if(packet.getAction() == 1) {
action = InteractAction.ATTACK;
} else {
action = InteractAction.INTERACT;
switch (packet.getAction()) {
case 1:
ClientPlayerInteractEntityPacket interactPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
InteractAction.INTERACT, Hand.MAIN_HAND);
session.getDownstream().getSession().send(interactPacket);
break;
case 2:
ClientPlayerInteractEntityPacket attackPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
InteractAction.ATTACK, Hand.MAIN_HAND);
session.getDownstream().getSession().send(attackPacket);
break;
}
ClientPlayerInteractEntityPacket entityPacket = new ClientPlayerInteractEntityPacket((int) packet.getRuntimeEntityId(),
action, vector.getX(), vector.getY(), vector.getZ(), Hand.MAIN_HAND);
session.getDownstream().getSession().send(entityPacket);
}
}

View file

@ -35,6 +35,8 @@ import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlaye
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerUseItemPacket;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.packet.InventoryTransactionPacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.PlayerEntity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
@ -56,19 +58,16 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
}
break;
case ITEM_USE_ON_ENTITY:
Entity entity = session.getEntityCache().getEntityByGeyserId(packet.getRuntimeEntityId());
if (entity == null)
return;
Vector3f vector = packet.getClickPosition();
InteractAction action;
if(packet.getActionType() == 1) {
action = InteractAction.ATTACK;
} else {
action = InteractAction.INTERACT;
}
ClientPlayerInteractEntityPacket entityPacket = new ClientPlayerInteractEntityPacket((int) packet.getRuntimeEntityId(),
action, vector.getX(), vector.getY(), vector.getZ(), Hand.MAIN_HAND);
ClientPlayerInteractEntityPacket entityPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
InteractAction.values()[packet.getActionType()], vector.getX(), vector.getY(), vector.getZ(), Hand.MAIN_HAND);
session.getDownstream().getSession().send(entityPacket);
break;
}
}
}