Fix different ResourcePackPushPacket handling, cache current input mode

This commit is contained in:
onebeastchris 2024-11-03 00:01:39 +08:00
parent 47ac22aecf
commit 4d15c7fbcc
3 changed files with 14 additions and 3 deletions

View file

@ -255,7 +255,6 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
private final EventLoop eventLoop;
@Setter
private AuthData authData;
@Setter
private BedrockClientData clientData;
/**
* Used for Floodgate skin uploading
@ -1411,6 +1410,12 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
this.cameraData.handleGameModeChange(currentlySpectator, newGamemode);
}
public void setClientData(BedrockClientData data) {
this.clientData = data;
this.inputCache.setInputMode(
org.cloudburstmc.protocol.bedrock.data.InputMode.values()[data.getCurrentInputMode().ordinal()]);
}
/**
* Convenience method to reduce amount of duplicate code. Sends ServerboundUseItemPacket.
*/
@ -2124,7 +2129,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
@Override
public @NonNull InputMode inputMode() {
return InputMode.values()[clientData.getCurrentInputMode().ordinal()]; //todo
return InputMode.values()[inputCache.getInputMode().ordinal()]; //todo
}
@Override

View file

@ -27,6 +27,7 @@ package org.geysermc.geyser.session.cache;
import lombok.Getter;
import lombok.Setter;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.cloudburstmc.math.vector.Vector2f;
import org.cloudburstmc.protocol.bedrock.data.InputMode;
import org.cloudburstmc.protocol.bedrock.data.PlayerAuthInputData;
@ -45,6 +46,8 @@ public final class InputCache {
private int jumpingTicks;
@Getter @Setter
private float jumpScale;
@Getter @Setter
private @MonotonicNonNull InputMode inputMode;
public InputCache(GeyserSession session) {
this.session = session;
@ -54,9 +57,10 @@ public final class InputCache {
// Input is sent to the server before packet positions, as of 1.21.2
Set<PlayerAuthInputData> bedrockInput = packet.getInputData();
var oldInputPacket = this.inputPacket;
this.inputMode = packet.getInputMode();
boolean up, down, left, right;
if (packet.getInputMode() == InputMode.MOUSE) {
if (this.inputMode == InputMode.MOUSE) {
up = bedrockInput.contains(PlayerAuthInputData.UP);
down = bedrockInput.contains(PlayerAuthInputData.DOWN);
left = bedrockInput.contains(PlayerAuthInputData.LEFT);

View file

@ -40,6 +40,8 @@ public class JavaClientboundResourcePackPushPacket extends PacketTranslator<Clie
// We need to "answer" this to avoid timeout issues related to resource packs
// If packs are required, we need to lie to the server that we accepted them, as we get kicked otherwise.
if (packet.isRequired()) {
session.sendDownstreamPacket(new ServerboundResourcePackPacket(packet.getId(), ResourcePackStatus.ACCEPTED));
session.sendDownstreamPacket(new ServerboundResourcePackPacket(packet.getId(), ResourcePackStatus.DOWNLOADED));
session.sendDownstreamPacket(new ServerboundResourcePackPacket(packet.getId(), ResourcePackStatus.SUCCESSFULLY_LOADED));
} else {
session.sendDownstreamPacket(new ServerboundResourcePackPacket(packet.getId(), ResourcePackStatus.DECLINED));