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

/**
 * %: 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 5 `add "%2/%0" \`{
    "type": "%1",
    "book": "${0}",
    "tag_type": "%2",
    "tag_subtype": "%3"
%4
}\``

alias item_stack 4 `add_basic "%2" "item_stack" "%0" "%1" \`,
    "stack": "%3"
\``
alias statement 4 `add_basic "%2" "statement" "%0" "%1" \`,
    "statement": "%3"
\``

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

// 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: name, type, subtype.
alias place 3 `add "placeholder/%0" \`{
    "type": "item_stack",
    "book": "${0}",
    "tag_type": "%1",
    "tag_subtype": "%2",
    "stack": "buildcraftunofficial:%0"
}\``

// 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.
alias place_creative 3 `add "placeholder/%0" \`{
    "type": "item_stack",
    "book": "${0}",
    "tag_type": "%1",
    "tag_subtype": "%2",
    "stack": "buildcraftunofficial:%0",
    "creative_only": true
}\``

alias item_stack_creative 4 `add_basic "%2" "item_stack" "%0" "%1" \`,
    "stack": "%3",
    "creative_only": true
\``
// 3-arg form used transitively by item_tool/item_gear/item_plug aliases
alias item_typed 3 `item_stack "item" "%0" "%1" "%2"`
alias block_full 3 `item_stack "block" "%0" "%1" "%2"`
alias block 2 `item_stack "block" "%0" "%1" "buildcraftunofficial:%1"`
alias pipe 3 `item_stack "pipe" "%0" "%1" "%2"`
alias trigger 3 `statement "trigger" "%0" "%1" "%2"`
alias action 3 `statement "action" "%0" "%1" "%2"`

alias item_tool 2 `item_typed "tool" "%0" "%1"`
alias item_gear 2 `item_typed "gear" "%0" "%1"`
alias item_plug 2 `item_typed "pipe_plug" "%0" "%1"`
alias pipe_item 2 `pipe "pipe_item" "%0" "%1"`
alias pipe_fluid 2 `pipe "pipe_fluid" "%0" "%1"`
alias pipe_power 2 `pipe "pipe_power" "%0" "%1"`
alias pipe_rf 2 `pipe "pipe_rf" "%0" "%1"`

// 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".
alias item_stack_s 5 `add_basic "%2" "item_stack" "%0" "%1" \`,
    "stack": "%3",
    "sort": %4
\``
alias pipe_s 4 `item_stack_s "pipe" "%0" "%1" "%2" "%3"`
alias pipe_item_s 3 `pipe_s "pipe_item" "%0" "%1" "%2"`
alias pipe_fluid_s 3 `pipe_s "pipe_fluid" "%0" "%1" "%2"`
alias pipe_power_s 3 `pipe_s "pipe_power" "%0" "%1" "%2"`
alias pipe_rf_s 3 `pipe_s "pipe_rf" "%0" "%1" "%2"`
alias block_engine 2 `block "engine" "%0" "%1"`
alias block_refining 1 `block "refining" "%0"`
alias block_fluid 1 `block "fluid" "%0"`
alias block_mining 1 `block "mining" "%0"`
alias block_auto 1 `block "automation" "%0"`
alias block_engine 2 `block_full "engine" "%0" "%1"`

alias tool 1 `item_tool "%0" "buildcraftunofficial:%0"`
alias gear 1 `item_gear "%0" "buildcraftunofficial:%0"`
alias plug 1 `item_plug "%0" "buildcraftunofficial:%0"`
alias paper 1 `item_typed "paperwork" "%0" "buildcraftunofficial:%0"`
alias chipset 1 `item_typed "chipset" "%0" "buildcraftunofficial:%0"`

alias block_refining 1 `block "refining" "%0"`
alias block_fluid 1 `block "fluid" "%0"`
alias block_mining 1 `block "mining" "%0"`
alias block_auto 1 `block "automation" "%0"`

// 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.
alias cfg_res 1 `add "config/%0" \`{
    "type": "external",
    "book": "${0}",
    "tag_type": "config",
    "tag_subtype": "resourcepack",
    "title": "%0"
}\``
