Limit item stack size#6383
Closed
valaphee wants to merge 0 commit into
Closed
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses Bedrock client disconnects caused by receiving item stacks with counts greater than 64 by clamping the translated Bedrock ItemData count.
Changes:
- Add a shared max stack size constant and clamp counts in the base
Item#translateToBedrockimplementation. - Clamp counts in
PotionItemandTippedArrowItemoverride paths that buildItemDatadirectly.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| core/src/main/java/org/geysermc/geyser/item/type/Item.java | Introduces a shared max stack size constant and clamps outgoing Bedrock item counts in the base translation path. |
| core/src/main/java/org/geysermc/geyser/item/type/PotionItem.java | Clamps counts in potion translation branches that bypass the base Item builder path. |
| core/src/main/java/org/geysermc/geyser/item/type/TippedArrowItem.java | Clamps counts in tipped-arrow translation branch that bypasses the base Item builder path. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
155
to
165
| public ItemData.Builder translateToBedrock(GeyserSession session, int count, DataComponents components, ItemMapping mapping, ItemMappings mappings) { | ||
| if (this == Items.AIR || count <= 0) { | ||
| // Return, essentially, air | ||
| return ItemData.builder(); | ||
| } | ||
|
|
||
| return ItemData.builder() | ||
| .definition(mapping.getBedrockDefinition()) | ||
| .damage(mapping.getBedrockData()) | ||
| .count(count); | ||
| .count(Math.min(count, MAX_STACK_SIZE)); | ||
| } |
| import java.util.Map; | ||
|
|
||
| public class Item { | ||
| public static final int MAX_STACK_SIZE = 64; |
| .definition(mapping.getBedrockDefinition()) | ||
| .damage(potion.tippedArrowId()) | ||
| .count(count); | ||
| .count(Math.min(count, MAX_STACK_SIZE)); |
970b265 to
d2ef08c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When an item stack which is larger than 64 is sent, the client just disconnects without any information.