Skip to content

OnMaxStackable ignores ItemContainer.maxStackSize — heavy fuses stack inside the Power Plant fuse box and count as one fuse #29

Description

@spzz10

Since the August 2026 "Power Trip" update, players on servers running Stack Size Controller can right-click a stack of Heavy Electric Fuses (fuse.highgrade) into the Power Plant fuse box and the whole stack lands in a single socket. The stack cannot be split again once it is in the box, and the power grid counts that socket as one fuse. When the socket burns out, the entire stack drops as broken fuses.

This does not happen on vanilla. The fuse box container caps every socket at one item, and the plugin's OnMaxStackable hook overrides that cap.

Steps to reproduce

  1. Run Stack Size Controller 4.1.3 with any config (the item's stack size can be left at the vanilla 3).
  2. Get 2 or 3 Heavy Electric Fuses in one stack.
  3. Open the fuse box in the Power Plant green-card room and right-click the stack into it.
  4. Expected (vanilla): one fuse moves into a socket, the rest stay in the player's inventory.
  5. Actual: the whole stack moves into one socket. powergrid.status shows the inserted fuse count go up by 1, not by the stack size.

Root cause

PowergridFuseBox.CreateInventory() in the game sets:

inventory.maxStackSize = 1;

Vanilla Item.MaxStackable() honours that:

int num = info.stackable;
if (parent != null && parent.maxStackSize > 0)
    num = !parent.allowItemsToIncreaseToMaxStackSize
        ? Mathf.Min(parent.maxStackSize, num)
        : Mathf.Max(parent.maxStackSize, num);
object obj = Interface.CallHook("OnMaxStackable", this);
if (obj is int) return (int)obj;
return num;

The plugin's hook returns the configured size and discards the container limit:

int OnMaxStackable(Item item)
{
    if (_vanillaDefaults == null)
        return item.info.stackable;
    return GetStackSize(item.info);
}

Item.CanStack() calls MaxStackable() on the item already in the socket. Because the hook answers 3 instead of 1, CanStack passes and Item.MoveToContainer's stacking branch merges the incoming fuses onto the socketed one. PowergridManager counts inserted Items, not amounts, so the stacked socket is one fuse.

Any other container that sets maxStackSize is affected the same way; the fuse box is just the first one where it costs players something.

Fix

Apply the container limit in the hook exactly as vanilla does:

int OnMaxStackable(Item item)
{
    int size = _vanillaDefaults == null ? item.info.stackable : GetStackSize(item.info);

    ItemContainer parent = item.parent;
    if (parent != null && parent.maxStackSize > 0)
    {
        size = parent.allowItemsToIncreaseToMaxStackSize
            ? Math.Max(parent.maxStackSize, size)
            : Math.Min(parent.maxStackSize, size);
    }

    return size;
}

Tested on two live servers (Rust build 2633, Oxide, plugin 4.1.3): after the change, right-clicking a stack moves exactly one fuse per click and each socket counts. Configured stack sizes are unchanged everywhere else, since only containers that set their own maxStackSize are affected, which is the game's intended behaviour.

Happy to open a PR with this change if that's easier.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions