123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- event.load("entity_click");
- event.load("block_break");
- event.load("inv_click");
- overworld = world.get("overworld");
- loc = loc.new(overworld, 66, 69, 444);
- plot_list = plot.get(loc);
- village_plot_id = plot.getId(list.getIndex(plot_list, 0));
- farmer_quest = list.new();
- farmer_inv = inv.new("222222222");
- farmer_inv_id = inv.getId(farmer_inv);
- air_item = read.item("minecraft:air");
- crops_tag = block.getTag("minecraft:crops");
- age7_property = block.getProperty("age_0_7");
- farm_loc1 = loc.new(overworld, 69, 69, 444);
- farm_loc2 = loc.new(overworld, 73, 69, 440);
- @wait
- wait();
- iGoto(event);
- goto("wait");
- @entity_click
- entity_name = entity.getName(entity);
- if(entity_name == "Bauer") {
- if(getGrowPercentage(farm_loc1, farm_loc2, "minecraft:wheat") >= 80) {
- inv.setItem(farmer_inv, 0, read.item("minecraft:wheat", 1, "Weizenfeld ernten"));
- } else {
- inv.setItem(farmer_inv, 0, air_item);
- }
- inv.open(farmer_inv, player, "Verfügbare Quests");
- }
- goto("wait");
- @inv_click
- if(item.getType(item) != "minecraft:air") {
- if(inv_id == farmer_inv_id) {
- if(inv_slot == 0) {
- player_uuid = player.getUuid(player);
- if(list.contains(farmer_quest, player_uuid)) {
- player.speak(player, "Bauer", "Du bist bereits mit dieser Aufgabe betraut. Geh dahin und ernte das gesamte Weizenfeld.");
- } else {
- player.speak(player, "Bauer", "Die Weizenernte kann beginnen. Geh dahin und ernte das gesamte Feld.");
- list.add(farmer_quest, player.getUuid(player));
- }
- }
- }
- }
- goto("wait");
-
- @block_break
- player_uuid = player.getUuid(player);
- //Hat der Spieler die Quest "Weizenfeld ernten"?
- if(list.contains(farmer_quest, player_uuid)) {
- //Baut der Spieler einen Block des Weizenfelds ab?
- if(loc.isBetween(block_loc, farm_loc1, farm_loc2) && block_type == "minecraft:wheat") {
- cancel = false;
- //Ist das Weizenfeld fertig abgeerntet?
- if(getGrowPercentage(farm_loc1, farm_loc2, "minecraft:wheat") == 0) {
- //An alle Spieler, die diese Quest haben, eine Erledigung schicken
- msgQuesters(farmer_quest, "Bauer", "Vielen Dank für das ernten des Weizenfelds! Hier hast du eine Belohnung.");
- rewardQuesters(farmer_quest, 5, 0, 0);
- }
- }
- }
- goto("wait");
- function getGrowPercentage(location1, location2, block_type) {
- crops_counter = 0;
- ready_counter = 0;
- loc.sort(location1, location2);
- x_diff = loc.getX(location2) - loc.getX(location1);
- y_diff = loc.getY(location2) - loc.getY(location1);
- z_diff = loc.getZ(location2) - loc.getZ(location1);
- for(x = 0; x <= x_diff; x++) {
- for(y = 0; y <= y_diff; y++) {
- for(z = 0; z <= z_diff; z++) {
- mod_loc = loc.mod(location1, x, y, z);
- if(block.getType(mod_loc) == block_type) {
- crops_counter++;
- if(block.property.getValue(mod_loc, $age7_property) == 7) {
- ready_counter++;
- }
- }
- }
- }
- }
- readyPercent = ready_counter / crops_counter * 100;
- return readyPercent;
- }
- function msgQuesters(farmer_quest, from, message) {
- for(i = 0; i < list.getSize(farmer_quest); i++) {
- player_uuid = list.getIndex(farmer_quest, i);
- player_name = player.getName(player_uuid);
- if(isOnline(player_name)) {
- player = read.player(player_name);
- player.speak(player, from, message);
- }
- }
- return;
- }
- function rewardQuesters(farmer_quest, copper, silver, gold) {
- for(i = 0; i < list.getSize(farmer_quest); i++) {
- player_uuid = list.getIndex(farmer_quest, i);
- player_name = player.getName(player_uuid);
- if(isOnline(player_name)) {
- player = read.player(player_name);
- if(copper > 0) {
- safeGiveItemPlayer(player, read.item("km:coin_copper", copper));
- }
- if(silver > 0) {
- safeGiveItemPlayer(player, read.item("km:coin_silver", silver));
- }
- if(gold> 0) {
- safeGiveItemPlayer(player, read.item("km:coin_gold", gold));
- }
- }
- }
- return;
- }
- function safeGiveItemPlayer(player, item) {
- rest_item = player.giveItem(player, item);
- item.drop(entity.getLocation(player), rest_item);
- return;
- }
- function isOnline(player_name) {
- if(read.player(player_name) == null) {
- return false;
- }
- return true;
- }
|