Advertisement
Nick2253

WorldEdit Macro

May 25th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.87 KB | None | 0 0
  1. //worldedit macro
  2. // used to change arrow keys to match currently facing direction
  3. // also provides capability related to modifier functions
  4. //
  5. // This does not work very well if the player is not looking level.
  6. // If you are looking up or down, this macro will have unexpected behavior.
  7. //
  8. // Inputs:
  9. //    &direction = direction for input key (forward, back, right, left, up, down)
  10. //    &function_array  = string of world edit functions, of form: <key>=<value>,<key2>=<value2>,...
  11. //
  12. //      Keys:
  13. //        function = (required) fuction to run (shift, move, expand, contract, etc)
  14. //                   (use move -s to move the selection with the region)
  15. //        shift =  worldedit function to run when the shift key is pressed
  16. //        ctrl  =  worldedit function to run when the ctrl key is pressed
  17. //        alt  =  worldedit function to run when the alt key is pressed
  18. //        shift-ctrl =  worldedit function to run when the shift+ctrl key is pressed
  19. //        shift-alt  =  worldedit function to run when the shift+alt key is pressed
  20. //        ctrl-alt  =  worldedit function to run when the ctrl+alt key is pressed
  21. //        shift-ctrl-alt = function to run when shift+ctrl+alt key is pressed
  22. //
  23.  
  24. //clear variables
  25.  
  26. unset(&key)
  27. unset(&value)
  28. unset(&keyvalue)
  29. unset(&func)
  30.  
  31. unset(&function)
  32. unset(&shiftf)
  33. unset(&ctrlf)
  34. unset(&altf)
  35. unset(&shift_ctrlf)
  36. unset(&shift_altf)
  37. unset(&ctrl_altf)
  38. unset(&shift_ctrl_altf)
  39.  
  40. // Parse &fuction_array
  41. &function_array[] = split(",","$$[2]")
  42.  
  43. DO
  44.   pop(&function_array[],&func)
  45.   &keyvalue[] = split("=",%&func%)
  46.   &key = %&keyvalue[0]%
  47.   &value = %&keyvalue[1]%
  48.  
  49.   log(%&key% = %&value%)
  50.  
  51.   if(%&key% = "function")
  52.     &function = %&value%
  53.   elseif(%&key% = "shift")
  54.     &shiftf = %&value%
  55.   elseif(%&key% = "ctrl")
  56.     &ctrlf = %&value%
  57.   elseif(%&key% = "alt")
  58.     &altf = %&value%
  59.   elseif(%&key% = "shift-ctrl")
  60.     &shift_ctrlf = %&value%
  61.   elseif(%&key% = "shift-alt")
  62.     &shift_altf = %&value%
  63.   elseif(%&key% = "ctrl-alt")
  64.     &ctrl_altf = %&value%
  65.   elseif(%&key% = "shift-ctrl-alt")
  66.     &shift_ctrl_altf = %&value%
  67.   else
  68.     LOG(WARN: %&key% is not recognized (value: %&value%))
  69.   endif
  70. WHILE(&function_array[0])
  71.  
  72. if(!&function)
  73.   log(ERR: no function provided)
  74.   stop()
  75. endif
  76.  
  77. // Set initial variables and index.
  78.  
  79. //array of directions, used to rotate frame of reference
  80. &dir_array[] = split(",","N,E,S,W,N,E,S,W,N")
  81.  
  82. //the input direction
  83. &direction = $$[1]
  84.  
  85. //determine rotation to shift index in dir_array
  86. //this command takes advantage of integer division.
  87. //We want N to be all angles -45 to +45, so we rotate
  88. //by 45 degrees so we can perform integer division into
  89. //the quarters of the unit circle.
  90. #index_adj = (%CARDINALYAW%+45)/90
  91.  
  92. //set the default index, relative to N
  93. if(%&direction% = "forward")
  94.   #index = 0
  95. elseif(%&direction% = "right")
  96.   #index = 1
  97. elseif(%&direction% = "back")
  98.   #index = 2
  99. elseif(%&direction% = "left")
  100.   #index = 3
  101. else
  102.   LOG(Err: bad input.  Direction does not match options, or was not provided.)
  103.   log(  direction = %&direction%)
  104.   STOP()
  105. endif
  106.  
  107. //increment the default index by the index adjustment
  108. INC(#index,%#index_adj%)
  109.  
  110. //set the command based on the modifier keys and functions present
  111. if((SHIFT) && (CTRL) && (ALT) && (ctrlf))
  112.   &command = %&shift_ctrl_altf%
  113. elseif((CTRL) && (ALT) && (ctrlf))
  114.   &command = %&ctrl_altf%
  115. elseif((SHIFT) && (CTRL) && (&shift_ctrlf))
  116.   &command = %&shift_ctrlf%
  117. elseif((SHIFT) && (ALT) && (&shift_altf))
  118.   &command = %&shift_altf%
  119. elseif((SHIFT) && (&shiftf))
  120.   log(SHIFT IS IN THE HOUSE)
  121.   &command = %&shiftf%
  122. elseif((CTRL) && (&ctrlf))
  123.   &command = %&ctrlf%
  124. elseif((ALT) && (&altf))
  125.   &command = %&altf%
  126. else
  127.   //no modifier keys or other functions present, so use default function
  128.   &command = %&function%
  129. endif
  130.  
  131. &output = //%&command% 1 %&dir_array[%#index%]%
  132.  
  133. echo(%&output%)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement