event.load("item_air_click"); event.load("left_click_air"); event.load("block_break"); stone_state = block.newState("minecraft:stone"); air_state = block.newState("minecraft:air"); radius_per_player = map.new(); msg("dev", "§bVoxel §rwurde geladen"); @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 = stone_state; last = true; } else { goto("wait"); } if(item.getType(entity.getEquip(player, "hand")) == "km:plus_green") { goto("doshit"); } if(item.getType(entity.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, stone_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, stone_state, true); } } } goto("wait");