Strip the template example block. Create Goal lives in memory, recipes are a stub, the play overlay sits on the right, and /satistaskory add is the first capture path. Restarting the world forgets the plan.
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 settled (ADRs 012–014): [[▶️ Create Goal]], stub [[🔌 Recipe Provider]], player inventory, play overlay.
|
The first slice is in code (ADRs 012–014): [[▶️ Create Goal]], stub [[🔌 Recipe Provider]], player inventory, play overlay.
|
||||||
|
|
||||||
Domain code for that slice may start. Do not start EMI, persistence, or Project until those are settled in the vault.
|
Do not start EMI, persistence, or Project until those are settled in the vault.
|
||||||
|
|
||||||
The NeoForge template example block/item is not the architecture. Remove it when domain types land.
|
The NeoForge template example block/item is gone. Do not put it back.
|
||||||
|
|||||||
@@ -47,11 +47,9 @@ Those may be integrated with later. They are not owned by Satistaskory.
|
|||||||
|
|
||||||
## Status
|
## Status
|
||||||
|
|
||||||
The domain, architecture, player day, packages, RecipeProvider port, and **Create Goal** use case are documented. Domain code is not written.
|
First slice is in `src/`: domain types, stub recipes, in-memory Create Goal, player inventory, play overlay on the right.
|
||||||
|
|
||||||
The NeoForge template example block and item in `src/` are not the architecture.
|
Add a goal with `/satistaskory add minecraft:furnace`. The plan is RAM-only. Not EMI. Template example block/item is gone.
|
||||||
|
|
||||||
Next: write the first slice — domain types, stub RecipeProvider, Create Goal, player inventory, play overlay. Not EMI.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
+7
-6
@@ -96,14 +96,11 @@ configurations {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// Specify the version of Minecraft to use.
|
|
||||||
// Depending on the plugin applied there are several options. We will assume you applied the userdev plugin as shown above.
|
|
||||||
// The group for userdev is net.neoforged, the module name is neoforge, and the version is the same as the neoforge version.
|
|
||||||
// You can however also use the vanilla plugin (net.neoforged.gradle.vanilla) to use a version of Minecraft without the neoforge loader.
|
|
||||||
// And its provides the option to then use net.minecraft as the group, and one of; client, server or joined as the module name, plus the game version as version.
|
|
||||||
// For all intends and purposes: You can treat this dependency as if it is a normal library you would use.
|
|
||||||
implementation "net.neoforged:neoforge:${neo_version}"
|
implementation "net.neoforged:neoforge:${neo_version}"
|
||||||
|
|
||||||
|
testImplementation "org.junit.jupiter:junit-jupiter:5.10.2"
|
||||||
|
testRuntimeOnly "org.junit.platform:junit-platform-launcher:1.10.2"
|
||||||
|
|
||||||
// Example optional mod dependency with JEI
|
// Example optional mod dependency with JEI
|
||||||
// The JEI API is declared for compile time use, while the full JEI artifact is used at runtime
|
// The JEI API is declared for compile time use, while the full JEI artifact is used at runtime
|
||||||
// compileOnly "mezz.jei:jei-${mc_version}-common-api:${jei_version}"
|
// compileOnly "mezz.jei:jei-${mc_version}-common-api:${jei_version}"
|
||||||
@@ -168,6 +165,10 @@ tasks.withType(JavaCompile).configureEach {
|
|||||||
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
|
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.withType(Test).configureEach {
|
||||||
|
useJUnitPlatform()
|
||||||
|
}
|
||||||
|
|
||||||
// IDEA no longer automatically downloads sources/javadoc jars for dependencies, so we need to explicitly enable the behavior.
|
// IDEA no longer automatically downloads sources/javadoc jars for dependencies, so we need to explicitly enable the behavior.
|
||||||
idea {
|
idea {
|
||||||
module {
|
module {
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ Vision, philosophy, language, and an architecture scaffold exist.
|
|||||||
|
|
||||||
A player day exists: name a goal by pointing at an item; walk with missing materials on the play screen. See [[🚶 Day in the Life]].
|
A player day exists: name a goal by pointing at an item; walk with missing materials on the play screen. See [[🚶 Day in the Life]].
|
||||||
|
|
||||||
The first slice is settled in the vault: [[▶️ Create Goal]], stub [[🔌 Recipe Provider]], play overlay. Domain code is not written yet.
|
The first slice is in code: [[▶️ Create Goal]], stub [[🔌 Recipe Provider]], play overlay. Capture is `/satistaskory add`. RAM only.
|
||||||
|
|
||||||
See [[🗺️ Roadmap]].
|
See [[🗺️ Roadmap]].
|
||||||
|
|
||||||
|
|||||||
@@ -12,27 +12,26 @@ What exists, and what is next. Implementation detail will live in an Implementat
|
|||||||
- 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)
|
||||||
|
|
||||||
Domain code does not exist. The NeoForge template example block/item is not the architecture.
|
First slice **code exists**: domain, stub `RecipeProvider`, in-memory Create Goal, player inventory, play overlay. Capture is `/satistaskory add <item>`. Plan does not survive restart.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🔲 Next
|
## 🔲 Next
|
||||||
|
|
||||||
The first slice is settled. **Write the code** for that slice. Do not start EMI.
|
Play the slice. Then, only if the walk is real:
|
||||||
|
|
||||||
1. Packages + domain types (`ItemId`, `Goal`, `MaterialRequirement`, `InventoryState`)
|
1. Hover-add on one inventory host (the other two later)
|
||||||
2. `RecipeProvider` + `StubRecipeProvider`
|
2. World-save persistence
|
||||||
3. **Create Goal** (and Adjust / Remove / Clear / Refresh Progress)
|
3. Real recipe adapter (still not required to start with EMI)
|
||||||
4. Player-inventory snapshot
|
|
||||||
5. Play overlay (right side)
|
|
||||||
|
|
||||||
`🌾 Implementation Plan` opens when that code starts — not before.
|
Do not start EMI because the port exists.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## ⏸ Not opened
|
## ⏸ Not opened
|
||||||
|
|
||||||
- `🌾 Implementation Plan` — nothing is shipped to map
|
- Hover-add on inventory / bench / craft book
|
||||||
|
- World save
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -271,6 +271,31 @@ Avoid:
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## 📜 2026-09-08 (the first slice)
|
||||||
|
|
||||||
|
Greetings, Wayfinder.
|
||||||
|
|
||||||
|
The example block is gone. Domain types live under `com.sufficient.satistaskory.domain`. They do not import NeoForge.
|
||||||
|
|
||||||
|
What shipped:
|
||||||
|
|
||||||
|
- `ItemId`, `Goal`, requirements, inventory snapshot, progress
|
||||||
|
- `StubRecipeProvider` (furnace / crafting table / chest + gather fallback)
|
||||||
|
- In-memory `Planner` (create / + / − / clear)
|
||||||
|
- Player inventory adapter
|
||||||
|
- Play overlay on the right
|
||||||
|
- `/satistaskory add <item>` and `/satistaskory clear`
|
||||||
|
|
||||||
|
Restarting the world forgets the plan. That is the freeze, not a bug.
|
||||||
|
|
||||||
|
Hover-add is still the experience target. The command is the first caller of Create Goal.
|
||||||
|
|
||||||
|
Unit tests cover increment, remove-at-1, plank aggregation (84 / 24), owned furnaces reducing cobble, gather diamonds.
|
||||||
|
|
||||||
|
Avoid: EMI next “because we can.”
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Related Documents
|
## Related Documents
|
||||||
|
|
||||||
[[🌟 Project Vision]]
|
[[🌟 Project Vision]]
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
package com.sufficient.satistaskory;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import net.minecraft.core.registries.BuiltInRegistries;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.minecraft.world.item.Item;
|
|
||||||
import net.neoforged.bus.api.SubscribeEvent;
|
|
||||||
import net.neoforged.fml.common.EventBusSubscriber;
|
|
||||||
import net.neoforged.fml.event.config.ModConfigEvent;
|
|
||||||
import net.neoforged.neoforge.common.ModConfigSpec;
|
|
||||||
|
|
||||||
// An example config class. This is not required, but it's a good idea to have one to keep your config organized.
|
|
||||||
// Demonstrates how to use Neo's config APIs
|
|
||||||
public class Config {
|
|
||||||
private static final ModConfigSpec.Builder BUILDER = new ModConfigSpec.Builder();
|
|
||||||
|
|
||||||
public static final ModConfigSpec.BooleanValue LOG_DIRT_BLOCK = BUILDER
|
|
||||||
.comment("Whether to log the dirt block on common setup")
|
|
||||||
.define("logDirtBlock", true);
|
|
||||||
|
|
||||||
public static final ModConfigSpec.IntValue MAGIC_NUMBER = BUILDER
|
|
||||||
.comment("A magic number")
|
|
||||||
.defineInRange("magicNumber", 42, 0, Integer.MAX_VALUE);
|
|
||||||
|
|
||||||
public static final ModConfigSpec.ConfigValue<String> MAGIC_NUMBER_INTRODUCTION = BUILDER
|
|
||||||
.comment("What you want the introduction message to be for the magic number")
|
|
||||||
.define("magicNumberIntroduction", "The magic number is... ");
|
|
||||||
|
|
||||||
// a list of strings that are treated as resource locations for items
|
|
||||||
public static final ModConfigSpec.ConfigValue<List<? extends String>> ITEM_STRINGS = BUILDER
|
|
||||||
.comment("A list of items to log on common setup.")
|
|
||||||
.defineListAllowEmpty("items", List.of("minecraft:iron_ingot"), () -> "", Config::validateItemName);
|
|
||||||
|
|
||||||
static final ModConfigSpec SPEC = BUILDER.build();
|
|
||||||
|
|
||||||
private static boolean validateItemName(final Object obj) {
|
|
||||||
return obj instanceof String itemName && BuiltInRegistries.ITEM.containsKey(ResourceLocation.parse(itemName));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,114 +4,16 @@ import org.slf4j.Logger;
|
|||||||
|
|
||||||
import com.mojang.logging.LogUtils;
|
import com.mojang.logging.LogUtils;
|
||||||
|
|
||||||
import net.minecraft.core.registries.BuiltInRegistries;
|
|
||||||
import net.minecraft.core.registries.Registries;
|
|
||||||
import net.minecraft.network.chat.Component;
|
|
||||||
import net.minecraft.world.food.FoodProperties;
|
|
||||||
import net.minecraft.world.item.BlockItem;
|
|
||||||
import net.minecraft.world.item.CreativeModeTab;
|
|
||||||
import net.minecraft.world.item.CreativeModeTabs;
|
|
||||||
import net.minecraft.world.item.Item;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
|
||||||
import net.minecraft.world.level.block.Blocks;
|
|
||||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
|
||||||
import net.minecraft.world.level.material.MapColor;
|
|
||||||
import net.neoforged.api.distmarker.Dist;
|
|
||||||
import net.neoforged.bus.api.IEventBus;
|
import net.neoforged.bus.api.IEventBus;
|
||||||
import net.neoforged.bus.api.SubscribeEvent;
|
|
||||||
import net.neoforged.fml.common.Mod;
|
|
||||||
import net.neoforged.fml.config.ModConfig;
|
|
||||||
import net.neoforged.fml.ModContainer;
|
import net.neoforged.fml.ModContainer;
|
||||||
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
|
import net.neoforged.fml.common.Mod;
|
||||||
import net.neoforged.neoforge.common.NeoForge;
|
|
||||||
import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent;
|
|
||||||
import net.neoforged.neoforge.event.server.ServerStartingEvent;
|
|
||||||
import net.neoforged.neoforge.registries.DeferredBlock;
|
|
||||||
import net.neoforged.neoforge.registries.DeferredHolder;
|
|
||||||
import net.neoforged.neoforge.registries.DeferredItem;
|
|
||||||
import net.neoforged.neoforge.registries.DeferredRegister;
|
|
||||||
|
|
||||||
// The value here should match an entry in the META-INF/neoforge.mods.toml file
|
|
||||||
@Mod(Satistaskory.MODID)
|
@Mod(Satistaskory.MODID)
|
||||||
public class Satistaskory {
|
public class Satistaskory {
|
||||||
// Define mod id in a common place for everything to reference
|
|
||||||
public static final String MODID = "satistaskory";
|
public static final String MODID = "satistaskory";
|
||||||
// Directly reference a slf4j logger
|
|
||||||
public static final Logger LOGGER = LogUtils.getLogger();
|
public static final Logger LOGGER = LogUtils.getLogger();
|
||||||
// Create a Deferred Register to hold Blocks which will all be registered under the "satistaskory" namespace
|
|
||||||
public static final DeferredRegister.Blocks BLOCKS = DeferredRegister.createBlocks(MODID);
|
|
||||||
// Create a Deferred Register to hold Items which will all be registered under the "satistaskory" namespace
|
|
||||||
public static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(MODID);
|
|
||||||
// Create a Deferred Register to hold CreativeModeTabs which will all be registered under the "satistaskory" namespace
|
|
||||||
public static final DeferredRegister<CreativeModeTab> CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, MODID);
|
|
||||||
|
|
||||||
// Creates a new Block with the id "satistaskory:example_block", combining the namespace and path
|
|
||||||
public static final DeferredBlock<Block> EXAMPLE_BLOCK = BLOCKS.registerSimpleBlock("example_block", BlockBehaviour.Properties.of().mapColor(MapColor.STONE));
|
|
||||||
// Creates a new BlockItem with the id "satistaskory:example_block", combining the namespace and path
|
|
||||||
public static final DeferredItem<BlockItem> EXAMPLE_BLOCK_ITEM = ITEMS.registerSimpleBlockItem("example_block", EXAMPLE_BLOCK);
|
|
||||||
|
|
||||||
// Creates a new food item with the id "satistaskory:example_id", nutrition 1 and saturation 2
|
|
||||||
public static final DeferredItem<Item> EXAMPLE_ITEM = ITEMS.registerSimpleItem("example_item", new Item.Properties().food(new FoodProperties.Builder()
|
|
||||||
.alwaysEdible().nutrition(1).saturationModifier(2f).build()));
|
|
||||||
|
|
||||||
// Creates a creative tab with the id "satistaskory:example_tab" for the example item, that is placed after the combat tab
|
|
||||||
public static final DeferredHolder<CreativeModeTab, CreativeModeTab> EXAMPLE_TAB = CREATIVE_MODE_TABS.register("example_tab", () -> CreativeModeTab.builder()
|
|
||||||
.title(Component.translatable("itemGroup.satistaskory")) //The language key for the title of your CreativeModeTab
|
|
||||||
.withTabsBefore(CreativeModeTabs.COMBAT)
|
|
||||||
.icon(() -> EXAMPLE_ITEM.get().getDefaultInstance())
|
|
||||||
.displayItems((parameters, output) -> {
|
|
||||||
output.accept(EXAMPLE_ITEM.get());// Add the example item to the tab. For your own tabs, this method is preferred over the event
|
|
||||||
}).build());
|
|
||||||
|
|
||||||
// The constructor for the mod class is the first code that is run when your mod is loaded.
|
|
||||||
// FML will recognize some parameter types like IEventBus or ModContainer and pass them in automatically.
|
|
||||||
public Satistaskory(IEventBus modEventBus, ModContainer modContainer) {
|
public Satistaskory(IEventBus modEventBus, ModContainer modContainer) {
|
||||||
// Register the commonSetup method for modloading
|
LOGGER.info("Satistaskory loaded. Goals are the domain.");
|
||||||
modEventBus.addListener(this::commonSetup);
|
|
||||||
|
|
||||||
// Register the Deferred Register to the mod event bus so blocks get registered
|
|
||||||
BLOCKS.register(modEventBus);
|
|
||||||
// Register the Deferred Register to the mod event bus so items get registered
|
|
||||||
ITEMS.register(modEventBus);
|
|
||||||
// Register the Deferred Register to the mod event bus so tabs get registered
|
|
||||||
CREATIVE_MODE_TABS.register(modEventBus);
|
|
||||||
|
|
||||||
// Register ourselves for server and other game events we are interested in.
|
|
||||||
// Note that this is necessary if and only if we want *this* class (Satistaskory) to respond directly to events.
|
|
||||||
// Do not add this line if there are no @SubscribeEvent-annotated functions in this class, like onServerStarting() below.
|
|
||||||
NeoForge.EVENT_BUS.register(this);
|
|
||||||
|
|
||||||
// Register the item to a creative tab
|
|
||||||
modEventBus.addListener(this::addCreative);
|
|
||||||
|
|
||||||
// Register our mod's ModConfigSpec so that FML can create and load the config file for us
|
|
||||||
modContainer.registerConfig(ModConfig.Type.COMMON, Config.SPEC);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void commonSetup(FMLCommonSetupEvent event) {
|
|
||||||
// Some common setup code
|
|
||||||
LOGGER.info("HELLO FROM COMMON SETUP");
|
|
||||||
|
|
||||||
if (Config.LOG_DIRT_BLOCK.getAsBoolean()) {
|
|
||||||
LOGGER.info("DIRT BLOCK >> {}", BuiltInRegistries.BLOCK.getKey(Blocks.DIRT));
|
|
||||||
}
|
|
||||||
|
|
||||||
LOGGER.info("{}{}", Config.MAGIC_NUMBER_INTRODUCTION.get(), Config.MAGIC_NUMBER.getAsInt());
|
|
||||||
|
|
||||||
Config.ITEM_STRINGS.get().forEach((item) -> LOGGER.info("ITEM >> {}", item));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the example block item to the building blocks tab
|
|
||||||
private void addCreative(BuildCreativeModeTabContentsEvent event) {
|
|
||||||
if (event.getTabKey() == CreativeModeTabs.BUILDING_BLOCKS) {
|
|
||||||
event.accept(EXAMPLE_BLOCK_ITEM);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// You can use SubscribeEvent and let the Event Bus discover methods to call
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onServerStarting(ServerStartingEvent event) {
|
|
||||||
// Do something when the server starts
|
|
||||||
LOGGER.info("HELLO from server starting");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,31 +1,63 @@
|
|||||||
package com.sufficient.satistaskory;
|
package com.sufficient.satistaskory;
|
||||||
|
|
||||||
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
|
import com.sufficient.satistaskory.infrastructure.client.ClientCommands;
|
||||||
|
import com.sufficient.satistaskory.infrastructure.client.PlannerSession;
|
||||||
|
import com.sufficient.satistaskory.infrastructure.client.PlayOverlay;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.neoforged.api.distmarker.Dist;
|
import net.neoforged.api.distmarker.Dist;
|
||||||
|
import net.neoforged.bus.api.IEventBus;
|
||||||
import net.neoforged.bus.api.SubscribeEvent;
|
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.fml.event.lifecycle.FMLClientSetupEvent;
|
import net.neoforged.neoforge.client.event.InputEvent;
|
||||||
import net.neoforged.neoforge.client.gui.ConfigurationScreen;
|
import net.neoforged.neoforge.client.event.RegisterClientCommandsEvent;
|
||||||
import net.neoforged.neoforge.client.gui.IConfigScreenFactory;
|
import net.neoforged.neoforge.client.event.RegisterGuiLayersEvent;
|
||||||
|
import net.neoforged.neoforge.common.NeoForge;
|
||||||
|
|
||||||
// This class will not load on dedicated servers. Accessing client side code from here is safe.
|
|
||||||
@Mod(value = Satistaskory.MODID, dist = Dist.CLIENT)
|
@Mod(value = Satistaskory.MODID, dist = Dist.CLIENT)
|
||||||
// You can use EventBusSubscriber to automatically register all static methods in the class annotated with @SubscribeEvent
|
|
||||||
@EventBusSubscriber(modid = Satistaskory.MODID, value = Dist.CLIENT)
|
|
||||||
public class SatistaskoryClient {
|
public class SatistaskoryClient {
|
||||||
public SatistaskoryClient(ModContainer container) {
|
public SatistaskoryClient(IEventBus modEventBus, ModContainer container) {
|
||||||
// Allows NeoForge to create a config screen for this mod's configs.
|
PlannerSession.bootstrap();
|
||||||
// The config screen is accessed by going to the Mods screen > clicking on your mod > clicking on config.
|
modEventBus.addListener(SatistaskoryClient::registerGuiLayers);
|
||||||
// Do not forget to add translations for your config options to the en_us.json file.
|
NeoForge.EVENT_BUS.register(GameEvents.class);
|
||||||
container.registerExtensionPoint(IConfigScreenFactory.class, ConfigurationScreen::new);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
private static void registerGuiLayers(RegisterGuiLayersEvent event) {
|
||||||
static void onClientSetup(FMLClientSetupEvent event) {
|
event.registerAboveAll(
|
||||||
// Some client setup code
|
ResourceLocation.fromNamespaceAndPath(Satistaskory.MODID, "play_overlay"),
|
||||||
Satistaskory.LOGGER.info("HELLO FROM CLIENT SETUP");
|
PlayOverlay::render);
|
||||||
Satistaskory.LOGGER.info("MINECRAFT NAME >> {}", Minecraft.getInstance().getUser().getName());
|
}
|
||||||
|
|
||||||
|
@EventBusSubscriber(modid = Satistaskory.MODID, value = Dist.CLIENT)
|
||||||
|
public static class GameEvents {
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onClientCommands(RegisterClientCommandsEvent event) {
|
||||||
|
ClientCommands.register(event.getDispatcher());
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onMouse(InputEvent.MouseButton.Pre event) {
|
||||||
|
if (event.getAction() != GLFW.GLFW_PRESS || event.getButton() != GLFW.GLFW_MOUSE_BUTTON_LEFT) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Minecraft minecraft = Minecraft.getInstance();
|
||||||
|
if (minecraft.screen != null || minecraft.player == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
double mouseX = minecraft.mouseHandler.xpos()
|
||||||
|
* minecraft.getWindow().getGuiScaledWidth()
|
||||||
|
/ minecraft.getWindow().getScreenWidth();
|
||||||
|
double mouseY = minecraft.mouseHandler.ypos()
|
||||||
|
* minecraft.getWindow().getGuiScaledHeight()
|
||||||
|
/ minecraft.getWindow().getScreenHeight();
|
||||||
|
if (PlayOverlay.click(mouseX, mouseY)) {
|
||||||
|
event.setCanceled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.sufficient.satistaskory.application;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import com.sufficient.satistaskory.domain.Goal;
|
||||||
|
import com.sufficient.satistaskory.domain.ItemId;
|
||||||
|
|
||||||
|
public final class InMemoryGoalStore {
|
||||||
|
private final List<Goal> goals = new ArrayList<>();
|
||||||
|
|
||||||
|
public List<Goal> all() {
|
||||||
|
return List.copyOf(goals);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<Goal> find(ItemId item) {
|
||||||
|
return goals.stream().filter(goal -> goal.targetItem().equals(item)).findFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void put(Goal goal) {
|
||||||
|
goals.removeIf(existing -> existing.targetItem().equals(goal.targetItem()));
|
||||||
|
goals.add(goal);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(ItemId item) {
|
||||||
|
goals.removeIf(goal -> goal.targetItem().equals(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
goals.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package com.sufficient.satistaskory.application;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import com.sufficient.satistaskory.domain.Goal;
|
||||||
|
import com.sufficient.satistaskory.domain.InventoryState;
|
||||||
|
import com.sufficient.satistaskory.domain.ItemId;
|
||||||
|
import com.sufficient.satistaskory.domain.ProgressCalculation;
|
||||||
|
import com.sufficient.satistaskory.domain.ProgressSnapshot;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Application facade for the first slice. Persistence is this store, in RAM.
|
||||||
|
*/
|
||||||
|
public final class Planner {
|
||||||
|
private final InMemoryGoalStore store;
|
||||||
|
private final ProgressCalculation progress;
|
||||||
|
private final Supplier<InventoryState> inventory;
|
||||||
|
|
||||||
|
public Planner(InMemoryGoalStore store, ProgressCalculation progress, Supplier<InventoryState> inventory) {
|
||||||
|
this.store = Objects.requireNonNull(store, "store");
|
||||||
|
this.progress = Objects.requireNonNull(progress, "progress");
|
||||||
|
this.inventory = Objects.requireNonNull(inventory, "inventory");
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProgressSnapshot snapshot() {
|
||||||
|
return refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProgressSnapshot create(ItemId item) {
|
||||||
|
Objects.requireNonNull(item, "item");
|
||||||
|
store.find(item).ifPresentOrElse(
|
||||||
|
existing -> store.put(existing.increment()),
|
||||||
|
() -> store.put(new Goal(item, 1)));
|
||||||
|
return refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProgressSnapshot increment(ItemId item) {
|
||||||
|
Objects.requireNonNull(item, "item");
|
||||||
|
store.find(item).ifPresent(existing -> store.put(existing.increment()));
|
||||||
|
return refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProgressSnapshot decrement(ItemId item) {
|
||||||
|
Objects.requireNonNull(item, "item");
|
||||||
|
store.find(item).ifPresent(existing -> {
|
||||||
|
if (existing.quantity() == 1) {
|
||||||
|
store.remove(item);
|
||||||
|
} else {
|
||||||
|
store.put(existing.decrement());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProgressSnapshot remove(ItemId item) {
|
||||||
|
Objects.requireNonNull(item, "item");
|
||||||
|
store.remove(item);
|
||||||
|
return refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProgressSnapshot clear() {
|
||||||
|
store.clear();
|
||||||
|
return refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ProgressSnapshot refresh() {
|
||||||
|
return progress.calculate(store.all(), inventory.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package com.sufficient.satistaskory.domain;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A thing the player wishes to obtain. Quantity is always >= 1.
|
||||||
|
*/
|
||||||
|
public final class Goal {
|
||||||
|
private final ItemId targetItem;
|
||||||
|
private final int quantity;
|
||||||
|
|
||||||
|
public Goal(ItemId targetItem, int quantity) {
|
||||||
|
this.targetItem = Objects.requireNonNull(targetItem, "targetItem");
|
||||||
|
if (quantity < 1) {
|
||||||
|
throw new IllegalArgumentException("quantity must be >= 1");
|
||||||
|
}
|
||||||
|
this.quantity = quantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemId targetItem() {
|
||||||
|
return targetItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int quantity() {
|
||||||
|
return quantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Goal increment() {
|
||||||
|
return new Goal(targetItem, quantity + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Goal decrement() {
|
||||||
|
return new Goal(targetItem, quantity - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!(o instanceof Goal other)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return quantity == other.quantity && targetItem.equals(other.targetItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(targetItem, quantity);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package com.sufficient.satistaskory.domain;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Available quantities. How they were gathered is infrastructure.
|
||||||
|
*/
|
||||||
|
public final class InventoryState {
|
||||||
|
private static final InventoryState EMPTY = new InventoryState(Map.of());
|
||||||
|
|
||||||
|
private final Map<ItemId, Integer> available;
|
||||||
|
|
||||||
|
public InventoryState(Map<ItemId, Integer> available) {
|
||||||
|
Objects.requireNonNull(available, "available");
|
||||||
|
Map<ItemId, Integer> copy = new LinkedHashMap<>();
|
||||||
|
available.forEach((item, count) -> {
|
||||||
|
if (count != null && count > 0) {
|
||||||
|
copy.put(item, count);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.available = Collections.unmodifiableMap(copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static InventoryState empty() {
|
||||||
|
return EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int get(ItemId item) {
|
||||||
|
return available.getOrDefault(item, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package com.sufficient.satistaskory.domain;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Target item identity. {@code namespace:path}, not a Minecraft Item class.
|
||||||
|
*/
|
||||||
|
public final class ItemId {
|
||||||
|
private final String namespace;
|
||||||
|
private final String path;
|
||||||
|
|
||||||
|
public ItemId(String namespace, String path) {
|
||||||
|
this.namespace = Objects.requireNonNull(namespace, "namespace");
|
||||||
|
this.path = Objects.requireNonNull(path, "path");
|
||||||
|
if (this.namespace.isEmpty() || this.path.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("ItemId namespace and path must be non-empty");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemId parse(String id) {
|
||||||
|
Objects.requireNonNull(id, "id");
|
||||||
|
int colon = id.indexOf(':');
|
||||||
|
if (colon <= 0 || colon == id.length() - 1) {
|
||||||
|
throw new IllegalArgumentException("ItemId must be namespace:path, got: " + id);
|
||||||
|
}
|
||||||
|
return new ItemId(id.substring(0, colon), id.substring(colon + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public String namespace() {
|
||||||
|
return namespace;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String path() {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return namespace + ":" + path;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!(o instanceof ItemId other)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return namespace.equals(other.namespace) && path.equals(other.path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(namespace, path);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.sufficient.satistaskory.domain;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public final class MaterialAggregation {
|
||||||
|
public List<MaterialRequirement> aggregate(List<MaterialRequirement> requirements) {
|
||||||
|
Map<ItemId, Integer> sums = new LinkedHashMap<>();
|
||||||
|
for (MaterialRequirement requirement : requirements) {
|
||||||
|
sums.merge(requirement.item(), requirement.quantity(), Integer::sum);
|
||||||
|
}
|
||||||
|
List<MaterialRequirement> aggregated = new ArrayList<>();
|
||||||
|
sums.forEach((item, quantity) -> aggregated.add(new MaterialRequirement(item, quantity)));
|
||||||
|
return List.copyOf(aggregated);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package com.sufficient.satistaskory.domain;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public final class MaterialRequirement {
|
||||||
|
private final ItemId item;
|
||||||
|
private final int quantity;
|
||||||
|
|
||||||
|
public MaterialRequirement(ItemId item, int quantity) {
|
||||||
|
this.item = Objects.requireNonNull(item, "item");
|
||||||
|
if (quantity < 1) {
|
||||||
|
throw new IllegalArgumentException("quantity must be >= 1");
|
||||||
|
}
|
||||||
|
this.quantity = quantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemId item() {
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int quantity() {
|
||||||
|
return quantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!(o instanceof MaterialRequirement other)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return quantity == other.quantity && item.equals(other.item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(item, quantity);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package com.sufficient.satistaskory.domain;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public final class MissingMaterial {
|
||||||
|
private final ItemId item;
|
||||||
|
private final int quantity;
|
||||||
|
|
||||||
|
public MissingMaterial(ItemId item, int quantity) {
|
||||||
|
this.item = Objects.requireNonNull(item, "item");
|
||||||
|
if (quantity < 1) {
|
||||||
|
throw new IllegalArgumentException("quantity must be >= 1");
|
||||||
|
}
|
||||||
|
this.quantity = quantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemId item() {
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int quantity() {
|
||||||
|
return quantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!(o instanceof MissingMaterial other)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return quantity == other.quantity && item.equals(other.item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(item, quantity);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.sufficient.satistaskory.domain;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public final class ProgressCalculation {
|
||||||
|
private final RecipeResolution resolution;
|
||||||
|
private final MaterialAggregation aggregation;
|
||||||
|
|
||||||
|
public ProgressCalculation(RecipeResolution resolution, MaterialAggregation aggregation) {
|
||||||
|
this.resolution = Objects.requireNonNull(resolution, "resolution");
|
||||||
|
this.aggregation = Objects.requireNonNull(aggregation, "aggregation");
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProgressSnapshot calculate(List<Goal> goals, InventoryState inventory) {
|
||||||
|
Objects.requireNonNull(goals, "goals");
|
||||||
|
Objects.requireNonNull(inventory, "inventory");
|
||||||
|
|
||||||
|
List<MaterialRequirement> all = new ArrayList<>();
|
||||||
|
for (Goal goal : goals) {
|
||||||
|
int remaining = Math.max(0, goal.quantity() - inventory.get(goal.targetItem()));
|
||||||
|
all.addAll(resolution.resolve(goal.targetItem(), remaining));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<MissingMaterial> missing = new ArrayList<>();
|
||||||
|
for (MaterialRequirement requirement : aggregation.aggregate(all)) {
|
||||||
|
int stillNeeded = Math.max(0, requirement.quantity() - inventory.get(requirement.item()));
|
||||||
|
if (stillNeeded > 0) {
|
||||||
|
missing.add(new MissingMaterial(requirement.item(), stillNeeded));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new ProgressSnapshot(goals, missing);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.sufficient.satistaskory.domain;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public final class ProgressSnapshot {
|
||||||
|
private final List<Goal> goals;
|
||||||
|
private final List<MissingMaterial> missing;
|
||||||
|
|
||||||
|
public ProgressSnapshot(List<Goal> goals, List<MissingMaterial> missing) {
|
||||||
|
this.goals = List.copyOf(Objects.requireNonNull(goals, "goals"));
|
||||||
|
this.missing = List.copyOf(Objects.requireNonNull(missing, "missing"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Goal> goals() {
|
||||||
|
return goals;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<MissingMaterial> missing() {
|
||||||
|
return missing;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.sufficient.satistaskory.domain;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Port. Domain asks; infrastructure answers. No EMI/JEI/REI/NeoForge types here.
|
||||||
|
*/
|
||||||
|
public interface RecipeProvider {
|
||||||
|
/**
|
||||||
|
* Direct ingredients to produce {@code quantity} of {@code target}.
|
||||||
|
* One crafting level. No recipe → {@code (target, quantity)}. {@code quantity < 1} → empty.
|
||||||
|
*/
|
||||||
|
List<MaterialRequirement> resolve(ItemId target, int quantity);
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.sufficient.satistaskory.domain;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public final class RecipeResolution {
|
||||||
|
private final RecipeProvider provider;
|
||||||
|
|
||||||
|
public RecipeResolution(RecipeProvider provider) {
|
||||||
|
this.provider = Objects.requireNonNull(provider, "provider");
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<MaterialRequirement> resolve(ItemId target, int quantity) {
|
||||||
|
if (quantity < 1) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
return provider.resolve(target, quantity);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package com.sufficient.satistaskory.infrastructure.client;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
|
||||||
|
import com.sufficient.satistaskory.domain.ItemId;
|
||||||
|
|
||||||
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
|
import net.minecraft.commands.Commands;
|
||||||
|
import net.minecraft.commands.arguments.ResourceLocationArgument;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
|
public final class ClientCommands {
|
||||||
|
private ClientCommands() {}
|
||||||
|
|
||||||
|
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||||
|
dispatcher.register(Commands.literal("satistaskory")
|
||||||
|
.then(Commands.literal("add")
|
||||||
|
.then(Commands.argument("item", ResourceLocationArgument.id())
|
||||||
|
.executes(ClientCommands::add)))
|
||||||
|
.then(Commands.literal("clear")
|
||||||
|
.executes(ctx -> {
|
||||||
|
PlannerSession.get().clear();
|
||||||
|
ctx.getSource().sendSuccess(() -> Component.literal("Cleared crafting goals"), false);
|
||||||
|
return 1;
|
||||||
|
})));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int add(CommandContext<CommandSourceStack> ctx) {
|
||||||
|
ResourceLocation location = ResourceLocationArgument.getId(ctx, "item");
|
||||||
|
ItemId item = ItemId.parse(location.toString());
|
||||||
|
PlannerSession.get().create(item);
|
||||||
|
ctx.getSource().sendSuccess(() -> Component.literal("Added " + item), false);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package com.sufficient.satistaskory.infrastructure.client;
|
||||||
|
|
||||||
|
import com.sufficient.satistaskory.application.InMemoryGoalStore;
|
||||||
|
import com.sufficient.satistaskory.application.Planner;
|
||||||
|
import com.sufficient.satistaskory.domain.InventoryState;
|
||||||
|
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 net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Client-side in-memory plan. Gone when the game restarts.
|
||||||
|
*/
|
||||||
|
public final class PlannerSession {
|
||||||
|
private static Planner planner;
|
||||||
|
|
||||||
|
private PlannerSession() {}
|
||||||
|
|
||||||
|
public static void bootstrap() {
|
||||||
|
if (planner != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
RecipeResolution resolution = new RecipeResolution(new StubRecipeProvider());
|
||||||
|
ProgressCalculation progress = new ProgressCalculation(resolution, new MaterialAggregation());
|
||||||
|
planner = new Planner(new InMemoryGoalStore(), progress, PlannerSession::currentInventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Planner get() {
|
||||||
|
if (planner == null) {
|
||||||
|
bootstrap();
|
||||||
|
}
|
||||||
|
return planner;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static InventoryState currentInventory() {
|
||||||
|
LocalPlayer player = Minecraft.getInstance().player;
|
||||||
|
if (player == null) {
|
||||||
|
return InventoryState.empty();
|
||||||
|
}
|
||||||
|
return PlayerInventoryAdapter.from(player.getInventory());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,162 @@
|
|||||||
|
package com.sufficient.satistaskory.infrastructure.client;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.sufficient.satistaskory.domain.Goal;
|
||||||
|
import com.sufficient.satistaskory.domain.ItemId;
|
||||||
|
import com.sufficient.satistaskory.domain.MissingMaterial;
|
||||||
|
import com.sufficient.satistaskory.domain.ProgressSnapshot;
|
||||||
|
|
||||||
|
import net.minecraft.client.DeltaTracker;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.Font;
|
||||||
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.item.Item;
|
||||||
|
import net.minecraft.world.item.Items;
|
||||||
|
|
||||||
|
public final class PlayOverlay {
|
||||||
|
private static final int MARGIN = 6;
|
||||||
|
private static final int WIDTH = 156;
|
||||||
|
private static final int LINE = 12;
|
||||||
|
private static final int PAD = 6;
|
||||||
|
|
||||||
|
private static final List<Hit> HITS = new ArrayList<>();
|
||||||
|
|
||||||
|
private PlayOverlay() {}
|
||||||
|
|
||||||
|
public static void render(GuiGraphics graphics, DeltaTracker deltaTracker) {
|
||||||
|
HITS.clear();
|
||||||
|
Minecraft minecraft = Minecraft.getInstance();
|
||||||
|
if (minecraft.player == null || minecraft.options.hideGui) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProgressSnapshot snapshot = PlannerSession.get().snapshot();
|
||||||
|
if (snapshot.goals().isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Font font = minecraft.font;
|
||||||
|
int x = graphics.guiWidth() - WIDTH - MARGIN;
|
||||||
|
int y = MARGIN;
|
||||||
|
int goalLines = snapshot.goals().size();
|
||||||
|
int missingLines = Math.max(3, snapshot.missing().size());
|
||||||
|
int header = LINE + 4;
|
||||||
|
int footer = LINE + 10;
|
||||||
|
int height = PAD + header + goalLines * LINE + 6 + missingLines * LINE + footer + PAD;
|
||||||
|
|
||||||
|
graphics.fill(x, y, x + WIDTH, y + height, 0xE0101010);
|
||||||
|
graphics.fill(x + 1, y + 1, x + WIDTH - 1, y + height - 1, 0xE0181818);
|
||||||
|
|
||||||
|
int cursor = y + PAD;
|
||||||
|
graphics.drawCenteredString(font, "SATISTASKORY", x + WIDTH / 2, cursor, 0xFFFFFF);
|
||||||
|
cursor += LINE + 4;
|
||||||
|
|
||||||
|
int goalBoxBottom = cursor + goalLines * LINE + 2;
|
||||||
|
graphics.fill(x + 3, cursor - 2, x + WIDTH - 3, goalBoxBottom, 0xC0242424);
|
||||||
|
for (Goal goal : snapshot.goals()) {
|
||||||
|
drawGoalRow(graphics, font, goal, x, cursor);
|
||||||
|
cursor += LINE;
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor = goalBoxBottom + 4;
|
||||||
|
int missingBoxBottom = cursor + missingLines * LINE + 2;
|
||||||
|
graphics.fill(x + 3, cursor - 2, x + WIDTH - 3, missingBoxBottom, 0xC02C2C2C);
|
||||||
|
if (snapshot.missing().isEmpty()) {
|
||||||
|
graphics.drawString(font, "Ready", x + PAD, cursor, 0xA0A0A0, false);
|
||||||
|
} else {
|
||||||
|
for (MissingMaterial missing : snapshot.missing()) {
|
||||||
|
String name = displayName(missing.item());
|
||||||
|
String qty = Integer.toString(missing.quantity());
|
||||||
|
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);
|
||||||
|
cursor += LINE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String clear = "X Clear Items";
|
||||||
|
int clearWidth = font.width(clear) + 10;
|
||||||
|
int clearX = x + (WIDTH - clearWidth) / 2;
|
||||||
|
int clearY = y + height - PAD - LINE;
|
||||||
|
graphics.fill(clearX, clearY - 2, clearX + clearWidth, clearY + LINE, 0xFF3A3A3A);
|
||||||
|
graphics.drawCenteredString(font, clear, x + WIDTH / 2, clearY, 0xFFFFFF);
|
||||||
|
HITS.add(new Hit(clearX, clearY - 2, clearX + clearWidth, clearY + LINE, Kind.CLEAR, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean click(double mouseX, double mouseY) {
|
||||||
|
for (Hit hit : HITS) {
|
||||||
|
if (hit.contains(mouseX, mouseY)) {
|
||||||
|
switch (hit.kind) {
|
||||||
|
case PLUS -> PlannerSession.get().increment(hit.item);
|
||||||
|
case MINUS -> PlannerSession.get().decrement(hit.item);
|
||||||
|
case CLEAR -> PlannerSession.get().clear();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void drawGoalRow(GuiGraphics graphics, Font font, Goal goal, int panelX, int y) {
|
||||||
|
int plusX = panelX + PAD;
|
||||||
|
int minusX = plusX + 11;
|
||||||
|
drawButton(graphics, font, plusX, y, "+", Kind.PLUS, goal.targetItem());
|
||||||
|
drawButton(graphics, font, minusX, y, "-", Kind.MINUS, goal.targetItem());
|
||||||
|
|
||||||
|
String name = displayName(goal.targetItem()).toUpperCase();
|
||||||
|
String qty = Integer.toString(goal.quantity());
|
||||||
|
int nameX = minusX + 14;
|
||||||
|
int qtyX = panelX + WIDTH - PAD - font.width(qty);
|
||||||
|
graphics.drawString(font, trim(font, name, qtyX - nameX - 4), nameX, y, 0xFFFFFF, false);
|
||||||
|
graphics.drawString(font, qty, qtyX, y, 0xFFFFFF, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void drawButton(GuiGraphics graphics, Font font, int x, int y, String label, Kind kind, ItemId item) {
|
||||||
|
int w = 9;
|
||||||
|
int h = 9;
|
||||||
|
graphics.fill(x, y, x + w, y + h, 0xFF4A4A4A);
|
||||||
|
graphics.drawCenteredString(font, label, x + w / 2, y, 0xFFFFFF);
|
||||||
|
HITS.add(new Hit(x, y, x + w, y + h, kind, item));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String displayName(ItemId id) {
|
||||||
|
ResourceLocation location = ResourceLocation.parse(id.toString());
|
||||||
|
Item item = BuiltInRegistries.ITEM.get(location);
|
||||||
|
if (item == Items.AIR && !id.toString().equals("minecraft:air")) {
|
||||||
|
return id.path().replace('_', ' ');
|
||||||
|
}
|
||||||
|
return item.getDescription().getString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String trim(Font font, String text, int maxWidth) {
|
||||||
|
if (font.width(text) <= maxWidth) {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
String ellipsis = "...";
|
||||||
|
int budget = maxWidth - font.width(ellipsis);
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
for (int i = 0; i < text.length(); i++) {
|
||||||
|
String next = builder.toString() + text.charAt(i);
|
||||||
|
if (font.width(next) > budget) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
builder.append(text.charAt(i));
|
||||||
|
}
|
||||||
|
return builder + ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum Kind {
|
||||||
|
PLUS,
|
||||||
|
MINUS,
|
||||||
|
CLEAR
|
||||||
|
}
|
||||||
|
|
||||||
|
private record Hit(int x0, int y0, int x1, int y1, Kind kind, ItemId item) {
|
||||||
|
boolean contains(double x, double y) {
|
||||||
|
return x >= x0 && x < x1 && y >= y0 && y < y1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
package com.sufficient.satistaskory.infrastructure.inventory;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.sufficient.satistaskory.domain.InventoryState;
|
||||||
|
import com.sufficient.satistaskory.domain.ItemId;
|
||||||
|
|
||||||
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
|
public final class PlayerInventoryAdapter {
|
||||||
|
private PlayerInventoryAdapter() {}
|
||||||
|
|
||||||
|
public static InventoryState from(Inventory inventory) {
|
||||||
|
Map<ItemId, Integer> counts = new LinkedHashMap<>();
|
||||||
|
for (int slot = 0; slot < inventory.getContainerSize(); slot++) {
|
||||||
|
ItemStack stack = inventory.getItem(slot);
|
||||||
|
if (stack.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ResourceLocation key = BuiltInRegistries.ITEM.getKey(stack.getItem());
|
||||||
|
ItemId id = ItemId.parse(key.toString());
|
||||||
|
counts.merge(id, stack.getCount(), Integer::sum);
|
||||||
|
}
|
||||||
|
return new InventoryState(counts);
|
||||||
|
}
|
||||||
|
}
|
||||||
+48
@@ -0,0 +1,48 @@
|
|||||||
|
package com.sufficient.satistaskory.infrastructure.recipe;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* First implementation. A few shaped recipes plus identity fallback. Not EMI. Not vanilla-complete.
|
||||||
|
*/
|
||||||
|
public final class StubRecipeProvider implements RecipeProvider {
|
||||||
|
private static final ItemId FURNACE = ItemId.parse("minecraft:furnace");
|
||||||
|
private static final ItemId CRAFTING_TABLE = ItemId.parse("minecraft:crafting_table");
|
||||||
|
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 final Map<ItemId, Recipe> recipes = new HashMap<>();
|
||||||
|
|
||||||
|
public StubRecipeProvider() {
|
||||||
|
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))));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<MaterialRequirement> resolve(ItemId target, int quantity) {
|
||||||
|
if (quantity < 1) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
Recipe recipe = recipes.get(target);
|
||||||
|
if (recipe == null) {
|
||||||
|
return List.of(new MaterialRequirement(target, quantity));
|
||||||
|
}
|
||||||
|
int crafts = (quantity + recipe.outputCount() - 1) / recipe.outputCount();
|
||||||
|
List<MaterialRequirement> scaled = new ArrayList<>();
|
||||||
|
for (MaterialRequirement ingredient : recipe.ingredients()) {
|
||||||
|
scaled.add(new MaterialRequirement(ingredient.item(), ingredient.quantity() * crafts));
|
||||||
|
}
|
||||||
|
return List.copyOf(scaled);
|
||||||
|
}
|
||||||
|
|
||||||
|
private record Recipe(int outputCount, List<MaterialRequirement> ingredients) {}
|
||||||
|
}
|
||||||
@@ -1,13 +1,4 @@
|
|||||||
{
|
{
|
||||||
"itemGroup.satistaskory": "Example Mod Tab",
|
"satistaskory.overlay.title": "SATISTASKORY",
|
||||||
"block.satistaskory.example_block": "Example Block",
|
"satistaskory.overlay.clear": "X Clear Items"
|
||||||
"item.satistaskory.example_item": "Example Item",
|
|
||||||
|
|
||||||
"satistaskory.configuration.title": "Satistaskory Configs",
|
|
||||||
"satistaskory.configuration.section.satistaskory.common.toml": "Satistaskory Configs",
|
|
||||||
"satistaskory.configuration.section.satistaskory.common.toml.title": "Satistaskory Configs",
|
|
||||||
"satistaskory.configuration.items": "Item List",
|
|
||||||
"satistaskory.configuration.logDirtBlock": "Log Dirt Block",
|
|
||||||
"satistaskory.configuration.magicNumberIntroduction": "Magic Number Text",
|
|
||||||
"satistaskory.configuration.magicNumber": "Magic Number"
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,110 @@
|
|||||||
|
package com.sufficient.satistaskory.application;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import com.sufficient.satistaskory.domain.InventoryState;
|
||||||
|
import com.sufficient.satistaskory.domain.ItemId;
|
||||||
|
import com.sufficient.satistaskory.domain.MaterialAggregation;
|
||||||
|
import com.sufficient.satistaskory.domain.ProgressCalculation;
|
||||||
|
import com.sufficient.satistaskory.domain.ProgressSnapshot;
|
||||||
|
import com.sufficient.satistaskory.domain.RecipeResolution;
|
||||||
|
import com.sufficient.satistaskory.infrastructure.recipe.StubRecipeProvider;
|
||||||
|
|
||||||
|
class PlannerTest {
|
||||||
|
private static final ItemId FURNACE = ItemId.parse("minecraft:furnace");
|
||||||
|
private static final ItemId CRAFTING_TABLE = ItemId.parse("minecraft:crafting_table");
|
||||||
|
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 DIAMOND = ItemId.parse("minecraft:diamond");
|
||||||
|
|
||||||
|
private Planner planner;
|
||||||
|
private InventoryState inventory;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
inventory = InventoryState.empty();
|
||||||
|
RecipeResolution resolution = new RecipeResolution(new StubRecipeProvider());
|
||||||
|
ProgressCalculation progress = new ProgressCalculation(resolution, new MaterialAggregation());
|
||||||
|
planner = new Planner(new InMemoryGoalStore(), progress, () -> inventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void createStartsAtOneAndIncrementsExisting() {
|
||||||
|
planner.create(FURNACE);
|
||||||
|
ProgressSnapshot second = planner.create(FURNACE);
|
||||||
|
assertEquals(1, second.goals().size());
|
||||||
|
assertEquals(2, second.goals().getFirst().quantity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void decrementAtOneRemoves() {
|
||||||
|
planner.create(FURNACE);
|
||||||
|
ProgressSnapshot after = planner.decrement(FURNACE);
|
||||||
|
assertTrue(after.goals().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void aggregatesPlanksAcrossBenchAndChest() {
|
||||||
|
planner.create(CRAFTING_TABLE);
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
planner.increment(CRAFTING_TABLE);
|
||||||
|
}
|
||||||
|
planner.create(CHEST);
|
||||||
|
for (int i = 0; i < 7; i++) {
|
||||||
|
planner.increment(CHEST);
|
||||||
|
}
|
||||||
|
planner.create(FURNACE);
|
||||||
|
planner.increment(FURNACE);
|
||||||
|
planner.increment(FURNACE);
|
||||||
|
|
||||||
|
ProgressSnapshot snapshot = planner.snapshot();
|
||||||
|
assertEquals(84, quantity(snapshot, OAK_PLANKS));
|
||||||
|
assertEquals(24, quantity(snapshot, COBBLESTONE));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void ownedTargetReducesResolution() {
|
||||||
|
inventory = new InventoryState(Map.of(FURNACE, 1));
|
||||||
|
planner.create(FURNACE);
|
||||||
|
planner.increment(FURNACE);
|
||||||
|
planner.increment(FURNACE);
|
||||||
|
ProgressSnapshot snapshot = planner.snapshot();
|
||||||
|
assertEquals(16, quantity(snapshot, COBBLESTONE));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void gatherItemWithNoRecipeIsItself() {
|
||||||
|
planner.create(DIAMOND);
|
||||||
|
ProgressSnapshot snapshot = planner.snapshot();
|
||||||
|
assertEquals(1, quantity(snapshot, DIAMOND));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void availableIngredientsCoverTheGoal() {
|
||||||
|
inventory = new InventoryState(Map.of(COBBLESTONE, 10));
|
||||||
|
planner.create(FURNACE);
|
||||||
|
assertTrue(planner.snapshot().missing().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void partialIngredientsShowRemainder() {
|
||||||
|
inventory = new InventoryState(Map.of(COBBLESTONE, 3));
|
||||||
|
planner.create(FURNACE);
|
||||||
|
assertEquals(5, quantity(planner.snapshot(), COBBLESTONE));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int quantity(ProgressSnapshot snapshot, ItemId item) {
|
||||||
|
return snapshot.missing().stream()
|
||||||
|
.filter(missing -> missing.item().equals(item))
|
||||||
|
.findFirst()
|
||||||
|
.orElseThrow()
|
||||||
|
.quantity();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user