Jump to content

Recommended Posts

Posted (edited)

I have created a custom furnace but am having trouble getting part of it working. In the vanilla furnace, it overrides setInventorySlotContents to watch for items getting put into the input slot, and sets the totalCookTime field based on that. The GUI checks the value in that field to update the white progress arrow. However, setInventorySlotContents is a method from IInventory. I am using ItemStackHandler. I am guessing I need to override setStackInSlot, or perhaps insertItem, with similar code to setInventorySlotContents. Am I thinking of that right? 

 

Here's setInventorySlotContents for reference:

Spoiler

 


    /**
     * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
     */
    public void setInventorySlotContents(int index, @Nullable ItemStack stack)
    {
        boolean flag = stack != null && stack.isItemEqual(this.furnaceItemStacks[index]) && ItemStack.areItemStackTagsEqual(stack, this.furnaceItemStacks[index]);
        this.furnaceItemStacks[index] = stack;

        if (stack != null && stack.stackSize > this.getInventoryStackLimit())
        {
            stack.stackSize = this.getInventoryStackLimit();
        }

        if (index == 0 && !flag)
        {
            this.totalCookTime = this.getCookTime(stack);
            this.cookTime = 0;
            this.markDirty();
        }
    }

 

 

Edited by Daeruin
Posted (edited)

I hate when I answer my own questions 5 minutes after posting. Looks like I was thinking of it right. I used an anonymous class to override setStackInSlot, and it seems to be working OK.

 

        this.inventory = new ItemStackHandler(3)

        {

 

            @Override

            public void setStackInSlot(int slot, ItemStack stack)

            {

                validateSlotIndex(slot);

                if (ItemStack.areItemStacksEqual(this.stacks[slot], stack))

                    return;

                this.stacks[slot] = stack;

                if (slot == SLOT_INPUT)

                {

                    setField(FIELD_TOTAL_COOK_TIME, getCookTime(stack));

                }

                onContentsChanged(slot);

            }

 

 

I have seen at least one case of someone using an anonymous class like this, where they accessed, say, setField using the class name, like TileEntityFurnace.this.setField(...). Is that important, and why? 

Edited by Daeruin

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.