закомментировать код каждой строки {

function block1_1(event) {

const name = "Yuriu";

const age = "20";

const player = event.player;

player.sendTitle(name, age, 5, 60, 5);

}

function block1_2(event) {

let name = "Yuriu";

let age = "20";

const player = event.player;

name = "Igor";

age = "24";

player.sendTitle(name, age, 5, 60, 5);

}

function block1_3(event) {

const name = "Yuriu";

const age = "20";

const player = event.player;

sendTitleWithNameAndAge(name, age);

player.sendMessage("Is avalaible = " + isAvalaible(age));

function sendTitleWithNameAndAge(name, age) {

player.sendTitle(name, age, 5, 60, 5);

};

function isAvalaible(level) {

/* if(level > 15){

return true;

} else {

return false;

} */

return level > 15

}

}

function block2_1(event) {

const player = event.player;

const world = player.getWorld();

const cat = {

type: EntityType.ocelot,

entity: null,

spawn(loc) {

this.entity = world.spawnEntity(loc, this.type);

}

};

factory.delay(() => {

cat.spawn(player.getLocation());

}, 1);

}

function block2_2(event) {

const player = event.player;

const world = player.getWorld();

const item = api.newItemStack("iron_sword");

factory.delay(() => {

const entity = world.spawnEntity(player.getLocation(), EntityType.pillager);

entity.getEquipment().setItemInHand(item);

}, 1)

}

function block2_3(event) {

const player = event.player;

const world = player.getWorld();

const count = 10;

spawnChickens(player.getLocation(), count);

player.sendMessage("Создано " + count + " куриц");

function spawnChickens(loc, count) {

for (let i = 0; i < count; i++) {

factory.delay(() => {

world.spawnEntity(randomLocRadius(loc, 3), EntityType.chicken);

}, 1)

}

}

}

function block3_1(event) {

const player = event.player;

const inv = player.getInventory();

const contains = inv.contains(Material.oak_planks, 4);

if (contains) {

inv.addItem(factory.newItemStack(Material.crafting_table));

player.sendMessage("Вам выдан верстак");

} else {

player.sendMessage("У вас нет досок!");

}

}

function block3_2(event) {

const player = event.player;

const snowball = factory.newItemStack(Material.snowball);

snowball.onLaunchProjectile(ev => {

if (ev.getPlayer() != player) {

return;

}

const inv = player.getInventory();

while (!inv.contains(Material.snowball, 16)) {

inv.addItem(snowball);

}

})

}

function block4_1(event) {

const player = event.player;

const inv = player.getInventory();

let count = 0;

for (let item of inv.getItems()) {

if (item == null || item.getType() != Material.diamond) {

continue;

}

count += item.amount;

}

player.sendMessage("У тебя " + count + " алмазов");

}

function block4_2(event) {

const player = event.player;

const inv = player.getInventory();

const map = new Map();

for (let item of inv.getItems()) {

if (item == null) {

continue;

}

const material = item.type;

if (map.has(material)) {

map.set(material, map.get(material) + item.amount);

} else {

map.set(material, item.amount);

}

}

map.forEach((value, key, map) => {

player.sendMessage(`У тебя в инвентаре ${key}: ${value}`);

});

}

// запуск через чат

factory.server.onChat(event => {

let cancel = true;

switch (event.getMessage()) {

case "block 1 1.1":

block1_1(event);

break;

case "block 1 1.2":

block1_2(event);

break;

case "block 1 1.3":

block1_3(event);

break;

case "block 1 2.1":

block2_1(event);

break;

case "block 1 2.2":

block2_2(event);

break;

case "block 1 2.3":

block2_3(event);

break;

case "block 1 3.1":

block3_1(event);

break;

case "block 1 3.2":

block3_2(event);

break;

case "block 1 4.1":

block4_1(event);

break;

case "block 1 4.2":

block4_2(event);

break;

default:

cancel = false;

}

if (cancel) {

event.setCancelled(true);

}

});

function randomLocRadius(loc, radius) {

radius = Math.abs(radius)

x = loc.getX() + (((radius * 2) * Math.random()) - radius)

z = loc.getZ() + (((radius * 2) * Math.random()) - radius)

loc.setX(x)

loc.setZ(z)

return loc

}

}

baron2032012 baron2032012    1   09.12.2021 12:38    0

Другие вопросы по теме Информатика