Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-27 16:40:14 +01:00
Fix/implement entity interaction and fix sprinting
Dieser Commit ist enthalten in:
Ursprung
7571df9903
Commit
d548647367
@ -151,6 +151,7 @@ public class TranslatorsInit {
|
|||||||
Registry.registerBedrock(MovePlayerPacket.class, new BedrockMovePlayerTranslator());
|
Registry.registerBedrock(MovePlayerPacket.class, new BedrockMovePlayerTranslator());
|
||||||
Registry.registerBedrock(PlayerActionPacket.class, new BedrockActionTranslator());
|
Registry.registerBedrock(PlayerActionPacket.class, new BedrockActionTranslator());
|
||||||
Registry.registerBedrock(SetLocalPlayerAsInitializedPacket.class, new BedrockPlayerInitializedTranslator());
|
Registry.registerBedrock(SetLocalPlayerAsInitializedPacket.class, new BedrockPlayerInitializedTranslator());
|
||||||
|
Registry.registerBedrock(InteractPacket.class, new BedrockInteractTranslator());
|
||||||
Registry.registerBedrock(TextPacket.class, new BedrockTextTranslator());
|
Registry.registerBedrock(TextPacket.class, new BedrockTextTranslator());
|
||||||
|
|
||||||
itemTranslator = new ItemTranslator();
|
itemTranslator = new ItemTranslator();
|
||||||
|
@ -43,7 +43,7 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translate(PlayerActionPacket packet, GeyserSession session) {
|
public void translate(PlayerActionPacket packet, GeyserSession session) {
|
||||||
Entity entity = session.getPlayerEntity();
|
Entity entity = session.getEntityCache().getEntityByGeyserId(packet.getRuntimeEntityId());
|
||||||
if (entity == null)
|
if (entity == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -57,32 +57,31 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
|||||||
break;
|
break;
|
||||||
case START_GLIDE:
|
case START_GLIDE:
|
||||||
case STOP_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);
|
session.getDownstream().getSession().send(glidePacket);
|
||||||
break;
|
break;
|
||||||
case START_SNEAK:
|
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);
|
session.getDownstream().getSession().send(startSneakPacket);
|
||||||
break;
|
break;
|
||||||
case STOP_SNEAK:
|
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);
|
session.getDownstream().getSession().send(stopSneakPacket);
|
||||||
break;
|
break;
|
||||||
// Apparently the code below breaks sprinting...
|
|
||||||
case START_SPRINT:
|
case START_SPRINT:
|
||||||
// ClientPlayerStatePacket startSprintPacket = new ClientPlayerStatePacket((int) session.getPlayerEntity().getGeyserId(), PlayerState.START_SPRINTING);
|
ClientPlayerStatePacket startSprintPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_SPRINTING);
|
||||||
// session.getDownstream().getSession().send(startSprintPacket);
|
session.getDownstream().getSession().send(startSprintPacket);
|
||||||
break;
|
break;
|
||||||
case STOP_SPRINT:
|
case STOP_SPRINT:
|
||||||
// ClientPlayerStatePacket stopSprintPacket = new ClientPlayerStatePacket((int) session.getPlayerEntity().getGeyserId(), PlayerState.STOP_SPRINTING);
|
ClientPlayerStatePacket stopSprintPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.STOP_SPRINTING);
|
||||||
// session.getDownstream().getSession().send(stopSprintPacket);
|
session.getDownstream().getSession().send(stopSprintPacket);
|
||||||
break;
|
break;
|
||||||
case DROP_ITEM:
|
case DROP_ITEM:
|
||||||
ClientPlayerActionPacket dropItemPacket = new ClientPlayerActionPacket(PlayerAction.DROP_ITEM, position, BlockFace.values()[packet.getFace()]);
|
ClientPlayerActionPacket dropItemPacket = new ClientPlayerActionPacket(PlayerAction.DROP_ITEM, position, BlockFace.values()[packet.getFace()]);
|
||||||
session.getDownstream().getSession().send(dropItemPacket);
|
session.getDownstream().getSession().send(dropItemPacket);
|
||||||
break;
|
break;
|
||||||
case STOP_SLEEP:
|
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);
|
session.getDownstream().getSession().send(stopSleepingPacket);
|
||||||
break;
|
break;
|
||||||
case BLOCK_INTERACT:
|
case BLOCK_INTERACT:
|
||||||
|
@ -39,6 +39,7 @@ public class BedrockAnimateTranslator extends PacketTranslator<AnimatePacket> {
|
|||||||
case SWING_ARM:
|
case SWING_ARM:
|
||||||
ClientPlayerSwingArmPacket swingArmPacket = new ClientPlayerSwingArmPacket(Hand.MAIN_HAND);
|
ClientPlayerSwingArmPacket swingArmPacket = new ClientPlayerSwingArmPacket(Hand.MAIN_HAND);
|
||||||
session.getDownstream().getSession().send(swingArmPacket);
|
session.getDownstream().getSession().send(swingArmPacket);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerInteractEntityPacket;
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
import com.nukkitx.protocol.bedrock.packet.InteractPacket;
|
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.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
|
|
||||||
@ -37,18 +39,21 @@ public class BedrockInteractTranslator extends PacketTranslator<InteractPacket>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translate(InteractPacket packet, GeyserSession session) {
|
public void translate(InteractPacket packet, GeyserSession session) {
|
||||||
Vector3f vector = packet.getMousePosition();
|
Entity entity = session.getEntityCache().getEntityByGeyserId(packet.getRuntimeEntityId());
|
||||||
InteractAction action;
|
if (entity == null)
|
||||||
|
return;
|
||||||
|
|
||||||
if(packet.getAction() == 1) {
|
switch (packet.getAction()) {
|
||||||
action = InteractAction.ATTACK;
|
case 1:
|
||||||
} else {
|
ClientPlayerInteractEntityPacket interactPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
|
||||||
action = InteractAction.INTERACT;
|
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerUseItemPacket;
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
import com.nukkitx.protocol.bedrock.packet.InventoryTransactionPacket;
|
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.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
|
|
||||||
@ -56,19 +58,16 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ITEM_USE_ON_ENTITY:
|
case ITEM_USE_ON_ENTITY:
|
||||||
|
Entity entity = session.getEntityCache().getEntityByGeyserId(packet.getRuntimeEntityId());
|
||||||
|
if (entity == null)
|
||||||
|
return;
|
||||||
|
|
||||||
Vector3f vector = packet.getClickPosition();
|
Vector3f vector = packet.getClickPosition();
|
||||||
InteractAction action;
|
ClientPlayerInteractEntityPacket entityPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
|
||||||
|
InteractAction.values()[packet.getActionType()], vector.getX(), vector.getY(), vector.getZ(), Hand.MAIN_HAND);
|
||||||
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);
|
|
||||||
|
|
||||||
session.getDownstream().getSession().send(entityPacket);
|
session.getDownstream().getSession().send(entityPacket);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren