voxel.txt 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. event.load("item_air_click");
  2. event.load("left_click_air");
  3. event.load("block_break");
  4. stone_state = block.newState("minecraft:stone");
  5. air_state = block.newState("minecraft:air");
  6. radius_per_player = map.new();
  7. msg("dev", "§bVoxel §rwurde geladen");
  8. @wait
  9. wait();
  10. if(!perm.has(player, "voxel")) {
  11. goto("wait");
  12. }
  13. if(event == "left_click_air" || event == "block_break") {
  14. state = air_state;
  15. last = false;
  16. } elseif(event == "item_air_click") {
  17. state = stone_state;
  18. last = true;
  19. } else {
  20. goto("wait");
  21. }
  22. if(item.getType(entity.getEquip(player, "hand")) == "km:plus_green") {
  23. goto("doshit");
  24. }
  25. if(item.getType(entity.getEquip(player, "hand")) == "km:minus_green") {
  26. goto("dosmooth");
  27. }
  28. goto("wait");
  29. @doshit
  30. loc = entity.getLocation(player);
  31. world = loc.getWorld(loc);
  32. look = entity.getLook(player);
  33. loc.setX(loc, loc.getCoord(loc, "bx"));
  34. loc.setY(loc, loc.getCoord(loc, "by") + 1);
  35. loc.setZ(loc, loc.getCoord(loc, "bz"));
  36. list = list.new();
  37. radius = map.getOrDefault(radius_per_player, player.getUuid(player), 5);
  38. for(y = -radius; y <= radius; y += 0.5) {
  39. for(x = -radius; x <= radius; x += 0.5) {
  40. other_loc = loc.mod(loc, x, y, 0);
  41. if(loc.distance(loc, other_loc) < radius) {
  42. list.add(list, other_loc);
  43. }
  44. }
  45. }
  46. yaw = loc.getYaw(loc);
  47. pitch = loc.getPitch(loc);
  48. while(yaw < 0) {
  49. yaw += 360;
  50. }
  51. while(yaw >= 360) {
  52. yaw -= 360;
  53. }
  54. yaw = yaw * math.pi() / 180;
  55. pitch = pitch * math.pi() / 180;
  56. matrix = matrix.newRotationY(-yaw);
  57. matrix = matrix.mul(matrix, matrix.newRotationX(-pitch));
  58. list2 = list.new();
  59. vector = vector.new(0, 0, 0);
  60. iter = list.iterator(list);
  61. while(hasNext(iter)) {
  62. other_loc = next(iter);
  63. vector.set(vector, loc.getX(other_loc) - loc.getX(loc), loc.getY(other_loc) - loc.getY(loc), loc.getZ(other_loc) - loc.getZ(loc));
  64. matrix.mulVector(matrix, vector);
  65. loc.set(other_loc, loc.getX(loc) + vector.getX(vector), loc.getY(loc) + vector.getY(vector), loc.getZ(loc) + vector.getZ(vector));
  66. check = loc.trace(other_loc, look[0], look[1], look[2], 60, last);
  67. if(check) {
  68. list.add(list2, other_loc);
  69. }
  70. }
  71. list = list2;
  72. iter = list.iterator(list);
  73. while(hasNext(iter)) {
  74. block.setState(next(iter), state, true);
  75. }
  76. lowest_x = 5000000;
  77. lowest_y = 5000000;
  78. lowest_z = 5000000;
  79. highest_x = -5000000;
  80. highest_y = -5000000;
  81. highest_z = -5000000;
  82. iter = list.iterator(list);
  83. while(hasNext(iter)) {
  84. set_loc = next(iter);
  85. x = loc.getX(set_loc);
  86. y = loc.getY(set_loc);
  87. z = loc.getZ(set_loc);
  88. lowest_x = math.min(x, lowest_x);
  89. lowest_y = math.min(y, lowest_y);
  90. lowest_z = math.min(z, lowest_z);
  91. highest_x = math.max(x, highest_x);
  92. highest_y = math.max(y, highest_y);
  93. highest_z = math.max(z, highest_z);
  94. }
  95. lowest_x--;
  96. lowest_y--;
  97. lowest_z--;
  98. highest_x++;
  99. highest_y++;
  100. highest_z++;
  101. for(k = 0; k < 5; k++) {
  102. iter = loc.iterator(world, lowest_x, lowest_y, lowest_z, highest_x, highest_y, highest_z);
  103. while(hasNext(iter)) {
  104. smooth_loc = next(iter);
  105. //neighbours includes the original block
  106. neighbours = 19 - block.countAir(smooth_loc);
  107. if(neighbours <= 8) {
  108. block.setState(smooth_loc, air_state, true);
  109. } elseif(neighbours >= 12) {
  110. block.setState(smooth_loc, stone_state, true);
  111. }
  112. }
  113. }
  114. goto("wait");
  115. @dosmooth
  116. loc = entity.getLocation(player);
  117. world = loc.getWorld(loc);
  118. look = entity.getLook(player);
  119. loc.setX(loc, loc.getCoord(loc, "bx"));
  120. loc.setY(loc, loc.getCoord(loc, "by") + 1);
  121. loc.setZ(loc, loc.getCoord(loc, "bz"));
  122. list = list.new();
  123. radius = map.getOrDefault(radius_per_player, player.getUuid(player), 5);
  124. for(y = -radius; y <= radius; y += 0.5) {
  125. for(x = -radius; x <= radius; x += 0.5) {
  126. other_loc = loc.mod(loc, x, y, 0);
  127. if(loc.distance(loc, other_loc) < radius) {
  128. list.add(list, other_loc);
  129. }
  130. }
  131. }
  132. yaw = loc.getYaw(loc);
  133. pitch = loc.getPitch(loc);
  134. while(yaw < 0) {
  135. yaw += 360;
  136. }
  137. while(yaw >= 360) {
  138. yaw -= 360;
  139. }
  140. yaw = yaw * math.pi() / 180;
  141. pitch = pitch * math.pi() / 180;
  142. matrix = matrix.newRotationY(-yaw);
  143. matrix = matrix.mul(matrix, matrix.newRotationX(-pitch));
  144. list2 = list.new();
  145. vector = vector.new(0, 0, 0);
  146. iter = list.iterator(list);
  147. while(hasNext(iter)) {
  148. other_loc = next(iter);
  149. vector.set(vector, loc.getX(other_loc) - loc.getX(loc), loc.getY(other_loc) - loc.getY(loc), loc.getZ(other_loc) - loc.getZ(loc));
  150. matrix.mulVector(matrix, vector);
  151. loc.set(other_loc, loc.getX(loc) + vector.getX(vector), loc.getY(loc) + vector.getY(vector), loc.getZ(loc) + vector.getZ(vector));
  152. check = loc.trace(other_loc, look[0], look[1], look[2], 60, last);
  153. if(check) {
  154. list.add(list2, other_loc);
  155. }
  156. }
  157. list = list2;
  158. lowest_x = 5000000;
  159. lowest_y = 5000000;
  160. lowest_z = 5000000;
  161. highest_x = -5000000;
  162. highest_y = -5000000;
  163. highest_z = -5000000;
  164. iter = list.iterator(list);
  165. while(hasNext(iter)) {
  166. set_loc = next(iter);
  167. x = loc.getX(set_loc);
  168. y = loc.getY(set_loc);
  169. z = loc.getZ(set_loc);
  170. lowest_x = math.min(x, lowest_x);
  171. lowest_y = math.min(y, lowest_y);
  172. lowest_z = math.min(z, lowest_z);
  173. highest_x = math.max(x, highest_x);
  174. highest_y = math.max(y, highest_y);
  175. highest_z = math.max(z, highest_z);
  176. }
  177. lowest_x--;
  178. lowest_y--;
  179. lowest_z--;
  180. highest_x++;
  181. highest_y++;
  182. highest_z++;
  183. for(k = 0; k < 5; k++) {
  184. iter = loc.iterator(world, lowest_x, lowest_y, lowest_z, highest_x, highest_y, highest_z);
  185. while(hasNext(iter)) {
  186. smooth_loc = next(iter);
  187. //neighbours includes the original block
  188. neighbours = 19 - block.countAir(smooth_loc);
  189. if(neighbours <= 9) {
  190. block.setState(smooth_loc, air_state, true);
  191. } elseif(neighbours >= 11) {
  192. block.setState(smooth_loc, stone_state, true);
  193. }
  194. }
  195. }
  196. goto("wait");