1
0
mirror of https://github.com/GeyserMC/Geyser.git synced 2025-12-19 14:59:27 +00:00

Fix: only use touch rotation for certain items (#5705)

This commit is contained in:
oryxel
2025-07-19 18:56:05 +07:00
committed by GitHub
parent 9d3d0dabf1
commit 5a00fa4170
2 changed files with 22 additions and 8 deletions

View File

@@ -149,6 +149,7 @@ import org.geysermc.geyser.inventory.recipe.GeyserSmithingRecipe;
import org.geysermc.geyser.inventory.recipe.GeyserStonecutterData;
import org.geysermc.geyser.item.Items;
import org.geysermc.geyser.item.type.BlockItem;
import org.geysermc.geyser.item.type.Item;
import org.geysermc.geyser.level.BedrockDimension;
import org.geysermc.geyser.level.JavaDimension;
import org.geysermc.geyser.level.physics.CollisionManager;
@@ -1390,14 +1391,27 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
}
/**
* Convenience method to reduce amount of duplicate code. Sends ServerboundUseItemPacket.
* Same as useItem but always default to useTouchRotation false.
*/
public void useItem(Hand hand) {
useItem(hand, false);
}
/**
* Convenience method to reduce amount of duplicate code. Sends ServerboundUseItemPacket.
*/
public void useItem(Hand hand, boolean useTouchRotation) {
if (playerEntity.getFlag(EntityFlag.USING_ITEM)) {
return;
}
sendDownstreamGamePacket(new ServerboundUseItemPacket(hand, worldCache.nextPredictionSequence(), playerEntity.getBedrockInteractRotation().getY(), playerEntity.getBedrockInteractRotation().getX()));
float yaw = playerEntity.getYaw(), pitch = playerEntity.getPitch();
if (useTouchRotation) { // Only use touch rotation when we actually needed to, resolve https://github.com/GeyserMC/Geyser/issues/5704
yaw = playerEntity.getBedrockInteractRotation().getY();
pitch = playerEntity.getBedrockInteractRotation().getX();
}
sendDownstreamGamePacket(new ServerboundUseItemPacket(hand, worldCache.nextPredictionSequence(), yaw, pitch));
}
public void releaseItem() {

View File

@@ -290,7 +290,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
if (packet.getItemInHand() != null && session.getItemMappings().getMapping(packet.getItemInHand()).getJavaItem() instanceof SpawnEggItem) {
if (blockState.is(Blocks.WATER) && blockState.getValue(Properties.LEVEL) == 0) {
// Otherwise causes multiple mobs to spawn - just send a use item packet
useItem(session, packet, blockState.javaId());
useItem(session, packet, blockState.javaId(), false);
break;
}
}
@@ -313,14 +313,14 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
ItemDefinition definition = packet.getItemInHand().getDefinition();
// Otherwise boats will not be able to be placed in survival and buckets, lily pads, frogspawn, and glass bottles won't work on mobile
if (item instanceof BoatItem || item == Items.LILY_PAD || item == Items.FROGSPAWN) {
useItem(session, packet, blockState.javaId());
useItem(session, packet, blockState.javaId(), true);
} else if (item == Items.GLASS_BOTTLE) {
Block block = blockState.block();
if (!session.isSneaking() && block instanceof CauldronBlock && block != Blocks.WATER_CAULDRON) {
// ServerboundUseItemPacket is not sent for water cauldrons and glass bottles
return;
}
useItem(session, packet, blockState.javaId());
useItem(session, packet, blockState.javaId(), false);
} else if (session.getItemMappings().getBuckets().contains(definition)) {
// Don't send ServerboundUseItemPacket for powder snow buckets
if (definition != session.getItemMappings().getStoredItems().powderSnowBucket().getBedrockDefinition()) {
@@ -328,7 +328,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
// ServerboundUseItemPacket is not sent for cauldrons and buckets
return;
}
session.setPlacedBucket(useItem(session, packet, blockState.javaId()));
session.setPlacedBucket(useItem(session, packet, blockState.javaId(), true));
} else {
session.setPlacedBucket(true);
}
@@ -598,7 +598,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
return false;
}
private boolean useItem(GeyserSession session, InventoryTransactionPacket packet, int blockState) {
private boolean useItem(GeyserSession session, InventoryTransactionPacket packet, int blockState, boolean useTouchRotation) {
// Update the player's inventory to remove any items added by the client itself
PlayerInventory playerInventory = session.getPlayerInventory();
int heldItemSlot = playerInventory.getOffsetForHotbar(packet.getHotbarSlot());
@@ -633,7 +633,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
}
}
session.useItem(Hand.MAIN_HAND);
session.useItem(Hand.MAIN_HAND, useTouchRotation);
return true;
}
}