Skip to content

Expose the machine that a crafting interface targets - #225

Open
rubensworks wants to merge 1 commit into
master-1.21-ltsfrom
feature/crafting-interface-target-machine
Open

Expose the machine that a crafting interface targets#225
rubensworks wants to merge 1 commit into
master-1.21-ltsfrom
feature/crafting-interface-target-machine

Conversation

@rubensworks

Copy link
Copy Markdown
Member

Adds ICraftingInterface#getTargetMachineItem(), an item representation of the block that a crafting interface is targeting.

Why

Crafting interfaces already know which block they point at: the part state holds a PartTarget, and getPosition() returns the center half of it. The target half was not exposed, so a caller that wanted the machine had to look the part up again through PartHelpers and re-run IPartType#getTarget to reconstruct what the state was already holding. That duplicates the logic deciding where a part points at (offsets, side overrides), and drifts silently if that logic ever changes.

What

// ICraftingInterface
public default ItemStack getTargetMachineItem() {
    return ItemStack.EMPTY;
}

PartTypeInterfaceCraftingBase.State answers it from the target it already holds, returning an empty stack when there is no target yet or the position is not loaded. It is a default method, so other implementations of the interface keep working unchanged.

This also covers running crafting jobs: ICraftingNetwork#getCraftingJobInterface already hands out the interface a job runs in, so its machine is now reachable too.

Needed by

CyclopsMC/IntegratedTerminals#181 — showing the crafting machine in the storage terminal's tooltips. The IntegratedTerminals side is CyclopsMC/IntegratedTerminals#216, which needs a release of this change before its CI can pass.

Testing

New game tests in GameTestsCraftingInterfaceTargetMachine, covering both the regular and the attuned crafting interface against a crafting table and a furnace.

All 66 required tests passed :)

./gradlew build and ./gradlew runGameTestServer both pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RM86uiqD4soLkMyjC9Eeid


Generated by Claude Code

Crafting interfaces know which block they are targeting, but only exposed
their own (center) position through getPosition(). Callers that want the
machine had to look the part up again and re-derive its target, which
duplicates the logic that decides where a part points at.

Add ICraftingInterface#getTargetMachineItem(), which the part state answers
from the target it already holds. It is a default method returning an empty
stack, so other implementations keep working.

Needed by CyclopsMC/IntegratedTerminals#181, to show the crafting machine in
the storage terminal's tooltips.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RM86uiqD4soLkMyjC9Eeid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant