Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
for forms that are not named `<material>_<form>`, and `in_all: false` for
forms a material must name. `!all` still excludes every form, and a
script's `removeItems("all")` / `removeBlocks("all")` still clear them.
- XML machine drawer migration. Machines with configurable resources that inherit
only `mmdlib:base_machine` now need
`<feature id="automation" type="mmdlib:side_config"/>` to retain the Side
Configuration drawer. Standalone definitions also need explicit features for
the Statistics, Curios, and Backpack drawers they use.
See [upgrading existing XML machines](docs/xml-machines.md#upgrading-existing-xml-machines).

## Unreleased — 2.0.2

Expand Down
16 changes: 14 additions & 2 deletions docs/gui-screens.md
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,8 @@ opacity with `+1` at the top, without creating a real stack. Mixed consume/produ
both signed counts on the top row. Tooltips provide reservation counts and the planned output's
name. Clearing the plan removes the badge and ghost. Player inventory, equipment and filter
slots are unaffected by default; custom elements can opt into overlays using the hooks above.
Chance outputs show their reserved capacity, not a guarantee that the product will be rolled.
Only guaranteed item outputs reserve capacity. Chance items roll when the cycle finishes
and use any remaining room after the guaranteed products.
No extra packet or XML binding is needed; `MachineMenu.reservationPlan(index)` exposes the existing
synchronized snapshot for real machine slots.

Expand Down Expand Up @@ -2195,9 +2196,20 @@ for the same component; a plain `<gauge>` remains a general display with getter
With a fluid container on the cursor, **left-click fills the tank** and **right-click drains
it into the container**. Input and manual tanks can be drained by players. Insertion retains
fluid/recipe filters and rejects output tanks; both directions respect reservations. Each
click handles one container, including partial modded containers. Stacked results go into the
click handles one container, including partial modded containers. Tank gauges fade the reserved
portion of the current fluid and preview reserved output as translucent fluid. When one tank
reserves both, it shows the two previews side by side. Hover to see exact amounts and the
planned output fluid. Stacked results go into the
player inventory (or drop when full); creative containers remain unchanged.

Click the small brass valve below a tank with fluid to open or close it. An open
valve discards up to 5 mB of unreserved fluid per game tick, even with the screen
closed. The valve closes automatically when the tank is empty and takes up no
layout space.
Use `drain-button="false"` to hide it on a tank.
`BaseMachine` ticks the valves automatically. Custom screen hosts can call
`FluidStorage.tickDrains()` from their server tick.

Getters and element-owned snapshots run only on the server, each tick while the screen is open.
The client only receives their values.

Expand Down
25 changes: 23 additions & 2 deletions docs/multiblocks.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Java multiblock machines
# Multiblock machines

MMDLib provides whole-machine placement for fixed Java-defined structures. One controller owns storage and processing; linked physical parts expose interactions and optional resource ports. The companion's **Multiblock Test Bench** is a complete registration example in `MultiblockDemo` and `MultiblockDemoEntity`.
MMDLib provides whole-machine placement for fixed structures defined in Java or XML. One controller owns storage and processing. Linked physical parts expose interactions and optional resource ports. The companion's **Multiblock Test Bench** is a complete registration example in `MultiblockDemo` and `MultiblockDemoEntity`.

The common structure model is in `zone.moddev.mc.lib.machine.multiblock`. NeoForge placement, blocks, linked block entities and capability adapters live in `machine.neoforge`. These APIs do not depend on the XML machine-definition runtime. Screens can still use ordinary MMDLib XML.

Expand Down Expand Up @@ -30,6 +30,27 @@ The controller is the sole member with role `controller`, at offset zero. Member

Required space is separate from physical membership. A rule is a mod-owned `(Level, BlockPos) -> boolean` predicate. Set `continuous` for conditions that suspend operation while obstructed; otherwise a requirement is checked only at formation. Clearance rules for an animal gym should allow the intended animal while refusing obstructing blocks. Requirements never become removable dummy blocks.

### Load a fixed layout from XML

Bundle `data/<namespace>/mmdlib/multiblock/<path>.xml` and pass its ID and a class from the owning mod to `MultiblockDefinitions.load(id, OwnerMod.class)` after the member blocks are registered. Reuse the returned definition for the placement item and controller.

```xml
<structure xmlns="https://moddev.zone/mmdlib/multiblock" version="1"
max-members="2" max-extent="1" dismantling="remove-owned">
<member id="controller" role="controller" offset="0 0 0"
state="example:controller[facing=north]"/>
<member id="apron" role="apron" offset="0 0 1" state="example:apron"/>
<rule id="clearance" type="air"/>
<requirement rule="clearance" offset="0 1 1" continuous="true"/>
<port member="controller" resource="energy" kind="energy"
faces="back bottom" output="true"/>
</structure>
```

Member states use vanilla block-state syntax. The `air` rule uses `BlockState.isAir()`. Port kinds are `items`, `fluids`, and `energy`. Face names are relative to a viewer looking at the front (`front back left right top bottom`). The `continuous`, `unsided`, `input`, and `output` flags default to `false`. `version` is the saved structure version. To move an existing fixed layout to XML, preserve its version, member keys, member states, and requirements in their original order so saved manifests still match.

XML defines the layout for Java-registered blocks, block entities, and placement items. It is read from the bundled resource at startup. Custom processors, models, and lifecycle callbacks use the same APIs as Java-defined layouts.

## Register the blocks and item

Register a controller block/type, one or more physical part blocks/types and one `MultiblockItem`. No independent part item or part loot is needed for packaged machines.
Expand Down
161 changes: 151 additions & 10 deletions docs/xml-machines.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,19 @@ ordinary work ticks, so normal energy checks still apply and total FE per
recipe or action does not increase. Energy-producing processors likewise run
more work ticks; external automation and transfer rates are not accelerated.

Enable capability-based component storage with `<upgrades/>`. MMDLib adds a gearbox socket for a processor and a capacitor socket for energy storage. The inventories `mmdlib_gearbox` and `mmdlib_capacitor` each have one manual, non-automated slot of capacity eight. `<machine-upgrades/>` displays just those sockets; its optional `storage` attribute adds a machine-owned extra grid.
Enable capability-based component storage with
`<feature id="upgrades" type="mmdlib:upgrades"/>`. MMDLib adds a gearbox socket for a
processor and a capacitor socket for eligible energy storage. Set `gearbox="false"`
or `capacitor="false"` to omit the corresponding socket. The inventories
`mmdlib_gearbox` and `mmdlib_capacitor` each have one manual, non-automated slot of capacity
eight. `<machine-upgrades/>` displays the enabled sockets. Its optional `storage`
attribute adds a machine-owned extra grid. Existing `<upgrades>` declarations are
also supported.

Existing machines may still bind a manual socket by its stable storage slot ID:

```xml
<upgrades gearbox-slot="upgrades/4"/>
<feature id="upgrades" type="mmdlib:upgrades" gearbox-slot="upgrades/4"/>
```

For `<slots id="upgrades" count="11" role="manual" limit="1" automation="false"/>`,
Expand Down Expand Up @@ -148,7 +155,8 @@ integer limit rather than overflowing. Processor energy costs are unaffected.
Bind the second socket independently or alongside the gearbox:

```xml
<upgrades gearbox-slot="upgrades/4" capacitor-slot="upgrades/5"/>
<feature id="upgrades" type="mmdlib:upgrades"
gearbox-slot="upgrades/4" capacitor-slot="upgrades/5"/>
```

The capacitor socket must be a different manual slot without automation, and
Expand Down Expand Up @@ -199,6 +207,8 @@ stops at WorkingArea's existing ±128 local-coordinate bounds. For example,

- `width()`, `depth()`, `height()` and `size()` use inclusive block dimensions.
- `blockAt(origin, facing, index)` returns an immutable world position.
- `snakeBlockAt(origin, facing, index)` alternates left-to-right and right-to-left rows;
each layer starts left-to-right. `row(index)` keeps the same meaning.
- `blocks(origin, facing)` lazily enumerates positions without accessing a world
or loading chunks. Retaining returned positions is safe.
- `row(index)` gives the row within a layer, for row-based processing modes.
Expand All @@ -207,8 +217,7 @@ stops at WorkingArea's existing ±128 local-coordinate bounds. For example,

Traversal goes left to right, row by row, bottom layer first. Rear areas begin
at their near row and move backward; other areas begin at `minForward`.
Agri-Brain now uses this same indexing for scanning, planting rows and work
particles. Callers remain responsible for loaded chunks, world limits and
Agri-Brain uses snake traversal for scanning and work particles, with unchanged row numbers for planting. Callers remain responsible for loaded chunks, world limits and
permissions before acting. Entity enumeration is not implemented yet.

### Migrating development upgrade inventories
Expand Down Expand Up @@ -582,15 +591,91 @@ the root model's `textures` object, without `#`.
Its declarations and conditions must match the Java subscriptions.
Getters are never invoked on the rendering thread.

## Machine features and drawers

Use `<feature id="…" type="namespace:path"/>` to install a feature. An abstract
machine can declare a mod's common features and let its children override individual
settings by ID. An override can omit `type`. Use `enabled="false"` on the feature
to disable it, or on its nested `<drawer>` to hide its drawer while retaining the
feature's behavior. The drawer also accepts `edge="left|right"`,
`anchor="top|bottom"`, and an integer `order`. Lower order values sit closer to
the anchor. Drawer attributes inherit individually.

```xml
<machine xmlns="https://moddev.zone/mmdlib/machine" version="1"
abstract="true" extends="mmdlib:base_powered_machine">
<feature id="backpack" enabled="false"/>
<feature id="redstone" default-mode="pause-while-powered">
<drawer enabled="false"/>
</feature>
<feature id="upgrades" gearbox="false">
<drawer edge="right" order="5"/>
</feature>
</machine>
```

This base removes Backpack, keeps a capacitor socket and its drawer, and pauses
processing when a signal of 1–15 reaches any face. The redstone drawer can be
re-enabled by a child. The default redstone mode is `ignore`. A saved face
configuration takes precedence over the default.

| Feature type | ID in MMDLib's bases | Drawer or behavior |
| --- | --- | --- |
| `mmdlib:info` | `info` | Screen popouts with `kind="info"` |
| `mmdlib:stats` | `statistics` | Machine statistics |
| `mmdlib:curios` | `curios` | A player's available Curios equipment |
| `mmdlib:backpack` | `backpack` | A player's available equipped containers |
| `mmdlib:side_config` | `automation` | Side configuration for machines with configurable resources |
| `mmdlib:redstone` | `redstone` | Redstone input, output and comparator configuration |
| `mmdlib:upgrades` | `upgrades` | Upgrade sockets and their screen layout |
| `mmdlib:popout` | | Warning and error popouts declared in the screen |
| `mmdlib:side_tab` | | Side tabs declared in the screen |

The common machine base declares Info, Statistics, Curios, Backpack, and Redstone.
Redstone defaults to ignoring input and uses any saved face settings on load.
The powered preset adds Side Configuration and Upgrades. A machine without an inherited
Redstone feature can still opt in through the version-1 `<redstone enabled="true"/>` shorthand.

Mods can register a feature type, its allowed XML attributes, and a per-machine
factory using `MachineFeatureTypes.register` on both sides. The factory returns a
`MachineFeature` whose key is the XML feature ID. To contribute drawers, also
implement `MachineFeatureDrawers` and return common-side drawer definitions. The
usual client drawer factory and menu component registrations handle rendering and
server interactions.

### Upgrading existing XML machines

Side Configuration, Statistics, Curios, and Backpack now require a matching
feature, declared on the machine or inherited from a base. For an existing machine
with configurable resources that inherits only `mmdlib:base_machine`, add this
line inside `<machine>` or in a shared base to retain its Side Configuration drawer:

```xml
<feature id="automation" type="mmdlib:side_config"/>
```

`mmdlib:base_powered_machine` already declares this feature.

For standalone XML definitions, also add the declarations for the other drawers
you want to retain. Both MMDLib machine bases already supply these features:

```xml
<feature id="statistics" type="mmdlib:stats"/>
<feature id="curios" type="mmdlib:curios"/>
<feature id="backpack" type="mmdlib:backpack"/>
```

## Base machine and storage

The generic [`base_machine.xml`](../src/main/resources/mmdlib/machine/base_machine.xml)
provides block settings, redstone control, recovery and the common screen with generated
tank fills. It declares no storage. The powered base extends it:
provides block settings, the shared drawer features, recovery and the common screen
with generated tank fills. It declares no storage. The powered base extends it:

```xml
<machine xmlns="https://moddev.zone/mmdlib/machine" version="1" abstract="true"
extends="mmdlib:base_machine">
<feature id="automation" type="mmdlib:side_config"/>
<feature id="upgrades" type="mmdlib:upgrades"/>
<storage>
<energy id="energy" capacity="100000" input-rate="1000" output-rate="0" color="energy"/>
</storage>
Expand Down Expand Up @@ -984,6 +1069,60 @@ area before the base template's energy gauge. Generated processor arrows open
their recipe type in JEI when clicked. SimpleCrusher needs no `<screen>` or
`<fill>` of its own.

Generated arrows show a warning badge and a red **Output blocked** tooltip
when a ready recipe cannot place its products. Set `processor-key` on an authored
`<progress>` element to link it to the same warning.

Use machine-level `<parts>` to declare resources and processors in the order they
should appear in the generated screen.

```xml
<parts>
<tank id="raw_input" name="Input" role="input" capacity="4000"/>
<processor id="filter" recipe-type="example:filtering"/>
<inventory id="solids" name="Solid Output" count="9" role="output"/>
<tank id="filtered_output" name="Liquid Output" role="output" capacity="4000"/>
<energy/>
</parts>
```

An inventory takes the same storage attributes as `<slots>`. It defaults to one
slot and three display columns. Set `columns` to change its width. A tank takes
the usual storage attributes and an optional `tooltip` translation key. Use
`<tanks count="…">` to show a group of tanks together. A processor uses the same
attributes as a top-level processor. An empty `<energy/>` places the inherited
energy gauge. Supply the usual energy attributes on it to define energy storage
there as well.

The loader reuses the inherited item and fluid storage IDs, with `items` and
`fluids` as defaults. Keep part IDs stable for save data and recipe bindings.
A child that declares its own `<parts>` supplies a new row while inheriting
storage and processors under the usual machine inheritance rules.

Use a machine-level `<layout>` when the controls should reference declarations
that already live elsewhere. Declare one row per machine XML using either
`<parts>` or `<layout>`.

```xml
<layout>
<tank ref="raw_input"/>
<processor ref="filter"/>
<inventory ref="solids" columns="3"/>
<tank ref="filtered_output"/>
<energy/>
</layout>
```

Entries appear from left to right. `tank`, `processor`, and `inventory`
reference their existing machine IDs. An inventory can reference an item group
or ghost inventory and defaults to three columns. A tank accepts an optional
`tooltip` translation key. `energy` shows the machine's energy gauge.

The layout supplies the machine, tank, and energy regions of the standard
screen. Only the controls listed in the layout appear in that row. A derived
machine inherits the layout or replaces it as a whole. Use `<layout/>` to
restore the screen's usual fills.

A machine can replace that region:

```xml
Expand Down Expand Up @@ -1306,8 +1445,9 @@ Buttons without a processor target continue to use ordinary callback routing.

`<block>` also accepts `stack-size="1"`, `no-occlusion="true"`,
`immovable="true"`, `drawers="false"` and `portable="true"`.
These are opt-in policies; existing machines retain their defaults. `drawers`
controls the stats and automation drawers, while redstone remains separately configured.
The legacy `drawers="false"` shorthand suppresses Statistics and Side Configuration
together. [Machine features](#machine-features-and-drawers) can control each drawer
individually.

```xml
<shapes>
Expand Down Expand Up @@ -1750,7 +1890,8 @@ Sneak placement chooses the clicked face; ordinary placement faces the player.

## Comparator readout

`<redstone comparator-source="workshop/output"/>` selects one existing
`<feature id="redstone" type="mmdlib:redstone" comparator-source="workshop/output"/>`
selects one existing
`IRedstoneOutput` descriptor by its stable ID. The source is sampled together
with per-face outputs, once per selected source per tick. Comparator readout is
block-wide and independent of Emit faces and their inversion. Unknown source
Expand Down
26 changes: 26 additions & 0 deletions scripts/generate_gui_sprites.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,31 @@ def write_flat_buttons():
write_png(name, img, {"type": "nine_slice", "width": 14, "height": 14, "border": 1})


def write_tank_drain():
"""Brass drain valve, drawn at its native 11x10 GUI size."""
palette = {
".": CLEAR,
"#": (70, 39, 24, 255),
"S": (117, 64, 30, 255),
"M": (171, 99, 38, 255),
"H": (219, 153, 60, 255),
"L": (255, 208, 111, 255),
}
rows = [
".........##",
"......###L#",
"....##LHM#.",
"....#H###..",
"...##H##...",
"###LHLHH##.",
"#HLMLMMHLH#",
"#SM#HMS#SS#",
".##.#HS###.",
".....##....",
]
write_png("icon_tank_drain", [[palette[pixel] for pixel in row] for row in rows])


def write_filter_icons():
"""White/black list cards for the flat grey mode toggle."""
for mode, fill in (("whitelist", 0xF1), ("blacklist", 0x24)):
Expand Down Expand Up @@ -532,6 +557,7 @@ def main():
write_processor_progress_icon()
write_filter_icons()
write_flat_buttons()
write_tank_drain()
write_side_config_sprites()
write_upgrade_sprites()
write_png("checkbox", checkbox(False))
Expand Down
1 change: 1 addition & 0 deletions src/companion/resources/mmdlib/machine/admission_demo.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<machine xmlns="https://moddev.zone/mmdlib/machine" version="1"
extends="mmdlib:base_machine" name="Admission Demo">
<feature id="automation" type="mmdlib:side_config"/>
<appearance preset="cube-front" front="minecraft:block/furnace_front"
side="minecraft:block/bricks" top="minecraft:block/iron_block"/>
<storage>
Expand Down
3 changes: 2 additions & 1 deletion src/companion/resources/mmdlib/machine/porting_workshop.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</items>
<fluids id="fluids"><tank id="water" role="input" capacity="4000" fluid-tag="minecraft:water"/></fluids>
</storage>
<redstone comparator-source="workshop/output"/>
<feature id="redstone" comparator-source="workshop/output"/>
<feature id="automation" type="mmdlib:side_config"/>
<processor id="workshop" class="zone.moddev.mc.companion.WorkshopProcessor"/>
</machine>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<machine xmlns="https://moddev.zone/mmdlib/machine" version="1"
extends="mmdlib:base_machine" name="Simple Lava Furnace">
<feature id="automation" type="mmdlib:side_config"/>
<appearance preset="cube-front" front="minecraft:block/furnace_front"
side="minecraft:block/nether_bricks" top="minecraft:block/polished_blackstone"/>
<storage>
Expand Down
Loading