Capture with tooltip line and rebindable add key.
Build / build (push) Failing after 27s

Hover stays on the item. Tooltip shows the bound key. Default is the =/+ key under Controls > Satistaskory. No click-off-the-slot button.
This commit is contained in:
Stephen Fasciani
2026-09-08 04:57:12 -04:00
parent c336477c82
commit 3f3d8bff50
5 changed files with 66 additions and 80 deletions
+2 -2
View File
@@ -34,8 +34,8 @@ Places:
Interaction: Interaction:
1. Hover the item 1. Hover the item
2. `+ Add to Crafting Goals` appears 2. Tooltip includes `[+] Add to Crafting Goals` (bound key)
3. That is [[▶️ Create Goal]] — quantity **1**, or **+1** if that item is already a goal 3. Press that key — [[▶️ Create Goal]] — quantity **1**, or **+1** if that item is already a goal
4. Player closes the view and is back in the world 4. Player closes the view and is back in the world
5. The item is a row on the overlay’s goal list 5. The item is a row on the overlay’s goal list
+6 -7
View File
@@ -14,21 +14,20 @@ Screen 2 is the player’s concept art, finished with the domain: goals on top;
The player is already in inventory, the crafting bench craft pane, or the craft book. The player is already in inventory, the crafting bench craft pane, or the craft book.
Satistaskory draws only the hover control. Satistaskory draws only a tooltip line. The mouse stays on the item.
```text ```text
(host view we do not own) (host view we do not own)
[ item ] [ item ]
Tooltip
┌─────────────────────────┐ …
│ + Add to Crafting Goals │ [+] Add to Crafting Goals
└─────────────────────────┘
``` ```
**Primary action:** Add → [[▶️ Create Goal]] (quantity 1, or +1 if present) → player closes the host view → the item appears in Screen 2’s goal list. **Primary action:** hover the item, press the Add key (default `=`, rebindable in Controls) → [[▶️ Create Goal]] (quantity 1, or +1 if present) → close the host view → the item is a row on Screen 2.
Same button in all three hosts. We do not restyle the inventory, the bench, or the book. Same control in inventory, crafting pane, and craft book. We do not restyle those views. We do not draw a click target you have to leave the item to hit.
Target Quantity is not drawn here. First quantity is 1. Further edits are `[+]` / `[-]` on Screen 2. Target Quantity is not drawn here. First quantity is 1. Further edits are `[+]` / `[-]` on Screen 2.
@@ -20,12 +20,14 @@ import net.neoforged.neoforge.client.event.RegisterClientCommandsEvent;
import net.neoforged.neoforge.client.event.RegisterGuiLayersEvent; import net.neoforged.neoforge.client.event.RegisterGuiLayersEvent;
import net.neoforged.neoforge.client.event.ScreenEvent; import net.neoforged.neoforge.client.event.ScreenEvent;
import net.neoforged.neoforge.client.gui.VanillaGuiLayers; import net.neoforged.neoforge.client.gui.VanillaGuiLayers;
import net.neoforged.neoforge.event.entity.player.ItemTooltipEvent;
@Mod(value = Satistaskory.MODID, dist = Dist.CLIENT) @Mod(value = Satistaskory.MODID, dist = Dist.CLIENT)
public class SatistaskoryClient { public class SatistaskoryClient {
public SatistaskoryClient(IEventBus modEventBus, ModContainer container) { public SatistaskoryClient(IEventBus modEventBus, ModContainer container) {
PlannerSession.bootstrap(); PlannerSession.bootstrap();
modEventBus.addListener(SatistaskoryClient::registerGuiLayers); modEventBus.addListener(SatistaskoryClient::registerGuiLayers);
modEventBus.addListener(CaptureHook::registerKeys);
} }
private static void registerGuiLayers(RegisterGuiLayersEvent event) { private static void registerGuiLayers(RegisterGuiLayersEvent event) {
@@ -63,16 +65,13 @@ public class SatistaskoryClient {
} }
@SubscribeEvent @SubscribeEvent
public static void onScreenRender(ScreenEvent.Render.Post event) { public static void onTooltip(ItemTooltipEvent event) {
CaptureHook.render(event.getScreen(), event.getGuiGraphics(), event.getMouseX(), event.getMouseY()); CaptureHook.onTooltip(event);
} }
@SubscribeEvent @SubscribeEvent
public static void onScreenClick(ScreenEvent.MouseButtonPressed.Pre event) { public static void onScreenKey(ScreenEvent.KeyPressed.Pre event) {
if (event.getButton() != GLFW.GLFW_MOUSE_BUTTON_LEFT) { if (CaptureHook.onKey(event.getScreen(), event.getKeyCode(), event.getScanCode())) {
return;
}
if (CaptureHook.click(event.getMouseX(), event.getMouseY())) {
event.setCanceled(true); event.setCanceled(true);
} }
} }
@@ -2,11 +2,15 @@ package com.sufficient.satistaskory.infrastructure.client;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import org.lwjgl.glfw.GLFW;
import com.mojang.blaze3d.platform.InputConstants;
import com.sufficient.satistaskory.domain.ItemId; import com.sufficient.satistaskory.domain.ItemId;
import net.minecraft.ChatFormatting;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font; import net.minecraft.client.gui.components.EditBox;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.gui.screens.recipebook.RecipeBookComponent; import net.minecraft.client.gui.screens.recipebook.RecipeBookComponent;
@@ -19,15 +23,20 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.inventory.Slot; import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.client.event.RegisterKeyMappingsEvent;
import net.neoforged.neoforge.client.settings.KeyConflictContext;
import net.neoforged.neoforge.event.entity.player.ItemTooltipEvent;
/** /**
* Screen 1: a button on host views we do not own. * Screen 1: tooltip line + rebindable key. Stay on the item; do not chase a button.
* Inventory slots, crafting grid, and the craft book.
*/ */
public final class CaptureHook { public final class CaptureHook {
private static final String LABEL = "+ Add to Crafting Goals"; public static final KeyMapping ADD_GOAL = new KeyMapping(
private static final int PAD_X = 6; "key.satistaskory.add_goal",
private static final int PAD_Y = 4; KeyConflictContext.GUI,
InputConstants.Type.KEYSYM,
GLFW.GLFW_KEY_EQUAL,
"key.categories.satistaskory");
private static final Field RECIPE_PAGE; private static final Field RECIPE_PAGE;
private static final Field HOVERED_BUTTON; private static final Field HOVERED_BUTTON;
@@ -38,8 +47,7 @@ public final class CaptureHook {
try { try {
page = RecipeBookComponent.class.getDeclaredField("recipeBookPage"); page = RecipeBookComponent.class.getDeclaredField("recipeBookPage");
page.setAccessible(true); page.setAccessible(true);
Class<?> pageClass = page.getType(); hovered = page.getType().getDeclaredField("hoveredButton");
hovered = pageClass.getDeclaredField("hoveredButton");
hovered.setAccessible(true); hovered.setAccessible(true);
} catch (ReflectiveOperationException ignored) { } catch (ReflectiveOperationException ignored) {
// Slot hover still works if craft-book fields move. // Slot hover still works if craft-book fields move.
@@ -48,69 +56,45 @@ public final class CaptureHook {
HOVERED_BUTTON = hovered; HOVERED_BUTTON = hovered;
} }
private static int buttonX;
private static int buttonY;
private static int buttonW;
private static int buttonH;
private static ItemId hoveredItem;
private CaptureHook() {} private CaptureHook() {}
public static void render(Screen screen, GuiGraphics graphics, int mouseX, int mouseY) { public static void registerKeys(RegisterKeyMappingsEvent event) {
hoveredItem = null; event.register(ADD_GOAL);
}
public static void onTooltip(ItemTooltipEvent event) {
if (event.getEntity() == null || event.getItemStack().isEmpty()) {
return;
}
Minecraft minecraft = Minecraft.getInstance(); Minecraft minecraft = Minecraft.getInstance();
if (minecraft.player == null) { if (!(minecraft.screen instanceof AbstractContainerScreen<?>)) {
return; return;
} }
event.getToolTip()
ItemStack stack = hoveredStack(screen); .add(Component.translatable("satistaskory.tooltip.add", ADD_GOAL.getTranslatedKeyMessage())
if (stack.isEmpty()) { .withStyle(ChatFormatting.DARK_GRAY));
return;
} }
ResourceLocation key = BuiltInRegistries.ITEM.getKey(stack.getItem()); public static boolean onKey(Screen screen, int keyCode, int scanCode) {
hoveredItem = ItemId.parse(key.toString()); if (!ADD_GOAL.matches(keyCode, scanCode)) {
Font font = minecraft.font;
buttonW = font.width(LABEL) + PAD_X * 2;
buttonH = font.lineHeight + PAD_Y * 2;
buttonX = mouseX + 12;
buttonY = mouseY + 20;
if (buttonX + buttonW > screen.width - 4) {
buttonX = screen.width - 4 - buttonW;
}
if (buttonY + buttonH > screen.height - 4) {
buttonY = mouseY - buttonH - 8;
}
if (buttonX < 4) {
buttonX = 4;
}
if (buttonY < 4) {
buttonY = 4;
}
graphics.fill(buttonX, buttonY, buttonX + buttonW, buttonY + buttonH, 0xE0101010);
graphics.fill(buttonX + 1, buttonY + 1, buttonX + buttonW - 1, buttonY + buttonH - 1, 0xE0282828);
graphics.drawString(font, LABEL, buttonX + PAD_X, buttonY + PAD_Y, 0xFFFFFF, false);
}
public static boolean click(double mouseX, double mouseY) {
if (hoveredItem == null || !contains(mouseX, mouseY)) {
return false; return false;
} }
PlannerSession.get().create(hoveredItem); if (screen.getFocused() instanceof EditBox) {
return false;
}
ItemStack stack = hoveredStack(screen);
if (stack.isEmpty()) {
return false;
}
ResourceLocation key = BuiltInRegistries.ITEM.getKey(stack.getItem());
PlannerSession.get().create(ItemId.parse(key.toString()));
Minecraft minecraft = Minecraft.getInstance(); Minecraft minecraft = Minecraft.getInstance();
minecraft.getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F)); minecraft.getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F));
minecraft.player.displayClientMessage(Component.literal("Added " + hoveredItem), false); if (minecraft.player != null) {
return true; minecraft.player.displayClientMessage(
Component.translatable("satistaskory.message.added", stack.getHoverName()), false);
} }
return true;
private static boolean contains(double mouseX, double mouseY) {
return hoveredItem != null
&& mouseX >= buttonX
&& mouseX < buttonX + buttonW
&& mouseY >= buttonY
&& mouseY < buttonY + buttonH;
} }
private static ItemStack hoveredStack(Screen screen) { private static ItemStack hoveredStack(Screen screen) {
@@ -1,4 +1,8 @@
{ {
"satistaskory.overlay.title": "SATISTASKORY", "satistaskory.overlay.title": "SATISTASKORY",
"satistaskory.overlay.clear": "X Clear Items" "satistaskory.overlay.clear": "X Clear Items",
"key.categories.satistaskory": "Satistaskory",
"key.satistaskory.add_goal": "Add to Crafting Goals",
"satistaskory.tooltip.add": "[%s] Add to Crafting Goals",
"satistaskory.message.added": "Added %s to crafting goals"
} }