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