123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- event.load("item_air_click");
- event.load("left_click_air");
- event.load("block_break");
- default_state = block.newState("minecraft:stone");
- block_state = default_state;
- air_state = block.newState("minecraft:air");
- radius_per_player = map.new();
- state_per_player = map.new();
- msg("dev", "§bVoxel §rloaded.");
- @wait
- wait();
- if(!perm.has(player, "voxel")) {
- goto("wait");
- }
- if(event == "left_click_air" || event == "block_break") {
- state = air_state;
- last = false;
- } elseif(event == "item_air_click") {
- state = map.getOrDefault(state_per_player, player.getUuid(player), default_state);
- block_state = state;
- last = true;
- } else {
- goto("wait");
- }
- if(item.getType(living.getEquip(player, "hand")) == "km:plus_green") {
- goto("doshit");
- }
- if(item.getType(living.getEquip(player, "hand")) == "km:minus_green") {
- goto("dosmooth");
- }
- goto("wait");
- @doshit
- loc = entity.getLocation(player);
- world = loc.getWorld(loc);
- look = entity.getLook(player);
- loc.setX(loc, loc.getCoord(loc, "bx"));
- loc.setY(loc, loc.getCoord(loc, "by") + 1);
- loc.setZ(loc, loc.getCoord(loc, "bz"));
- list = list.new();
- radius = map.getOrDefault(radius_per_player, player.getUuid(player), 5);
- for(y = -radius; y <= radius; y += 0.5) {
- for(x = -radius; x <= radius; x += 0.5) {
- other_loc = loc.mod(loc, x, y, 0);
- if(loc.distance(loc, other_loc) < radius) {
- list.add(list, other_loc);
- }
- }
- }
- yaw = loc.getYaw(loc);
- pitch = loc.getPitch(loc);
- while(yaw < 0) {
- yaw += 360;
- }
- while(yaw >= 360) {
- yaw -= 360;
- }
- yaw = yaw * math.pi() / 180;
- pitch = pitch * math.pi() / 180;
- matrix = matrix.newRotationY(-yaw);
- matrix = matrix.mul(matrix, matrix.newRotationX(-pitch));
- list2 = list.new();
- vector = vector.new(0, 0, 0);
- iter = list.iterator(list);
- while(hasNext(iter)) {
- other_loc = next(iter);
- vector.set(vector, loc.getX(other_loc) - loc.getX(loc), loc.getY(other_loc) - loc.getY(loc), loc.getZ(other_loc) - loc.getZ(loc));
- matrix.mulVector(matrix, vector);
- loc.set(other_loc, loc.getX(loc) + vector.getX(vector), loc.getY(loc) + vector.getY(vector), loc.getZ(loc) + vector.getZ(vector));
- check = loc.trace(other_loc, look[0], look[1], look[2], 60, last);
- if(check) {
- list.add(list2, other_loc);
- }
- }
- list = list2;
- iter = list.iterator(list);
- while(hasNext(iter)) {
- block.setState(next(iter), state, true);
- }
- lowest_x = 5000000;
- lowest_y = 5000000;
- lowest_z = 5000000;
- highest_x = -5000000;
- highest_y = -5000000;
- highest_z = -5000000;
- iter = list.iterator(list);
- while(hasNext(iter)) {
- set_loc = next(iter);
- x = loc.getX(set_loc);
- y = loc.getY(set_loc);
- z = loc.getZ(set_loc);
- lowest_x = math.min(x, lowest_x);
- lowest_y = math.min(y, lowest_y);
- lowest_z = math.min(z, lowest_z);
- highest_x = math.max(x, highest_x);
- highest_y = math.max(y, highest_y);
- highest_z = math.max(z, highest_z);
- }
- lowest_x--;
- lowest_y--;
- lowest_z--;
- highest_x++;
- highest_y++;
- highest_z++;
- for(k = 0; k < 5; k++) {
- iter = loc.iterator(world, lowest_x, lowest_y, lowest_z, highest_x, highest_y, highest_z);
- while(hasNext(iter)) {
- smooth_loc = next(iter);
- //neighbours includes the original block
- neighbours = 19 - block.countAir(smooth_loc);
- if(neighbours <= 8) {
- block.setState(smooth_loc, air_state, true);
- } elseif(neighbours >= 12) {
- block.setState(smooth_loc, block_state, true);
- }
- }
- }
- goto("wait");
- @dosmooth
- loc = entity.getLocation(player);
- world = loc.getWorld(loc);
- look = entity.getLook(player);
- loc.setX(loc, loc.getCoord(loc, "bx"));
- loc.setY(loc, loc.getCoord(loc, "by") + 1);
- loc.setZ(loc, loc.getCoord(loc, "bz"));
- list = list.new();
- radius = map.getOrDefault(radius_per_player, player.getUuid(player), 5);
- for(y = -radius; y <= radius; y += 0.5) {
- for(x = -radius; x <= radius; x += 0.5) {
- other_loc = loc.mod(loc, x, y, 0);
- if(loc.distance(loc, other_loc) < radius) {
- list.add(list, other_loc);
- }
- }
- }
- yaw = loc.getYaw(loc);
- pitch = loc.getPitch(loc);
- while(yaw < 0) {
- yaw += 360;
- }
- while(yaw >= 360) {
- yaw -= 360;
- }
- yaw = yaw * math.pi() / 180;
- pitch = pitch * math.pi() / 180;
- matrix = matrix.newRotationY(-yaw);
- matrix = matrix.mul(matrix, matrix.newRotationX(-pitch));
- list2 = list.new();
- vector = vector.new(0, 0, 0);
- iter = list.iterator(list);
- while(hasNext(iter)) {
- other_loc = next(iter);
- vector.set(vector, loc.getX(other_loc) - loc.getX(loc), loc.getY(other_loc) - loc.getY(loc), loc.getZ(other_loc) - loc.getZ(loc));
- matrix.mulVector(matrix, vector);
- loc.set(other_loc, loc.getX(loc) + vector.getX(vector), loc.getY(loc) + vector.getY(vector), loc.getZ(loc) + vector.getZ(vector));
- check = loc.trace(other_loc, look[0], look[1], look[2], 60, last);
- if(check) {
- list.add(list2, other_loc);
- }
- }
- list = list2;
- lowest_x = 5000000;
- lowest_y = 5000000;
- lowest_z = 5000000;
- highest_x = -5000000;
- highest_y = -5000000;
- highest_z = -5000000;
- iter = list.iterator(list);
- while(hasNext(iter)) {
- set_loc = next(iter);
- x = loc.getX(set_loc);
- y = loc.getY(set_loc);
- z = loc.getZ(set_loc);
- lowest_x = math.min(x, lowest_x);
- lowest_y = math.min(y, lowest_y);
- lowest_z = math.min(z, lowest_z);
- highest_x = math.max(x, highest_x);
- highest_y = math.max(y, highest_y);
- highest_z = math.max(z, highest_z);
- }
- lowest_x--;
- lowest_y--;
- lowest_z--;
- highest_x++;
- highest_y++;
- highest_z++;
- for(k = 0; k < 5; k++) {
- iter = loc.iterator(world, lowest_x, lowest_y, lowest_z, highest_x, highest_y, highest_z);
- while(hasNext(iter)) {
- smooth_loc = next(iter);
- //neighbours includes the original block
- neighbours = 19 - block.countAir(smooth_loc);
- if(neighbours <= 9) {
- block.setState(smooth_loc, air_state, true);
- } elseif(neighbours >= 11) {
- block.setState(smooth_loc, block_state, true);
- }
- }
- }
- goto("wait");
|