Jump to content

Item count in inventory staying 64 after quickMoveStack is called.


CosmicKid

Recommended Posts

I've looked at plenty of other people's code as well as the Minecraft code for containers like this and I can't figure this out. When I shift+click the iron ore in my inventory, it fills up the slot in my furnace, but the stack size in my inventory stays what it was if the entire stack couldn't be moved to the furnace.

My slots are set up like this: 0-26 is the inner inventory, 27-35 is the hotbar, 36 is the furnace input and 37 is the output.

 

@Override
    public ItemStack quickMoveStack(PlayerEntity player, int index) {
        ItemStack itemstack = ItemStack.EMPTY;
        Slot slot = this.slots.get(index);
        if(slot != null && slot.hasItem()) {
            ItemStack stack = slot.getItem();
            itemstack = stack.copy();
            if(index == 36) {
                if(!this.moveItemStackTo(stack, 0, 36, true)) {
                    return ItemStack.EMPTY;
                } slot.onQuickCraft(stack, itemstack);
            } else {
                RecipeManager recipeManager = player.level.getRecipeManager();
                Inventory input = new Inventory(stack);
                Optional<FurnaceRecipe> matchingRecipe = recipeManager.getRecipeFor(IRecipeType.SMELTING, input, player.level);
                if(index == 37) {
                    if(!this.moveItemStackTo(stack, 27, 35, false)) {
                        if(!this.moveItemStackTo(stack, 0, 26, false)) {
                            return ItemStack.EMPTY;
                        }
                    }
                } else if(matchingRecipe.isPresent()) {
                    if(!this.moveItemStackTo(stack, 36, 37, true)) {
                        if(!this.moveItemStackTo(stack, index, index, false)) {
                            if(!this.moveItemStackTo(stack, 27, 35, false)) {
                                if(!this.moveItemStackTo(stack, 0, 26, false)) {
                                    return ItemStack.EMPTY;
                                }
                            }
                        }
                    }
                } else if(index < 27) {
                    if(!this.moveItemStackTo(stack, 27, 35, false)) {
                        return ItemStack.EMPTY;
                    }
                } else if(index < 36 && !this.moveItemStackTo(stack, 0, 26, false)) {
                    return ItemStack.EMPTY;
                }
            }

            if(stack.isEmpty()) {
                slot.set(ItemStack.EMPTY);
            } else {
                slot.setChanged();
            }

            if(stack.getCount() == itemstack.getCount()) {
                return ItemStack.EMPTY;
            } slot.onTake(player, stack);
        } return itemstack;
    }

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.