Paste #6692: blockUtil

Date: 2014/07/10 21:34:46 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


blockListTester:
  type: world
  events:
    on player right clicks with i@stick:
    - ^define playerLocation <player.location>
    # - define playerLocationRounded l@<def[playerLocation].x.as_int>,<def[playerLocation].y.as_int>,<def[playerLocation].z.as_int>,<player.location.world.after[w@]>
    - ^define endLocation <player.location.cursor_on[8]>
    - ^inject blockListUtil instantly
    - ^playeffect <def[blockList]> effect:flame qty:1
blockListUtil:
# USAGE:
#   Accepts two locations (playerLocation and endLocation) then
#   makes a cuboid and does some math to figure out which points
#   in the cuboid are on the line between the two points.
#   Then all points which are on the line are added to the
#   blockList definition which can then be used in a play effect command
#   eg. playeffect <def[blockList]> effect:name.
  type: task
  script:
  - ^define blockList li@
  - ^define checkDistance <def[playerLocation].distance[%endLocation%]>
  - ^note cu@%playerLocation%|%endLocation% as:blockListUtilCuboid
  - ^foreach <cu@blockListUtilCuboid.get_blocks> {
    - ^define playerToPoint <def[playerLocation].distance[%value%]>
    - ^define endToPoint <def[endLocation].distance[%value%]>
    - ^define currentDistance <def[playerToPoint].add[%endToPoint%]>
    - ^if <def[currentDistance].add[.2].is[MORE].than[%checkDistance%]> {
      - ^if <def[currentDistance].sub[.2].is[LESS].than[%checkDistance%]> {
        - ^define blockList <def[blockList].include[%value%]>
        }
      }
    }