Paste #71024: Untitled Paste

Date: 2020/06/19 08:20:34 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


## Instruments
## By: princil

## Configuration:
instruments_config:
  type: yaml data
  config:
    # Can players use instruments to craft items? [default=false]
    can_craft: false
    # Can players hurt entities using instruments? [default=true]
    can_damage: true
    # Can players break blocks using instruments? [default=true]
    can_break: true

## To add your own items, copy-paste the commented (green) text below the other items, remove each # from the copied text, and fill in the {item_name}, {material}, {sound} and {item_display_name} values.

#{item_name}:
#  type: item
#  material: {material}[nbt=sound/{sound}]
#  debug: false
#  display name: <&r>{item_display_name}

## Items
basedrum:
  type: item
  material: leather[nbt=sound/block_note_block_basedrum]
  debug: false
  display name: <&r>Drum
  recipes:
    1:
      type: shaped
      input:
      - leather|leather|leather
      - leather|oak_planks/birch_planks/spruce_planks/jungle_planks/acacia_planks/dark_oak_planks|leather
      - oak_planks/birch_planks/spruce_planks/jungle_planks/acacia_planks/dark_oak_planks|oak_planks/birch_planks/spruce_planks/jungle_planks/acacia_planks/dark_oak_planks|oak_planks/birch_planks/spruce_planks/jungle_planks/acacia_planks/dark_oak_planks
bell:
  type: item
  material: gold_ingot[nbt=sound/block_note_block_bell]
  debug: false
  display name: <&r>Bell
  recipes:
    1:
      type: shaped
      input:
      - air|gold_nugget|air
      - gold_ingot|gold_ingot|gold_ingot
      - gold_ingot|gold_nugget|gold_ingot
flute:
  type: item
  material: stick[nbt=sound/block_note_block_flute]
  debug: false
  display name: <&r>Flute
  recipes:
    1:
      type: shaped
      input:
      - air|air|dark_oak_planks
      - air|dark_oak_planks|air
      - birch_planks|air|air
guitar:
  type: item
  material: stick[nbt=sound/block_note_block_guitar]
  debug: false
  display name: <&r>Guitar
  recipes:
    1:
      type: shaped
      input:
      - air|string|oak_planks/birch_planks/spruce_planks/jungle_planks/acacia_planks/dark_oak_planks|oak_planks/birch_planks/spruce_planks/jungle_planks/acacia_planks/dark_oak_planks
      - oak_planks/birch_planks/spruce_planks/jungle_planks/acacia_planks/dark_oak_planks|oak_planks/birch_planks/spruce_planks/jungle_planks/acacia_planks/dark_oak_planks|oak_planks/birch_planks/spruce_planks/jungle_planks/acacia_planks/dark_oak_planks|oak_planks/birch_planks/spruce_planks/jungle_planks/acacia_planks/dark_oak_planks|string
      - oak_planks/birch_planks/spruce_planks/jungle_planks/acacia_planks/dark_oak_planks|oak_planks/birch_planks/spruce_planks/jungle_planks/acacia_planks/dark_oak_planks|oak_planks/birch_planks/spruce_planks/jungle_planks/acacia_planks/dark_oak_planks|oak_planks/birch_planks/spruce_planks/jungle_planks/acacia_planks/dark_oak_planks|string
harp:
  type: item
  material: gold_ingot[nbt=sound/block_note_block_harp]
  debug: false
  display name: <&r>Harp
  recipes:
    1:
      type: shaped
      input:
      - gold_ingot|gold_ingot|gold_ingot
      - gold_ingot|string|gold_ingot
      - gold_ingot|string|gold_ingot
xylophone:
  type: item
  material: bone[nbt=sound/block_note_block_xylophone]
  debug: false
  display name: <&r>Bone Xylophone
  recipes:
    1:
      type: shaped
      input:
      - bone|air|bone
      - bone|bone|air
      - air|bone|bone
snare:
  type: item
  material: leather[nbt=sound/block_note_block_snare]
  debug: false
  display name: <&r>Short Drum
  recipes:
    1:
      type: shaped
      input:
      - leather|leather
      - oak_planks/birch_planks/spruce_planks/jungle_planks/acacia_planks/dark_oak_planks|oak_planks/birch_planks/spruce_planks/jungle_planks/acacia_planks/dark_oak_planks

## Handlers
instrument_handler:
  type: world
  debug: false
  events:
    on entity damaged by player:
    - if <player.item_in_hand.has_nbt[sound]>:
      - if !<script[instruments_config].yaml_key[config.can_damage]>:
        - determine cancelled
    on player breaks block:
    - if <player.item_in_hand.has_nbt[sound]>:
      - if !<script[instruments_config].yaml_key[config.can_break]>:
        - determine cancelled
    on item recipe formed:
    - if <script[instruments_config].yaml_key[config.can_craft]>:
      - stop
    - foreach <context.recipe>:
      - if <[value].has_nbt[sound]>:
        - determine cancelled
    after player right clicks entity with item:
    - define pitch:<element[1.05946].power[<player.location.pitch.sub[90].mul[-1].mul[<element[12].div[180]>].round.add[12]>].div[2]>
    - inject instrument_task
    after player left clicks with item:
    - define pitch:<element[1.05946].power[<player.location.pitch.sub[90].mul[-1].mul[<element[12].div[180]>].round>].div[2]>
    - inject instrument_task
    after player right clicks with item:
    - define pitch:<element[1.05946].power[<player.location.pitch.sub[90].mul[-1].mul[<element[12].div[180]>].round.add[12]>].div[2]>
    - inject instrument_task
instrument_task:
  type: task
  debug: false
  script:
    - if <player.item_in_hand.has_nbt[sound]>:
      - if !<player.open_inventory.as_element.contains_text[player]>:
        - stop
      - determine passively cancelled
      - if <player.item_in_hand.has_nbt[custom]>:
        - playsound <player.location> sound:<player.item_in_hand.nbt[sound]> pitch:<[pitch]> custom sound_category:records
      - else:
        - playsound <player.location> sound:<player.item_in_hand.nbt[sound]> pitch:<[pitch]> sound_category:records
      - playeffect effect:NOTE at:<player.location.add[0,2,0].add[<util.random.decimal[-0.5].to[0.5]>,<util.random.decimal[0].to[0.5]>,<util.random.decimal[-0.5].to[0.5]>]> offset:<[pitch]>,0,0 quantity:0 data:1