box_core.txt 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. //---map specific---
  2. creative_world = world.get("creative");
  3. edge1 = loc.new(creative_world, 2991, 54, 2956);
  4. edge2 = loc.new(creative_world, 3009, 72, 2974);
  5. x1 = math.min(loc.getX(edge1), loc.getX(edge2));
  6. x2 = math.max(loc.getX(edge1), loc.getX(edge2));
  7. y1 = math.min(loc.getY(edge1), loc.getY(edge2));
  8. y2 = math.max(loc.getY(edge1), loc.getY(edge2));
  9. z1 = math.min(loc.getZ(edge1), loc.getZ(edge2));
  10. z2 = math.max(loc.getZ(edge1), loc.getZ(edge2));
  11. mid_x = (x1+x2)/2;
  12. mid_y = (y1+y2)/2;
  13. mid_z = (z1+z2)/2;
  14. //------------------
  15. air_material = material.get("AIR");
  16. stone_material = material.get("STONE");
  17. box_iterator = loc.iterator(creative_world, x1,y1,z1,x2,y2,z2);
  18. grav_down = list.new();
  19. while(hasnext(box_iterator)){
  20. temp_block = block.get(next(box_iterator));
  21. temp_type = block.getType(temp_block);
  22. if(temp_type != air_material){
  23. temp_array = array.new(2);
  24. temp_array[0] = temp_block;
  25. temp_array[1] = temp_type;
  26. list.add(grav_down, temp_array);
  27. }
  28. }
  29. //grav_down
  30. grav_up = list.new();
  31. grav_north = list.new();
  32. grav_south = list.new();
  33. grav_west = list.new();
  34. grav_east = list.new();
  35. box.create_rotations();
  36. active_grav = "down";
  37. possible_names_map = list.new();
  38. list.add(possible_names_map, "down");
  39. list.add(possible_names_map, "up");
  40. list.add(possible_names_map, "north");
  41. list.add(possible_names_map, "south");
  42. list.add(possible_names_map, "west");
  43. list.add(possible_names_map, "east");
  44. //Playerinv
  45. uuid = "6cc9f8c7-9dfd-44f4-a3f2-af30054411a8";//"e41b5335-3c74-46e9-a6c5-dafc6334a477"; (marvinius)
  46. player = player.get(uuid);
  47. player_inv = player.getInv(player);
  48. item_down = item.new(material.get("purple_concrete"),1);
  49. item.setName(item_down, text.new("down"));
  50. item_up = item.new(material.get("yellow_concrete"),1);
  51. item.setName(item_up, text.new("up"));
  52. item_north = item.new(material.get("pink_concrete"),1);
  53. item.setName(item_north, text.new("north"));
  54. item_south = item.new(material.get("magenta_concrete"),1);
  55. item.setName(item_south, text.new("south"));
  56. item_west = item.new(material.get("red_concrete"),1);
  57. item.setName(item_west, text.new("west"));
  58. item_east = item.new(material.get("blue_concrete"),1);
  59. item.setName(item_east, text.new("east"));
  60. inv.setItem(player_inv, 0, item_down);
  61. inv.setItem(player_inv, 1, item_up);
  62. inv.setItem(player_inv, 2, item_north);
  63. inv.setItem(player_inv, 3, item_south);
  64. inv.setItem(player_inv, 4, item_west);
  65. inv.setItem(player_inv, 5, item_east);
  66. //---events---
  67. event.load("block_click");
  68. //event.load("entity_damage");
  69. //event.load("player_move");
  70. //------------
  71. @wait
  72. wait();
  73. if(event == "block_click"){
  74. if(player.getName(player) != "SirTerence7"){
  75. goto("wait");
  76. }
  77. if(action == "PHYSICAL"){
  78. goto("wait");
  79. }
  80. player_hand = living.getHand(player);
  81. if(!item.hasName(player_hand)){
  82. goto("wait");
  83. }
  84. item_name = string.text(item.getName(player_hand));
  85. if(!list.contains(possible_names_map, item_name)){
  86. goto("wait");
  87. }
  88. cancel = true;
  89. active_grav = box.rotate(active_grav, item_name);
  90. }
  91. goto("wait");
  92. //---functions---
  93. function box.create_rotations(){
  94. list_iterator = iterator($grav_down);
  95. a = 0;
  96. while(hasnext(list_iterator)){
  97. if(a++ > 75){
  98. waitfor(2);
  99. a = 0;
  100. }
  101. temp_array = next(list_iterator);
  102. temp_loc = block.getLocation(temp_array[0]);
  103. list.add($grav_up, array.create(block.get(box.rotate_location(temp_loc, "down", "up")), temp_array[1]));
  104. list.add($grav_north, array.create(block.get(box.rotate_location(temp_loc, "down", "north")), temp_array[1]));
  105. list.add($grav_south, array.create(block.get(box.rotate_location(temp_loc, "down", "south")), temp_array[1]));
  106. list.add($grav_west, array.create(block.get(box.rotate_location(temp_loc, "down", "west")), temp_array[1]));
  107. list.add($grav_east, array.create(block.get(box.rotate_location(temp_loc, "down", "east")), temp_array[1]));
  108. }
  109. }
  110. function array.create(arg1, arg2){
  111. temp_array = array.new(2);
  112. temp_array[0] = arg1;
  113. temp_array[1] = arg2;
  114. return temp_array;
  115. }
  116. function box.rotate(from_rotation, to_rotation){
  117. New_Motion = box.rotate_Rotation(box.rotate_Rotation(entity.getMotion($player), from_rotation), to_rotation);
  118. Look_Array = entity.getLook($player);
  119. New_Look = box.rotate_Rotation(box.rotate_Rotation(Look_Array, from_rotation), to_rotation);
  120. player_loc = entity.getLocation($player);
  121. teleport_location = box.rotate_location(player_loc, from_rotation, to_rotation);
  122. entity.setGravity($player, false);
  123. entity.setMotion($player, 0, 0, 0);
  124. box.place(from_rotation, true);//clear
  125. box.place(to_rotation, false);//place
  126. entity.teleport($player, teleport_location);
  127. entity.setGravity($player, true);
  128. entity.setMotion($player, New_Motion[0], New_Motion[1], New_Motion[2]);
  129. entity.setLook($player, New_Look[0], New_Look[1], New_Look[2]);
  130. return to_rotation;
  131. }
  132. function box.place(rotation, clear){
  133. if(rotation == "down"){
  134. list_iterator = iterator($grav_down);
  135. }elseif(rotation == "up"){
  136. list_iterator = iterator($grav_up);
  137. }elseif(rotation == "north"){
  138. list_iterator = iterator($grav_north);
  139. }elseif(rotation == "south"){
  140. list_iterator = iterator($grav_south);
  141. }elseif(rotation == "west"){
  142. list_iterator = iterator($grav_west);
  143. }elseif(rotation == "east"){
  144. list_iterator = iterator($grav_east);
  145. }
  146. while(hasnext(list_iterator)){
  147. temp_array = next(list_iterator);
  148. if(clear){
  149. block_type = $air_material;
  150. }else{
  151. block_type = temp_array[1];
  152. }
  153. block.setMaterial(temp_array[0], block_type, false);//block.getType(temp_block));
  154. }
  155. }
  156. function box.rotate_location(loc, from_rotation, to_rotation){
  157. abs_loc = loc.mod(loc, 0, 0, 0);
  158. if(from_rotation == to_rotation){
  159. return abs_loc;
  160. }
  161. Coord_Array = array.new(3);
  162. Coord_Array[0] = loc.getX(abs_loc)-$mid_x;//X
  163. Coord_Array[1] = loc.getY(abs_loc)-$mid_y;//Y
  164. Coord_Array[2] = loc.getZ(abs_loc)-$mid_z;//Z
  165. //Coord_Array = box.rotate_Rotation(Coord_Array, from_rotation);
  166. Coord_Array = box.rotate_Rotation(box.rotate_Rotation(Coord_Array, from_rotation), to_rotation);
  167. loc.set(abs_loc, Coord_Array[0] + $mid_x, Coord_Array[1] + $mid_y, Coord_Array[2] + $mid_z);
  168. return abs_loc;
  169. }
  170. function box.rotate_Rotation(Coord_Array, rotation){
  171. New_Coord_Array = array.new(3);
  172. if(rotation == "down"){
  173. return Coord_Array;
  174. }elseif(rotation == "up"){
  175. New_Coord_Array[0] = Coord_Array[0]; // X = X
  176. New_Coord_Array[1] = -Coord_Array[1]; // Y = -Y
  177. New_Coord_Array[2] = Coord_Array[2]; // Z = Z
  178. }elseif(rotation == "north"){
  179. New_Coord_Array[0] = Coord_Array[0]; // X = X
  180. New_Coord_Array[1] = Coord_Array[2]; // Y = Z
  181. New_Coord_Array[2] = Coord_Array[1]; // Z = Y
  182. }elseif(rotation == "south"){
  183. New_Coord_Array[0] = Coord_Array[0]; // X = X
  184. New_Coord_Array[1] = -Coord_Array[2]; // Y = -Z
  185. New_Coord_Array[2] = -Coord_Array[1]; // Z = -Y
  186. }elseif(rotation == "west"){
  187. New_Coord_Array[0] = Coord_Array[1]; // X = -Y
  188. New_Coord_Array[1] = Coord_Array[0]; // Y = X
  189. New_Coord_Array[2] = Coord_Array[2]; // Z = Z
  190. }elseif(rotation == "east"){
  191. New_Coord_Array[0] = -Coord_Array[1]; // X = Y
  192. New_Coord_Array[1] = -Coord_Array[0]; // Y = -X
  193. New_Coord_Array[2] = Coord_Array[2]; // Z = Z
  194. }
  195. return New_Coord_Array;
  196. }
  197. function box.rotate_look(){
  198. return;
  199. }
  200. function box.get_look(){
  201. return;
  202. }