added trade
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
const {sleep} = require('../utils');
|
||||
const mineflayer = require('mineflayer');
|
||||
const Vec3 = require('vec3');
|
||||
const {sleep} = require('../utils');
|
||||
|
||||
|
||||
class CJbot{
|
||||
@ -111,7 +112,7 @@ class CJbot{
|
||||
// Call the internal listeners when the bot is ready
|
||||
for(let callback of this.listeners.onReady || []){
|
||||
console.log('calling listener', callback)
|
||||
await callback(this)
|
||||
await callback.call(this)
|
||||
}
|
||||
|
||||
this.isReady = true;
|
||||
@ -222,6 +223,14 @@ class CJbot{
|
||||
this.__doCommand(message.toString().split(' ')[0], '.invite');
|
||||
}
|
||||
|
||||
if(message.toString().includes(' wants to trade with you!')){
|
||||
// teleport invite
|
||||
|
||||
console.log('found Trade', message.toString().split(' ')[0])
|
||||
this.__doCommand(message.toString().split(' ')[0], '.trade');
|
||||
}
|
||||
|
||||
|
||||
if(message.toString().includes('You are combat tagged by')){
|
||||
try{
|
||||
this.combatTag = true;
|
||||
@ -316,6 +325,62 @@ class CJbot{
|
||||
|
||||
return this.bot.players;
|
||||
}
|
||||
|
||||
__blockOrVec(thing){
|
||||
if(thing instanceof Vec3.Vec3) return this.bot.blockAt(thing);
|
||||
if(thing.constructor && thing.constructor.name === 'Block') return thing;
|
||||
|
||||
throw new Error('Not supported block identifier');
|
||||
}
|
||||
|
||||
|
||||
async __nextContainerSlot(window, item) {
|
||||
let firstEmptySlot = false;
|
||||
|
||||
await window.containerItems();
|
||||
|
||||
for(let slot in window.slots.slice(0, window.inventoryStart)){
|
||||
if(window.slots[slot] === null ){
|
||||
if(!Number.isInteger(firstEmptySlot)) firstEmptySlot = Number(slot);
|
||||
continue;
|
||||
}
|
||||
if(item.type === window.slots[slot].type && window.slots[slot].count < window.slots[slot].stackSize){
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
|
||||
return firstEmptySlot;
|
||||
}
|
||||
|
||||
async putInChest(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){
|
||||
if(!item) return false;
|
||||
if(blockName && blockName !== item.name) return false;
|
||||
return true;
|
||||
})){
|
||||
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;
|
||||
}
|
||||
|
||||
await this.bot.closeWindow(window);
|
||||
|
||||
return amount ? amount : true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
module.exports = {CJbot};
|
||||
|
Reference in New Issue
Block a user