TGViewer
ботик ботик @botikst · 22 subscribers
Post #82 117
Буфер функция при еде
import { system, world } from "@minecraft/server";

function checkiuseit(player) {
try {
const inventory = player.getComponent('inventory')?.container;
if (!inventory) return {bread: 0, chicken: 0};

let breadTotal = 0;
let chickenTotal = 0;
for (let i = 0; i < inventory.size; i++) {
const item = inventory.getItem(i);
if (item?.typeId === 'minecraft:bread') {
breadTotal += item.amount;
} else if (item?.typeId === 'minecraft:cooked_chicken') {
chickenTotal += item.amount;
}
}
return {bread: breadTotal, chicken: chickenTotal};
} catch {
return {bread: 0, chicken: 0};
}
}

const choic = new Map();

world.afterEvents.itemUse.subscribe(event => {
const player = event.source;
const item = event.itemStack;

if ((item.typeId === 'minecraft:bread' || item.typeId === 'minecraft:cooked_chicken') && player.isValid()) {
const currentCounts = checkiuseit(player);
choic.set(player.id, {
breadCount: currentCounts.bread,
chickenCount: currentCounts.chicken,
lastUsedItem: item.typeId,
startTick: system.currentTick
});
}
});

system.runInterval(() => {
const currentTick = system.currentTick;

for (const [playerId, data] of choic) {
const player = [...world.getPlayers()].find(p => p.id === playerId);

if (!player || !player.isValid()) {
choic.delete(playerId);
continue;
}

if (currentTick - data.startTick > 600) {
choic.delete(playerId);
continue;
}

const currentCounts = checkiuseit(player);
if (currentCounts.bread < data.breadCount && data.lastUsedItem === 'minecraft:bread') {
player.runCommandAsync('title @a title 1');
choic.delete(playerId);
} else if (currentCounts.chicken < data.chickenCount && data.lastUsedItem === 'minecraft:cooked_chicken') {
player.runCommandAsync('title @a title 2');
choic.delete(playerId);
}
}
}, 5);
More from @botikst
  1. Sep 6, 2026пример WebSocket10
  2. Sep 6, 2026Файл скрипт WebSocket10
  3. Sep 6, 2026файл apk termux
  4. Sep 6, 2026Скрипт WebSocket10 const TelegramBot = require('node-telegram-bot-api'); const WebSocket =…
  5. Sep 6, 2026Команды termux: termux-setup-storage pkg update && pkg upgrade -y pkg install nodejs-lts n…
  6. Jul 26, 2026Пример «Импульс»
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →