# A shop sign that notices you. Every player walks this on their own: someone
# standing close sees it react while someone across the street sees it idle.
# From afar only the emerald shows; come close and the sign pops up and greets
# you; walk away and it tucks itself away again until you come back.
#
# Change `world` to a world you have, then /hbb reload. /hbb movehere example
# brings it to you.

location: { world: world, x: 0.5, y: 65.0, z: 0.5, yaw: 0 }
view-distance: 48
look-radius: 1.0

layers:
  title:
    type: text
    text: "<gradient:gold:yellow><b>SHOP</b></gradient>"
    offset: [0, 2.2, 0]
    shadow: true
  hint:
    type: text
    text: "<gray>Hello, {player}</gray>"
    offset: [0, 1.95, 0]
  icon:
    type: item
    item: EMERALD
    offset: [0, 1.4, 0]
    scale: 0.6
    glow: "#55ff88"

# Clips of your own, next to the built-in presets. Keyframes: tick, value, and
# the easing of the segment that starts there (easings.net names, or
# cubic-bezier(x1,y1,x2,y2)).
clips:
  sway:
    duration: 40
    loop: true
    tracks:
      - layer: title
        property: rotation-z
        keyframes:
          - { t: 0, value: -4, ease: ease-in-out-sine }
          - { t: 20, value: 4, ease: ease-in-out-sine }
          - { t: 40, value: -4 }
  # Size 0 for as long as it plays: the sign is tucked away until the first
  # visit. After that, the pop-out at leaving keeps it that way.
  hidden:
    duration: 20
    loop: true
    tracks:
      - property: scale
        keyframes:
          - { t: 0, value: 0 }
          - { t: 20, value: 0 }

behavior:
  initial: idle
  states:
    # Nobody came close yet, or just arrived in range: only the emerald.
    idle:
      loop: [ "bob", "spin@icon", "sway", "glow-pulse@icon", "hidden@title", "hidden@hint" ]
      on:
        - when: { near: 4 }
          play: [ "pop-in@title", "pop-in@hint", "typewriter@hint" ]
          run: [ "[sound] block.amethyst_block.chime 1 1.4" ]
          goto: close
    close:
      loop: [ "bob", "spin@icon", "sway", "glow-pulse@icon" ]
      on:
        - when: look
          play: [ "wiggle@icon" ]
        - when: right-click
          play: [ "bounce" ]
          run: [ "[message] <green>Welcome in, {player}!", "[sound] entity.villager.yes" ]
          text: { hint: "<yellow>Come in, {player}!</yellow>" }
        - when: { far: 6 }
          play: [ "pop-out@title", "pop-out@hint" ]
          goto: away
    # Walked off: the pop-out holds the sign at size 0 until they come back.
    away:
      loop: [ "bob", "spin@icon", "sway", "glow-pulse@icon" ]
      on:
        - when: { near: 4 }
          play: [ "pop-in@title", "pop-in@hint", "typewriter@hint" ]
          run: [ "[sound] block.amethyst_block.chime 1 1.4" ]
          goto: close
