forked from wmantly/mc-bot-town
more trade?
This commit is contained in:
parent
ee5e93e0cd
commit
d6c003850d
@ -69,7 +69,7 @@ module.exports = {
|
||||
// Give MC a moment
|
||||
await sleep(1000);
|
||||
|
||||
let isPutAway = await this.putInChest(chestBlock)
|
||||
let isPutAway = await this.dumpToChest(chestBlock)
|
||||
await this.whisper(from, `I put ${isPutAway ? 'all' : 'some'} items in your chest.`);
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
const {sleep} = require('../utils');
|
||||
const conf = require('../conf');
|
||||
const {CJbot} = require('../model/minecraft');
|
||||
// const inventoryViewer = require('mineflayer-web-inventory');
|
||||
const inventoryViewer = require('mineflayer-web-inventory');
|
||||
|
||||
const commands = require('./commands');
|
||||
|
||||
@ -21,6 +21,7 @@ for(let name in conf.mc.bots){
|
||||
}
|
||||
|
||||
bot.on('onReady', async function(argument) {
|
||||
inventoryViewer(bot.bot);
|
||||
await sleep(1000);
|
||||
bot.bot.setControlState('jump', true);
|
||||
setTimeout(()=> bot.bot.setControlState('jump', false), 5000)
|
||||
|
@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const mineflayer = require('mineflayer');
|
||||
const minecraftData = require('minecraft-data');
|
||||
const Vec3 = require('vec3');
|
||||
const {sleep} = require('../utils');
|
||||
|
||||
@ -105,6 +106,9 @@ class CJbot{
|
||||
// server
|
||||
async __onReady(){try{
|
||||
|
||||
this.mcData = minecraftData(this.bot.version);
|
||||
|
||||
|
||||
// Add the listeners to the bot. We do this so if the bot loses
|
||||
// connection, the mineflayer instance will also be lost.
|
||||
this.__startListeners();
|
||||
@ -352,35 +356,56 @@ class CJbot{
|
||||
return firstEmptySlot;
|
||||
}
|
||||
|
||||
async putInChest(block, blockName, amount) {
|
||||
async dumpToChest(block, blockName, amount) {
|
||||
block = this.__blockOrVec(block);
|
||||
|
||||
this.bot.openContainer(block);
|
||||
let window = await this.once('windowOpen');
|
||||
|
||||
for(let item of window.slots.slice(window.inventoryStart).filter(function(item){
|
||||
let items = window.slots.slice(window.inventoryStart).filter(function(item){
|
||||
if(!item) return false;
|
||||
if(blockName && blockName !== item.name) return false;
|
||||
return true;
|
||||
})){
|
||||
});
|
||||
|
||||
for(let item of items){
|
||||
console.log(`Trying to place ${item.name}`)
|
||||
await sleep(100);
|
||||
let currentSlot = Number(item.slot);
|
||||
if(!window.slots[currentSlot]) continue;
|
||||
|
||||
if(amount && !amount--) return;
|
||||
let chestSlot = await this.__nextContainerSlot(window, item);
|
||||
console.log('next slot', chestSlot);
|
||||
await this.bot.moveSlotItem(currentSlot, chestSlot)
|
||||
|
||||
let res = await this.putInChest(...arguments);
|
||||
if(res === false) return amount ? amount : false;
|
||||
// let chestSlot = await this.__nextContainerSlot(window, item);
|
||||
// console.log('next chest slot', chestSlot)
|
||||
// if(!chestSlot){
|
||||
// console.log(`No room for ${item.name}`)
|
||||
// continue;
|
||||
// }
|
||||
|
||||
console.log('item', this.mcData.itemsByName[item.name])
|
||||
|
||||
try{
|
||||
console.log('transfer', await this.bot.transfer({
|
||||
window,
|
||||
itemType: this.mcData.itemsByName[item.name].id,
|
||||
sourceStart: currentSlot,
|
||||
sourceEnd: currentSlot+1,
|
||||
destStart: 0,
|
||||
destEnd: window.inventoryStart,
|
||||
count: amount || item.count,
|
||||
}))
|
||||
|
||||
if(amount) amount -= item.count
|
||||
}catch(error){
|
||||
console.log('error?', item.count, error.message, error);
|
||||
}
|
||||
// await this.bot.moveSlotItem(currentSlot, chestSlot);
|
||||
}
|
||||
|
||||
await sleep(100);
|
||||
await this.bot.closeWindow(window);
|
||||
|
||||
return amount ? amount : true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
module.exports = {CJbot};
|
||||
|
Loading…
x
Reference in New Issue
Block a user