~{buildcraft/json/lib}
/**
 * %: The target book for all entries passed to add_basic
 */
~args 1

// ---------------------------------------------------------------------------
// Every alias below takes the game SYSTEM as its FIRST argument and writes it to the entry's
// "tag_system" field. The system is the top level of the contents page (Getting Started,
// Power, Transport, Gates and Logic, Building, Mining and Fluids, Silicon, Robots); the
// type/subtype tags that used to be the whole hierarchy now only order entries WITHIN a
// system. Valid systems: getting_started, power, transport, logic, building, mining_fluids,
// silicon, robots. The config book (cfg_res, bottom of the file) is a separate book with its
// own contents page and deliberately carries no system.
// ---------------------------------------------------------------------------

/**
 * %: The game system. One of getting_started, power, transport, logic, building, mining_fluids, silicon, robots.
 * %: The ending name for the page.
 * %: The json type. Like "item_stack" or "external"
 * %: The guide display type. Like "item" or "trigger"
 * %: The guide display subtype. Like "tool" or "engine"
 * %: Extra json to append to the object.
 */
alias add_basic 6 `add "%3/%1" \`{
    "type": "%2",
    "book": "${0}",
    "tag_system": "%0",
    "tag_type": "%3",
    "tag_subtype": "%4"
%5
}\``

// Args: system, display type, subtype, name, stack.
alias item_stack 5 `add_basic "%0" "%3" "item_stack" "%1" "%2" \`,
    "stack": "%4"
\``
// Args: system, display type, subtype, name, statement id.
alias statement 5 `add_basic "%0" "%3" "statement" "%1" "%2" \`,
    "statement": "%4"
\``

// 3-arg form for placeholder entries: `item "systemname" "placeholder/name" "mod:stack"`
// Registers directly via `add`, preserving the full path so loadLangInternal finds the .md file.
alias item 3 `add "%1" \`{
    "type": "item_stack",
    "book": "${0}",
    "tag_system": "%0",
    "tag_type": "placeholder",
    "tag_subtype": "",
    "stack": "%2"
}\``

// Placeholder entry with proper typing — path stays placeholder/<name>.md (so the
// stub content still loads) but tag_type/tag_subtype drive TOC categorization,
// so these show up under Blocks/Items/Pipes tabs instead of a single "Placeholder"
// tab. Stack is auto-derived as buildcraftunofficial:<name>. Args: system, name, type, subtype.
alias place 4 `add "placeholder/%1" \`{
    "type": "item_stack",
    "book": "${0}",
    "tag_system": "%0",
    "tag_type": "%2",
    "tag_subtype": "%3",
    "stack": "buildcraftunofficial:%1"
}\``

// Creative-only variants of `place` and `item_stack`. Flag the entry with
// `creative_only: true` so PageLink hides it from the TOC (and from search
// results) unless the local player can spawn the item — creative mode, OP
// level 2+, or singleplayer/LAN host with cheats on. Use for entries that
// document items with no survival recipe (creative engine, debugger,
// volume box) so survival players aren't shown things they can't obtain.
// Args mirror the non-creative aliases (system first).
alias place_creative 4 `add "placeholder/%1" \`{
    "type": "item_stack",
    "book": "${0}",
    "tag_system": "%0",
    "tag_type": "%2",
    "tag_subtype": "%3",
    "stack": "buildcraftunofficial:%1",
    "creative_only": true
}\``

alias item_stack_creative 5 `add_basic "%0" "%3" "item_stack" "%1" "%2" \`,
    "stack": "%4",
    "creative_only": true
\``
// 4-arg form used transitively by item_tool/item_gear/item_plug aliases. Args: system, subtype, name, stack.
alias item_typed 4 `item_stack "%0" "item" "%1" "%2" "%3"`
// Args: system, subtype, name, stack.
alias block_full 4 `item_stack "%0" "block" "%1" "%2" "%3"`
// Auto-stack form (stack is buildcraftunofficial:<name>). Args: system, subtype, name.
alias block 3 `item_stack "%0" "block" "%1" "%2" "buildcraftunofficial:%2"`
// Args: system, subtype, name, stack.
alias pipe 4 `item_stack "%0" "pipe" "%1" "%2" "%3"`
// Args: system, subtype, name, statement id.
alias trigger 4 `statement "%0" "trigger" "%1" "%2" "%3"`
alias action 4 `statement "%0" "action" "%1" "%2" "%3"`

// Args: system, name, stack.
alias item_tool 3 `item_typed "%0" "tool" "%1" "%2"`
alias item_gear 3 `item_typed "%0" "gear" "%1" "%2"`
alias item_plug 3 `item_typed "%0" "pipe_plug" "%1" "%2"`
alias pipe_item 3 `pipe "%0" "pipe_item" "%1" "%2"`
alias pipe_fluid 3 `pipe "%0" "pipe_fluid" "%1" "%2"`
alias pipe_power 3 `pipe "%0" "pipe_power" "%1" "%2"`
alias pipe_rf 3 `pipe "%0" "pipe_rf" "%1" "%2"`

// Sorted variants: identical to the aliases above but with a trailing TOC sort weight.
// Lower weights sort earlier; equal weights fall back to alphabetical; a chapter inherits
// the lowest weight among its members (so weighting a subtype's pages also orders the
// subtype itself). Weight 0 == the historical alphabetical order. Reuses add_basic's
// extra-JSON slot to append "sort".
// Args: system, display type, subtype, name, stack, sort.
alias item_stack_s 6 `add_basic "%0" "%3" "item_stack" "%1" "%2" \`,
    "stack": "%4",
    "sort": %5
\``
// Args: system, subtype, name, stack, sort.
alias pipe_s 5 `item_stack_s "%0" "pipe" "%1" "%2" "%3" "%4"`
// Args: system, name, stack, sort.
alias pipe_item_s 4 `pipe_s "%0" "pipe_item" "%1" "%2" "%3"`
alias pipe_fluid_s 4 `pipe_s "%0" "pipe_fluid" "%1" "%2" "%3"`
alias pipe_power_s 4 `pipe_s "%0" "pipe_power" "%1" "%2" "%3"`
alias pipe_rf_s 4 `pipe_s "%0" "pipe_rf" "%1" "%2" "%3"`
// Weighted tool item (auto-stack). Args: system, name, sort.
alias tool_s 3 `item_stack_s "%0" "item" "tool" "%1" "buildcraftunofficial:%1" "%2"`

// Args: system, name, stack.
alias block_engine 3 `block_full "%0" "engine" "%1" "%2"`
// Args: system, name.
alias block_refining 2 `block "%0" "refining" "%1"`
alias block_fluid 2 `block "%0" "fluid" "%1"`
alias block_mining 2 `block "%0" "mining" "%1"`

// Args: system, name.
alias tool 2 `item_tool "%0" "%1" "buildcraftunofficial:%1"`
alias gear 2 `item_gear "%0" "%1" "buildcraftunofficial:%1"`
alias plug 2 `item_plug "%0" "%1" "buildcraftunofficial:%1"`
alias paper 2 `item_typed "%0" "paperwork" "%1" "buildcraftunofficial:%1"`
alias chipset 2 `item_typed "%0" "chipset" "%1" "buildcraftunofficial:%1"`

// Robot board pages: `board "<name>" "<board id>"` -> board/<name>.md. A board is not an item of its own
// (every board is the one redstone_board item carrying a board id in its data), so these are
// `external` entries titled through buildcraft.guide.page.board_<name>, filed under
// Robots > Boards (Items > Boards by type). The icon is the programmed board itself: robotics
// registers the "board" icon kind, whose argument is the board's registry id.
alias board 2 `add "board/%0" \`{
    "type": "external",
    "book": "${0}",
    "tag_system": "robots",
    "tag_type": "item",
    "tag_subtype": "board",
    "title": "board_%0",
    "icon": { "board": "%1" }
}\``
// Concept page with an explicit TOC placement and weight: `concept "<sys>" "<subtype>" "<name>" "<sort>"`
// -> concept/<name>.md, titled through buildcraft.guide.page.<name>.
alias concept 4 `add "concept/%2" \`{
    "type": "external",
    "book": "${0}",
    "tag_system": "%0",
    "tag_type": "item",
    "tag_subtype": "%1",
    "title": "%2",
    "sort": %3
}\``

// Config-guide page registration. Path stays config/<name>.md so loadLangInternal
// finds the existing .md content. Uses ${0} so the book is set by the importer.
// No tag_system: the config book is a separate book with its own contents page.
alias cfg_res 1 `add "config/%0" \`{
    "type": "external",
    "book": "${0}",
    "tag_type": "config",
    "tag_subtype": "resourcepack",
    "title": "%0"
}\``
