Step goal quantity by one recipe's output, not always 1.
Build / build (push) Failing after 30s

Capture, +, and - use RecipeProvider.outputCount. Planks move by 4. Gather stays 1. Minus at or below one yield removes the goal.
This commit is contained in:
Stephen Fasciani
2026-09-09 01:40:16 -04:00
parent d0033d613a
commit 3beaa12706
21 changed files with 128 additions and 35 deletions
@@ -9,6 +9,7 @@ import com.sufficient.satistaskory.domain.InventoryState;
import com.sufficient.satistaskory.domain.ItemId;
import com.sufficient.satistaskory.domain.ProgressCalculation;
import com.sufficient.satistaskory.domain.ProgressSnapshot;
import com.sufficient.satistaskory.domain.RecipeResolution;
/**
* Application facade for the first slice. Persistence is the store's job.
@@ -17,11 +18,17 @@ public final class Planner {
private final GoalStore store;
private final ProgressCalculation progress;
private final Supplier<InventoryState> inventory;
private final RecipeResolution resolution;
public Planner(GoalStore store, ProgressCalculation progress, Supplier<InventoryState> inventory) {
public Planner(
GoalStore store,
ProgressCalculation progress,
Supplier<InventoryState> inventory,
RecipeResolution resolution) {
this.store = Objects.requireNonNull(store, "store");
this.progress = Objects.requireNonNull(progress, "progress");
this.inventory = Objects.requireNonNull(inventory, "inventory");
this.resolution = Objects.requireNonNull(resolution, "resolution");
}
public List<Goal> goals() {
@@ -34,25 +41,28 @@ public final class Planner {
public ProgressSnapshot create(ItemId item) {
Objects.requireNonNull(item, "item");
int step = step(item);
store.find(item).ifPresentOrElse(
existing -> store.put(existing.increment()),
() -> store.put(new Goal(item, 1)));
existing -> store.put(existing.plus(step)),
() -> store.put(new Goal(item, step)));
return refresh();
}
public ProgressSnapshot increment(ItemId item) {
Objects.requireNonNull(item, "item");
store.find(item).ifPresent(existing -> store.put(existing.increment()));
int step = step(item);
store.find(item).ifPresent(existing -> store.put(existing.plus(step)));
return refresh();
}
public ProgressSnapshot decrement(ItemId item) {
Objects.requireNonNull(item, "item");
int step = step(item);
store.find(item).ifPresent(existing -> {
if (existing.quantity() == 1) {
if (existing.quantity() <= step) {
store.remove(item);
} else {
store.put(existing.decrement());
store.put(new Goal(item, existing.quantity() - step));
}
});
return refresh();
@@ -87,6 +97,10 @@ public final class Planner {
});
}
private int step(ItemId item) {
return resolution.outputCount(item);
}
private ProgressSnapshot refresh() {
return progress.calculate(store.all(), inventory.get());
}
@@ -26,7 +26,14 @@ public final class Goal {
}
public Goal increment() {
return new Goal(targetItem, quantity + 1);
return plus(1);
}
public Goal plus(int amount) {
if (amount < 1) {
throw new IllegalArgumentException("amount must be >= 1");
}
return new Goal(targetItem, quantity + amount);
}
public Goal decrement() {
@@ -11,4 +11,11 @@ public interface RecipeProvider {
* One crafting level. No recipe → {@code (target, quantity)}. {@code quantity < 1} → empty.
*/
List<MaterialRequirement> resolve(ItemId target, int quantity);
/**
* How many of {@code target} one recipe produces. Gather / unknown → 1.
*/
default int outputCount(ItemId target) {
return 1;
}
}
@@ -16,4 +16,8 @@ public final class RecipeResolution {
}
return provider.resolve(target, quantity);
}
public int outputCount(ItemId target) {
return Math.max(1, provider.outputCount(target));
}
}
@@ -32,7 +32,7 @@ public final class PlannerSession {
RecipeResolution resolution = new RecipeResolution(new VanillaRecipeProvider());
ProgressCalculation progress = new ProgressCalculation(resolution, new MaterialAggregation());
store = new PersistingGoalStore();
planner = new Planner(store, progress, PlannerSession::currentInventory);
planner = new Planner(store, progress, PlannerSession::currentInventory, resolution);
ClientSettings.load();
obtained.reset();
}
@@ -18,6 +18,7 @@ public final class StubRecipeProvider implements RecipeProvider {
private static final ItemId CHEST = ItemId.parse("minecraft:chest");
private static final ItemId COBBLESTONE = ItemId.parse("minecraft:cobblestone");
private static final ItemId OAK_PLANKS = ItemId.parse("minecraft:oak_planks");
private static final ItemId OAK_LOG = ItemId.parse("minecraft:oak_log");
private final Map<ItemId, Recipe> recipes = new HashMap<>();
@@ -25,6 +26,13 @@ public final class StubRecipeProvider implements RecipeProvider {
recipes.put(FURNACE, new Recipe(1, List.of(new MaterialRequirement(COBBLESTONE, 8))));
recipes.put(CRAFTING_TABLE, new Recipe(1, List.of(new MaterialRequirement(OAK_PLANKS, 4))));
recipes.put(CHEST, new Recipe(1, List.of(new MaterialRequirement(OAK_PLANKS, 8))));
recipes.put(OAK_PLANKS, new Recipe(4, List.of(new MaterialRequirement(OAK_LOG, 1))));
}
@Override
public int outputCount(ItemId target) {
Recipe recipe = recipes.get(target);
return recipe == null ? 1 : recipe.outputCount();
}
@Override
@@ -34,20 +34,11 @@ public final class VanillaRecipeProvider implements RecipeProvider {
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);
RecipeHolder<?> chosen = chosen(target);
if (chosen == null) {
return gather(target, quantity);
}
HolderLookup.Provider registries = Minecraft.getInstance().level.registryAccess();
ItemStack result = chosen.value().getResultItem(registries);
int outputCount = Math.max(1, result.getCount());
@@ -77,6 +68,28 @@ public final class VanillaRecipeProvider implements RecipeProvider {
return List.copyOf(requirements);
}
@Override
public int outputCount(ItemId target) {
RecipeHolder<?> chosen = chosen(target);
if (chosen == null) {
return 1;
}
ItemStack result = chosen.value().getResultItem(Minecraft.getInstance().level.registryAccess());
return Math.max(1, result.getCount());
}
private static RecipeHolder<?> chosen(ItemId target) {
Minecraft minecraft = Minecraft.getInstance();
if (minecraft.level == null) {
return null;
}
Item item = BuiltInRegistries.ITEM.get(ResourceLocation.parse(target.toString()));
if (item == Items.AIR && !target.toString().equals("minecraft:air")) {
return null;
}
return pick(minecraft.level.getRecipeManager(), minecraft.level.registryAccess(), item);
}
private static RecipeHolder<?> pick(RecipeManager manager, HolderLookup.Provider registries, Item target) {
RecipeHolder<?> best = null;
int bestScore = Integer.MIN_VALUE;
@@ -25,7 +25,7 @@ class ObtainedCompletionTest {
void setUp() {
RecipeResolution resolution = new RecipeResolution(new StubRecipeProvider());
ProgressCalculation progress = new ProgressCalculation(resolution, new MaterialAggregation());
planner = new Planner(new InMemoryGoalStore(), progress, InventoryState::empty);
planner = new Planner(new InMemoryGoalStore(), progress, InventoryState::empty, resolution);
completion = new ObtainedCompletion();
}
@@ -32,7 +32,7 @@ class PlannerTest {
inventory = InventoryState.empty();
RecipeResolution resolution = new RecipeResolution(new StubRecipeProvider());
ProgressCalculation progress = new ProgressCalculation(resolution, new MaterialAggregation());
planner = new Planner(new InMemoryGoalStore(), progress, () -> inventory);
planner = new Planner(new InMemoryGoalStore(), progress, () -> inventory, resolution);
}
@Test
@@ -43,6 +43,17 @@ class PlannerTest {
assertEquals(2, second.goals().getFirst().quantity());
}
@Test
void plusStepsByRecipeOutput() {
planner.create(OAK_PLANKS);
assertEquals(4, planner.goals().getFirst().quantity());
planner.increment(OAK_PLANKS);
assertEquals(8, planner.goals().getFirst().quantity());
planner.decrement(OAK_PLANKS);
assertEquals(4, planner.goals().getFirst().quantity());
assertTrue(planner.decrement(OAK_PLANKS).goals().isEmpty());
}
@Test
void decrementAtOneRemoves() {
planner.create(FURNACE);