Skip to content

Crafting system (2x2 + 3x3 grid, recipe matching) #8

Description

@MichaelFisher1997

Phase 2 foundation. Do this first — smelting (#3), tools (#4) and farming (#5) all build on the recipe registry and slot/UI patterns established here.

Context

The inventory already ships a disabled 2x2 crafting grid placeholder at src/ui/InventoryUI.ts:77-88 — four slot slot-disabled divs with no backing data model. There is no recipe registry and no matcher anywhere in the codebase today.

Scope

  • New src/game/Recipes.ts — does not exist. Define:
    • Recipe type supporting shaped (pattern + key→itemId) and shapeless (set of inputs) recipes
    • RECIPES registry array
    • match(grid: (ItemId | null)[]): ItemId | null matcher that scans both 2x2 (inventory) and 3x3 (table) subregions
  • src/ui/InventoryUI.ts:77-88 — replace the four slot-disabled divs with interactive craft-input slots and a live output slot that re-resolves on every grid mutation; consume inputs on craft.
  • src/game/Inventory.ts — add a craftingGrid: ItemStack[9] field (separate from backpack slots); reuse existing getSlot/setSlot/add/remove helpers (lines 31-91). Persist craft-grid state with the save.
  • src/game/Items.ts — register newly craftable item ids (e.g. planks, stick, crafting_table); add to CREATIVE_PALETTE (line 84) and DROP_TABLE (line 114) as needed.
  • src/ui/ui.css (~.inv-craft-grid lines 695-712) — drop slot-disabled styling, add hover/active/drag state.
  • (Optional, unlock 3x3) Add a crafting_table block — requires touching Blocks.ts + BlockIds.ts + Textures.ts in lockstep per AGENTS.md (block ids must stay stable; atlas is 8x8 = 64 tiles).

Starter recipe set

  • 1 log → 4 planks (shapeless)
  • 2 planks → 4 sticks (shaped)
  • 4 planks → crafting table (shaped)

Acceptance criteria

  • Craft-input slots accept dragged items from the backpack; output slot shows the matched result live.
  • Crafting consumes inputs and places the result in the held/cursor slot.
  • Recipes.ts is exported and unit-testable (pure match() function).
  • At least the three starter recipes work end-to-end in survival mode.
  • No regressions to existing inventory drag/drop and hotbar behaviour.

Roadmap reference

Phase 2 — "Crafting system".

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestphase-2Phase 2 — Crafting & survival depth (active)

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions