Paste #70598: IcecapadeCratesScript

Date: 2020/06/12 09:41:51 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


#Script: 1.0.1
#Author: Icecapade
#Date 2020-06-20
IcecapadeCrates_Config:
    type: yaml data
    #Show Tripwires (does not affect existing crates)
    show_tripwire: true
    chests:
        #In that list diamonds have a chance of 2%, iron_ingots 8% and dirt has a chance of 30%. The remaining 60% have no result.
        #Works also with decimals. Start with the lowest value.
        #Format "<chance>/<item>"
        lightChestItems:
        - 2/i@diamond
        - 10/i@iron_ingot
        - 40/<item[dirt].with[quantity=12]>
        mediumChestItems:
        - 0.01/<item[diamond_block].with[quantity=64]>
        - 1.25/i@beacon
        - 25/<item[iron_ingot].with[quantity=8]>
        heavyChestItems:
        - "10/<item[diamond_sword].with[enchantments=sharpness,4|fire_aspect,1;display_name=<aqua>Fire Sword]>"
IcecapadeCrates_Command:
    type: command
    debug: false
    name: crates
    description: Creates Crates
    usage: /crates [Light/Medium/Heavy] (key) <&lt>#<&gt>
    aliases:
    - crate
    permission: icecapade.crates
    permission message: <&3>You need the permission <&b><permission> <&3>to use that command!
    tab complete:
    - choose <context.args.size>:
        - case 0:
            - determine <list[light|medium|heavy]>
        - case 1:
            - if "!<context.raw_args.ends_with[ ]>":
                - determine <list[light|medium|heavy].filter[starts_with[<context.args.first>]]>
            - else:
                - determine key
        - case 2:
            - if "!<context.raw_args.ends_with[ ]>":
                - determine key
    script:
    - choose <context.args.first||null>:
        - case light medium heavy:
            - if <context.args.get[2]||false> == key && <context.args.get[3].is_integer||true>:
                - give IcecapadeCrates_Key<context.args.first> q:<context.args.get[3]||8>
            - else:
                - give IcecapadeCrates_Chest<context.args.first>
                - narrate "<&3>You received a <&b><context.args.first.to_titlecase> crate<&3>."
        - default:
            - narrate "<&3>Syntax: <&b>/crates [Light/Medium/Heavy] (key) (<&lt>#<&gt>)"
IcecapadeCrates_CrateHandler:
    type: world
    debug: false
    events:
        on player right clicks armor_stand with:IcecapadeCrates_KeyLight:
        - determine passively cancelled
        - if <context.entity.flag[crate]||null> == light:
            - run IcecapadeCrates_Task def:light
        on player right clicks ender_chest with:IcecapadeCrates_KeyLight:
        - determine passively cancelled
        - if <server.flag[crates.light].get_sub_items[1].contains[<context.location>]>:
            - run IcecapadeCrates_Task def:light|<context.location>
        on player right clicks armor_stand with:IcecapadeCrates_KeyMedium:
        - determine passively cancelled
        - if <context.entity.flag[crate]||null> == medium:
            - run IcecapadeCrates_Task def:medium
        on player right clicks ender_chest with:IcecapadeCrates_KeyMedium:
        - determine passively cancelled
        - if <server.flag[crates.medium].get_sub_items[1].contains[<context.location>]>:
            - run IcecapadeCrates_Task def:medium|<context.location>
        on player right clicks armor_stand with:IcecapadeCrates_KeyHeavy:
        - determine passively cancelled
        - if <context.entity.flag[crate]||null> == heavy:
            - run IcecapadeCrates_Task def:heavy
        on player right clicks ender_chest with:IcecapadeCrates_KeyHeavy:
        - determine passively cancelled
        - if <server.flag[crates.heavy].get_sub_items[1].contains[<context.location>]>:
            - run IcecapadeCrates_Task def:heavy|<context.location>
        on player breaks ender_chest:
        - foreach <list[light|medium|heavy]> as:type:
            - if <server.flag[crates.<[type]>].get_sub_items[1].contains[<context.location>]||false>:
                - if <player.has_permission[icecapade.crates]>:
                    - define entry <server.flag[crates.<[type]>].get[<server.flag[crates.<[type]>].find_partial[<context.location>]>]>
                    - flag <[entry].after[/].as_list.first> crate:!
                    - flag <[entry].after[/].as_list.last> crate:!
                    - remove <[entry].after[/]>
                    - flag server crates.<[type]>:<-:<[entry]>
                    - stop
                - else:
                    - determine cancelled
        on player places IcecapadeCrates_Chest* permission:icecapade.crates:
        - define type <context.item_in_hand.nbt[crate].strip_color>
        - spawn armor_stand[gravity=false;visible=false;armor_pose=head|0,0,0] <context.location.add[0.5,-0.7,0.5].with_yaw[<player.location.direction[<context.location>].yaw.round_to_precision[90]>].forward_flat[0.25]> save:<[type]>
        - spawn armor_stand[gravity=false;visible=false;custom_name=<context.item_in_hand.nbt[crate]>;custom_name_visible=true] <context.location.add[0.5,-0.5,0.5]> save:name
        - if <script[IcecapadeCrates_Config].yaml_key[show_tripwire]>:
            - equip <entry[<[type]>].spawned_entity> head:<item[tripwire_hook].with[enchantments=durability,1]>
        - flag server crates.<[type]>:->:<context.location>/<entry[<[type]>].spawned_entity>|<entry[name].spawned_entity>
        - flag <entry[<[type]>].spawned_entity> crate:<[type]>
        - flag <entry[name].spawned_entity> crate:<[type]>
IcecapadeCrates_Task:
    type: task
    debug: false
    definitions: type|chest
    script:
    - if <[chest].as_location||false>:
        - if <server.flag[crates.light].get_sub_items[1].contains[<[chest]>]>:
            - stop
    - choose <[type]>:
        - case light medium heavy:
            - define chance <util.random.decimal[0].to[100]>
            - wait 1t
            - take iteminhand
            - foreach <script[IcecapadeCrates_Config].yaml_key[chests.<[type]>ChestItems].get_sub_items[1]>:
                - if <[chance]> <= <[value]>:
                    - firework <player.location.find.surface_blocks.within[4].random> random primary:<list[green|blue|yellow|aqua|white|orange].random[2]> fade:<list[green|blue|yellow|aqua|white|orange].random[2]> power:1
                    - firework <player.location.find.surface_blocks.within[4].random> random primary:<list[green|blue|yellow|aqua|white|orange].random[2]> fade:<list[green|blue|yellow|aqua|white|orange].random[2]> power:1
                    - firework <player.location.find.surface_blocks.within[4].random> random primary:<list[green|blue|yellow|aqua|white|orange].random[2]> fade:<list[green|blue|yellow|aqua|white|orange].random[2]> power:1
                    - define enderchest <player.location.find.blocks[ender_chest].within[5].first>
                    - animatechest <[enderchest]> open sound:false <player>
                    - playsound <player.location> sound:ENTITY_PLAYER_LEVELUP
                    - define item <script[IcecapadeCrates_Config].yaml_key[chests.<[type]>ChestItems].get[<[loop_index]>].after[/].parsed>
                    - give <[item]>
                    - narrate "<green>Congrats! <white>You won <gold><[item].quantity>x <&r><[item].display||<blue><[item].material.translated_name>>"
                    - wait 1s
                    - animatechest <[enderchest]> close sound:false <player>
                    - stop
            - narrate "<red>No Result"
IcecapadeCrates_ChestLight:
    type: item
    material: ender_chest
    display name: <green>Light Crate
    lore:
    - <&r>Place it to create a <green>Light Crate
    mechanisms:
        nbt:
        - crate/<green>Light
IcecapadeCrates_ChestMedium:
    type: item
    material: ender_chest
    display name: <yellow>Medium Crate
    lore:
    - <&r>Place it to create a <yellow>Medium Crate
    mechanisms:
        nbt:
        - crate/<yellow>Medium
IcecapadeCrates_ChestHeavy:
    type: item
    material: ender_chest
    display name: <red>Heavy Crate
    lore:
    - <&r>Place it to create a <red>Heavy Crate
    mechanisms:
        nbt:
        - crate/<red>Heavy
IcecapadeCrates_KeyLight:
    type: item
    material: tripwire_hook
    display name: <green>Light Key
    lore:
    - <&r>You can open a <green>Light Crate<&r> with it.
    enchantments:
    - durability:1
    mechanisms:
        hides:
        - ENCHANTS
IcecapadeCrates_KeyMedium:
    type: item
    material: tripwire_hook
    display name: <yellow>Medium Key
    lore:
    - <&r>You can open a <yellow>Medium Crate<&r> with it.
    enchantments:
    - durability:1
    mechanisms:
        hides:
        - ENCHANTS
IcecapadeCrates_KeyHeavy:
    type: item
    material: tripwire_hook
    display name: <red>Heavy Key
    lore:
    - <&r>You can open a <red>Heavy Crate<&r> with it.
    enchantments:
    - durability:1
    mechanisms:
        hides:
        - ENCHANTS