Paste #62346: Simple Backpack

Date: 2019/11/26 07:52:57 UTC-08:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


simple_backpack:
  type: item
  debug: false
  material: chest
  display name: <&7>Simple Backpack
  lore:
  - "<&a>9 Slot Backpack"
  - "<&e>A simple backpack for extra storage"
  - "<&e>Right click while holding to open it."
  backpack_size: 9

backpack_inventory:
  type: inventory
  debug: false
  size: <player.flag[backpacks.backpack.size]||9>
  title: <player.flag[backpacks.backpack.title]||<&c>BROKEN<&sp>INVENTORY>
  procedural items:
    - determine <player.flag[backpacks.backpack.contents].unescaped||<list[]>>

backpack_task_open:
  type: task
  script:
    - flag player backpacks.backpack.size:<context.item.script.yaml_key[backpack_size]||9> duration:2t
    - flag player backpacks.backpack.title:<context.item.display||<context.material>> duration:2t
    - flag player backpacks.backpack.contents:<context.item.nbt[backpack.contents]||<list[]>> duration:2t
    - inventory open d:backpack_inventory

backpack_events:
  type: world
  debug: false
  events:
    on player right clicks with simple_backpack:
      - determine passively cancelled
      - inject backpack_task_open

    on player clicks item in backpack_inventory:
      - if <context.item.script.yaml_key[backpack_size]||null> != null:
        - determine cancelled

    on player closes backpack_inventory:
      - adjust <player.item_in_hand> nbt:backpack.contents/<context.inventory.list_contents.escaped> save:new_bp
      - inventory set slot:<player.held_item_slot> o:<entry[new_bp].result>