Restrict game packets to state; Closes #4191 (#4210)

Signed-off-by: Joshua Castle <26531652+Kas-tle@users.noreply.github.com>
This commit is contained in:
Kas-tle 2023-10-12 06:02:57 -07:00 committed by GitHub
parent 00800acd6a
commit 3fa35b2cb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
40 changed files with 132 additions and 103 deletions

View File

@ -44,7 +44,7 @@ public class StatisticsCommand extends GeyserCommand {
session.setWaitingForStatistics(true); session.setWaitingForStatistics(true);
ServerboundClientCommandPacket ServerboundClientCommandPacket = new ServerboundClientCommandPacket(ClientCommand.STATS); ServerboundClientCommandPacket ServerboundClientCommandPacket = new ServerboundClientCommandPacket(ClientCommand.STATS);
session.sendDownstreamPacket(ServerboundClientCommandPacket); session.sendDownstreamGamePacket(ServerboundClientCommandPacket);
} }
@Override @Override

View File

@ -68,7 +68,7 @@ public class InteractionEntity extends Entity {
animatePacket.setAction(AnimatePacket.Action.SWING_ARM); animatePacket.setAction(AnimatePacket.Action.SWING_ARM);
session.sendUpstreamPacket(animatePacket); session.sendUpstreamPacket(animatePacket);
session.sendDownstreamPacket(new ServerboundSwingPacket(hand)); session.sendDownstreamGamePacket(new ServerboundSwingPacket(hand));
return InteractionResult.SUCCESS; return InteractionResult.SUCCESS;
} }

View File

@ -82,14 +82,14 @@ public class AnvilContainer extends Container {
correctRename = plainNewName; correctRename = plainNewName;
// Java Edition sends a packet every time an item is renamed even slightly in GUI. Fortunately, this works out for us now // Java Edition sends a packet every time an item is renamed even slightly in GUI. Fortunately, this works out for us now
ServerboundRenameItemPacket renameItemPacket = new ServerboundRenameItemPacket(plainNewName); ServerboundRenameItemPacket renameItemPacket = new ServerboundRenameItemPacket(plainNewName);
session.sendDownstreamPacket(renameItemPacket); session.sendDownstreamGamePacket(renameItemPacket);
} else { } else {
// Restore formatting for item since we're not renaming // Restore formatting for item since we're not renaming
correctRename = MessageTranslator.convertMessageLenient(originalName); correctRename = MessageTranslator.convertMessageLenient(originalName);
// Java Edition sends the original custom name when not renaming, // Java Edition sends the original custom name when not renaming,
// if there isn't a custom name an empty string is sent // if there isn't a custom name an empty string is sent
ServerboundRenameItemPacket renameItemPacket = new ServerboundRenameItemPacket(plainOriginalName); ServerboundRenameItemPacket renameItemPacket = new ServerboundRenameItemPacket(plainOriginalName);
session.sendDownstreamPacket(renameItemPacket); session.sendDownstreamGamePacket(renameItemPacket);
} }
useJavaLevelCost = false; useJavaLevelCost = false;

View File

@ -152,7 +152,7 @@ public final class ClickPlan {
changedItems changedItems
); );
session.sendDownstreamPacket(clickPacket); session.sendDownstreamGamePacket(clickPacket);
} }
session.getPlayerInventory().setCursor(simulatedCursor, session); session.getPlayerInventory().setCursor(simulatedCursor, session);

View File

@ -120,7 +120,7 @@ public class AnvilInventoryUpdater extends InventoryUpdater {
// does not result in a FilterTextPacket // does not result in a FilterTextPacket
String originalName = MessageTranslator.convertToPlainTextLenient(ItemUtils.getCustomName(input.getNbt()), session.locale()); String originalName = MessageTranslator.convertToPlainTextLenient(ItemUtils.getCustomName(input.getNbt()), session.locale());
ServerboundRenameItemPacket renameItemPacket = new ServerboundRenameItemPacket(originalName); ServerboundRenameItemPacket renameItemPacket = new ServerboundRenameItemPacket(originalName);
session.sendDownstreamPacket(renameItemPacket); session.sendDownstreamGamePacket(renameItemPacket);
anvilContainer.setNewName(null); anvilContainer.setNewName(null);
} }

View File

@ -1135,7 +1135,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
if (position != null) { if (position != null) {
ServerboundMovePlayerPosPacket packet = new ServerboundMovePlayerPosPacket(playerEntity.isOnGround(), ServerboundMovePlayerPosPacket packet = new ServerboundMovePlayerPosPacket(playerEntity.isOnGround(),
position.getX(), position.getY(), position.getZ()); position.getX(), position.getY(), position.getZ());
sendDownstreamPacket(packet); sendDownstreamGamePacket(packet);
} }
lastMovementTimestamp = System.currentTimeMillis(); lastMovementTimestamp = System.currentTimeMillis();
} }
@ -1317,7 +1317,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
return false; return false;
} }
sendDownstreamPacket(useItemPacket); sendDownstreamGamePacket(useItemPacket);
playerEntity.setFlag(EntityFlag.BLOCKING, true); playerEntity.setFlag(EntityFlag.BLOCKING, true);
// Metadata should be updated later // Metadata should be updated later
return true; return true;
@ -1351,7 +1351,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
if (playerEntity.getFlag(EntityFlag.BLOCKING)) { if (playerEntity.getFlag(EntityFlag.BLOCKING)) {
ServerboundPlayerActionPacket releaseItemPacket = new ServerboundPlayerActionPacket(PlayerAction.RELEASE_USE_ITEM, ServerboundPlayerActionPacket releaseItemPacket = new ServerboundPlayerActionPacket(PlayerAction.RELEASE_USE_ITEM,
Vector3i.ZERO, Direction.DOWN, 0); Vector3i.ZERO, Direction.DOWN, 0);
sendDownstreamPacket(releaseItemPacket); sendDownstreamGamePacket(releaseItemPacket);
playerEntity.setFlag(EntityFlag.BLOCKING, false); playerEntity.setFlag(EntityFlag.BLOCKING, false);
return true; return true;
} }
@ -1361,7 +1361,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
public void requestOffhandSwap() { public void requestOffhandSwap() {
ServerboundPlayerActionPacket swapHandsPacket = new ServerboundPlayerActionPacket(PlayerAction.SWAP_HANDS, Vector3i.ZERO, ServerboundPlayerActionPacket swapHandsPacket = new ServerboundPlayerActionPacket(PlayerAction.SWAP_HANDS, Vector3i.ZERO,
Direction.DOWN, 0); Direction.DOWN, 0);
sendDownstreamPacket(swapHandsPacket); sendDownstreamGamePacket(swapHandsPacket);
} }
@Override @Override
@ -1396,14 +1396,14 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
* Sends a chat message to the Java server. * Sends a chat message to the Java server.
*/ */
public void sendChat(String message) { public void sendChat(String message) {
sendDownstreamPacket(new ServerboundChatPacket(message, Instant.now().toEpochMilli(), 0L, null, 0, new BitSet())); sendDownstreamGamePacket(new ServerboundChatPacket(message, Instant.now().toEpochMilli(), 0L, null, 0, new BitSet()));
} }
/** /**
* Sends a command to the Java server. * Sends a command to the Java server.
*/ */
public void sendCommand(String command) { public void sendCommand(String command) {
sendDownstreamPacket(new ServerboundChatCommandPacket(command, Instant.now().toEpochMilli(), 0L, Collections.emptyList(), 0, new BitSet())); sendDownstreamGamePacket(new ServerboundChatCommandPacket(command, Instant.now().toEpochMilli(), 0L, Collections.emptyList(), 0, new BitSet()));
} }
public void setServerRenderDistance(int renderDistance) { public void setServerRenderDistance(int renderDistance) {
@ -1575,6 +1575,39 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
upstream.sendPacketImmediately(packet); upstream.sendPacketImmediately(packet);
} }
/**
* Send a packet to the remote server if in the game state.
*
* @param packet the java edition packet from MCProtocolLib
*/
public void sendDownstreamGamePacket(Packet packet) {
sendDownstreamPacket(packet, ProtocolState.GAME);
}
/**
* Send a packet to the remote server if in the login state.
*
* @param packet the java edition packet from MCProtocolLib
*/
public void sendDownstreamLoginPacket(Packet packet) {
sendDownstreamPacket(packet, ProtocolState.LOGIN);
}
/**
* Send a packet to the remote server if in the specified state.
*
* @param packet the java edition packet from MCProtocolLib
* @param intendedState the state the client should be in
*/
public void sendDownstreamPacket(Packet packet, ProtocolState intendedState) {
if (protocol.getState() != intendedState) {
geyser.getLogger().debug("Tried to send " + packet.getClass().getSimpleName() + " packet while not in " + intendedState.name() + " state");
return;
}
sendDownstreamPacket(packet);
}
/** /**
* Send a packet to the remote server. * Send a packet to the remote server.
* *
@ -1718,7 +1751,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
// We're "flying locked" in this gamemode // We're "flying locked" in this gamemode
flying = true; flying = true;
ServerboundPlayerAbilitiesPacket abilitiesPacket = new ServerboundPlayerAbilitiesPacket(true); ServerboundPlayerAbilitiesPacket abilitiesPacket = new ServerboundPlayerAbilitiesPacket(true);
sendDownstreamPacket(abilitiesPacket); sendDownstreamGamePacket(abilitiesPacket);
} }
abilities.add(Ability.FLYING); abilities.add(Ability.FLYING);
} }

View File

@ -97,7 +97,7 @@ public class AdvancementsCache {
} else { } else {
// Send a packet indicating that we intend to open this particular advancement window // Send a packet indicating that we intend to open this particular advancement window
ServerboundSeenAdvancementsPacket packet = new ServerboundSeenAdvancementsPacket(id); ServerboundSeenAdvancementsPacket packet = new ServerboundSeenAdvancementsPacket(id);
session.sendDownstreamPacket(packet); session.sendDownstreamGamePacket(packet);
// Wait for a response there // Wait for a response there
} }
} }
@ -137,7 +137,7 @@ public class AdvancementsCache {
builder.closedResultHandler(() -> { builder.closedResultHandler(() -> {
// Indicate that we have closed the current advancement tab // Indicate that we have closed the current advancement tab
session.sendDownstreamPacket(new ServerboundSeenAdvancementsPacket()); session.sendDownstreamGamePacket(new ServerboundSeenAdvancementsPacket());
}).validResultHandler((response) -> { }).validResultHandler((response) -> {
if (response.getClickedButtonId() < visibleAdvancements.size()) { if (response.getClickedButtonId() < visibleAdvancements.size()) {
@ -146,7 +146,7 @@ public class AdvancementsCache {
} else { } else {
buildAndShowMenuForm(); buildAndShowMenuForm();
// Indicate that we have closed the current advancement tab // Indicate that we have closed the current advancement tab
session.sendDownstreamPacket(new ServerboundSeenAdvancementsPacket()); session.sendDownstreamGamePacket(new ServerboundSeenAdvancementsPacket());
} }
}); });

View File

@ -68,7 +68,7 @@ public class BookEditCache {
packet = null; packet = null;
return; return;
} }
session.sendDownstreamPacket(packet); session.sendDownstreamGamePacket(packet);
packet = null; packet = null;
lastBookUpdate = System.currentTimeMillis(); lastBookUpdate = System.currentTimeMillis();
} }

View File

@ -114,7 +114,7 @@ public class BeaconInventoryTranslator extends AbstractBlockInventoryTranslator
// Input a beacon payment // Input a beacon payment
BeaconPaymentAction beaconPayment = (BeaconPaymentAction) request.getActions()[0]; BeaconPaymentAction beaconPayment = (BeaconPaymentAction) request.getActions()[0];
ServerboundSetBeaconPacket packet = new ServerboundSetBeaconPacket(toJava(beaconPayment.getPrimaryEffect()), toJava(beaconPayment.getSecondaryEffect())); ServerboundSetBeaconPacket packet = new ServerboundSetBeaconPacket(toJava(beaconPayment.getPrimaryEffect()), toJava(beaconPayment.getSecondaryEffect()));
session.sendDownstreamPacket(packet); session.sendDownstreamGamePacket(packet);
return acceptRequest(request, makeContainerEntries(session, inventory, IntSets.emptySet())); return acceptRequest(request, makeContainerEntries(session, inventory, IntSets.emptySet()));
} }

View File

@ -129,7 +129,7 @@ public class EnchantingInventoryTranslator extends AbstractBlockInventoryTransla
return rejectRequest(request); return rejectRequest(request);
} }
ServerboundContainerButtonClickPacket packet = new ServerboundContainerButtonClickPacket(inventory.getJavaId(), javaSlot); ServerboundContainerButtonClickPacket packet = new ServerboundContainerButtonClickPacket(inventory.getJavaId(), javaSlot);
session.sendDownstreamPacket(packet); session.sendDownstreamGamePacket(packet);
return acceptRequest(request, makeContainerEntries(session, inventory, IntSets.emptySet())); return acceptRequest(request, makeContainerEntries(session, inventory, IntSets.emptySet()));
} }

View File

@ -102,7 +102,7 @@ public class LecternInventoryTranslator extends BaseInventoryTranslator {
if (session.isDroppingLecternBook()) { if (session.isDroppingLecternBook()) {
// We have to enter the inventory GUI to eject the book // We have to enter the inventory GUI to eject the book
ServerboundContainerButtonClickPacket packet = new ServerboundContainerButtonClickPacket(inventory.getJavaId(), 3); ServerboundContainerButtonClickPacket packet = new ServerboundContainerButtonClickPacket(inventory.getJavaId(), 3);
session.sendDownstreamPacket(packet); session.sendDownstreamGamePacket(packet);
session.setDroppingLecternBook(false); session.setDroppingLecternBook(false);
InventoryUtils.closeInventory(session, inventory.getJavaId(), false); InventoryUtils.closeInventory(session, inventory.getJavaId(), false);
} else if (lecternContainer.getBlockEntityTag() == null) { } else if (lecternContainer.getBlockEntityTag() == null) {
@ -153,7 +153,7 @@ public class LecternInventoryTranslator extends BaseInventoryTranslator {
session.getLecternCache().add(position); session.getLecternCache().add(position);
// Close the window - we will reopen it once the client has this data synced // Close the window - we will reopen it once the client has this data synced
ServerboundContainerClosePacket closeWindowPacket = new ServerboundContainerClosePacket(lecternContainer.getJavaId()); ServerboundContainerClosePacket closeWindowPacket = new ServerboundContainerClosePacket(lecternContainer.getJavaId());
session.sendDownstreamPacket(closeWindowPacket); session.sendDownstreamGamePacket(closeWindowPacket);
InventoryUtils.closeInventory(session, inventory.getJavaId(), false); InventoryUtils.closeInventory(session, inventory.getJavaId(), false);
} }
} }

View File

@ -149,7 +149,7 @@ public class LoomInventoryTranslator extends AbstractBlockInventoryTranslator {
// And the Java loom window has a fixed row/width of four // And the Java loom window has a fixed row/width of four
// So... Number / 4 = row (so we don't have to bother there), and number % 4 is our column, which leads us back to our index. :) // So... Number / 4 = row (so we don't have to bother there), and number % 4 is our column, which leads us back to our index. :)
ServerboundContainerButtonClickPacket packet = new ServerboundContainerButtonClickPacket(inventory.getJavaId(), index); ServerboundContainerButtonClickPacket packet = new ServerboundContainerButtonClickPacket(inventory.getJavaId(), index);
session.sendDownstreamPacket(packet); session.sendDownstreamGamePacket(packet);
GeyserItemStack inputCopy = inventory.getItem(0).copy(1); GeyserItemStack inputCopy = inventory.getItem(0).copy(1);
inputCopy.setNetId(session.getNextItemNetId()); inputCopy.setNetId(session.getNextItemNetId());

View File

@ -155,7 +155,7 @@ public class MerchantInventoryTranslator extends BaseInventoryTranslator {
private ItemStackResponse handleTrade(GeyserSession session, Inventory inventory, ItemStackRequest request, int tradeChoice) { private ItemStackResponse handleTrade(GeyserSession session, Inventory inventory, ItemStackRequest request, int tradeChoice) {
ServerboundSelectTradePacket packet = new ServerboundSelectTradePacket(tradeChoice); ServerboundSelectTradePacket packet = new ServerboundSelectTradePacket(tradeChoice);
session.sendDownstreamPacket(packet); session.sendDownstreamGamePacket(packet);
if (session.isEmulatePost1_13Logic()) { if (session.isEmulatePost1_13Logic()) {
// 1.18 Java cooperates nicer than older versions // 1.18 Java cooperates nicer than older versions

View File

@ -359,7 +359,7 @@ public class PlayerInventoryTranslator extends InventoryTranslator {
} }
ServerboundSetCreativeModeSlotPacket creativeDropPacket = new ServerboundSetCreativeModeSlotPacket(-1, sourceItem.getItemStack(dropAction.getCount())); ServerboundSetCreativeModeSlotPacket creativeDropPacket = new ServerboundSetCreativeModeSlotPacket(-1, sourceItem.getItemStack(dropAction.getCount()));
session.sendDownstreamPacket(creativeDropPacket); session.sendDownstreamGamePacket(creativeDropPacket);
sourceItem.sub(dropAction.getCount()); sourceItem.sub(dropAction.getCount());
} }
@ -494,7 +494,7 @@ public class PlayerInventoryTranslator extends InventoryTranslator {
dropStack = new ItemStack(javaCreativeItem.getId(), dropAction.getCount(), javaCreativeItem.getNbt()); dropStack = new ItemStack(javaCreativeItem.getId(), dropAction.getCount(), javaCreativeItem.getNbt());
} }
ServerboundSetCreativeModeSlotPacket creativeDropPacket = new ServerboundSetCreativeModeSlotPacket(-1, dropStack); ServerboundSetCreativeModeSlotPacket creativeDropPacket = new ServerboundSetCreativeModeSlotPacket(-1, dropStack);
session.sendDownstreamPacket(creativeDropPacket); session.sendDownstreamGamePacket(creativeDropPacket);
break; break;
} }
default: default:
@ -515,7 +515,7 @@ public class PlayerInventoryTranslator extends InventoryTranslator {
ItemStack itemStack = item.isEmpty() ? new ItemStack(-1, 0, null) : item.getItemStack(); ItemStack itemStack = item.isEmpty() ? new ItemStack(-1, 0, null) : item.getItemStack();
ServerboundSetCreativeModeSlotPacket creativePacket = new ServerboundSetCreativeModeSlotPacket(slot, itemStack); ServerboundSetCreativeModeSlotPacket creativePacket = new ServerboundSetCreativeModeSlotPacket(slot, itemStack);
session.sendDownstreamPacket(creativePacket); session.sendDownstreamGamePacket(creativePacket);
} }
private static boolean isCraftingGrid(ItemStackRequestSlotData slotInfoData) { private static boolean isCraftingGrid(ItemStackRequestSlotData slotInfoData) {

View File

@ -69,7 +69,7 @@ public class StonecutterInventoryTranslator extends AbstractBlockInventoryTransl
if (container.getStonecutterButton() != button) { if (container.getStonecutterButton() != button) {
// Getting the index of the item in the Java stonecutter list // Getting the index of the item in the Java stonecutter list
ServerboundContainerButtonClickPacket packet = new ServerboundContainerButtonClickPacket(inventory.getJavaId(), button); ServerboundContainerButtonClickPacket packet = new ServerboundContainerButtonClickPacket(inventory.getJavaId(), button);
session.sendDownstreamPacket(packet); session.sendDownstreamGamePacket(packet);
container.setStonecutterButton(button); container.setStonecutterButton(button);
} }

View File

@ -64,7 +64,7 @@ public class BedrockAnimateTranslator extends PacketTranslator<AnimatePacket> {
// and Bedrock 1.19.51. // and Bedrock 1.19.51.
// Note for the future: we should probably largely ignore this packet and instead replicate // Note for the future: we should probably largely ignore this packet and instead replicate
// all actions on our end, and send swings where needed. // all actions on our end, and send swings where needed.
session.sendDownstreamPacket(new ServerboundSwingPacket(Hand.MAIN_HAND)); session.sendDownstreamGamePacket(new ServerboundSwingPacket(Hand.MAIN_HAND));
session.activateArmAnimationTicking(); session.activateArmAnimationTicking();
} }
}, },
@ -77,12 +77,12 @@ public class BedrockAnimateTranslator extends PacketTranslator<AnimatePacket> {
// Packet value is a float of how long one has been rowing, so we convert that into a boolean // Packet value is a float of how long one has been rowing, so we convert that into a boolean
session.setSteeringLeft(packet.getRowingTime() > 0.0); session.setSteeringLeft(packet.getRowingTime() > 0.0);
ServerboundPaddleBoatPacket steerLeftPacket = new ServerboundPaddleBoatPacket(session.isSteeringLeft(), session.isSteeringRight()); ServerboundPaddleBoatPacket steerLeftPacket = new ServerboundPaddleBoatPacket(session.isSteeringLeft(), session.isSteeringRight());
session.sendDownstreamPacket(steerLeftPacket); session.sendDownstreamGamePacket(steerLeftPacket);
} }
case ROW_RIGHT -> { case ROW_RIGHT -> {
session.setSteeringRight(packet.getRowingTime() > 0.0); session.setSteeringRight(packet.getRowingTime() > 0.0);
ServerboundPaddleBoatPacket steerRightPacket = new ServerboundPaddleBoatPacket(session.isSteeringLeft(), session.isSteeringRight()); ServerboundPaddleBoatPacket steerRightPacket = new ServerboundPaddleBoatPacket(session.isSteeringLeft(), session.isSteeringRight());
session.sendDownstreamPacket(steerRightPacket); session.sendDownstreamGamePacket(steerRightPacket);
} }
} }
} }

View File

@ -108,7 +108,7 @@ public class BedrockBlockEntityDataTranslator extends PacketTranslator<BlockEnti
if (iterator < lines.length) lines[iterator] = newMessage.toString(); if (iterator < lines.length) lines[iterator] = newMessage.toString();
Vector3i pos = Vector3i.from(tag.getInt("x"), tag.getInt("y"), tag.getInt("z")); Vector3i pos = Vector3i.from(tag.getInt("x"), tag.getInt("y"), tag.getInt("z"));
ServerboundSignUpdatePacket signUpdatePacket = new ServerboundSignUpdatePacket(pos, lines, session.getWorldCache().isEditingSignOnFront()); ServerboundSignUpdatePacket signUpdatePacket = new ServerboundSignUpdatePacket(pos, lines, session.getWorldCache().isEditingSignOnFront());
session.sendDownstreamPacket(signUpdatePacket); session.sendDownstreamGamePacket(signUpdatePacket);
} else if (id.equals("JigsawBlock")) { } else if (id.equals("JigsawBlock")) {
// Client has just sent a jigsaw block update // Client has just sent a jigsaw block update
@ -120,7 +120,7 @@ public class BedrockBlockEntityDataTranslator extends PacketTranslator<BlockEnti
String joint = tag.getString("joint"); String joint = tag.getString("joint");
ServerboundSetJigsawBlockPacket jigsawPacket = new ServerboundSetJigsawBlockPacket(pos, name, target, pool, ServerboundSetJigsawBlockPacket jigsawPacket = new ServerboundSetJigsawBlockPacket(pos, name, target, pool,
finalState, joint); finalState, joint);
session.sendDownstreamPacket(jigsawPacket); session.sendDownstreamGamePacket(jigsawPacket);
} }
} }

View File

@ -53,13 +53,13 @@ public class BedrockCommandBlockUpdateTranslator extends PacketTranslator<Comman
boolean automatic = !packet.isRedstoneMode(); // Automatic = Always Active option in Java boolean automatic = !packet.isRedstoneMode(); // Automatic = Always Active option in Java
ServerboundSetCommandBlockPacket commandBlockPacket = new ServerboundSetCommandBlockPacket( ServerboundSetCommandBlockPacket commandBlockPacket = new ServerboundSetCommandBlockPacket(
packet.getBlockPosition(), command, mode, outputTracked, isConditional, automatic); packet.getBlockPosition(), command, mode, outputTracked, isConditional, automatic);
session.sendDownstreamPacket(commandBlockPacket); session.sendDownstreamGamePacket(commandBlockPacket);
} else { } else {
ServerboundSetCommandMinecartPacket commandMinecartPacket = new ServerboundSetCommandMinecartPacket( ServerboundSetCommandMinecartPacket commandMinecartPacket = new ServerboundSetCommandMinecartPacket(
session.getEntityCache().getEntityByGeyserId(packet.getMinecartRuntimeEntityId()).getEntityId(), session.getEntityCache().getEntityByGeyserId(packet.getMinecartRuntimeEntityId()).getEntityId(),
command, outputTracked command, outputTracked
); );
session.sendDownstreamPacket(commandMinecartPacket); session.sendDownstreamGamePacket(commandMinecartPacket);
} }
} }
} }

View File

@ -55,7 +55,7 @@ public class BedrockContainerCloseTranslator extends PacketTranslator<ContainerC
if (openInventory != null) { if (openInventory != null) {
if (bedrockId == openInventory.getBedrockId()) { if (bedrockId == openInventory.getBedrockId()) {
ServerboundContainerClosePacket closeWindowPacket = new ServerboundContainerClosePacket(openInventory.getJavaId()); ServerboundContainerClosePacket closeWindowPacket = new ServerboundContainerClosePacket(openInventory.getJavaId());
session.sendDownstreamPacket(closeWindowPacket); session.sendDownstreamGamePacket(closeWindowPacket);
InventoryUtils.closeInventory(session, openInventory.getJavaId(), false); InventoryUtils.closeInventory(session, openInventory.getJavaId(), false);
} else if (openInventory.isPending()) { } else if (openInventory.isPending()) {
InventoryUtils.displayInventory(session, openInventory); InventoryUtils.displayInventory(session, openInventory);

View File

@ -137,7 +137,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
ServerboundContainerClickPacket dropPacket = new ServerboundContainerClickPacket( ServerboundContainerClickPacket dropPacket = new ServerboundContainerClickPacket(
inventory.getJavaId(), inventory.getStateId(), hotbarSlot, clickType.actionType, clickType.action, inventory.getJavaId(), inventory.getStateId(), hotbarSlot, clickType.actionType, clickType.action,
inventory.getCursor().getItemStack(), changedItem); inventory.getCursor().getItemStack(), changedItem);
session.sendDownstreamPacket(dropPacket); session.sendDownstreamGamePacket(dropPacket);
return; return;
} }
if (session.getPlayerInventory().getItemInHand().isEmpty()) { if (session.getPlayerInventory().getItemInHand().isEmpty()) {
@ -150,7 +150,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
Direction.DOWN, Direction.DOWN,
0 0
); );
session.sendDownstreamPacket(dropPacket); session.sendDownstreamGamePacket(dropPacket);
if (dropAll) { if (dropAll) {
session.getPlayerInventory().setItemInHand(GeyserItemStack.EMPTY); session.getPlayerInventory().setItemInHand(GeyserItemStack.EMPTY);
@ -309,7 +309,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
packet.getClickPosition().getX(), packet.getClickPosition().getY(), packet.getClickPosition().getZ(), packet.getClickPosition().getX(), packet.getClickPosition().getY(), packet.getClickPosition().getZ(),
false, false,
session.getWorldCache().nextPredictionSequence()); session.getWorldCache().nextPredictionSequence());
session.sendDownstreamPacket(blockPacket); session.sendDownstreamGamePacket(blockPacket);
Item item = session.getPlayerInventory().getItemInHand().asItem(); Item item = session.getPlayerInventory().getItemInHand().asItem();
if (packet.getItemInHand() != null) { if (packet.getItemInHand() != null) {
@ -384,7 +384,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
} }
ServerboundUseItemPacket useItemPacket = new ServerboundUseItemPacket(Hand.MAIN_HAND, session.getWorldCache().nextPredictionSequence()); ServerboundUseItemPacket useItemPacket = new ServerboundUseItemPacket(Hand.MAIN_HAND, session.getWorldCache().nextPredictionSequence());
session.sendDownstreamPacket(useItemPacket); session.sendDownstreamGamePacket(useItemPacket);
List<LegacySetItemSlotData> legacySlots = packet.getLegacySlots(); List<LegacySetItemSlotData> legacySlots = packet.getLegacySlots();
if (packet.getActions().size() == 1 && legacySlots.size() > 0) { if (packet.getActions().size() == 1 && legacySlots.size() > 0) {
@ -453,13 +453,13 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
if (itemFrameEntity != null) { if (itemFrameEntity != null) {
ServerboundInteractPacket attackPacket = new ServerboundInteractPacket(itemFrameEntity.getEntityId(), ServerboundInteractPacket attackPacket = new ServerboundInteractPacket(itemFrameEntity.getEntityId(),
InteractAction.ATTACK, session.isSneaking()); InteractAction.ATTACK, session.isSneaking());
session.sendDownstreamPacket(attackPacket); session.sendDownstreamGamePacket(attackPacket);
break; break;
} }
PlayerAction action = session.getGameMode() == GameMode.CREATIVE ? PlayerAction.START_DIGGING : PlayerAction.FINISH_DIGGING; PlayerAction action = session.getGameMode() == GameMode.CREATIVE ? PlayerAction.START_DIGGING : PlayerAction.FINISH_DIGGING;
ServerboundPlayerActionPacket breakPacket = new ServerboundPlayerActionPacket(action, packet.getBlockPosition(), Direction.VALUES[packet.getBlockFace()], sequence); ServerboundPlayerActionPacket breakPacket = new ServerboundPlayerActionPacket(action, packet.getBlockPosition(), Direction.VALUES[packet.getBlockFace()], sequence);
session.sendDownstreamPacket(breakPacket); session.sendDownstreamGamePacket(breakPacket);
} }
} }
break; break;
@ -468,7 +468,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
// Followed to the Minecraft Protocol specification outlined at wiki.vg // Followed to the Minecraft Protocol specification outlined at wiki.vg
ServerboundPlayerActionPacket releaseItemPacket = new ServerboundPlayerActionPacket(PlayerAction.RELEASE_USE_ITEM, Vector3i.ZERO, ServerboundPlayerActionPacket releaseItemPacket = new ServerboundPlayerActionPacket(PlayerAction.RELEASE_USE_ITEM, Vector3i.ZERO,
Direction.DOWN, 0); Direction.DOWN, 0);
session.sendDownstreamPacket(releaseItemPacket); session.sendDownstreamGamePacket(releaseItemPacket);
} }
break; break;
case ITEM_USE_ON_ENTITY: case ITEM_USE_ON_ENTITY:
@ -490,7 +490,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
} }
ServerboundInteractPacket attackPacket = new ServerboundInteractPacket(entityId, ServerboundInteractPacket attackPacket = new ServerboundInteractPacket(entityId,
InteractAction.ATTACK, session.isSneaking()); InteractAction.ATTACK, session.isSneaking());
session.sendDownstreamPacket(attackPacket); session.sendDownstreamGamePacket(attackPacket);
// Since 1.19.10, LevelSoundEventPackets are no longer sent by the client when attacking entities // Since 1.19.10, LevelSoundEventPackets are no longer sent by the client when attacking entities
CooldownUtils.sendCooldown(session); CooldownUtils.sendCooldown(session);
@ -510,7 +510,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
Vector3f clickPosition = packet.getClickPosition().sub(entityPosition); Vector3f clickPosition = packet.getClickPosition().sub(entityPosition);
boolean isSpectator = session.getGameMode() == GameMode.SPECTATOR; boolean isSpectator = session.getGameMode() == GameMode.SPECTATOR;
for (Hand hand : EntityUtils.HANDS) { for (Hand hand : EntityUtils.HANDS) {
session.sendDownstreamPacket(new ServerboundInteractPacket(entity.getEntityId(), session.sendDownstreamGamePacket(new ServerboundInteractPacket(entity.getEntityId(),
InteractAction.INTERACT_AT, clickPosition.getX(), clickPosition.getY(), clickPosition.getZ(), InteractAction.INTERACT_AT, clickPosition.getX(), clickPosition.getY(), clickPosition.getZ(),
hand, session.isSneaking())); hand, session.isSneaking()));
@ -522,7 +522,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
} }
if (!result.consumesAction()) { if (!result.consumesAction()) {
session.sendDownstreamPacket(new ServerboundInteractPacket(entity.getEntityId(), session.sendDownstreamGamePacket(new ServerboundInteractPacket(entity.getEntityId(),
InteractAction.INTERACT, hand, session.isSneaking())); InteractAction.INTERACT, hand, session.isSneaking()));
if (!isSpectator) { if (!isSpectator) {
result = entity.interact(hand); result = entity.interact(hand);
@ -532,7 +532,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
if (result.consumesAction()) { if (result.consumesAction()) {
if (result.shouldSwing() && hand == Hand.OFF_HAND) { if (result.shouldSwing() && hand == Hand.OFF_HAND) {
// Currently, Bedrock will send us the arm swing packet in most cases. But it won't for offhand. // Currently, Bedrock will send us the arm swing packet in most cases. But it won't for offhand.
session.sendDownstreamPacket(new ServerboundSwingPacket(hand)); session.sendDownstreamGamePacket(new ServerboundSwingPacket(hand));
// Note here to look into sending the animation packet back to Bedrock // Note here to look into sending the animation packet back to Bedrock
} }
return; return;
@ -629,7 +629,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
lookAt(session, target); lookAt(session, target);
ServerboundUseItemPacket itemPacket = new ServerboundUseItemPacket(Hand.MAIN_HAND, session.getWorldCache().nextPredictionSequence()); ServerboundUseItemPacket itemPacket = new ServerboundUseItemPacket(Hand.MAIN_HAND, session.getWorldCache().nextPredictionSequence());
session.sendDownstreamPacket(itemPacket); session.sendDownstreamGamePacket(itemPacket);
return true; return true;
} }
@ -671,7 +671,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
ServerboundMovePlayerPosRotPacket returnPacket = new ServerboundMovePlayerPosRotPacket(entity.isOnGround(), playerPosition.getX(), playerPosition.getY(), playerPosition.getZ(), entity.getYaw(), entity.getPitch()); ServerboundMovePlayerPosRotPacket returnPacket = new ServerboundMovePlayerPosRotPacket(entity.isOnGround(), playerPosition.getX(), playerPosition.getY(), playerPosition.getZ(), entity.getYaw(), entity.getPitch());
// This matches Java edition behavior // This matches Java edition behavior
ServerboundMovePlayerPosRotPacket movementPacket = new ServerboundMovePlayerPosRotPacket(entity.isOnGround(), playerPosition.getX(), playerPosition.getY(), playerPosition.getZ(), yaw, pitch); ServerboundMovePlayerPosRotPacket movementPacket = new ServerboundMovePlayerPosRotPacket(entity.isOnGround(), playerPosition.getX(), playerPosition.getY(), playerPosition.getZ(), yaw, pitch);
session.sendDownstreamPacket(movementPacket); session.sendDownstreamGamePacket(movementPacket);
if (session.getLookBackScheduledFuture() != null) { if (session.getLookBackScheduledFuture() != null) {
session.getLookBackScheduledFuture().cancel(false); session.getLookBackScheduledFuture().cancel(false);
@ -683,7 +683,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
// The player moved/rotated so there is no need to change their rotation back // The player moved/rotated so there is no need to change their rotation back
return; return;
} }
session.sendDownstreamPacket(returnPacket); session.sendDownstreamGamePacket(returnPacket);
}, 150, TimeUnit.MILLISECONDS)); }, 150, TimeUnit.MILLISECONDS));
} }
} }

View File

@ -49,7 +49,7 @@ public class BedrockItemFrameDropItemTranslator extends PacketTranslator<ItemFra
if (entity != null) { if (entity != null) {
ServerboundInteractPacket interactPacket = new ServerboundInteractPacket(entity.getEntityId(), ServerboundInteractPacket interactPacket = new ServerboundInteractPacket(entity.getEntityId(),
InteractAction.ATTACK, Hand.MAIN_HAND, session.isSneaking()); InteractAction.ATTACK, Hand.MAIN_HAND, session.isSneaking());
session.sendDownstreamPacket(interactPacket); session.sendDownstreamGamePacket(interactPacket);
} }
} }
} }

View File

@ -58,7 +58,7 @@ public class BedrockLecternUpdateTranslator extends PacketTranslator<LecternUpda
0, 0, 0, // Java doesn't care about these when dealing with a lectern 0, 0, 0, // Java doesn't care about these when dealing with a lectern
false, false,
session.getWorldCache().nextPredictionSequence()); session.getWorldCache().nextPredictionSequence());
session.sendDownstreamPacket(blockPacket); session.sendDownstreamGamePacket(blockPacket);
} else { } else {
// Bedrock wants to either move a page or exit // Bedrock wants to either move a page or exit
if (!(session.getOpenInventory() instanceof LecternContainer lecternContainer)) { if (!(session.getOpenInventory() instanceof LecternContainer lecternContainer)) {
@ -69,7 +69,7 @@ public class BedrockLecternUpdateTranslator extends PacketTranslator<LecternUpda
if (lecternContainer.getCurrentBedrockPage() == packet.getPage()) { if (lecternContainer.getCurrentBedrockPage() == packet.getPage()) {
// The same page means Bedrock is closing the window // The same page means Bedrock is closing the window
ServerboundContainerClosePacket closeWindowPacket = new ServerboundContainerClosePacket(lecternContainer.getJavaId()); ServerboundContainerClosePacket closeWindowPacket = new ServerboundContainerClosePacket(lecternContainer.getJavaId());
session.sendDownstreamPacket(closeWindowPacket); session.sendDownstreamGamePacket(closeWindowPacket);
InventoryUtils.closeInventory(session, lecternContainer.getJavaId(), false); InventoryUtils.closeInventory(session, lecternContainer.getJavaId(), false);
} else { } else {
// Each "page" Bedrock gives to us actually represents two pages (think opening a book and seeing two pages) // Each "page" Bedrock gives to us actually represents two pages (think opening a book and seeing two pages)
@ -83,12 +83,12 @@ public class BedrockLecternUpdateTranslator extends PacketTranslator<LecternUpda
if (newJavaPage > currentJavaPage) { if (newJavaPage > currentJavaPage) {
for (int i = currentJavaPage; i < newJavaPage; i++) { for (int i = currentJavaPage; i < newJavaPage; i++) {
ServerboundContainerButtonClickPacket clickButtonPacket = new ServerboundContainerButtonClickPacket(session.getOpenInventory().getJavaId(), 2); ServerboundContainerButtonClickPacket clickButtonPacket = new ServerboundContainerButtonClickPacket(session.getOpenInventory().getJavaId(), 2);
session.sendDownstreamPacket(clickButtonPacket); session.sendDownstreamGamePacket(clickButtonPacket);
} }
} else { } else {
for (int i = currentJavaPage; i > newJavaPage; i--) { for (int i = currentJavaPage; i > newJavaPage; i--) {
ServerboundContainerButtonClickPacket clickButtonPacket = new ServerboundContainerButtonClickPacket(session.getOpenInventory().getJavaId(), 1); ServerboundContainerButtonClickPacket clickButtonPacket = new ServerboundContainerButtonClickPacket(session.getOpenInventory().getJavaId(), 1);
session.sendDownstreamPacket(clickButtonPacket); session.sendDownstreamGamePacket(clickButtonPacket);
} }
} }
} }

View File

@ -58,7 +58,7 @@ public class BedrockMobEquipmentTranslator extends PacketTranslator<MobEquipment
session.getPlayerInventory().setHeldItemSlot(newSlot); session.getPlayerInventory().setHeldItemSlot(newSlot);
ServerboundSetCarriedItemPacket setCarriedItemPacket = new ServerboundSetCarriedItemPacket(newSlot); ServerboundSetCarriedItemPacket setCarriedItemPacket = new ServerboundSetCarriedItemPacket(newSlot);
session.sendDownstreamPacket(setCarriedItemPacket); session.sendDownstreamGamePacket(setCarriedItemPacket);
GeyserItemStack newItem = session.getPlayerInventory().getItemInHand(); GeyserItemStack newItem = session.getPlayerInventory().getItemInHand();
@ -66,7 +66,7 @@ public class BedrockMobEquipmentTranslator extends PacketTranslator<MobEquipment
// Activate shield since we are already sneaking // Activate shield since we are already sneaking
// (No need to send a release item packet - Java doesn't do this when swapping items) // (No need to send a release item packet - Java doesn't do this when swapping items)
// Required to do it a tick later or else it doesn't register // Required to do it a tick later or else it doesn't register
session.scheduleInEventLoop(() -> session.sendDownstreamPacket(new ServerboundUseItemPacket(Hand.MAIN_HAND, session.getWorldCache().nextPredictionSequence())), session.scheduleInEventLoop(() -> session.sendDownstreamGamePacket(new ServerboundUseItemPacket(Hand.MAIN_HAND, session.getWorldCache().nextPredictionSequence())),
50, TimeUnit.MILLISECONDS); 50, TimeUnit.MILLISECONDS);
} }

View File

@ -72,6 +72,6 @@ public class BedrockMoveEntityAbsoluteTranslator extends PacketTranslator<MoveEn
packet.getPosition().getX(), y, packet.getPosition().getZ(), packet.getPosition().getX(), y, packet.getPosition().getZ(),
packet.getRotation().getY() - 90, packet.getRotation().getX() packet.getRotation().getY() - 90, packet.getRotation().getX()
); );
session.sendDownstreamPacket(ServerboundMoveVehiclePacket); session.sendDownstreamGamePacket(ServerboundMoveVehiclePacket);
} }
} }

View File

@ -50,7 +50,7 @@ public class BedrockPlayerInputTranslator extends PacketTranslator<PlayerInputPa
packet.getInputMotion().getX(), packet.getInputMotion().getY(), packet.isJumping(), packet.isSneaking() packet.getInputMotion().getX(), packet.getInputMotion().getY(), packet.isJumping(), packet.isSneaking()
); );
session.sendDownstreamPacket(playerInputPacket); session.sendDownstreamGamePacket(playerInputPacket);
// Bedrock only sends movement vehicle packets while moving // Bedrock only sends movement vehicle packets while moving
// This allows horses to take damage while standing on magma // This allows horses to take damage while standing on magma
@ -83,7 +83,7 @@ public class BedrockPlayerInputTranslator extends PacketTranslator<PlayerInputPa
vehiclePosition.getX(), vehiclePosition.getY(), vehiclePosition.getZ(), vehiclePosition.getX(), vehiclePosition.getY(), vehiclePosition.getZ(),
vehicle.getYaw() - 90, vehicle.getPitch() vehicle.getYaw() - 90, vehicle.getPitch()
); );
session.sendDownstreamPacket(moveVehiclePacket); session.sendDownstreamGamePacket(moveVehiclePacket);
} }
} }
} }

View File

@ -58,7 +58,7 @@ public class BedrockRequestAbilityTranslator extends PacketTranslator<RequestAbi
session.setFlying(isFlying); session.setFlying(isFlying);
ServerboundPlayerAbilitiesPacket abilitiesPacket = new ServerboundPlayerAbilitiesPacket(isFlying); ServerboundPlayerAbilitiesPacket abilitiesPacket = new ServerboundPlayerAbilitiesPacket(isFlying);
session.sendDownstreamPacket(abilitiesPacket); session.sendDownstreamGamePacket(abilitiesPacket);
} }
} }
} }

View File

@ -39,7 +39,7 @@ public class BedrockRespawnTranslator extends PacketTranslator<RespawnPacket> {
public void translate(GeyserSession session, RespawnPacket packet) { public void translate(GeyserSession session, RespawnPacket packet) {
if (packet.getState() == RespawnPacket.State.CLIENT_READY) { if (packet.getState() == RespawnPacket.State.CLIENT_READY) {
ServerboundClientCommandPacket javaRespawnPacket = new ServerboundClientCommandPacket(ClientCommand.RESPAWN); ServerboundClientCommandPacket javaRespawnPacket = new ServerboundClientCommandPacket(ClientCommand.RESPAWN);
session.sendDownstreamPacket(javaRespawnPacket); session.sendDownstreamGamePacket(javaRespawnPacket);
} }
} }
} }

View File

@ -39,7 +39,7 @@ public class BedrockShowCreditsTranslator extends PacketTranslator<ShowCreditsPa
public void translate(GeyserSession session, ShowCreditsPacket packet) { public void translate(GeyserSession session, ShowCreditsPacket packet) {
if (packet.getStatus() == ShowCreditsPacket.Status.END_CREDITS) { if (packet.getStatus() == ShowCreditsPacket.Status.END_CREDITS) {
ServerboundClientCommandPacket javaRespawnPacket = new ServerboundClientCommandPacket(ClientCommand.RESPAWN); ServerboundClientCommandPacket javaRespawnPacket = new ServerboundClientCommandPacket(ClientCommand.RESPAWN);
session.sendDownstreamPacket(javaRespawnPacket); session.sendDownstreamGamePacket(javaRespawnPacket);
} }
} }
} }

View File

@ -49,7 +49,7 @@ public class BedrockEntityEventTranslator extends PacketTranslator<EntityEventPa
case COMPLETE_TRADE -> { case COMPLETE_TRADE -> {
// Not sent as of 1.18.10 // Not sent as of 1.18.10
ServerboundSelectTradePacket selectTradePacket = new ServerboundSelectTradePacket(packet.getData()); ServerboundSelectTradePacket selectTradePacket = new ServerboundSelectTradePacket(packet.getData());
session.sendDownstreamPacket(selectTradePacket); session.sendDownstreamGamePacket(selectTradePacket);
session.scheduleInEventLoop(() -> { session.scheduleInEventLoop(() -> {
Inventory openInventory = session.getOpenInventory(); Inventory openInventory = session.getOpenInventory();

View File

@ -26,10 +26,6 @@
package org.geysermc.geyser.translator.protocol.bedrock.entity.player; package org.geysermc.geyser.translator.protocol.bedrock.entity.player;
import com.github.steveice10.mc.protocol.data.game.entity.object.Direction; import com.github.steveice10.mc.protocol.data.game.entity.object.Direction;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundInteractPacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerAbilitiesPacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerActionPacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerCommandPacket;
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode; import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
import com.github.steveice10.mc.protocol.data.game.entity.player.InteractAction; import com.github.steveice10.mc.protocol.data.game.entity.player.InteractAction;
@ -97,7 +93,7 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
case START_SWIMMING: case START_SWIMMING:
if (!entity.getFlag(EntityFlag.SWIMMING)) { if (!entity.getFlag(EntityFlag.SWIMMING)) {
ServerboundPlayerCommandPacket startSwimPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.START_SPRINTING); ServerboundPlayerCommandPacket startSwimPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.START_SPRINTING);
session.sendDownstreamPacket(startSwimPacket); session.sendDownstreamGamePacket(startSwimPacket);
session.setSwimming(true); session.setSwimming(true);
} }
@ -106,7 +102,7 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
// Prevent packet spam when Bedrock players are crawling near the edge of a block // Prevent packet spam when Bedrock players are crawling near the edge of a block
if (!session.getCollisionManager().mustPlayerCrawlHere()) { if (!session.getCollisionManager().mustPlayerCrawlHere()) {
ServerboundPlayerCommandPacket stopSwimPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.STOP_SPRINTING); ServerboundPlayerCommandPacket stopSwimPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.STOP_SPRINTING);
session.sendDownstreamPacket(stopSwimPacket); session.sendDownstreamGamePacket(stopSwimPacket);
session.setSwimming(false); session.setSwimming(false);
} }
@ -114,45 +110,45 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
case START_GLIDE: case START_GLIDE:
// Otherwise gliding will not work in creative // Otherwise gliding will not work in creative
ServerboundPlayerAbilitiesPacket playerAbilitiesPacket = new ServerboundPlayerAbilitiesPacket(false); ServerboundPlayerAbilitiesPacket playerAbilitiesPacket = new ServerboundPlayerAbilitiesPacket(false);
session.sendDownstreamPacket(playerAbilitiesPacket); session.sendDownstreamGamePacket(playerAbilitiesPacket);
case STOP_GLIDE: case STOP_GLIDE:
ServerboundPlayerCommandPacket glidePacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.START_ELYTRA_FLYING); ServerboundPlayerCommandPacket glidePacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.START_ELYTRA_FLYING);
session.sendDownstreamPacket(glidePacket); session.sendDownstreamGamePacket(glidePacket);
break; break;
case START_SNEAK: case START_SNEAK:
ServerboundPlayerCommandPacket startSneakPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.START_SNEAKING); ServerboundPlayerCommandPacket startSneakPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.START_SNEAKING);
session.sendDownstreamPacket(startSneakPacket); session.sendDownstreamGamePacket(startSneakPacket);
session.startSneaking(); session.startSneaking();
break; break;
case STOP_SNEAK: case STOP_SNEAK:
ServerboundPlayerCommandPacket stopSneakPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.STOP_SNEAKING); ServerboundPlayerCommandPacket stopSneakPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.STOP_SNEAKING);
session.sendDownstreamPacket(stopSneakPacket); session.sendDownstreamGamePacket(stopSneakPacket);
session.stopSneaking(); session.stopSneaking();
break; break;
case START_SPRINT: case START_SPRINT:
if (!entity.getFlag(EntityFlag.SWIMMING)) { if (!entity.getFlag(EntityFlag.SWIMMING)) {
ServerboundPlayerCommandPacket startSprintPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.START_SPRINTING); ServerboundPlayerCommandPacket startSprintPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.START_SPRINTING);
session.sendDownstreamPacket(startSprintPacket); session.sendDownstreamGamePacket(startSprintPacket);
session.setSprinting(true); session.setSprinting(true);
} }
break; break;
case STOP_SPRINT: case STOP_SPRINT:
if (!entity.getFlag(EntityFlag.SWIMMING)) { if (!entity.getFlag(EntityFlag.SWIMMING)) {
ServerboundPlayerCommandPacket stopSprintPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.STOP_SPRINTING); ServerboundPlayerCommandPacket stopSprintPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.STOP_SPRINTING);
session.sendDownstreamPacket(stopSprintPacket); session.sendDownstreamGamePacket(stopSprintPacket);
} }
session.setSprinting(false); session.setSprinting(false);
break; break;
case DROP_ITEM: case DROP_ITEM:
ServerboundPlayerActionPacket dropItemPacket = new ServerboundPlayerActionPacket(PlayerAction.DROP_ITEM, ServerboundPlayerActionPacket dropItemPacket = new ServerboundPlayerActionPacket(PlayerAction.DROP_ITEM,
vector, Direction.VALUES[packet.getFace()], 0); vector, Direction.VALUES[packet.getFace()], 0);
session.sendDownstreamPacket(dropItemPacket); session.sendDownstreamGamePacket(dropItemPacket);
break; break;
case STOP_SLEEP: case STOP_SLEEP:
ServerboundPlayerCommandPacket stopSleepingPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.LEAVE_BED); ServerboundPlayerCommandPacket stopSleepingPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.LEAVE_BED);
session.sendDownstreamPacket(stopSleepingPacket); session.sendDownstreamGamePacket(stopSleepingPacket);
break; break;
case START_BREAK: { case START_BREAK: {
// Ignore START_BREAK when the player is CREATIVE to avoid Spigot receiving 2 packets it interpets as block breaking. https://github.com/GeyserMC/Geyser/issues/4021 // Ignore START_BREAK when the player is CREATIVE to avoid Spigot receiving 2 packets it interpets as block breaking. https://github.com/GeyserMC/Geyser/issues/4021
@ -189,12 +185,12 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
if (identifier.startsWith("minecraft:fire") || identifier.startsWith("minecraft:soul_fire")) { if (identifier.startsWith("minecraft:fire") || identifier.startsWith("minecraft:soul_fire")) {
ServerboundPlayerActionPacket startBreakingPacket = new ServerboundPlayerActionPacket(PlayerAction.START_DIGGING, fireBlockPos, ServerboundPlayerActionPacket startBreakingPacket = new ServerboundPlayerActionPacket(PlayerAction.START_DIGGING, fireBlockPos,
Direction.VALUES[packet.getFace()], session.getWorldCache().nextPredictionSequence()); Direction.VALUES[packet.getFace()], session.getWorldCache().nextPredictionSequence());
session.sendDownstreamPacket(startBreakingPacket); session.sendDownstreamGamePacket(startBreakingPacket);
} }
ServerboundPlayerActionPacket startBreakingPacket = new ServerboundPlayerActionPacket(PlayerAction.START_DIGGING, ServerboundPlayerActionPacket startBreakingPacket = new ServerboundPlayerActionPacket(PlayerAction.START_DIGGING,
vector, Direction.VALUES[packet.getFace()], session.getWorldCache().nextPredictionSequence()); vector, Direction.VALUES[packet.getFace()], session.getWorldCache().nextPredictionSequence());
session.sendDownstreamPacket(startBreakingPacket); session.sendDownstreamGamePacket(startBreakingPacket);
break; break;
} }
case CONTINUE_BREAK: case CONTINUE_BREAK:
@ -236,7 +232,7 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
// Break the block // Break the block
ServerboundPlayerActionPacket finishBreakingPacket = new ServerboundPlayerActionPacket(PlayerAction.FINISH_DIGGING, ServerboundPlayerActionPacket finishBreakingPacket = new ServerboundPlayerActionPacket(PlayerAction.FINISH_DIGGING,
vector, Direction.VALUES[packet.getFace()], session.getWorldCache().nextPredictionSequence()); vector, Direction.VALUES[packet.getFace()], session.getWorldCache().nextPredictionSequence());
session.sendDownstreamPacket(finishBreakingPacket); session.sendDownstreamGamePacket(finishBreakingPacket);
session.setBlockBreakStartTime(0); session.setBlockBreakStartTime(0);
break; break;
} }
@ -253,13 +249,13 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
if (itemFrameEntity != null) { if (itemFrameEntity != null) {
ServerboundInteractPacket interactPacket = new ServerboundInteractPacket(itemFrameEntity.getEntityId(), ServerboundInteractPacket interactPacket = new ServerboundInteractPacket(itemFrameEntity.getEntityId(),
InteractAction.ATTACK, Hand.MAIN_HAND, session.isSneaking()); InteractAction.ATTACK, Hand.MAIN_HAND, session.isSneaking());
session.sendDownstreamPacket(interactPacket); session.sendDownstreamGamePacket(interactPacket);
break; break;
} }
} }
ServerboundPlayerActionPacket abortBreakingPacket = new ServerboundPlayerActionPacket(PlayerAction.CANCEL_DIGGING, vector, Direction.DOWN, 0); ServerboundPlayerActionPacket abortBreakingPacket = new ServerboundPlayerActionPacket(PlayerAction.CANCEL_DIGGING, vector, Direction.DOWN, 0);
session.sendDownstreamPacket(abortBreakingPacket); session.sendDownstreamGamePacket(abortBreakingPacket);
LevelEventPacket stopBreak = new LevelEventPacket(); LevelEventPacket stopBreak = new LevelEventPacket();
stopBreak.setType(LevelEvent.BLOCK_STOP_BREAK); stopBreak.setType(LevelEvent.BLOCK_STOP_BREAK);
stopBreak.setPosition(vector.toFloat()); stopBreak.setPosition(vector.toFloat());
@ -287,7 +283,7 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
case MISSED_SWING: case MISSED_SWING:
// TODO Re-evaluate after pre-1.20.10 is no longer supported? // TODO Re-evaluate after pre-1.20.10 is no longer supported?
if (session.getArmAnimationTicks() == -1) { if (session.getArmAnimationTicks() == -1) {
session.sendDownstreamPacket(new ServerboundSwingPacket(Hand.MAIN_HAND)); session.sendDownstreamGamePacket(new ServerboundSwingPacket(Hand.MAIN_HAND));
session.activateArmAnimationTicking(); session.activateArmAnimationTicking();
// Send packet to Bedrock so it knows // Send packet to Bedrock so it knows
@ -313,7 +309,7 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
} }
session.setFlying(true); session.setFlying(true);
session.sendDownstreamPacket(new ServerboundPlayerAbilitiesPacket(true)); session.sendDownstreamGamePacket(new ServerboundPlayerAbilitiesPacket(true));
} else { } else {
// update whether we can fly // update whether we can fly
session.sendAdventureSettings(); session.sendAdventureSettings();
@ -329,7 +325,7 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
break; break;
case STOP_FLYING: case STOP_FLYING:
session.setFlying(false); session.setFlying(false);
session.sendDownstreamPacket(new ServerboundPlayerAbilitiesPacket(false)); session.sendDownstreamGamePacket(new ServerboundPlayerAbilitiesPacket(false));
break; break;
} }
} }

View File

@ -68,16 +68,16 @@ public class BedrockInteractTranslator extends PacketTranslator<InteractPacket>
} }
ServerboundInteractPacket interactPacket = new ServerboundInteractPacket(entity.getEntityId(), ServerboundInteractPacket interactPacket = new ServerboundInteractPacket(entity.getEntityId(),
InteractAction.INTERACT, Hand.MAIN_HAND, session.isSneaking()); InteractAction.INTERACT, Hand.MAIN_HAND, session.isSneaking());
session.sendDownstreamPacket(interactPacket); session.sendDownstreamGamePacket(interactPacket);
break; break;
case DAMAGE: case DAMAGE:
ServerboundInteractPacket attackPacket = new ServerboundInteractPacket(entity.getEntityId(), ServerboundInteractPacket attackPacket = new ServerboundInteractPacket(entity.getEntityId(),
InteractAction.ATTACK, Hand.MAIN_HAND, session.isSneaking()); InteractAction.ATTACK, Hand.MAIN_HAND, session.isSneaking());
session.sendDownstreamPacket(attackPacket); session.sendDownstreamGamePacket(attackPacket);
break; break;
case LEAVE_VEHICLE: case LEAVE_VEHICLE:
ServerboundPlayerCommandPacket sneakPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.START_SNEAKING); ServerboundPlayerCommandPacket sneakPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.START_SNEAKING);
session.sendDownstreamPacket(sneakPacket); session.sendDownstreamGamePacket(sneakPacket);
Entity currentVehicle = session.getPlayerEntity().getVehicle(); Entity currentVehicle = session.getPlayerEntity().getVehicle();
if (currentVehicle != null) { if (currentVehicle != null) {
@ -123,7 +123,7 @@ public class BedrockInteractTranslator extends PacketTranslator<InteractPacket>
if (ridingEntity instanceof AbstractHorseEntity || (ridingEntity != null && ridingEntity.getDefinition().entityType() == EntityType.CHEST_BOAT)) { if (ridingEntity instanceof AbstractHorseEntity || (ridingEntity != null && ridingEntity.getDefinition().entityType() == EntityType.CHEST_BOAT)) {
// This mob has an inventory of its own that we should open instead. // This mob has an inventory of its own that we should open instead.
ServerboundPlayerCommandPacket openVehicleWindowPacket = new ServerboundPlayerCommandPacket(session.getPlayerEntity().getEntityId(), PlayerState.OPEN_VEHICLE_INVENTORY); ServerboundPlayerCommandPacket openVehicleWindowPacket = new ServerboundPlayerCommandPacket(session.getPlayerEntity().getEntityId(), PlayerState.OPEN_VEHICLE_INVENTORY);
session.sendDownstreamPacket(openVehicleWindowPacket); session.sendDownstreamGamePacket(openVehicleWindowPacket);
} else { } else {
session.setOpenInventory(session.getPlayerInventory()); session.setOpenInventory(session.getPlayerInventory());

View File

@ -83,7 +83,7 @@ public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPack
entity.setHeadYaw(headYaw); entity.setHeadYaw(headYaw);
entity.setOnGround(packet.isOnGround()); entity.setOnGround(packet.isOnGround());
session.sendDownstreamPacket(playerRotationPacket); session.sendDownstreamGamePacket(playerRotationPacket);
} else { } else {
if (session.getWorldBorder().isPassingIntoBorderBoundaries(packet.getPosition(), true)) { if (session.getWorldBorder().isPassingIntoBorderBoundaries(packet.getPosition(), true)) {
return; return;
@ -130,7 +130,7 @@ public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPack
entity.setOnGround(onGround); entity.setOnGround(onGround);
// Send final movement changes // Send final movement changes
session.sendDownstreamPacket(movePacket); session.sendDownstreamGamePacket(movePacket);
if (teleportThroughVoidFloor) { if (teleportThroughVoidFloor) {
// Work around there being a floor at the bottom of the world and teleport the player below it // Work around there being a floor at the bottom of the world and teleport the player below it

View File

@ -41,7 +41,7 @@ public class BedrockRiderJumpTranslator extends PacketTranslator<RiderJumpPacket
Entity vehicle = session.getPlayerEntity().getVehicle(); Entity vehicle = session.getPlayerEntity().getVehicle();
if (vehicle instanceof AbstractHorseEntity) { if (vehicle instanceof AbstractHorseEntity) {
ServerboundPlayerCommandPacket playerCommandPacket = new ServerboundPlayerCommandPacket(vehicle.getEntityId(), PlayerState.START_HORSE_JUMP, packet.getJumpStrength()); ServerboundPlayerCommandPacket playerCommandPacket = new ServerboundPlayerCommandPacket(vehicle.getEntityId(), PlayerState.START_HORSE_JUMP, packet.getJumpStrength());
session.sendDownstreamPacket(playerCommandPacket); session.sendDownstreamGamePacket(playerCommandPacket);
} }
} }
} }

View File

@ -57,7 +57,7 @@ public class BedrockLevelSoundEventTranslator extends PacketTranslator<LevelSoun
// ATTACK_NODAMAGE = player clicked air // ATTACK_NODAMAGE = player clicked air
// This should only be revisited if Bedrock packets get full Java parity, or Bedrock starts sending arm // 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 // 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.sendDownstreamGamePacket(new ServerboundSwingPacket(Hand.MAIN_HAND));
session.activateArmAnimationTicking(); session.activateArmAnimationTicking();
// Send packet to Bedrock so it knows // Send packet to Bedrock so it knows

View File

@ -40,7 +40,7 @@ public class JavaCustomQueryTranslator extends PacketTranslator<ClientboundCusto
public void translate(GeyserSession session, ClientboundCustomQueryPacket packet) { public void translate(GeyserSession session, ClientboundCustomQueryPacket packet) {
// A vanilla client doesn't know any PluginMessage in the Login state, so we don't know any either. // A vanilla client doesn't know any PluginMessage in the Login state, so we don't know any either.
// Note: Fabric Networking API v1 will not let the client log in without sending this // Note: Fabric Networking API v1 will not let the client log in without sending this
session.sendDownstreamPacket( session.sendDownstreamLoginPacket(
new ServerboundCustomQueryAnswerPacket(packet.getMessageId(), null) new ServerboundCustomQueryAnswerPacket(packet.getMessageId(), null)
); );
} }

View File

@ -133,9 +133,9 @@ public class JavaPlayerPositionTranslator extends PacketTranslator<ClientboundPl
private void acceptTeleport(GeyserSession session, double x, double y, double z, float yaw, float pitch, int id) { private void acceptTeleport(GeyserSession session, double x, double y, double z, float yaw, float pitch, int id) {
// Confirm the teleport when we receive it to match Java edition // Confirm the teleport when we receive it to match Java edition
ServerboundAcceptTeleportationPacket teleportConfirmPacket = new ServerboundAcceptTeleportationPacket(id); ServerboundAcceptTeleportationPacket teleportConfirmPacket = new ServerboundAcceptTeleportationPacket(id);
session.sendDownstreamPacket(teleportConfirmPacket); session.sendDownstreamGamePacket(teleportConfirmPacket);
// Servers (especially ones like Hypixel) expect exact coordinates given back to them. // Servers (especially ones like Hypixel) expect exact coordinates given back to them.
ServerboundMovePlayerPosRotPacket positionPacket = new ServerboundMovePlayerPosRotPacket(false, x, y, z, yaw, pitch); ServerboundMovePlayerPosRotPacket positionPacket = new ServerboundMovePlayerPosRotPacket(false, x, y, z, yaw, pitch);
session.sendDownstreamPacket(positionPacket); session.sendDownstreamGamePacket(positionPacket);
} }
} }

View File

@ -63,7 +63,7 @@ public class JavaOpenScreenTranslator extends PacketTranslator<ClientboundOpenSc
InventoryUtils.closeInventory(session, openInventory.getJavaId(), true); InventoryUtils.closeInventory(session, openInventory.getJavaId(), true);
} }
ServerboundContainerClosePacket closeWindowPacket = new ServerboundContainerClosePacket(packet.getContainerId()); ServerboundContainerClosePacket closeWindowPacket = new ServerboundContainerClosePacket(packet.getContainerId());
session.sendDownstreamPacket(closeWindowPacket); session.sendDownstreamGamePacket(closeWindowPacket);
return; return;
} }

View File

@ -39,6 +39,6 @@ public class JavaChunkBatchFinishedTranslator extends PacketTranslator<Clientbou
// server just sent a batch of LevelChunkWithLightPackets // server just sent a batch of LevelChunkWithLightPackets
// the vanilla client uses a ChunkBatchSizeCalculator to calculate the desiredChunksPerTick, // the vanilla client uses a ChunkBatchSizeCalculator to calculate the desiredChunksPerTick,
// but currently we just send an arbitrary value. server clamps the value between 0.01 and 64. // but currently we just send an arbitrary value. server clamps the value between 0.01 and 64.
session.sendDownstreamPacket(new ServerboundChunkBatchReceivedPacket(20)); session.sendDownstreamGamePacket(new ServerboundChunkBatchReceivedPacket(20));
} }
} }

View File

@ -131,7 +131,7 @@ public class JavaGameEventTranslator extends PacketTranslator<ClientboundGameEve
switch ((EnterCreditsValue) packet.getValue()) { switch ((EnterCreditsValue) packet.getValue()) {
case SEEN_BEFORE -> { case SEEN_BEFORE -> {
ServerboundClientCommandPacket javaRespawnPacket = new ServerboundClientCommandPacket(ClientCommand.RESPAWN); ServerboundClientCommandPacket javaRespawnPacket = new ServerboundClientCommandPacket(ClientCommand.RESPAWN);
session.sendDownstreamPacket(javaRespawnPacket); session.sendDownstreamGamePacket(javaRespawnPacket);
} }
case FIRST_TIME -> { case FIRST_TIME -> {
ShowCreditsPacket showCreditsPacket = new ShowCreditsPacket(); ShowCreditsPacket showCreditsPacket = new ShowCreditsPacket();

View File

@ -260,7 +260,7 @@ public class InventoryUtils {
// If this is the item we're looking for // If this is the item we're looking for
if (geyserItem.getJavaId() == itemStack.getId() && Objects.equals(geyserItem.getNbt(), itemStack.getNbt())) { if (geyserItem.getJavaId() == itemStack.getId() && Objects.equals(geyserItem.getNbt(), itemStack.getNbt())) {
ServerboundPickItemPacket packetToSend = new ServerboundPickItemPacket(i); // https://wiki.vg/Protocol#Pick_Item ServerboundPickItemPacket packetToSend = new ServerboundPickItemPacket(i); // https://wiki.vg/Protocol#Pick_Item
session.sendDownstreamPacket(packetToSend); session.sendDownstreamGamePacket(packetToSend);
return; return;
} }
} }
@ -274,7 +274,7 @@ public class InventoryUtils {
if ((slot - 36) != inventory.getHeldItemSlot()) { if ((slot - 36) != inventory.getHeldItemSlot()) {
setHotbarItem(session, slot); setHotbarItem(session, slot);
} }
session.sendDownstreamPacket(actionPacket); session.sendDownstreamGamePacket(actionPacket);
} }
} }
@ -325,7 +325,7 @@ public class InventoryUtils {
} }
ServerboundPickItemPacket packetToSend = new ServerboundPickItemPacket(i); // https://wiki.vg/Protocol#Pick_Item ServerboundPickItemPacket packetToSend = new ServerboundPickItemPacket(i); // https://wiki.vg/Protocol#Pick_Item
session.sendDownstreamPacket(packetToSend); session.sendDownstreamGamePacket(packetToSend);
return; return;
} }
@ -340,7 +340,7 @@ public class InventoryUtils {
if ((slot - 36) != inventory.getHeldItemSlot()) { if ((slot - 36) != inventory.getHeldItemSlot()) {
setHotbarItem(session, slot); setHotbarItem(session, slot);
} }
session.sendDownstreamPacket(actionPacket); session.sendDownstreamGamePacket(actionPacket);
} else { } else {
session.getGeyser().getLogger().debug("Cannot find item for block " + itemName); session.getGeyser().getLogger().debug("Cannot find item for block " + itemName);
} }