|
|
|
|
|
async function placeItem(bot, name, position) { |
|
|
const item = bot.inventory.findInventoryItem(mcData.itemsByName[name].id); |
|
|
|
|
|
const faceVectors = [ |
|
|
new Vec3(0, 1, 0), |
|
|
new Vec3(0, -1, 0), |
|
|
new Vec3(1, 0, 0), |
|
|
new Vec3(-1, 0, 0), |
|
|
new Vec3(0, 0, 1), |
|
|
new Vec3(0, 0, -1), |
|
|
]; |
|
|
let referenceBlock = null; |
|
|
let faceVector = null; |
|
|
for (const vector of faceVectors) { |
|
|
const block = bot.blockAt(position.minus(vector)); |
|
|
if (block?.name !== "air") { |
|
|
referenceBlock = block; |
|
|
faceVector = vector; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
await bot.pathfinder.goto(new GoalPlaceBlock(position, bot.world, {})); |
|
|
|
|
|
await bot.equip(item, "hand"); |
|
|
await bot.placeBlock(referenceBlock, faceVector); |
|
|
} |
|
|
|