Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

  • Author

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.