// Get all entities at the block location
const targetEntities = overworld.getEntitiesAtBlockLocation(blockAtQuery);
// Loop through each entity and count the number of items found
for (const entity of targetEntities) {
const inventory = entity.getComponent('inventory').container;
const items = inventory.getSlot(0);
// Check if the slot has an item
if (items.typeId) {
// Check if the array contains the identifier of the item in the new slot
const index = itemInfo.findIndex(info => info.id === items.typeId);
if (index !== -1) {
// If it does, just increase the quantity in the old object
itemInfo[index].quantity += items.amount;
} else {
// If it doesn't, put the identifier & item quantity in an object and push that object into the array
itemInfo.push({ id: items.typeId, quantity: items.amount });
}
}
}
// Run code based on the item information
for (const info of itemInfo) {
if (info.quantity === 3 && info.id === "minecraft:wheat") {
console.log("craft");
} else if (info.quantity === 2 && info.id === "minecraft:iron_ingot") {
console.log("craft");
} else if (info.quantity === 9 && (info.id === "minecraft:gold_ingot" || info.id === "minecraft:apple")) {
console.log("craftrep1");
} else if (info.quantity === 8 && info.id === "minecraft:cobblestone") {
console.log("craftrep1");
}
}