Paste #34672: Edit of P#34669 Darkness Warding Items

Date: 2016/07/11 20:30:21 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


Luminescent Items:
    affected_mobs:
    - wolf
    - spider
    - cavespider
    - witch
    luminescent_items:
    - i@torch
    - i@glowstone
    - i@sea_lantern
    - i@redstone_torch_on
    - i@lava_bucket
    - i@jack_o_lantern
    - i@glowstone_dust
    - i@beacon
    success max: 10
    success min: 6
    duration: d@2s-15s
    light_time_update: d@12t
    light_levels:
        i@torch: 12
        i@glowstone: 15
        i@sea_lantern: 15
        i@redstone_torch_on: 4
        i@lava_bucket: 6
        i@jack_o_lantern: 8
        i@glowstone_dust: 5
        i@beacon: 15


    type: world
    events:
        on entity damages entity:
        - async:
            - if <context.damager.item_in_hand.simple||none> != i@torch
              queue clear
            - define max "<script.yaml_key[success max]>"
            - define min "<script.yaml_key[success min]>"
            - define roll <util.random.int[0].to[<def[max]>]>
            - if !<def[roll].is[or_more].than[<def[min]>]> queue clear
            - narrate "<gray>You set your enemies on <red>fire<yellow>!"
            - define duration <script.yaml_key[duration]>
            - burn <context.entity> duration:%duration%

        on entity targets:
        - if !<script.yaml_key[affected_mobs].contains[<context.entity.name>]>                  queue clear
        - if !<context.reason.contains[closest_player]>                                         queue clear
        - if !<script.yaml_key[luminescent_items].contains[<context.target.item_in_hand>]>
          && !<script.yaml_key[luminescent_items].contains[<context.target.item_in_offhand>]>   queue clear
        - determine cancelled


        on player holds item:
        - async:
            - define name <player.name>_light_update_queue
            - if <queue.exists[<def[name]>]> queue clear
            - run "Hand Item Light Update" def:<script>|<player> id:<def[name]>



Hand Item Light Update:
    type: task
    definitions: script|entity
    speed: 0t
    default_script: "s@Luminescent Items"
    type_script: as_script
    type_entity: as_entity
    script:
    - inject typecheck

    - if !<def[entity].is_spawned> queue clear

    - define items <def[script].yaml_key[luminescent_items]>

    - while <def[items].contains[<def[entity].item_in_hand.simple>].or[<def[items].contains[<def[entity].item_in_offhand.simple>]>]> {

        - wait <def[script].yaml_key[light_time_update]>

        - if !<def[entity].is_spawned> while stop

        - define location
          <def[entity].location.simple.as_location>

        #if didnt move, dont do anything
        - if <def[location]> == <def[last_location]||no_last_location>
          while next

        #hand light values even if the item isnt a luminessent item
        - define hand_light
          <def[script].yaml_key[light_levels.<def[entity].item_in_hand.simple>]||0>

        - define off_hand_light
          <def[script].yaml_key[light_levels.<def[entity].item_in_offhand.simple>]||0>

        - if <def[hand_light].is[or_more].than[<def[off_hand_light]>]> {
            - define light <def[hand_light]>
            } else {
            - define light <def[off_hand_light]>
            }

        #change lighting according to scripted values
        - light
          <def[location]>
          <def[light]>
          duration:d@1m

        #reset old lighting if last_location exists
        - if <def[last_location].exists||false>
          light
          <def[last_location]>
          reset

        #define last_location as this location
        - define last_location
          <def[location]>
        }

    - if <def[last_location].exists||false>
      light 
      <def[last_location]>
      reset