Count every plank a chest will take, not only oak.
Build / build (push) Failing after 32s

Tag ingredients are one interchangeable requirement. Available is the sum. Overlay names the stack the player holds; empty shows Planks, not oak-by-default.
This commit is contained in:
Stephen Fasciani
2026-09-08 06:28:04 -04:00
parent 5d49f1482f
commit bac020f335
20 changed files with 361 additions and 34 deletions
+1 -1
View File
@@ -40,7 +40,7 @@ Read [[🧠 Philosophy]] before changing the vault. The Bookshelf Principle, Pre
## Code ## Code
The first slice is in code and has been played (ADRs 012–018): [[▶️ Create Goal]], [[🔌 Recipe Provider]] via `RecipeManager`, overlay HUD, capture = tooltip + rebindable Add key, client-owned plan files. The first slice is in code and has been played (ADRs 012–019): [[▶️ Create Goal]], [[🔌 Recipe Provider]] via `RecipeManager`, overlay HUD, capture = tooltip + rebindable Add key, client-owned plan files. Tag ingredients are any-of (ADR-019).
Do not start EMI/JEI/REI. Recipe source is `RecipeManager` (ADR-016). The host does not need this mod (ADR-018). Project waits until settled. Do not rewrite the overlay as a `Screen` unless the HUD path fails. Do not start EMI/JEI/REI. Recipe source is `RecipeManager` (ADR-016). The host does not need this mod (ADR-018). Project waits until settled. Do not rewrite the overlay as a `Screen` unless the HUD path fails.
@@ -14,6 +14,8 @@ Combines requirements from multiple [[🎯 Goal|goals]].
Same material from two goals is one entry. Goal A needs Diamond x4. Goal B needs Diamond x8. Aggregated: Diamond x12. Same material from two goals is one entry. Goal A needs Diamond x4. Goal B needs Diamond x8. Aggregated: Diamond x12.
The same interchangeable set (every plank type) from two goals is one entry.
--- ---
## Rule ## Rule
@@ -31,6 +31,7 @@ aggregate requirements
(same material → one row) (same material → one row)
for each material: for each material:
available = sum of every interchangeable option (or that one item)
missing = max(0, required − available) missing = max(0, required − available)
``` ```
+2 -2
View File
@@ -11,7 +11,7 @@ Missing = Required - Available
``` ```
Required comes from goals (after resolution and aggregation). Required comes from goals (after resolution and aggregation).
Available comes from [[🎒 Inventory State]]. Available comes from [[🎒 Inventory State]]. For interchangeable items (any plank), available is the **sum** of every option.
--- ---
@@ -19,7 +19,7 @@ Available comes from [[🎒 Inventory State]].
Missing materials are the **default** materials view. On the golden day they live in the **lower region** of the play overlay, under the goal list. See [[🚶 Day in the Life]] and [[🖼️ Wireframes]]. Missing materials are the **default** materials view. On the golden day they live in the **lower region** of the play overlay, under the goal list. See [[🚶 Day in the Life]] and [[🖼️ Wireframes]].
The player should see this first — one row per material, with how many are still needed: The player should see this first — one row per material, with how many are still needed. A tag ingredient is still one row. If they hold spruce, the row says spruce. If they hold none, a generic label (Planks), not oak-by-default.
- Diamond x12 - Diamond x12
- Redstone x82 - Redstone x82
+5 -1
View File
@@ -2,7 +2,9 @@
A quantity of a material required to complete a [[🎯 Goal]]. A quantity of a material required to complete a [[🎯 Goal]].
Identified by the same **ItemId** as Target Item (`namespace:path`). Quantity ≥ 1. Identified by one **ItemId**, or by **any of several** ItemIds when the recipe accepts substitutes (planks for a chest). Quantity ≥ 1.
Tags are not a domain type. The provider names the concrete items that all count.
--- ---
@@ -28,6 +30,8 @@ Aggregated requirement:
Diamond x12 Diamond x12
Chest needs any plank ×8. Crafting table needs any plank ×4. Aggregated: any plank ×12. Spruce and oak both count.
Projects do not change this. See [[📁 Project]] and [[➕ Material Aggregation]]. Projects do not change this. See [[📁 Project]] and [[➕ Material Aggregation]].
--- ---
+18
View File
@@ -330,6 +330,24 @@ Remote identity is the **multiplayer list name plus MOTD**, not the IP. Hostname
--- ---
### ADR-019 — Interchangeable ingredients are any-of, not the first tag member
**Date:** 2026-09-08
**Decision:** When a recipe ingredient matches several items (a tag, a custom ingredient), [[🧱 Material Requirement]] is one row with **all** of those ItemIds. Available is the sum. The overlay shows the option the player holds most of; if they hold none, a generic path label (Planks), not oak-by-default.
Not a tag type in the domain. Not biome-based wood. Not a recipe browser.
**Reason:**
A chest crafts from any `#minecraft:planks`. Picking `getItems()[0]` made spruce in a spruce biome invisible, and mixed stacks look short. The walk failed.
**Status:** ✅ Accepted
**Refines:** ADR-014 (concrete items; this is how several concretes count)
---
## Related Documents ## Related Documents
[[🏛️ Architecture]] [[🏛️ Architecture]]
+3 -3
View File
@@ -17,7 +17,7 @@ RecipeProvider
`ItemId` is `namespace:path` (e.g. `minecraft:furnace`). Not `net.minecraft.world.item.Item`. `ItemId` is `namespace:path` (e.g. `minecraft:furnace`). Not `net.minecraft.world.item.Item`.
`MaterialRequirement` is `(ItemId, quantity)`. `MaterialRequirement` is `(options, quantity)`. `options` is one ItemId, or several that all count.
--- ---
@@ -29,7 +29,7 @@ RecipeProvider
| Item has a recipe | **One crafting level** of ingredients, already scaled for `quantity` (including recipe output count) | | Item has a recipe | **One crafting level** of ingredients, already scaled for `quantity` (including recipe output count) |
| Item has no recipe | One requirement: `(target, quantity)` — a gather | | Item has no recipe | One requirement: `(target, quantity)` — a gather |
| Several recipes exist | Provider picks **one**. Recipe choice is not in the slice | | Several recipes exist | Provider picks **one**. Recipe choice is not in the slice |
| Ingredient is a tag | Provider returns **concrete** ItemIds. Tags are not a domain type yet | | Ingredient is a tag | One requirement whose **options** are every concrete member. Tags are not a domain type. Available = sum of the members. |
Not a recipe tree. Not a recipe browser. Not a recipe tree. Not a recipe browser.
@@ -50,7 +50,7 @@ Catalysts (AE2 press not consumed) are not modelled yet. The adapter may list th
## Shipped implementation ## Shipped implementation
`VanillaRecipeProvider` over `RecipeManager` (all types, by output). Crafting-table recipes preferred when several match; else first highest score. Empty `getIngredients()` → gather. `VanillaRecipeProvider` over `RecipeManager` (all types, by output). Crafting-table recipes preferred when several match; else first highest score. Empty `getIngredients()` → gather. Several `getItems()` → one interchangeable requirement (chest + spruce planks).
`StubRecipeProvider` remains for unit tests. `StubRecipeProvider` remains for unit tests.
+1 -1
View File
@@ -6,7 +6,7 @@ What exists, and what is next. Implementation detail will live in an Implementat
## ✅ Now (docs) ## ✅ Now (docs)
- Philosophy Rules #1–#10; ADRs **001–018** - Philosophy Rules #1–#10; ADRs **001–019**
- Vision, ubiquitous language, bounded context (one: Goal Planning) - Vision, ubiquitous language, bounded context (one: Goal Planning)
- Goal invariants: one per ItemId, quantity ≥ 1, create at 1 / +1, `[-]` at 1 removes - Goal invariants: one per ItemId, quantity ≥ 1, create at 1 / +1, `[-]` at 1 removes
- Packages named; [[🔌 Recipe Provider]] sketched; [[▶️ Create Goal]] written - Packages named; [[🔌 Recipe Provider]] sketched; [[▶️ Create Goal]] written
@@ -425,6 +425,16 @@ The frozen first slice has been walked. Still listen. Still do not open Project
--- ---
## 📜 2026-09-08 (any plank counts)
Greetings, Wayfinder.
The walk reported: chests take more than oak. Spruce in a spruce biome did not count.
ADR-019: a tag ingredient is one requirement, every member counts. Overlay names the stack they have; empty → “Planks”, not oak. Not biome. Mixed spruce + birch covering a chest is Ready.
---
## Related Documents ## Related Documents
[[🌟 Project Vision]] [[🌟 Project Vision]]
+1 -1
View File
@@ -62,7 +62,7 @@ The overlay answers both halves of the vision question:
Walking has no cursor. Overlay `[+]` / `[-]` / Clear are HUD hit-tests (vanilla button sprites + click sound), not a `Screen`. Open chat (`T` or `/`) to click them. Capture does not use a clickable chip you leave the item to hit. Walking has no cursor. Overlay `[+]` / `[-]` / Clear are HUD hit-tests (vanilla button sprites + click sound), not a `Screen`. Open chat (`T` or `/`) to click them. Capture does not use a clickable chip you leave the item to hit.
Same material from two goals is one row. Changing a goal quantity recalculates the lower list. As inventory fills, counts shrink. Same material from two goals is one row. Any-plank recipes (chest, crafting table) are one row too: spruce counts, mixed stacks count. If they hold none, the row says Planks, not Oak. Changing a goal quantity recalculates the lower list. As inventory fills, counts shrink.
Coming back is part of the prosthetic. Singleplayer: the plan belongs to that world. A server: the plan belongs to **the name you gave it in the multiplayer list**, plus that server’s description (MOTD). Not the IP. Two list entries with different names are two plans, even if they are the same host. Coming back is part of the prosthetic. Singleplayer: the plan belongs to that world. A server: the plan belongs to **the name you gave it in the multiplayer list**, plus that server’s description (MOTD). Not the IP. Two list entries with different names are two plans, even if they are the same host.
@@ -0,0 +1,81 @@
package com.sufficient.satistaskory.domain;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
/**
* Interchangeable items from one ingredient (a tag, a custom ingredient). Not a tag type.
*/
final class Alternatives {
private Alternatives() {}
static List<ItemId> copy(List<ItemId> options) {
if (options == null || options.isEmpty()) {
throw new IllegalArgumentException("options must be non-empty");
}
LinkedHashSet<ItemId> unique = new LinkedHashSet<>();
for (ItemId option : options) {
if (option == null) {
throw new IllegalArgumentException("options must not contain null");
}
unique.add(option);
}
return List.copyOf(unique);
}
static Set<ItemId> members(List<ItemId> options) {
return Set.copyOf(options);
}
static ItemId preferred(List<ItemId> options, InventoryState inventory) {
ItemId best = options.getFirst();
int bestCount = -1;
for (ItemId option : options) {
int count = inventory.get(option);
if (count > bestCount) {
bestCount = count;
best = option;
}
}
return best;
}
/**
* Shared trailing path tokens: oak_planks + spruce_planks → {@code planks}.
* Empty when there is no shared suffix.
*/
static String commonPathLabel(List<ItemId> options) {
if (options.size() < 2) {
return "";
}
List<String[]> tokens = new ArrayList<>(options.size());
int minLen = Integer.MAX_VALUE;
for (ItemId option : options) {
String[] parts = option.path().split("_");
tokens.add(parts);
minLen = Math.min(minLen, parts.length);
}
List<String> suffix = new ArrayList<>();
for (int offset = 1; offset <= minLen; offset++) {
String[] first = tokens.getFirst();
String token = first[first.length - offset];
boolean all = true;
for (String[] parts : tokens) {
if (!parts[parts.length - offset].equals(token)) {
all = false;
break;
}
}
if (!all) {
break;
}
suffix.addFirst(token);
}
if (suffix.isEmpty()) {
return "";
}
return String.join("_", suffix);
}
}
@@ -2,6 +2,7 @@ package com.sufficient.satistaskory.domain;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@@ -31,4 +32,12 @@ public final class InventoryState {
public int get(ItemId item) { public int get(ItemId item) {
return available.getOrDefault(item, 0); return available.getOrDefault(item, 0);
} }
public int getAny(List<ItemId> items) {
int total = 0;
for (ItemId item : items) {
total += get(item);
}
return total;
}
} }
@@ -4,15 +4,19 @@ import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
public final class MaterialAggregation { public final class MaterialAggregation {
public List<MaterialRequirement> aggregate(List<MaterialRequirement> requirements) { public List<MaterialRequirement> aggregate(List<MaterialRequirement> requirements) {
Map<ItemId, Integer> sums = new LinkedHashMap<>(); Map<Set<ItemId>, Integer> sums = new LinkedHashMap<>();
Map<Set<ItemId>, List<ItemId>> order = new LinkedHashMap<>();
for (MaterialRequirement requirement : requirements) { for (MaterialRequirement requirement : requirements) {
sums.merge(requirement.item(), requirement.quantity(), Integer::sum); Set<ItemId> key = requirement.members();
sums.merge(key, requirement.quantity(), Integer::sum);
order.putIfAbsent(key, requirement.options());
} }
List<MaterialRequirement> aggregated = new ArrayList<>(); List<MaterialRequirement> aggregated = new ArrayList<>();
sums.forEach((item, quantity) -> aggregated.add(new MaterialRequirement(item, quantity))); sums.forEach((key, quantity) -> aggregated.add(new MaterialRequirement(order.get(key), quantity)));
return List.copyOf(aggregated); return List.copyOf(aggregated);
} }
} }
@@ -1,27 +1,59 @@
package com.sufficient.satistaskory.domain; package com.sufficient.satistaskory.domain;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Set;
/**
* A quantity of material. One item, or any of several (tag / custom ingredient).
*/
public final class MaterialRequirement { public final class MaterialRequirement {
private final ItemId item; private final List<ItemId> options;
private final int quantity; private final int quantity;
public MaterialRequirement(ItemId item, int quantity) { public MaterialRequirement(ItemId item, int quantity) {
this.item = Objects.requireNonNull(item, "item"); this(List.of(item), quantity);
}
public MaterialRequirement(List<ItemId> options, int quantity) {
this.options = Alternatives.copy(options);
if (quantity < 1) { if (quantity < 1) {
throw new IllegalArgumentException("quantity must be >= 1"); throw new IllegalArgumentException("quantity must be >= 1");
} }
this.quantity = quantity; this.quantity = quantity;
} }
public List<ItemId> options() {
return options;
}
/**
* First option. Display fallback, not the only item that counts.
*/
public ItemId item() { public ItemId item() {
return item; return options.getFirst();
} }
public int quantity() { public int quantity() {
return quantity; return quantity;
} }
public boolean interchangeable() {
return options.size() > 1;
}
public ItemId preferred(InventoryState inventory) {
return Alternatives.preferred(options, inventory);
}
public String groupLabel() {
return Alternatives.commonPathLabel(options);
}
Set<ItemId> members() {
return Alternatives.members(options);
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) { if (this == o) {
@@ -30,11 +62,11 @@ public final class MaterialRequirement {
if (!(o instanceof MaterialRequirement other)) { if (!(o instanceof MaterialRequirement other)) {
return false; return false;
} }
return quantity == other.quantity && item.equals(other.item); return quantity == other.quantity && members().equals(other.members());
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(item, quantity); return Objects.hash(quantity, members());
} }
} }
@@ -1,27 +1,56 @@
package com.sufficient.satistaskory.domain; package com.sufficient.satistaskory.domain;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Set;
public final class MissingMaterial { public final class MissingMaterial {
private final ItemId item; private final List<ItemId> options;
private final int quantity; private final int quantity;
public MissingMaterial(ItemId item, int quantity) { public MissingMaterial(ItemId item, int quantity) {
this.item = Objects.requireNonNull(item, "item"); this(List.of(item), quantity);
}
public MissingMaterial(List<ItemId> options, int quantity) {
this.options = Alternatives.copy(options);
if (quantity < 1) { if (quantity < 1) {
throw new IllegalArgumentException("quantity must be >= 1"); throw new IllegalArgumentException("quantity must be >= 1");
} }
this.quantity = quantity; this.quantity = quantity;
} }
public List<ItemId> options() {
return options;
}
/**
* First option. Display fallback, not the only item that counts.
*/
public ItemId item() { public ItemId item() {
return item; return options.getFirst();
} }
public int quantity() { public int quantity() {
return quantity; return quantity;
} }
public boolean interchangeable() {
return options.size() > 1;
}
public ItemId preferred(InventoryState inventory) {
return Alternatives.preferred(options, inventory);
}
public String groupLabel() {
return Alternatives.commonPathLabel(options);
}
Set<ItemId> members() {
return Alternatives.members(options);
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) { if (this == o) {
@@ -30,11 +59,11 @@ public final class MissingMaterial {
if (!(o instanceof MissingMaterial other)) { if (!(o instanceof MissingMaterial other)) {
return false; return false;
} }
return quantity == other.quantity && item.equals(other.item); return quantity == other.quantity && members().equals(other.members());
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(item, quantity); return Objects.hash(quantity, members());
} }
} }
@@ -25,9 +25,9 @@ public final class ProgressCalculation {
List<MissingMaterial> missing = new ArrayList<>(); List<MissingMaterial> missing = new ArrayList<>();
for (MaterialRequirement requirement : aggregation.aggregate(all)) { for (MaterialRequirement requirement : aggregation.aggregate(all)) {
int stillNeeded = Math.max(0, requirement.quantity() - inventory.get(requirement.item())); int stillNeeded = Math.max(0, requirement.quantity() - inventory.getAny(requirement.options()));
if (stillNeeded > 0) { if (stillNeeded > 0) {
missing.add(new MissingMaterial(requirement.item(), stillNeeded)); missing.add(new MissingMaterial(requirement.options(), stillNeeded));
} }
} }
return new ProgressSnapshot(goals, missing); return new ProgressSnapshot(goals, missing);
@@ -4,9 +4,11 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.sufficient.satistaskory.domain.Goal; import com.sufficient.satistaskory.domain.Goal;
import com.sufficient.satistaskory.domain.InventoryState;
import com.sufficient.satistaskory.domain.ItemId; import com.sufficient.satistaskory.domain.ItemId;
import com.sufficient.satistaskory.domain.MissingMaterial; import com.sufficient.satistaskory.domain.MissingMaterial;
import com.sufficient.satistaskory.domain.ProgressSnapshot; import com.sufficient.satistaskory.domain.ProgressSnapshot;
import com.sufficient.satistaskory.infrastructure.inventory.PlayerInventoryAdapter;
import net.minecraft.client.DeltaTracker; import net.minecraft.client.DeltaTracker;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
@@ -84,8 +86,9 @@ public final class PlayOverlay {
if (snapshot.missing().isEmpty()) { if (snapshot.missing().isEmpty()) {
graphics.drawString(font, "Ready", x + PAD, cursor, 0xA0A0A0, false); graphics.drawString(font, "Ready", x + PAD, cursor, 0xA0A0A0, false);
} else { } else {
InventoryState inventory = PlayerInventoryAdapter.from(minecraft.player.getInventory());
for (MissingMaterial missing : snapshot.missing()) { for (MissingMaterial missing : snapshot.missing()) {
String name = displayName(missing.item()); String name = displayName(missing, inventory);
String qty = Integer.toString(missing.quantity()); String qty = Integer.toString(missing.quantity());
graphics.drawString(font, trim(font, name, WIDTH - PAD * 2 - 24), x + PAD, cursor, 0xFFFFFF, false); graphics.drawString(font, trim(font, name, WIDTH - PAD * 2 - 24), x + PAD, cursor, 0xFFFFFF, false);
graphics.drawString(font, qty, x + WIDTH - PAD - font.width(qty), cursor, 0xFFFFFF, false); graphics.drawString(font, qty, x + WIDTH - PAD - font.width(qty), cursor, 0xFFFFFF, false);
@@ -150,6 +153,16 @@ public final class PlayOverlay {
HITS.add(new Hit(x, y, x + w, y + h, kind, item)); HITS.add(new Hit(x, y, x + w, y + h, kind, item));
} }
private static String displayName(MissingMaterial missing, InventoryState inventory) {
if (missing.interchangeable() && inventory.getAny(missing.options()) == 0) {
String group = missing.groupLabel();
if (!group.isEmpty()) {
return titleCase(group);
}
}
return displayName(missing.preferred(inventory));
}
private static String displayName(ItemId id) { private static String displayName(ItemId id) {
ResourceLocation location = ResourceLocation.parse(id.toString()); ResourceLocation location = ResourceLocation.parse(id.toString());
Item item = BuiltInRegistries.ITEM.get(location); Item item = BuiltInRegistries.ITEM.get(location);
@@ -159,6 +172,23 @@ public final class PlayOverlay {
return item.getDescription().getString(); return item.getDescription().getString();
} }
private static String titleCase(String path) {
StringBuilder builder = new StringBuilder();
for (String part : path.split("_")) {
if (part.isEmpty()) {
continue;
}
if (builder.length() > 0) {
builder.append(' ');
}
builder.append(Character.toUpperCase(part.charAt(0)));
if (part.length() > 1) {
builder.append(part.substring(1));
}
}
return builder.toString();
}
private static String trim(Font font, String text, int maxWidth) { private static String trim(Font font, String text, int maxWidth) {
if (font.width(text) <= maxWidth) { if (font.width(text) <= maxWidth) {
return text; return text;
@@ -2,8 +2,11 @@ package com.sufficient.satistaskory.infrastructure.recipe;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Set;
import com.sufficient.satistaskory.domain.ItemId; import com.sufficient.satistaskory.domain.ItemId;
import com.sufficient.satistaskory.domain.MaterialRequirement; import com.sufficient.satistaskory.domain.MaterialRequirement;
@@ -23,7 +26,7 @@ import net.minecraft.world.item.crafting.RecipeType;
/** /**
* One crafting level from {@link RecipeManager}. All recipe types, by output. * One crafting level from {@link RecipeManager}. All recipe types, by output.
* Crafting-table recipes win when several match. Tags become the first concrete item. * Crafting-table recipes win when several match. Tags become one interchangeable requirement.
*/ */
public final class VanillaRecipeProvider implements RecipeProvider { public final class VanillaRecipeProvider implements RecipeProvider {
@Override @Override
@@ -50,24 +53,27 @@ public final class VanillaRecipeProvider implements RecipeProvider {
int outputCount = Math.max(1, result.getCount()); int outputCount = Math.max(1, result.getCount());
int crafts = (quantity + outputCount - 1) / outputCount; int crafts = (quantity + outputCount - 1) / outputCount;
Map<ItemId, Integer> counts = new LinkedHashMap<>(); Map<OptionGroup, Integer> counts = new LinkedHashMap<>();
for (Ingredient ingredient : chosen.value().getIngredients()) { for (Ingredient ingredient : chosen.value().getIngredients()) {
if (ingredient.isEmpty() || ingredient.hasNoItems()) { if (ingredient.isEmpty() || ingredient.hasNoItems()) {
continue; continue;
} }
ItemStack[] options = ingredient.getItems(); ItemStack[] stacks = ingredient.getItems();
if (options.length == 0) { if (stacks.length == 0) {
continue; continue;
} }
ItemStack option = options[0]; OptionGroup group = OptionGroup.of(stacks);
int perCraft = Math.max(1, option.getCount()); if (group.options.isEmpty()) {
counts.merge(itemId(option), perCraft * crafts, Integer::sum); continue;
}
int perCraft = Math.max(1, stacks[0].getCount());
counts.merge(group, perCraft * crafts, Integer::sum);
} }
if (counts.isEmpty()) { if (counts.isEmpty()) {
return gather(target, quantity); return gather(target, quantity);
} }
List<MaterialRequirement> requirements = new ArrayList<>(); List<MaterialRequirement> requirements = new ArrayList<>();
counts.forEach((id, count) -> requirements.add(new MaterialRequirement(id, count))); counts.forEach((group, count) -> requirements.add(new MaterialRequirement(group.options, count)));
return List.copyOf(requirements); return List.copyOf(requirements);
} }
@@ -101,4 +107,35 @@ public final class VanillaRecipeProvider implements RecipeProvider {
private static List<MaterialRequirement> gather(ItemId target, int quantity) { private static List<MaterialRequirement> gather(ItemId target, int quantity) {
return List.of(new MaterialRequirement(target, quantity)); return List.of(new MaterialRequirement(target, quantity));
} }
private static final class OptionGroup {
private final List<ItemId> options;
private final Set<ItemId> members;
private OptionGroup(List<ItemId> options) {
this.options = List.copyOf(options);
this.members = Set.copyOf(options);
}
static OptionGroup of(ItemStack[] stacks) {
LinkedHashSet<ItemId> ids = new LinkedHashSet<>();
for (ItemStack stack : stacks) {
if (stack.isEmpty()) {
continue;
}
ids.add(itemId(stack));
}
return new OptionGroup(List.copyOf(ids));
}
@Override
public boolean equals(Object o) {
return o instanceof OptionGroup other && members.equals(other.members);
}
@Override
public int hashCode() {
return Objects.hash(members);
}
}
} }
@@ -102,7 +102,7 @@ class PlannerTest {
private static int quantity(ProgressSnapshot snapshot, ItemId item) { private static int quantity(ProgressSnapshot snapshot, ItemId item) {
return snapshot.missing().stream() return snapshot.missing().stream()
.filter(missing -> missing.item().equals(item)) .filter(missing -> missing.options().contains(item))
.findFirst() .findFirst()
.orElseThrow() .orElseThrow()
.quantity(); .quantity();
@@ -0,0 +1,70 @@
package com.sufficient.satistaskory.domain;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;
class InterchangeableIngredientsTest {
private static final ItemId CHEST = ItemId.parse("minecraft:chest");
private static final ItemId TABLE = ItemId.parse("minecraft:crafting_table");
private static final ItemId OAK = ItemId.parse("minecraft:oak_planks");
private static final ItemId SPRUCE = ItemId.parse("minecraft:spruce_planks");
private static final ItemId BIRCH = ItemId.parse("minecraft:birch_planks");
private static final List<ItemId> PLANKS = List.of(OAK, SPRUCE, BIRCH);
private final ProgressCalculation progress = new ProgressCalculation(
new RecipeResolution((target, quantity) -> {
if (target.equals(CHEST)) {
return List.of(new MaterialRequirement(PLANKS, 8 * quantity));
}
if (target.equals(TABLE)) {
return List.of(new MaterialRequirement(PLANKS, 4 * quantity));
}
return List.of(new MaterialRequirement(target, quantity));
}),
new MaterialAggregation());
@Test
void spruceCoversAChest() {
InventoryState inventory = new InventoryState(Map.of(SPRUCE, 8));
ProgressSnapshot snapshot = progress.calculate(List.of(new Goal(CHEST, 1)), inventory);
assertTrue(snapshot.missing().isEmpty());
}
@Test
void mixedPlanksCoverAChest() {
InventoryState inventory = new InventoryState(Map.of(SPRUCE, 4, BIRCH, 4));
ProgressSnapshot snapshot = progress.calculate(List.of(new Goal(CHEST, 1)), inventory);
assertTrue(snapshot.missing().isEmpty());
}
@Test
void partialSpruceShowsRemainder() {
InventoryState inventory = new InventoryState(Map.of(SPRUCE, 3));
ProgressSnapshot snapshot = progress.calculate(List.of(new Goal(CHEST, 1)), inventory);
assertEquals(1, snapshot.missing().size());
assertEquals(5, snapshot.missing().getFirst().quantity());
assertEquals(SPRUCE, snapshot.missing().getFirst().preferred(inventory));
}
@Test
void chestAndTableShareOnePlankRow() {
ProgressSnapshot snapshot = progress.calculate(
List.of(new Goal(CHEST, 1), new Goal(TABLE, 1)),
InventoryState.empty());
assertEquals(1, snapshot.missing().size());
assertEquals(12, snapshot.missing().getFirst().quantity());
assertEquals("planks", snapshot.missing().getFirst().groupLabel());
}
@Test
void emptyInventoryPrefersOakAsFallback() {
MissingMaterial missing = new MissingMaterial(PLANKS, 8);
assertEquals(OAK, missing.preferred(InventoryState.empty()));
assertEquals("planks", missing.groupLabel());
}
}