#AutoCrafter

1 messages · Page 1 of 1 (latest)

cunning cradle
#

// 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");
}
}

real sluice
#

?question

foggy wolf
# cunning cradle // Get all entities at the block location const targetEntities = overworld.getEn...

const itemRecords = {
    wheat: {
        current: 0,
        cost: 3,
        output: 'craft bread'
    },
    iron_ingot: {
        current: 0,
        cost: 2,
        output: 'craft mineral'
    },
    gold_ingot: {
        current: 0,
        cost: 9,
        output: 'craftrep1'
    },
    apple: {
        current: 0,
        cost: 9,
        output: 'craftrep1'
    },
    cobblestone: {
        current: 0,
        cost: 8,
        output: 'cobbles'
    }
}``````js

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 containerSlot = inventory.getSlot(0);
    let { typeId, amount } = containerSlot
    // Check if the slot has an item
    if (typeId = (typeId?.split(':').pop())) {
        if (!itemRecords[typeId]) continue
        itemRecords[typeId].current += amount
        containerSlot.setItem()
    }
}

// Run code based on the item information
function produce() {
    for (const typeId in itemRecords) {
        const {cost,current} = itemRecords[typeId]
        if (current < cost) continue;
        itemRecords[typeId].current -= cost
        console.log(itemRecords[typeId].output)
    }
}
real sluice
#

ok then

cunning cradle
foggy wolf
#

use the output as the property

cunning cradle
#

I think I get what you mean but is their a way to set the property for the propertys component in a blocks json file

foggy wolf
#
const perm = BlockPermutation.resolve(block.typeId).withProperty('direction',10)
block.setPermutation(perm)
cunning cradle
#

ty

real sluice
#

lol

cunning cradle
#

please ignore that, my friend thought it would be funny to get on my computer and write that