Skip to content

TankWidget

Image title

The TankWidget represents a fluid slot widget within a container GUI. It displays a fluid in a designated tank and supports fluid interactions such as filling and emptying. In addition, it integrates with external systems (JEI/REI/EMI) to show fluid ingredient details and provides configurable options for hover overlays, tooltips, and click behavior.

Basic Properties

FieldDescription
fluidTankThe fluid storage or transfer handler associated with this widget
tankThe index of the fluid tank being represented
showAmountDetermines whether the fluid amount is displayed
allowClickFilledControls whether clicking the slot when filled triggers container-filling behavior
allowClickDrainedControls whether clicking the slot when empty triggers container-emptying behavior
drawHoverOverlayIndicates if a hover overlay should be drawn when the mouse is over the widget
drawHoverTipsIndicates if hover tooltips should be displayed
fillDirectionThe direction in which the fluid fill is rendered (e.g. DOWN_TO_UP)
lastFluidInTankLast fluid stored in the tank
lastTankCapacityLast tank capacity

APIs

setFluidTank (IFluidStorage)

Associates the widget with a fluid storage and sets the tank index to 0.

java
tankWidget.setFluidTank(fluidStorage);

setFluidTank (IFluidTransfer, int)

Associates the widget with a fluid transfer handler and specifies the tank index.

java
tankWidget.setFluidTank(fluidTransfer, 1);

setFluid

Set the internal fluidstack with/without notify.

java
tankWidget.setFluid(fluidstack); // it will also trigger the listen you set
tankWidget.setFluid(fluidstack, false); // it wont trigger the listen

getFluid

Get the internal fluidstack stored.

java
var fluidstack = tankWidget.getFluid();

setChangeListener

Configures additional slot location information, such as whether it belongs to the player container or hotbar. It will affect the shift move behaviour.

java
tankWidget.setChangeListener(() -> {
    var last = tankWidget.getLastFluidInTank();
    var current = tankWidget.getFluid();
});

Released under the MIT License.