Advertisement
peacestorm

Test_BuildTree

Apr 20th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let isInGame = false;
  2. const Thread_ = java.lang.Thread;
  3. const Handler_ = android.os.Handler;
  4. const Runnable_ = java.lang.Runnable;
  5.  
  6. let treeCoords = [
  7.     [+0,+1,0,17],
  8.     [+0,+2,0,17],
  9.     [+0,+3,0,17],
  10.     [+0,+4,0,17],
  11.     [+0,+5,0,17],
  12.     [+0,+6,0,17],
  13.       //Leaves
  14.     [+2,+4,+2,18],
  15.     [+1,+4,+2,18],
  16.     [+0,+4,+2,18],
  17.     [-1,+4,+2,18],
  18.     [-2,+4,+2,18],
  19.     [+2,+4,+1,18],
  20.     [+1,+4,+1,18],
  21.     [+0,+4,+1,18],
  22.     [-1,+4,+1,18],
  23.     [-2,+4,+1,18],
  24.     [+2,+4,0,18],
  25.     [+1,+4,0,18],
  26.     [-1,+4,0,18],
  27.     [-2,+4,0,18],
  28.     [+2,+4,-1,18],
  29.     [+1,+4,-1,18],
  30.     [+0,+4,-1,18],
  31.     [-1,+4,-1,18],
  32.     [-2,+4,-1,18],
  33.     [+2,+4,-2,18],
  34.     [+1,+4,-2,18],
  35.     [+0,+4,-2,18],
  36.     [-1,+4,-2,18],
  37. //2nd layer
  38.     [+2,+5,+2,18],
  39.     [+1,+5,+2,18],
  40.     [+0,+5,+2,18],
  41.     [-1,+5,+2,18],
  42.     [+2,+5,+1,18],
  43.     [+1,+5,+1,18],
  44.     [+0,+5,+1,18],
  45.     [-1,+5,+1,18],
  46.     [-2,+5,+1,18],
  47.     [+2,+5,0,18],
  48.     [+1,+5,0,18],
  49.     [-1,+5,0,18],
  50.     [-2,+5,0,18],
  51.     [+2,+5,-1,18],
  52.     [+1,+5,-1,18],
  53.     [+0,+5,-1,18],
  54.     [-1,+5,-1,18],
  55.     [-2,+5,-1,18],
  56.     [+2,+5,-2,18],
  57.     [+1,+5,-2,18],
  58.     [+0,+5,-2,18],
  59.     [-1,+5,-2,18],
  60.     [-2,+5,-2,18],
  61. //3rd layer
  62.     [+0,+6,+1,18],
  63.     [+1,+6,0,18],
  64.     [-1,+6,0,18],
  65.     [+1,+6,-1,18],
  66.     [+0,+6,-1,18],
  67. //4th layer
  68.     [+0,+7,+1,18],
  69.     [+1,+7,0,18],
  70.     [+0,+7,0,18],
  71.     [-1,+7,0,18],
  72.     [+0,+7,-1,18]
  73. ];
  74.  
  75. let ctx = com.mojang.minecraftpe.MainActivity.currentMainActivity.get();
  76.  
  77. function delayFunction(func, delay) {
  78.     ctx.runOnUiThread(new java.lang.Runnable({
  79.         run: function() {
  80.             new Handler_().postDelayed(
  81.                 new Runnable_() {
  82.                     run: func
  83.                 },
  84.             delay);
  85.         }
  86.     }));
  87. }
  88.  
  89. function buildTree(x, y, z, count) {
  90.     if(count == null) {
  91.         count = 0;
  92.     }
  93.     if(isInGame && count < treeCoords.length) {
  94.         delayFunction(function() {
  95.             let currentCoords = treeCoords[count];
  96.             setTile(x + currentCoords[0], y + currentCoords[1], z + currentCoords[2], currentCoords[3]); //above or below setTile, you can add more functions
  97.             buildTree(x, y, z, count + 1); //<< don't remove this part
  98.         }, 320);
  99.     }
  100. }
  101.  
  102. function newLevel() {
  103.     //make sure to add isInGame = true; into our own newLevel, example:
  104.     isInGame = true;
  105. }
  106.  
  107. function leaveGame() {
  108.     isInGame = false;
  109. }
  110.  
  111. function useItem(x, y, z) {
  112.     //test
  113.     //if you want to delay for 5 seconds before starting to build, do it like this:
  114.     delayFunction(function() {
  115.         buildTree(x, y, z);
  116.     }, 5000); //<< 5000 is the amount of milliseconds
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement