Guess when the client is clicking air on mobile

Should address #2113
This commit is contained in:
Camotoy 2023-01-03 19:28:43 -05:00
parent d1afb81a3b
commit b5e1ddc3c8
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
3 changed files with 56 additions and 24 deletions

View file

@ -455,7 +455,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
/**
* Counts how many ticks have occurred since an arm animation started.
* -1 means there is no active arm swing.
* -1 means there is no active arm swing; -2 means an arm swing will start in a tick.
*/
private int armAnimationTicks = -1;
@ -1157,7 +1157,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
entity.tick();
}
if (armAnimationTicks != -1) {
if (armAnimationTicks >= 0) {
// As of 1.18.2 Java Edition, it appears that the swing time is dynamically updated depending on the
// player's effect status, but the animation can cut short if the duration suddenly decreases
// (from suddenly no longer having mining fatigue, for example)
@ -1196,7 +1196,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
public void startSneaking() {
// Toggle the shield, if there is no ongoing arm animation
// This matches Bedrock Edition behavior as of 1.18.12
if (armAnimationTicks == -1) {
if (armAnimationTicks < 0) {
attemptToBlock();
}
@ -1328,6 +1328,16 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
}
}
/**
* For https://github.com/GeyserMC/Geyser/issues/2113 and combating arm ticking activating being delayed in
* BedrockAnimateTranslator.
*/
public void armSwingPending() {
if (armAnimationTicks == -1) {
armAnimationTicks = -2;
}
}
/**
* Indicates to the client to stop blocking and tells the Java server the same.
*/

View file

@ -46,7 +46,8 @@ public class BedrockAnimateTranslator extends PacketTranslator<AnimatePacket> {
}
switch (packet.getAction()) {
case SWING_ARM ->
case SWING_ARM -> {
session.armSwingPending();
// Delay so entity damage can be processed first
session.scheduleInEventLoop(() -> {
if (session.getArmAnimationTicks() != 0) {
@ -70,6 +71,7 @@ public class BedrockAnimateTranslator extends PacketTranslator<AnimatePacket> {
25,
TimeUnit.MILLISECONDS
);
}
// These two might need to be flipped, but my recommendation is getting moving working first
case ROW_LEFT -> {
// Packet value is a float of how long one has been rowing, so we convert that into a boolean

View file

@ -25,7 +25,10 @@
package org.geysermc.geyser.translator.protocol.bedrock.world;
import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundSwingPacket;
import com.nukkitx.protocol.bedrock.data.SoundEvent;
import com.nukkitx.protocol.bedrock.packet.AnimatePacket;
import com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.protocol.PacketTranslator;
@ -46,5 +49,22 @@ public class BedrockLevelSoundEventTranslator extends PacketTranslator<LevelSoun
// Sent here because Java still sends a cooldown if the player doesn't hit anything but Bedrock always sends a sound
CooldownUtils.sendCooldown(session);
}
if (packet.getSound() == SoundEvent.ATTACK_NODAMAGE && session.getArmAnimationTicks() == -1) {
// https://github.com/GeyserMC/Geyser/issues/2113
// Seems like consoles and Android with keyboard send the animation packet on 1.19.51, hence the animation
// tick check - the animate packet is sent first.
// ATTACK_NODAMAGE = player clicked air
// This should only be revisited if Bedrock packets get full Java parity, or Bedrock starts sending arm
// animation packets after ATTACK_NODAMAGE, OR ATTACK_NODAMAGE gets removed/isn't sent in the same spot
session.sendDownstreamPacket(new ServerboundSwingPacket(Hand.MAIN_HAND));
session.activateArmAnimationTicking();
// Send packet to Bedrock so it knows
AnimatePacket animatePacket = new AnimatePacket();
animatePacket.setRuntimeEntityId(session.getPlayerEntity().getGeyserId());
animatePacket.setAction(AnimatePacket.Action.SWING_ARM);
session.sendUpstreamPacket(animatePacket);
}
}
}