diff --git a/AGENTS.md b/AGENTS.md index 34feeac..81b875b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -40,7 +40,7 @@ Read [[🧠 Philosophy]] before changing the vault. The Bookshelf Principle, Pre ## Code -The first slice is in code and has been played (ADRs 012–015): [[▢️ Create Goal]], stub [[πŸ”Œ Recipe Provider]], overlay HUD, capture = tooltip + rebindable Add key. +The first slice is in code and has been played (ADRs 012–016): [[▢️ Create Goal]], [[πŸ”Œ Recipe Provider]] via `RecipeManager`, overlay HUD, capture = tooltip + rebindable Add key. Do not start EMI/JEI/REI. Recipe source is `RecipeManager` (ADR-016). Persistence and Project wait until settled. Do not rewrite the overlay as a `Screen` unless the HUD path fails. diff --git a/README.md b/README.md index 01c8416..394b415 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Those may be integrated with later. They are not owned by Satistaskory. ## Status -First slice is in `src/` and has been played: domain, stub recipes, in-memory plan, overlay on the right, hover + Add key (default `=`). +First slice is in `src/` and has been played: domain, `VanillaRecipeProvider` (`RecipeManager`, one level), in-memory plan, overlay on the right, hover + Add key (default `=`). `/satistaskory add minecraft:furnace` is a debug command. The plan is RAM-only. Not EMI. Template example block/item is gone. diff --git a/docs/03-Architecture/πŸ›οΈ Architecture.md b/docs/03-Architecture/πŸ›οΈ Architecture.md index 9567306..8f17e04 100644 --- a/docs/03-Architecture/πŸ›οΈ Architecture.md +++ b/docs/03-Architecture/πŸ›οΈ Architecture.md @@ -119,7 +119,7 @@ Examples: - Save data storage - Inventory scanning -Shipped this slice: `StubRecipeProvider`, player-inventory snapshot, HUD overlay, tooltip+key capture. No save adapter yet. EMI/JEI/REI are not dependencies. +Shipped this slice: `VanillaRecipeProvider` (`RecipeManager`, all types, one level), player-inventory snapshot, HUD overlay, tooltip+key capture. `StubRecipeProvider` is unit tests only. No save adapter yet. EMI/JEI/REI are not dependencies. Infrastructure is never the source of domain truth. @@ -131,7 +131,7 @@ The domain should never import a recipe viewer. Port: [[πŸ”Œ Recipe Provider]] β€” `resolve(ItemId, quantity) β†’ list of MaterialRequirement`. -Shipped: `StubRecipeProvider`. Next: `VanillaRecipeProvider` on `RecipeManager`. EMI/JEI/REI are not required. See ADR-016. +Shipped: `VanillaRecipeProvider` on `RecipeManager`. EMI/JEI/REI are not required. See ADR-016. Recipe viewing is out of scope. This port exists so the domain can resolve requirements, not so Satistaskory can become a recipe browser. diff --git a/docs/03-Architecture/πŸ“ Decisions.md b/docs/03-Architecture/πŸ“ Decisions.md index 09c058e..571a9e2 100644 --- a/docs/03-Architecture/πŸ“ Decisions.md +++ b/docs/03-Architecture/πŸ“ Decisions.md @@ -264,7 +264,7 @@ A button next to the slot vanishes when the cursor leaves the item. A `Screen` r **Decision:** Satistaskory does **not** depend on EMI, JEI, or REI. -Recipe lookup for [[πŸ”Œ Recipe Provider]] is Minecraft’s `RecipeManager` (vanilla + every mod that registers recipes through that API). Scan **by output** across **all** recipe types, not only `minecraft:crafting`. Next implementation after the stub: `VanillaRecipeProvider`. +Recipe lookup for [[πŸ”Œ Recipe Provider]] is Minecraft’s `RecipeManager` (vanilla + every mod that registers recipes through that API). Scan **by output** across **all** recipe types, not only `minecraft:crafting`. Implementation: `VanillaRecipeProvider`. `StubRecipeProvider` remains for unit tests. Examples that must work without EMI: CC:Tweaked turtle, AE2 crafting and inscriber items. diff --git a/docs/03-Architecture/πŸ“¦ Packages.md b/docs/03-Architecture/πŸ“¦ Packages.md index c736246..c01b908 100644 --- a/docs/03-Architecture/πŸ“¦ Packages.md +++ b/docs/03-Architecture/πŸ“¦ Packages.md @@ -29,7 +29,8 @@ com.sufficient.satistaskory infrastructure/ recipe/ - StubRecipeProvider # furnace, crafting_table, chest; else gather + VanillaRecipeProvider # RecipeManager, all types, by output + StubRecipeProvider # unit tests only inventory/ PlayerInventoryAdapter # player inventory β†’ InventoryState client/ @@ -49,7 +50,6 @@ Dependencies point inward: `infrastructure` and `application` may import `domain |---------|-----| | `Project` | Organizational only; not in the slice | | Completion strategy | Ready β‰  complete; complete is not in the slice | -| `VanillaRecipeProvider` | Next recipe impl; `RecipeManager` | | Persistence | In-memory goals. ADR-004 still holds; no save adapter yet | | Full-screen planner | Not discovered | diff --git a/docs/03-Architecture/πŸ”Œ Recipe Provider.md b/docs/03-Architecture/πŸ”Œ Recipe Provider.md index d043ff5..4278bfe 100644 --- a/docs/03-Architecture/πŸ”Œ Recipe Provider.md +++ b/docs/03-Architecture/πŸ”Œ Recipe Provider.md @@ -39,7 +39,7 @@ Dependency chains as an auto-expanded tree remain an expanded view, not this por Lookup is **by output item**, across **every** `RecipeType` in `RecipeManager`, not only `minecraft:crafting`. Custom types (`computercraft:…`, `ae2:inscriber`, …) still live in `RecipeManager` if the mod registered them. Prefer a crafting-table recipe when several types match; otherwise pick one (ADR-014). -Acceptance when `VanillaRecipeProvider` ships: +Acceptance: - A **CC:Tweaked turtle** resolves to its registered ingredients (computer, chest, ingots β€” one level, not the computer’s own recipe). - An **AE2** item that has a `RecipeManager` entry (crafting *or* inscriber) resolves to those ingredients. Processors are inscriber recipes, still in `RecipeManager`, not in EMI. @@ -48,11 +48,11 @@ Catalysts (AE2 press not consumed) are not modelled yet. The adapter may list th --- -## First implementation: stub +## Shipped implementation -`StubRecipeProvider` in `infrastructure.recipe` β€” three shaped recipes plus gather. Shipped. +`VanillaRecipeProvider` over `RecipeManager` (all types, by output). Crafting-table recipes preferred when several match; else first highest score. Empty `getIngredients()` β†’ gather. -Next: `VanillaRecipeProvider` over `RecipeManager` (vanilla and modded recipes registered with Minecraft). See ADR-016. +`StubRecipeProvider` remains for unit tests. EMI / JEI / REI are not implementations and not Gradle dependencies. diff --git a/docs/04-Planning/πŸ—ΊοΈ Roadmap.md b/docs/04-Planning/πŸ—ΊοΈ Roadmap.md index 19c7de7..eb1c3a1 100644 --- a/docs/04-Planning/πŸ—ΊοΈ Roadmap.md +++ b/docs/04-Planning/πŸ—ΊοΈ Roadmap.md @@ -6,22 +6,19 @@ What exists, and what is next. Implementation detail will live in an Implementat ## βœ… Now (docs) -- Philosophy Rules #1–#10; ADRs **001–014** +- Philosophy Rules #1–#10; ADRs **001–016** - Vision, ubiquitous language, bounded context (one: Goal Planning) - Goal invariants: one per ItemId, quantity β‰₯ 1, create at 1 / +1, `[-]` at 1 removes - Packages named; [[πŸ”Œ Recipe Provider]] sketched; [[▢️ Create Goal]] written - Experience: capture in place; overlay on the right (goals + aggregated needed counts) -First slice **code exists** and has been played: domain, stub `RecipeProvider` (furnace / crafting table / chest; else gather), in-memory `Planner`, player inventory, play overlay on the right. Capture is hover + rebindable Add key (default `=`). `/satistaskory add` is a debug caller. Plan does not survive restart. +First slice **code exists** and has been played: domain, `VanillaRecipeProvider` (`RecipeManager`, all types, one level), in-memory `Planner`, player inventory, play overlay, hover + Add key. Plan does not survive restart. --- ## πŸ”² Next -The walk is real. - 1. World-save persistence -2. Vanilla `RecipeProvider` on `RecipeManager` (one crafting level). No EMI/JEI/REI. EMI is not a dependency. See ADR-016. diff --git a/docs/04-Planning/🧭 Notes for the Wayfinder.md b/docs/04-Planning/🧭 Notes for the Wayfinder.md index c0b7f5b..d56f189 100644 --- a/docs/04-Planning/🧭 Notes for the Wayfinder.md +++ b/docs/04-Planning/🧭 Notes for the Wayfinder.md @@ -353,6 +353,20 @@ EMI may be where they *see* the computer. Capture still does not depend on EMI; --- +## πŸ“œ 2026-09-08 (VanillaRecipeProvider) + +Greetings, Wayfinder. + +`PlannerSession` now asks `VanillaRecipeProvider`. It scans every `RecipeType` in `RecipeManager` by output, one level, crafting-table preferred. Empty ingredients still gather. + +`StubRecipeProvider` is tests only. Oak planks as a goal should now be logs (or the first tag member), not more planks. + +Play on the gaming PC: furnace, crafting table, chest, oak planks, then a CC turtle and an AE2 processor if those mods are loaded. + +Next is still world save. Not EMI. Not a Screen rewrite. + +--- + ## Related Documents [[🌟 Project Vision]] diff --git a/docs/99-backlog/🚧 Future Ideas.md b/docs/99-backlog/🚧 Future Ideas.md index 5391573..5a8cb79 100644 --- a/docs/99-backlog/🚧 Future Ideas.md +++ b/docs/99-backlog/🚧 Future Ideas.md @@ -6,7 +6,6 @@ Not a build queue. --- -- Vanilla `RecipeProvider` on `RecipeManager` (next after world save) - Viewer-only recipe adapter (EMI/JEI/REI) **if** a recipe never appears in `RecipeManager` - Persistence (world save / server / cloud) - Inventory-detection completion (alongside manual) diff --git a/src/main/java/com/sufficient/satistaskory/infrastructure/client/PlannerSession.java b/src/main/java/com/sufficient/satistaskory/infrastructure/client/PlannerSession.java index 1d15c89..6ca4daf 100644 --- a/src/main/java/com/sufficient/satistaskory/infrastructure/client/PlannerSession.java +++ b/src/main/java/com/sufficient/satistaskory/infrastructure/client/PlannerSession.java @@ -7,7 +7,7 @@ import com.sufficient.satistaskory.domain.MaterialAggregation; import com.sufficient.satistaskory.domain.ProgressCalculation; import com.sufficient.satistaskory.domain.RecipeResolution; import com.sufficient.satistaskory.infrastructure.inventory.PlayerInventoryAdapter; -import com.sufficient.satistaskory.infrastructure.recipe.StubRecipeProvider; +import com.sufficient.satistaskory.infrastructure.recipe.VanillaRecipeProvider; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; @@ -24,7 +24,7 @@ public final class PlannerSession { if (planner != null) { return; } - RecipeResolution resolution = new RecipeResolution(new StubRecipeProvider()); + RecipeResolution resolution = new RecipeResolution(new VanillaRecipeProvider()); ProgressCalculation progress = new ProgressCalculation(resolution, new MaterialAggregation()); planner = new Planner(new InMemoryGoalStore(), progress, PlannerSession::currentInventory); } diff --git a/src/main/java/com/sufficient/satistaskory/infrastructure/recipe/StubRecipeProvider.java b/src/main/java/com/sufficient/satistaskory/infrastructure/recipe/StubRecipeProvider.java index f1aae66..5d5dc4e 100644 --- a/src/main/java/com/sufficient/satistaskory/infrastructure/recipe/StubRecipeProvider.java +++ b/src/main/java/com/sufficient/satistaskory/infrastructure/recipe/StubRecipeProvider.java @@ -10,7 +10,7 @@ import com.sufficient.satistaskory.domain.MaterialRequirement; import com.sufficient.satistaskory.domain.RecipeProvider; /** - * First implementation. A few shaped recipes plus identity fallback. Not EMI. Not vanilla-complete. + * Unit-test recipes. Furnace, crafting table, chest, plus identity fallback. Not the play adapter. */ public final class StubRecipeProvider implements RecipeProvider { private static final ItemId FURNACE = ItemId.parse("minecraft:furnace"); diff --git a/src/main/java/com/sufficient/satistaskory/infrastructure/recipe/VanillaRecipeProvider.java b/src/main/java/com/sufficient/satistaskory/infrastructure/recipe/VanillaRecipeProvider.java new file mode 100644 index 0000000..4201e30 --- /dev/null +++ b/src/main/java/com/sufficient/satistaskory/infrastructure/recipe/VanillaRecipeProvider.java @@ -0,0 +1,104 @@ +package com.sufficient.satistaskory.infrastructure.recipe; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import com.sufficient.satistaskory.domain.ItemId; +import com.sufficient.satistaskory.domain.MaterialRequirement; +import com.sufficient.satistaskory.domain.RecipeProvider; + +import net.minecraft.client.Minecraft; +import net.minecraft.core.HolderLookup; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.item.crafting.RecipeHolder; +import net.minecraft.world.item.crafting.RecipeManager; +import net.minecraft.world.item.crafting.RecipeType; + +/** + * One crafting level from {@link RecipeManager}. All recipe types, by output. + * Crafting-table recipes win when several match. Tags become the first concrete item. + */ +public final class VanillaRecipeProvider implements RecipeProvider { + @Override + public List resolve(ItemId target, int quantity) { + if (quantity < 1) { + return List.of(); + } + Minecraft minecraft = Minecraft.getInstance(); + if (minecraft.level == null) { + return gather(target, quantity); + } + Item item = BuiltInRegistries.ITEM.get(ResourceLocation.parse(target.toString())); + if (item == Items.AIR && !target.toString().equals("minecraft:air")) { + return gather(target, quantity); + } + + HolderLookup.Provider registries = minecraft.level.registryAccess(); + RecipeHolder chosen = pick(minecraft.level.getRecipeManager(), registries, item); + if (chosen == null) { + return gather(target, quantity); + } + + ItemStack result = chosen.value().getResultItem(registries); + int outputCount = Math.max(1, result.getCount()); + int crafts = (quantity + outputCount - 1) / outputCount; + + Map counts = new LinkedHashMap<>(); + for (Ingredient ingredient : chosen.value().getIngredients()) { + if (ingredient.isEmpty() || ingredient.hasNoItems()) { + continue; + } + ItemStack[] options = ingredient.getItems(); + if (options.length == 0) { + continue; + } + ItemStack option = options[0]; + int perCraft = Math.max(1, option.getCount()); + counts.merge(itemId(option), perCraft * crafts, Integer::sum); + } + if (counts.isEmpty()) { + return gather(target, quantity); + } + List requirements = new ArrayList<>(); + counts.forEach((id, count) -> requirements.add(new MaterialRequirement(id, count))); + return List.copyOf(requirements); + } + + private static RecipeHolder pick(RecipeManager manager, HolderLookup.Provider registries, Item target) { + RecipeHolder best = null; + int bestScore = Integer.MIN_VALUE; + for (RecipeHolder holder : manager.getRecipes()) { + ItemStack result = holder.value().getResultItem(registries); + if (result.isEmpty() || result.getItem() != target) { + continue; + } + int score = 0; + if (holder.value().getType() == RecipeType.CRAFTING) { + score += 2; + } + if (ItemStack.isSameItemSameComponents(result, new ItemStack(target))) { + score += 1; + } + if (score > bestScore) { + bestScore = score; + best = holder; + } + } + return best; + } + + private static ItemId itemId(ItemStack stack) { + return ItemId.parse(BuiltInRegistries.ITEM.getKey(stack.getItem()).toString()); + } + + private static List gather(ItemId target, int quantity) { + return List.of(new MaterialRequirement(target, quantity)); + } +}