Skip to content

Commit

Permalink
use existing method to translate item stack request
Browse files Browse the repository at this point in the history
  • Loading branch information
onebeastchris committed Feb 20, 2025
1 parent cb5009a commit be58f47
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ private static void handle(GeyserSession session, PlayerBlockActionData blockAct

// The Bedrock client won't send a new start_break packet, but just continue breaking blocks
if (!vector.equals(session.getBlockBreakPosition())) {
GeyserImpl.getInstance().getLogger().error("Invalid block break position! Expected " + session.getBlockBreakPosition() + ", got " + vector);

// Start breaking new block
startBlockBreak(session, vector, blockFace);
break;
Expand Down Expand Up @@ -224,7 +222,8 @@ private static void startBlockBreak(GeyserSession session, Vector3i vector, int
vector, direction, session.getWorldCache().nextPredictionSequence());
session.sendDownstreamGamePacket(startBreakingPacket);

spawnBlockBreakParticles(session, direction, vector, BlockState.of(blockState));
// TODO test
//spawnBlockBreakParticles(session, direction, vector, BlockState.of(blockState));
}

private static void breakBlock(GeyserSession session, Vector3i vector, int blockFace) {
Expand Down Expand Up @@ -256,6 +255,12 @@ private static void breakBlock(GeyserSession session, Vector3i vector, int block
blockState = Block.JAVA_AIR_ID;
}

LevelEventPacket breakingPacket = new LevelEventPacket();
breakingPacket.setType(LevelEvent.BLOCK_STOP_BREAK);
breakingPacket.setPosition(vector.toFloat());
breakingPacket.setData(0);
session.sendUpstreamPacket(breakingPacket);

LevelEventPacket blockBreakPacket = new LevelEventPacket();
blockBreakPacket.setType(LevelEvent.PARTICLE_DESTROY_BLOCK);
blockBreakPacket.setPosition(vector.toFloat());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.cloudburstmc.protocol.bedrock.data.PlayerAuthInputData;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
import org.cloudburstmc.protocol.bedrock.data.inventory.transaction.ItemUseTransaction;
import org.cloudburstmc.protocol.bedrock.packet.ItemStackResponsePacket;
import org.cloudburstmc.protocol.bedrock.packet.PlayerActionPacket;
import org.cloudburstmc.protocol.bedrock.packet.PlayerAuthInputPacket;
import org.geysermc.geyser.GeyserImpl;
Expand All @@ -56,6 +55,7 @@
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundPlayerAbilitiesPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundPlayerCommandPacket;

import java.util.List;
import java.util.Set;

@Translator(packet = PlayerAuthInputPacket.class)
Expand All @@ -76,11 +76,7 @@ public void translate(GeyserSession session, PlayerAuthInputPacket packet) {
for (PlayerAuthInputData input : inputData) {
switch (input) {
case PERFORM_ITEM_INTERACTION -> processItemUseTransaction(session, packet.getItemUseTransaction());
case PERFORM_ITEM_STACK_REQUEST -> {
ItemStackResponsePacket responsePacket = new ItemStackResponsePacket();
responsePacket.getEntries().add(session.getInventoryTranslator().translateRequest(session, session.getPlayerInventory(), packet.getItemStackRequest()));
session.sendUpstreamPacket(responsePacket);
}
case PERFORM_ITEM_STACK_REQUEST -> session.getInventoryTranslator().translateRequests(session, session.getPlayerInventory(), List.of(packet.getItemStackRequest()));
case PERFORM_BLOCK_ACTIONS -> BedrockBlockActions.translate(session, packet.getPlayerActions());
case START_SNEAKING -> {
ServerboundPlayerCommandPacket startSneakPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.START_SNEAKING);
Expand Down

0 comments on commit be58f47

Please sign in to comment.