Goals persist as a player attachment: load on join, write after each change, unload on leave so worlds do not leak. Dying does not wipe the list. Remote dedicated servers stay RAM-only.
This commit is contained in:
@@ -40,8 +40,8 @@ Read [[🧠 Philosophy]] before changing the vault. The Bookshelf Principle, Pre
|
|||||||
|
|
||||||
## Code
|
## Code
|
||||||
|
|
||||||
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.
|
The first slice is in code and has been played (ADRs 012–017): [[▶️ Create Goal]], [[🔌 Recipe Provider]] via `RecipeManager`, overlay HUD, capture = tooltip + rebindable Add key, player world save.
|
||||||
|
|
||||||
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.
|
Do not start EMI/JEI/REI. Recipe source is `RecipeManager` (ADR-016). Persistence is the player in this world (ADR-017). Project waits until settled. Do not rewrite the overlay as a `Screen` unless the HUD path fails.
|
||||||
|
|
||||||
The NeoForge template example block/item is gone. Do not put it back.
|
The NeoForge template example block/item is gone. Do not put it back.
|
||||||
|
|||||||
@@ -47,9 +47,9 @@ Those may be integrated with later. They are not owned by Satistaskory.
|
|||||||
|
|
||||||
## Status
|
## Status
|
||||||
|
|
||||||
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 `=`).
|
First slice is in `src/` and has been played: domain, `VanillaRecipeProvider` (`RecipeManager`, one level), player world save, 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.
|
`/satistaskory add minecraft:furnace` is a debug command. Not EMI. Template example block/item is gone.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ RefreshProgress
|
|||||||
missing = required − available
|
missing = required − available
|
||||||
```
|
```
|
||||||
|
|
||||||
Persistence: none in this slice. The list lives in memory.
|
Persistence: the player in this world's save (ADR-017). Leave the world and the overlay unloads; come back and the goals load.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -76,6 +76,8 @@ Do not start EMI. Do not start a planner menu.
|
|||||||
|
|
||||||
[[🔌 Recipe Provider]]
|
[[🔌 Recipe Provider]]
|
||||||
|
|
||||||
|
[[💾 Persistence]]
|
||||||
|
|
||||||
[[📈 Progress Calculation]]
|
[[📈 Progress Calculation]]
|
||||||
|
|
||||||
[[🖥️ Experience]]
|
[[🖥️ Experience]]
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ First use case: [[▶️ Create Goal]]. In code this slice is one `Planner` faca
|
|||||||
|
|
||||||
Mark Goal Complete is named. It is not in the first slice.
|
Mark Goal Complete is named. It is not in the first slice.
|
||||||
|
|
||||||
The application layer calls infrastructure through ports (`RecipeProvider`, inventory snapshot). It does not contain domain rules. It loads what the use case needs, asks the domain to decide, and presents the result. Persistence is in-memory for this slice.
|
The application layer calls infrastructure through ports (`RecipeProvider`, inventory snapshot, `GoalStore`). It does not contain domain rules. It loads what the use case needs, asks the domain to decide, and presents the result. Persistence is the player in this world's save (ADR-017).
|
||||||
|
|
||||||
Packages: [[📦 Packages]].
|
Packages: [[📦 Packages]].
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ Examples:
|
|||||||
- Save data storage
|
- Save data storage
|
||||||
- Inventory scanning
|
- Inventory scanning
|
||||||
|
|
||||||
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.
|
Shipped this slice: `VanillaRecipeProvider` (`RecipeManager`, all types, one level), player-inventory snapshot, HUD overlay, tooltip+key capture, player world save. `StubRecipeProvider` is unit tests only. EMI/JEI/REI are not dependencies.
|
||||||
|
|
||||||
Infrastructure is never the source of domain truth.
|
Infrastructure is never the source of domain truth.
|
||||||
|
|
||||||
@@ -147,7 +147,7 @@ Possible implementations:
|
|||||||
- Server Save
|
- Server Save
|
||||||
- Future Cloud Sync
|
- Future Cloud Sync
|
||||||
|
|
||||||
First slice: in-memory. No save adapter yet.
|
Shipped: player attachment in this world's save. Survives quit and death. Remote multiplayer stays RAM-only until a server adapter exists. See [[💾 Persistence]] and ADR-017.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -215,6 +215,10 @@ See [[🎯 Success Metrics]].
|
|||||||
|
|
||||||
[[🧾 Recipe Resolution]]
|
[[🧾 Recipe Resolution]]
|
||||||
|
|
||||||
|
[[💾 Persistence]]
|
||||||
|
|
||||||
|
[[🔌 Recipe Provider]]
|
||||||
|
|
||||||
[[🖥️ Experience]]
|
[[🖥️ Experience]]
|
||||||
|
|
||||||
[[🚶 Day in the Life]]
|
[[🚶 Day in the Life]]
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
# 💾 Persistence
|
||||||
|
|
||||||
|
Port used by [[▶️ Create Goal]] (and the sibling quantity / clear paths).
|
||||||
|
|
||||||
|
The domain does not know where the plan is stored (ADR-004). Infrastructure answers.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Shape
|
||||||
|
|
||||||
|
```text
|
||||||
|
GoalStore
|
||||||
|
all() / find / put / remove / clear
|
||||||
|
```
|
||||||
|
|
||||||
|
Play uses `PersistingGoalStore`: RAM plus a write after each change.
|
||||||
|
|
||||||
|
`InMemoryGoalStore` remains for unit tests.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Shipped implementation
|
||||||
|
|
||||||
|
Player attachment in **this world's save** (ADR-017).
|
||||||
|
|
||||||
|
| Event | Result |
|
||||||
|
|-------|--------|
|
||||||
|
| Join world | Load this player's goals |
|
||||||
|
| Create / + / − / Clear | Write the attachment |
|
||||||
|
| Leave world | Unload RAM. Do not write empty (that would wipe the save) |
|
||||||
|
| Death | Plan is copied. It is not loot |
|
||||||
|
|
||||||
|
Singleplayer and LAN host. Remote dedicated server: RAM-only this slice.
|
||||||
|
|
||||||
|
Server save and cloud remain possible later. They do not change `GoalStore`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Related Documents
|
||||||
|
|
||||||
|
[[🏛️ Architecture]]
|
||||||
|
|
||||||
|
[[📦 Packages]]
|
||||||
|
|
||||||
|
[[📝 Decisions]]
|
||||||
|
|
||||||
|
[[▶️ Create Goal]]
|
||||||
|
|
||||||
|
[[🎯 Goal]]
|
||||||
@@ -282,6 +282,27 @@ The port remains. The **order** was wrong.
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
### ADR-017 — First persistence is the player in this world
|
||||||
|
|
||||||
|
**Date:** 2026-09-08
|
||||||
|
|
||||||
|
**Decision:** Active goals persist as a NeoForge player attachment in the current world's save.
|
||||||
|
|
||||||
|
- Per player, not one list for the whole world
|
||||||
|
- Copy on death: dying does not wipe the plan
|
||||||
|
- Load on join, write after each change, unload RAM on leave so worlds do not leak
|
||||||
|
- Singleplayer and LAN host. A remote dedicated server has no integrated world save on the client; that session stays RAM-only until a server adapter exists
|
||||||
|
|
||||||
|
**Reason:**
|
||||||
|
|
||||||
|
The first slice is a prosthetic the player can quit and resume. ADR-004 named world save, server save, and cloud. World save is the one they play.
|
||||||
|
|
||||||
|
**Status:** ✅ Accepted
|
||||||
|
|
||||||
|
**Refines:** ADR-004. **Supersedes** ADR-013’s “Persistence: in-memory” freeze for this slice.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Related Documents
|
## Related Documents
|
||||||
|
|
||||||
[[🏛️ Architecture]]
|
[[🏛️ Architecture]]
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Java packages for the first slice. Root: `com.sufficient.satistaskory`.
|
Java packages for the first slice. Root: `com.sufficient.satistaskory`.
|
||||||
|
|
||||||
Rule #9: do not add a package until the slice needs it. No `project`, `emi`, or `persistence` until those are in the slice.
|
Rule #9: do not add a package until the slice needs it. No `project` or `emi` until those are in the slice.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -25,7 +25,8 @@ com.sufficient.satistaskory
|
|||||||
|
|
||||||
application/
|
application/
|
||||||
Planner # create / increment / decrement / clear / snapshot
|
Planner # create / increment / decrement / clear / snapshot
|
||||||
InMemoryGoalStore
|
GoalStore # port
|
||||||
|
InMemoryGoalStore # unit tests; inner store for persist
|
||||||
|
|
||||||
infrastructure/
|
infrastructure/
|
||||||
recipe/
|
recipe/
|
||||||
@@ -33,6 +34,10 @@ com.sufficient.satistaskory
|
|||||||
StubRecipeProvider # unit tests only
|
StubRecipeProvider # unit tests only
|
||||||
inventory/
|
inventory/
|
||||||
PlayerInventoryAdapter # player inventory → InventoryState
|
PlayerInventoryAdapter # player inventory → InventoryState
|
||||||
|
persistence/
|
||||||
|
GoalPlan # NBT codec
|
||||||
|
PersistingGoalStore
|
||||||
|
PlayerGoalPersistence # player attachment in this world
|
||||||
client/
|
client/
|
||||||
PlayOverlay # Screen 2 HUD (not a Screen)
|
PlayOverlay # Screen 2 HUD (not a Screen)
|
||||||
CaptureHook # tooltip + KeyMapping ADD_GOAL
|
CaptureHook # tooltip + KeyMapping ADD_GOAL
|
||||||
@@ -50,7 +55,6 @@ Dependencies point inward: `infrastructure` and `application` may import `domain
|
|||||||
|---------|-----|
|
|---------|-----|
|
||||||
| `Project` | Organizational only; not in the slice |
|
| `Project` | Organizational only; not in the slice |
|
||||||
| Completion strategy | Ready ≠ complete; complete is not in the slice |
|
| Completion strategy | Ready ≠ complete; complete is not in the slice |
|
||||||
| Persistence | In-memory goals. ADR-004 still holds; no save adapter yet |
|
|
||||||
| Full-screen planner | Not discovered |
|
| Full-screen planner | Not discovered |
|
||||||
|
|
||||||
The NeoForge template example block/item is gone. Do not put it back.
|
The NeoForge template example block/item is gone. Do not put it back.
|
||||||
@@ -65,6 +69,8 @@ The NeoForge template example block/item is gone. Do not put it back.
|
|||||||
|
|
||||||
[[🔌 Recipe Provider]]
|
[[🔌 Recipe Provider]]
|
||||||
|
|
||||||
|
[[💾 Persistence]]
|
||||||
|
|
||||||
[[🎯 Goal]]
|
[[🎯 Goal]]
|
||||||
|
|
||||||
[[📝 Decisions]]
|
[[📝 Decisions]]
|
||||||
|
|||||||
@@ -6,19 +6,19 @@ What exists, and what is next. Implementation detail will live in an Implementat
|
|||||||
|
|
||||||
## ✅ Now (docs)
|
## ✅ Now (docs)
|
||||||
|
|
||||||
- Philosophy Rules #1–#10; ADRs **001–016**
|
- Philosophy Rules #1–#10; ADRs **001–017**
|
||||||
- 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
|
||||||
- Experience: capture in place; overlay on the right (goals + aggregated needed counts)
|
- Experience: capture in place; overlay on the right (goals + aggregated needed counts)
|
||||||
|
|
||||||
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.
|
First slice **code exists** and has been played: domain, `VanillaRecipeProvider` (`RecipeManager`, all types, one level), player world save, player inventory, play overlay, hover + Add key.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🔲 Next
|
## 🔲 Next
|
||||||
|
|
||||||
1. World-save persistence
|
The frozen first slice is in play. Listen. Do not open Project, completion, or a Screen rewrite because the list is empty.
|
||||||
|
|
||||||
EMI is not a dependency. See ADR-016.
|
EMI is not a dependency. See ADR-016.
|
||||||
|
|
||||||
@@ -26,7 +26,9 @@ EMI is not a dependency. See ADR-016.
|
|||||||
|
|
||||||
## ⏸ Not opened
|
## ⏸ Not opened
|
||||||
|
|
||||||
- World save
|
- Project
|
||||||
|
- Completion
|
||||||
|
- Full-screen planner
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -35,7 +37,7 @@ EMI is not a dependency. See ADR-016.
|
|||||||
Not a queue. See [[🚧 Future Ideas]].
|
Not a queue. See [[🚧 Future Ideas]].
|
||||||
|
|
||||||
- Viewer-only recipe adapter if `RecipeManager` is not enough
|
- Viewer-only recipe adapter if `RecipeManager` is not enough
|
||||||
- Persistence (world / server / cloud)
|
- Persistence (server / cloud)
|
||||||
- Projects packaged
|
- Projects packaged
|
||||||
- Completion
|
- Completion
|
||||||
- Full-screen planner
|
- Full-screen planner
|
||||||
|
|||||||
@@ -367,6 +367,20 @@ Next is still world save. Not EMI. Not a Screen rewrite.
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## 📜 2026-09-08 (player world save)
|
||||||
|
|
||||||
|
Greetings, Wayfinder.
|
||||||
|
|
||||||
|
Recipes worked in play: spruce fence gate → sticks + spruce planks. The first slice's last freeze was persistence.
|
||||||
|
|
||||||
|
ADR-017: the plan lives on the player in this world's save. Copy on death. Unload RAM when leaving so World B does not inherit World A. Remote dedicated server is still RAM-only.
|
||||||
|
|
||||||
|
The frozen slice is now: name a goal, see missing materials, quit, come back, still see them.
|
||||||
|
|
||||||
|
Do not open Project because that feels like "what's next." Listen.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Related Documents
|
## Related Documents
|
||||||
|
|
||||||
[[🌟 Project Vision]]
|
[[🌟 Project Vision]]
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Not a build queue.
|
|||||||
---
|
---
|
||||||
|
|
||||||
- Viewer-only recipe adapter (EMI/JEI/REI) **if** a recipe never appears in `RecipeManager`
|
- Viewer-only recipe adapter (EMI/JEI/REI) **if** a recipe never appears in `RecipeManager`
|
||||||
- Persistence (world save / server / cloud)
|
- Persistence (server save / cloud)
|
||||||
- Inventory-detection completion (alongside manual)
|
- Inventory-detection completion (alongside manual)
|
||||||
- Ender chest / later storage in the inventory snapshot
|
- Ender chest / later storage in the inventory snapshot
|
||||||
- Projects packaged
|
- Projects packaged
|
||||||
|
|||||||
@@ -4,16 +4,32 @@ import org.slf4j.Logger;
|
|||||||
|
|
||||||
import com.mojang.logging.LogUtils;
|
import com.mojang.logging.LogUtils;
|
||||||
|
|
||||||
|
import com.sufficient.satistaskory.infrastructure.persistence.GoalPlan;
|
||||||
|
|
||||||
import net.neoforged.bus.api.IEventBus;
|
import net.neoforged.bus.api.IEventBus;
|
||||||
import net.neoforged.fml.ModContainer;
|
import net.neoforged.fml.ModContainer;
|
||||||
import net.neoforged.fml.common.Mod;
|
import net.neoforged.fml.common.Mod;
|
||||||
|
import net.neoforged.neoforge.attachment.AttachmentType;
|
||||||
|
import net.neoforged.neoforge.registries.DeferredHolder;
|
||||||
|
import net.neoforged.neoforge.registries.DeferredRegister;
|
||||||
|
import net.neoforged.neoforge.registries.NeoForgeRegistries;
|
||||||
|
|
||||||
@Mod(Satistaskory.MODID)
|
@Mod(Satistaskory.MODID)
|
||||||
public class Satistaskory {
|
public class Satistaskory {
|
||||||
public static final String MODID = "satistaskory";
|
public static final String MODID = "satistaskory";
|
||||||
public static final Logger LOGGER = LogUtils.getLogger();
|
public static final Logger LOGGER = LogUtils.getLogger();
|
||||||
|
|
||||||
|
public static final DeferredRegister<AttachmentType<?>> ATTACHMENT_TYPES =
|
||||||
|
DeferredRegister.create(NeoForgeRegistries.Keys.ATTACHMENT_TYPES, MODID);
|
||||||
|
|
||||||
|
public static final DeferredHolder<AttachmentType<?>, AttachmentType<GoalPlan>> PLAYER_GOALS =
|
||||||
|
ATTACHMENT_TYPES.register("player_goals", () -> AttachmentType.builder(GoalPlan::empty)
|
||||||
|
.serialize(GoalPlan.CODEC)
|
||||||
|
.copyOnDeath()
|
||||||
|
.build());
|
||||||
|
|
||||||
public Satistaskory(IEventBus modEventBus, ModContainer modContainer) {
|
public Satistaskory(IEventBus modEventBus, ModContainer modContainer) {
|
||||||
|
ATTACHMENT_TYPES.register(modEventBus);
|
||||||
LOGGER.info("Satistaskory loaded. Goals are the domain.");
|
LOGGER.info("Satistaskory loaded. Goals are the domain.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import net.neoforged.bus.api.SubscribeEvent;
|
|||||||
import net.neoforged.fml.ModContainer;
|
import net.neoforged.fml.ModContainer;
|
||||||
import net.neoforged.fml.common.EventBusSubscriber;
|
import net.neoforged.fml.common.EventBusSubscriber;
|
||||||
import net.neoforged.fml.common.Mod;
|
import net.neoforged.fml.common.Mod;
|
||||||
|
import net.neoforged.neoforge.client.event.ClientPlayerNetworkEvent;
|
||||||
import net.neoforged.neoforge.client.event.InputEvent;
|
import net.neoforged.neoforge.client.event.InputEvent;
|
||||||
import net.neoforged.neoforge.client.event.RegisterClientCommandsEvent;
|
import net.neoforged.neoforge.client.event.RegisterClientCommandsEvent;
|
||||||
import net.neoforged.neoforge.client.event.RegisterGuiLayersEvent;
|
import net.neoforged.neoforge.client.event.RegisterGuiLayersEvent;
|
||||||
@@ -39,6 +40,16 @@ public class SatistaskoryClient {
|
|||||||
|
|
||||||
@EventBusSubscriber(modid = Satistaskory.MODID, value = Dist.CLIENT)
|
@EventBusSubscriber(modid = Satistaskory.MODID, value = Dist.CLIENT)
|
||||||
public static class GameEvents {
|
public static class GameEvents {
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onJoinWorld(ClientPlayerNetworkEvent.LoggingIn event) {
|
||||||
|
PlannerSession.onJoinWorld();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onLeaveWorld(ClientPlayerNetworkEvent.LoggingOut event) {
|
||||||
|
PlannerSession.onLeaveWorld();
|
||||||
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onClientCommands(RegisterClientCommandsEvent event) {
|
public static void onClientCommands(RegisterClientCommandsEvent event) {
|
||||||
ClientCommands.register(event.getDispatcher());
|
ClientCommands.register(event.getDispatcher());
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.sufficient.satistaskory.application;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import com.sufficient.satistaskory.domain.Goal;
|
||||||
|
import com.sufficient.satistaskory.domain.ItemId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Where active goals live. Domain does not know the backing store (ADR-004).
|
||||||
|
*/
|
||||||
|
public interface GoalStore {
|
||||||
|
List<Goal> all();
|
||||||
|
|
||||||
|
Optional<Goal> find(ItemId item);
|
||||||
|
|
||||||
|
void put(Goal goal);
|
||||||
|
|
||||||
|
void remove(ItemId item);
|
||||||
|
|
||||||
|
void clear();
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@ import java.util.Optional;
|
|||||||
import com.sufficient.satistaskory.domain.Goal;
|
import com.sufficient.satistaskory.domain.Goal;
|
||||||
import com.sufficient.satistaskory.domain.ItemId;
|
import com.sufficient.satistaskory.domain.ItemId;
|
||||||
|
|
||||||
public final class InMemoryGoalStore {
|
public final class InMemoryGoalStore implements GoalStore {
|
||||||
private final List<Goal> goals = new ArrayList<>();
|
private final List<Goal> goals = new ArrayList<>();
|
||||||
|
|
||||||
public List<Goal> all() {
|
public List<Goal> all() {
|
||||||
|
|||||||
@@ -10,14 +10,14 @@ import com.sufficient.satistaskory.domain.ProgressCalculation;
|
|||||||
import com.sufficient.satistaskory.domain.ProgressSnapshot;
|
import com.sufficient.satistaskory.domain.ProgressSnapshot;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Application facade for the first slice. Persistence is this store, in RAM.
|
* Application facade for the first slice. Persistence is the store's job.
|
||||||
*/
|
*/
|
||||||
public final class Planner {
|
public final class Planner {
|
||||||
private final InMemoryGoalStore store;
|
private final GoalStore store;
|
||||||
private final ProgressCalculation progress;
|
private final ProgressCalculation progress;
|
||||||
private final Supplier<InventoryState> inventory;
|
private final Supplier<InventoryState> inventory;
|
||||||
|
|
||||||
public Planner(InMemoryGoalStore store, ProgressCalculation progress, Supplier<InventoryState> inventory) {
|
public Planner(GoalStore store, ProgressCalculation progress, Supplier<InventoryState> inventory) {
|
||||||
this.store = Objects.requireNonNull(store, "store");
|
this.store = Objects.requireNonNull(store, "store");
|
||||||
this.progress = Objects.requireNonNull(progress, "progress");
|
this.progress = Objects.requireNonNull(progress, "progress");
|
||||||
this.inventory = Objects.requireNonNull(inventory, "inventory");
|
this.inventory = Objects.requireNonNull(inventory, "inventory");
|
||||||
|
|||||||
+17
-3
@@ -1,21 +1,23 @@
|
|||||||
package com.sufficient.satistaskory.infrastructure.client;
|
package com.sufficient.satistaskory.infrastructure.client;
|
||||||
|
|
||||||
import com.sufficient.satistaskory.application.InMemoryGoalStore;
|
|
||||||
import com.sufficient.satistaskory.application.Planner;
|
import com.sufficient.satistaskory.application.Planner;
|
||||||
import com.sufficient.satistaskory.domain.InventoryState;
|
import com.sufficient.satistaskory.domain.InventoryState;
|
||||||
import com.sufficient.satistaskory.domain.MaterialAggregation;
|
import com.sufficient.satistaskory.domain.MaterialAggregation;
|
||||||
import com.sufficient.satistaskory.domain.ProgressCalculation;
|
import com.sufficient.satistaskory.domain.ProgressCalculation;
|
||||||
import com.sufficient.satistaskory.domain.RecipeResolution;
|
import com.sufficient.satistaskory.domain.RecipeResolution;
|
||||||
import com.sufficient.satistaskory.infrastructure.inventory.PlayerInventoryAdapter;
|
import com.sufficient.satistaskory.infrastructure.inventory.PlayerInventoryAdapter;
|
||||||
|
import com.sufficient.satistaskory.infrastructure.persistence.PersistingGoalStore;
|
||||||
|
import com.sufficient.satistaskory.infrastructure.persistence.PlayerGoalPersistence;
|
||||||
import com.sufficient.satistaskory.infrastructure.recipe.VanillaRecipeProvider;
|
import com.sufficient.satistaskory.infrastructure.recipe.VanillaRecipeProvider;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.player.LocalPlayer;
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client-side in-memory plan. Gone when the game restarts.
|
* Client plan for the current world. Written to the player in this world's save.
|
||||||
*/
|
*/
|
||||||
public final class PlannerSession {
|
public final class PlannerSession {
|
||||||
|
private static PersistingGoalStore store;
|
||||||
private static Planner planner;
|
private static Planner planner;
|
||||||
|
|
||||||
private PlannerSession() {}
|
private PlannerSession() {}
|
||||||
@@ -26,7 +28,8 @@ public final class PlannerSession {
|
|||||||
}
|
}
|
||||||
RecipeResolution resolution = new RecipeResolution(new VanillaRecipeProvider());
|
RecipeResolution resolution = new RecipeResolution(new VanillaRecipeProvider());
|
||||||
ProgressCalculation progress = new ProgressCalculation(resolution, new MaterialAggregation());
|
ProgressCalculation progress = new ProgressCalculation(resolution, new MaterialAggregation());
|
||||||
planner = new Planner(new InMemoryGoalStore(), progress, PlannerSession::currentInventory);
|
store = new PersistingGoalStore();
|
||||||
|
planner = new Planner(store, progress, PlannerSession::currentInventory);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Planner get() {
|
public static Planner get() {
|
||||||
@@ -36,6 +39,17 @@ public final class PlannerSession {
|
|||||||
return planner;
|
return planner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void onJoinWorld() {
|
||||||
|
bootstrap();
|
||||||
|
store.loadFromWorld(PlayerGoalPersistence.load());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onLeaveWorld() {
|
||||||
|
if (store != null) {
|
||||||
|
store.unload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static InventoryState currentInventory() {
|
private static InventoryState currentInventory() {
|
||||||
LocalPlayer player = Minecraft.getInstance().player;
|
LocalPlayer player = Minecraft.getInstance().player;
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package com.sufficient.satistaskory.infrastructure.persistence;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||||
|
|
||||||
|
import com.sufficient.satistaskory.domain.Goal;
|
||||||
|
import com.sufficient.satistaskory.domain.ItemId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NBT shape for the player's goal list. Not a domain type.
|
||||||
|
*/
|
||||||
|
public record GoalPlan(List<GoalEntry> goals) {
|
||||||
|
public static final GoalPlan EMPTY = new GoalPlan(List.of());
|
||||||
|
|
||||||
|
public static final Codec<GoalPlan> CODEC = RecordCodecBuilder.create(instance -> instance.group(
|
||||||
|
GoalEntry.CODEC.listOf().fieldOf("goals").forGetter(GoalPlan::goals)
|
||||||
|
).apply(instance, GoalPlan::new));
|
||||||
|
|
||||||
|
public GoalPlan {
|
||||||
|
goals = List.copyOf(goals);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GoalPlan empty() {
|
||||||
|
return EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GoalPlan fromGoals(List<Goal> goals) {
|
||||||
|
List<GoalEntry> entries = new ArrayList<>(goals.size());
|
||||||
|
for (Goal goal : goals) {
|
||||||
|
entries.add(new GoalEntry(goal.targetItem().toString(), goal.quantity()));
|
||||||
|
}
|
||||||
|
return new GoalPlan(entries);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Goal> toGoals() {
|
||||||
|
List<Goal> result = new ArrayList<>();
|
||||||
|
for (GoalEntry entry : goals) {
|
||||||
|
if (entry.quantity() < 1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
result.add(new Goal(ItemId.parse(entry.item()), entry.quantity()));
|
||||||
|
} catch (IllegalArgumentException ignored) {
|
||||||
|
// skip a corrupt row; do not fail the world
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public record GoalEntry(String item, int quantity) {
|
||||||
|
public static final Codec<GoalEntry> CODEC = RecordCodecBuilder.create(instance -> instance.group(
|
||||||
|
Codec.STRING.fieldOf("item").forGetter(GoalEntry::item),
|
||||||
|
Codec.INT.fieldOf("quantity").forGetter(GoalEntry::quantity)
|
||||||
|
).apply(instance, GoalEntry::new));
|
||||||
|
}
|
||||||
|
}
|
||||||
+67
@@ -0,0 +1,67 @@
|
|||||||
|
package com.sufficient.satistaskory.infrastructure.persistence;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import com.sufficient.satistaskory.application.GoalStore;
|
||||||
|
import com.sufficient.satistaskory.application.InMemoryGoalStore;
|
||||||
|
import com.sufficient.satistaskory.domain.Goal;
|
||||||
|
import com.sufficient.satistaskory.domain.ItemId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RAM store that writes the player's world save after each change.
|
||||||
|
* Load and leave-world must not write; otherwise logout would wipe the save.
|
||||||
|
*/
|
||||||
|
public final class PersistingGoalStore implements GoalStore {
|
||||||
|
private final InMemoryGoalStore inner = new InMemoryGoalStore();
|
||||||
|
private boolean persist = true;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Goal> all() {
|
||||||
|
return inner.all();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Goal> find(ItemId item) {
|
||||||
|
return inner.find(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void put(Goal goal) {
|
||||||
|
inner.put(goal);
|
||||||
|
persist();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove(ItemId item) {
|
||||||
|
inner.remove(item);
|
||||||
|
persist();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
inner.clear();
|
||||||
|
persist();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadFromWorld(List<Goal> goals) {
|
||||||
|
persist = false;
|
||||||
|
inner.clear();
|
||||||
|
for (Goal goal : goals) {
|
||||||
|
inner.put(goal);
|
||||||
|
}
|
||||||
|
persist = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unload() {
|
||||||
|
persist = false;
|
||||||
|
inner.clear();
|
||||||
|
persist = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void persist() {
|
||||||
|
if (persist) {
|
||||||
|
PlayerGoalPersistence.save(inner.all());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+49
@@ -0,0 +1,49 @@
|
|||||||
|
package com.sufficient.satistaskory.infrastructure.persistence;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import com.sufficient.satistaskory.Satistaskory;
|
||||||
|
import com.sufficient.satistaskory.domain.Goal;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.server.IntegratedServer;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Player attachment in this world's save. Singleplayer and LAN host.
|
||||||
|
* A remote server has no integrated save; the session stays RAM-only there.
|
||||||
|
*/
|
||||||
|
public final class PlayerGoalPersistence {
|
||||||
|
private PlayerGoalPersistence() {}
|
||||||
|
|
||||||
|
public static List<Goal> load() {
|
||||||
|
Minecraft minecraft = Minecraft.getInstance();
|
||||||
|
IntegratedServer server = minecraft.getSingleplayerServer();
|
||||||
|
if (server == null || minecraft.player == null) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
ServerPlayer player = server.getPlayerList().getPlayer(minecraft.player.getUUID());
|
||||||
|
if (player == null) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
return player.getData(Satistaskory.PLAYER_GOALS).toGoals();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void save(List<Goal> goals) {
|
||||||
|
Minecraft minecraft = Minecraft.getInstance();
|
||||||
|
IntegratedServer server = minecraft.getSingleplayerServer();
|
||||||
|
if (server == null || minecraft.player == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
UUID id = minecraft.player.getUUID();
|
||||||
|
GoalPlan plan = GoalPlan.fromGoals(goals);
|
||||||
|
server.execute(() -> {
|
||||||
|
ServerPlayer player = server.getPlayerList().getPlayer(id);
|
||||||
|
if (player == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
player.setData(Satistaskory.PLAYER_GOALS, plan);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
package com.sufficient.satistaskory.infrastructure.persistence;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import com.sufficient.satistaskory.domain.Goal;
|
||||||
|
import com.sufficient.satistaskory.domain.ItemId;
|
||||||
|
import com.sufficient.satistaskory.infrastructure.persistence.GoalPlan.GoalEntry;
|
||||||
|
|
||||||
|
class GoalPlanTest {
|
||||||
|
private static final ItemId FURNACE = ItemId.parse("minecraft:furnace");
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void roundTripKeepsItemAndQuantity() {
|
||||||
|
GoalPlan plan = GoalPlan.fromGoals(List.of(new Goal(FURNACE, 3)));
|
||||||
|
List<Goal> goals = plan.toGoals();
|
||||||
|
assertEquals(1, goals.size());
|
||||||
|
assertEquals(FURNACE, goals.getFirst().targetItem());
|
||||||
|
assertEquals(3, goals.getFirst().quantity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void skipsCorruptRows() {
|
||||||
|
GoalPlan plan = new GoalPlan(List.of(
|
||||||
|
new GoalEntry("minecraft:furnace", 2),
|
||||||
|
new GoalEntry("not-an-id", 1),
|
||||||
|
new GoalEntry("minecraft:chest", 0)));
|
||||||
|
List<Goal> goals = plan.toGoals();
|
||||||
|
assertEquals(1, goals.size());
|
||||||
|
assertEquals(FURNACE, goals.getFirst().targetItem());
|
||||||
|
assertEquals(2, goals.getFirst().quantity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void emptyPlanIsEmpty() {
|
||||||
|
assertTrue(GoalPlan.empty().toGoals().isEmpty());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user