Developer API

TrashSlot supports JSON-based container layouts for customizing the trash slot on custom container screens, such as defining additional bounding boxes and snapping points.

TrashSlot supports JSON-based container layouts for customizing the trash slot on custom container screens, such as defining additional bounding boxes and snapping points.

Container Layouts

Container layout files are loaded from:

assets/<namespace>/trashslot/container_layout/<menu_type>.json

The file id is matched against the container menu type id. For example, a menu registered as examplemod:storage_box should use:

assets/examplemod/trashslot/container_layout/storage_box.json

Basic Example

This enables TrashSlot by default for the container and uses the standard snap positions inherited from TrashSlot's default layout:

{
  "availability": "default"
}

If the screen texture is taller or shorter than the menu reports, override the layout height so the trash slot snaps to the visible UI instead:

{
  "availability": "default",
  "height": 167
}

Fields

FieldDescriptionDefault
availabilityWhether TrashSlot is available on this screen. Can be never, optional, or default.Required
widthOverrides the screen bounds width used for snap positions. If omitted, the menu screen's image width is used.Screen width
heightOverrides the screen bounds height used for snap positions. If omitted, the menu screen's image height is used.Screen height
snapsAdditional or replacement snap positions for the trash slot. Snap ids from the default layout can be overridden.Default snaps
defaultSnapThe snap id used as the default trash slot position.bottom_right

availability controls how TrashSlot behaves on the screen:

ValueDescription
neverTrashSlot is not available for this container.
optionalTrashSlot can be enabled by the player.
defaultTrashSlot is enabled by default.

Custom Snap Positions

Each snap position can define an x coordinate, a y coordinate, and a visual. Coordinates can be fixed values or relative to the screen bounds.

{
  "availability": "default",
  "defaultSnap": "right_bottom",
  "height": 221,
  "snaps": {
    "right_bottom": {
      "x": {
        "type": "right",
        "offset": -1
      },
      "y": {
        "type": "bottom",
        "offset": -24
      },
      "visual": "attach_right_bottom"
    }
  }
}

Available coordinate types are:

TypeDescription
constantUses a fixed coordinate from the value field.
leftUses the left edge of the screen bounds plus offset.
rightUses the right edge of the screen bounds plus offset.
topUses the top edge of the screen bounds plus offset.
bottomUses the bottom edge of the screen bounds plus offset.
rangeKeeps the player's dragged coordinate if it is between from and to; otherwise the snap is not used.

The standard visual values are default, attach_top, attach_top_left, attach_top_right, attach_bottom, attach_bottom_left, attach_bottom_right, attach_left, attach_left_top, attach_left_bottom, attach_right, attach_right_top, and attach_right_bottom.

You can learn more from the built-in layout files in the TrashSlot GitHub repository.

Java API

For dynamic layouts that cannot be expressed as JSON, TrashSlot still provides a Java API. Register custom layouts from RegisterTrashSlotContainerLayoutsEvent.

You can find the Java API classes in the API package.

If you have any questions or need help, feel free to join our Discord server.

repositories {
    maven {
        url "https://maven.twelveiterations.com/repository/maven-public/"

        content {
            includeGroup "net.blay09.mods"
        }
    }
}

dependencies {
    // Common (mojmap):
    compileOnly "net.blay09.mods:trashslot-common:${mod_version}"
    // NeoForge:
    implementation "net.blay09.mods:trashslot-neoforge:${mod_version}"
    // Fabric:
    implementation "net.blay09.mods:trashslot-fabric:${mod_version}"
}