123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- function stage.increase(player) {
- $stage++;
- quest.display(player, $quest_name, $stage, $all_stages);
- sound = sound.get("minecraft:entity.experience_orb.pickup");
- category = sound.getCategory("MASTER");
- sound.spawnForPlayer(player, sound, category);
- }
- function quest.start(player, path) {
- modTimer(-45);
- script = script.start(path, "utils/u_quest", "utils/u_general", "utils/u_questerror");
- if(script == null) {
- msg.dev("quest not started");
- return;
- }
- quest.addPlayer(script, player);
- script.setVar(script, "player", player);
- script.setVar(script, "script", script);
- script.callEvent("quest_start", script);
- inv.close(player);
- }
- function player.unlockedLumberjack(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- return config.getBool(config, "skillshop.lumberjack", false);
- }
- function player.unlockLumberjack(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "skillshop.lumberjack", true);
- config.saveAsync(config);
- }
- function player.unlockedMage(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- return config.getBool(config, "skillshop.mage", false);
- }
- function player.unlockMage(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "skillshop.mage", true);
- config.saveAsync(config);
- }
- function player.getShipProgress(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- return config.getDouble(config, "ship.progress", 0);
- }
- function player.setShipProgress(player_or_id, progress) {
- config = playerdata.getSurvival(player_or_id);
- old_progress = config.getDouble(config, "ship.progress", 0);
- if(progress > old_progress) {
- config.set(config, "ship.progress", progress);
- config.saveAsync(config);
- }
- }
- function citizen.giveItem(citizen_name, player, needed_type_or_tag, needed_amount) {
- if(needed_amount == 0) {
- return -1;
- }
- item = living.getHand(player);
- if(item == null) {
- return needed_amount;
- }
- item_type = item.getType(item);
- citizen_name = string.concat("§d", citizen_name);
- needed = false;
- tag_check = false;
- if(isMaterial(needed_type_or_tag)) {
- if(item_type == needed_type_or_tag) {
- needed = true;
- }
- } else {
- if(item.hasTag(item, needed_type_or_tag)) {
- needed = true;
- tag_check = true;
- }
- }
- if(needed) {
- amount_not_removed = player.removeItem(player, item.new(item_type, needed_amount));
- if(amount_not_removed == 0) {
- return 0;
- }
- player.removeItem(player, item.new(item_type, amount_not_removed));
- rest_item_amount = needed_amount - amount_not_removed;
-
- rest_item = item.new(item_type, rest_item_amount);
- rest_item = player.removeItemNbt(player, rest_item);
- rest_item_amount = item.getAmount(rest_item);
- if(rest_item_amount > 0) {
- if(tag_check) {
- rest_item = player.removeItemTag(player, needed_type_or_tag, rest_item_amount);
- rest_item_amount = item.getAmount(rest_item);
- if(rest_item_amount > 0) {
- msg.prefix(player, citizen_name, string.concat("I need ", string.number(rest_item_amount), " more of these please."));
- }
- } else {
- msg.prefix(player, citizen_name, string.concat("I need ", string.number(rest_item_amount), " more of these please."));
- }
- }
- return rest_item_amount;
- }
- msg.prefix(player, citizen_name, "I do not need this.");
- return needed_amount;
- }
- /*
- stable(stable_mid_loc, stable_spawn_loc_list) while there aren't enough, spawns animals
- */
- function stable(stable_mid_loc, stable_spawn_loc_list){
- living_list = living.near(stable_mid_loc, 10);
- list_iterator = iterator(living_list);
-
- cow_count = 0;
- pig_count = 0;
- sheep_count = 0;
-
- while(hasnext(list_iterator)){
- living_entity_type = entity.getType(next(list_iterator));
- if(living_entity_type == "cow"){
- cow_count++;
- }elseif(living_entity_type == "pig"){
- pig_count++;
- }elseif(living_entity_type == "sheep"){
- sheep_count++;
- }
- }
- while(cow_count < 4){//cow_max
- spawned_entity = entity.spawn(loc.mod(list.getIndex(stable_spawn_loc_list, math.random(0, $spawn_list_size)), 0.5, 0, 0.5), "COW");
- cow_count++;
- }
- while(pig_count < 3){//pig_max
- spawned_entity = entity.spawn(loc.mod(list.getIndex(stable_spawn_loc_list, math.random(0, $spawn_list_size)), 0.5, 0, 0.5), "PIG");
- pig_count++;
- }
- while(sheep_count < 5){//sheep_max
- spawned_entity = entity.spawn(loc.mod(list.getIndex(stable_spawn_loc_list, math.random(0, $spawn_list_size)), 0.5, 0, 0.5), "SHEEP");
- sheep_count++;
- }
- }
- /*
- stable.getSpawn_locs(loc) returns list with all spawn_locations for animals in given surrounding stable
- */
- function stable.getSpawn_locs(loc){
- stable_spawn_loc_list = list.new();
- list.add(stable_spawn_loc_list, loc.mod(loc, 0.5, 1, 0.5));
- $stable_temp_list = list.new();
- $stable_temp_list2 = list.new();
- list.add($stable_temp_list, loc);
- while(list.getSize($stable_temp_list) != 0){
- block_loc = list.getIndex($stable_temp_list, 0);
- list.removeIndex($stable_temp_list, 0);
- distance = loc.distance(block_loc, loc);
- if(distance < 25){
- temp_block = stable.addLoc_if(loc.mod(block_loc,1,0,0));
- if(temp_block != null){
- list.add(stable_spawn_loc_list, temp_block);
- }
- temp_block = stable.addLoc_if(loc.mod(block_loc,-1,0,0));
- if(temp_block != null){
- list.add(stable_spawn_loc_list, temp_block);
- }
- temp_block = stable.addLoc_if(loc.mod(block_loc,0,0,1));
- if(temp_block != null){
- list.add(stable_spawn_loc_list, temp_block);
- }
- temp_block = stable.addLoc_if(loc.mod(block_loc,0,0,-1));
- if(temp_block != null){
- list.add(stable_spawn_loc_list, temp_block);
- }
-
- temp_block = stable.addLoc_if(loc.mod(block_loc,1,1,0));
- if(temp_block != null){
- list.add(stable_spawn_loc_list, temp_block);
- }
- temp_block = stable.addLoc_if(loc.mod(block_loc,-1,1,0));
- if(temp_block != null){
- list.add(stable_spawn_loc_list, temp_block);
- }
- temp_block = stable.addLoc_if(loc.mod(block_loc,0,1,1));
- if(temp_block != null){
- list.add(stable_spawn_loc_list, temp_block);
- }
- temp_block = stable.addLoc_if(loc.mod(block_loc,0,1,-1));
- if(temp_block != null){
- list.add(stable_spawn_loc_list, temp_block);
- }
-
- temp_block = stable.addLoc_if(loc.mod(block_loc,1,-1,0));
- if(temp_block != null){
- list.add(stable_spawn_loc_list, temp_block);
- }
- temp_block = stable.addLoc_if(loc.mod(block_loc,-1,-1,0));
- if(temp_block != null){
- list.add(stable_spawn_loc_list, temp_block);
- }
- temp_block = stable.addLoc_if(loc.mod(block_loc,0,-1,1));
- if(temp_block != null){
- list.add(stable_spawn_loc_list, temp_block);
- }
- temp_block = stable.addLoc_if(loc.mod(block_loc,0,-1,-1));
- if(temp_block != null){
- list.add(stable_spawn_loc_list, temp_block);
- }
- }
- }
- return stable_spawn_loc_list;
- }
- function stable.addLoc_if(temp_loc){
- if(!list.contains($stable_temp_list2, temp_loc)){
- temp_block = block.get(temp_loc);
- temp_block2 = loc.mod(temp_loc, 0, 1, 0);
- temp_type1 = block.getType(temp_block);
- temp_type2 = block.getType(block.get(temp_block2));
- temp_type3 = block.getType(block.get(loc.mod(temp_block2, 0, 1, 0)));
- if(temp_type1 == $grass_block_material && temp_type2 == $air_material && temp_type3 == $air_material){
- list.add($stable_temp_list, temp_loc);
- list.add($stable_temp_list2, temp_loc);
- return temp_block2;
- }
- }
- }
|