Skip to content

Commit

Permalink
Fix inserting items that already exist in a bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy committed Jan 1, 2025
1 parent fe52a6e commit d40911c
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequest;
import org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequestSlotData;
import org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.action.ItemStackRequestAction;
import org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.action.SwapAction;
import org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.action.TransferItemStackRequestAction;
import org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponse;
import org.geysermc.geyser.inventory.GeyserItemStack;
Expand All @@ -58,8 +59,16 @@ public final class BundleInventoryTranslator {
static ItemStackResponse handleBundle(GeyserSession session, InventoryTranslator translator, Inventory inventory, ItemStackRequest request, boolean sendCreativePackets) {
TransferItemStackRequestAction action = null;
for (ItemStackRequestAction requestAction : request.getActions()) {
if (requestAction instanceof SwapAction swapAction) {
if (isBundle(swapAction.getSource()) && isBundle(swapAction.getDestination())) {
// Can be seen when inserting an item that's already present within the bundle
continue;
}
return null;
}

if (!(requestAction instanceof TransferItemStackRequestAction transferAction)) {
// No known bundle action that does not use transfer actions
// No other known bundle action that does not use transfer actions
return null;
}
boolean sourceIsBundle = isBundle(transferAction.getSource());
Expand Down Expand Up @@ -305,7 +314,7 @@ private static Fraction calculateWeight(GeyserItemStack itemStack) {
return Fraction.ONE;
}
}
return Fraction.getFraction(1, itemStack.asItem().maxStackSize());
return Fraction.getFraction(1, itemStack.getComponentOrFallback(DataComponentType.MAX_STACK_SIZE, itemStack.asItem().defaultMaxStackSize()));
}

public static int capacityForItemStack(Fraction bundleWeight, GeyserItemStack itemStack) {
Expand Down

0 comments on commit d40911c

Please sign in to comment.