better trade
This commit is contained in:
parent
d6c003850d
commit
77513c4c8d
@ -55,7 +55,6 @@ let sites = {
|
|||||||
german: {
|
german: {
|
||||||
bot: 'linda',
|
bot: 'linda',
|
||||||
desc: `Get an invite you Germans area.`,
|
desc: `Get an invite you Germans area.`,
|
||||||
allowed: ['wmantly', 'useless666', 'tux4242', 'owenshorts', 'VinceNL', 'Ethan63020', 'Ethan63021', 'pi_chef', 'YTMatze', 'mytzor', 'pi_chef', '1_cut', 'nootbot'],
|
|
||||||
allowed: ['wmantly', 'useless666', 'tux4242', 'owenshorts', 'VinceNL', 'Ethan63020', 'Ethan63021', 'pi_chef', 'YTMatze', 'mytzor', 'pi_chef', '1_cut', 'nootbot', 'Lost_Imback',],
|
allowed: ['wmantly', 'useless666', 'tux4242', 'owenshorts', 'VinceNL', 'Ethan63020', 'Ethan63021', 'pi_chef', 'YTMatze', 'mytzor', 'pi_chef', '1_cut', 'nootbot', 'Lost_Imback',],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ const customerSlots = [5, 6, 7, 8, 14, 15, 16, 17, 23, 24, 25, 26];
|
|||||||
function findChestBySign(bot, text){
|
function findChestBySign(bot, text){
|
||||||
let sign = bot.bot.findBlock({
|
let sign = bot.bot.findBlock({
|
||||||
useExtraInfo: true,
|
useExtraInfo: true,
|
||||||
// maxDistance: 1,
|
maxDistance: 32,
|
||||||
matching: (block)=> {
|
matching: (block)=> {
|
||||||
if(block.name.includes('sign') && block.signText.includes(text)){
|
if(block.name.includes('sign') && block.signText.includes(text)){
|
||||||
return true;
|
return true;
|
||||||
@ -49,7 +49,7 @@ module.exports = {
|
|||||||
this.bot.closeWindow('window');
|
this.bot.closeWindow('window');
|
||||||
this.bot.removeAllListeners('windowOpen');
|
this.bot.removeAllListeners('windowOpen');
|
||||||
this.whisper(from, `I have things to do, I cant wait on you all day!`)
|
this.whisper(from, `I have things to do, I cant wait on you all day!`)
|
||||||
}, 30000);
|
}, 120000);
|
||||||
|
|
||||||
// Check to see if the remote user has agreed to the trade.
|
// Check to see if the remote user has agreed to the trade.
|
||||||
let confirmationCheck = setInterval(async ()=>{
|
let confirmationCheck = setInterval(async ()=>{
|
||||||
@ -64,15 +64,30 @@ module.exports = {
|
|||||||
|
|
||||||
// If the trade took so long it timed out, just kill the whole thing.
|
// If the trade took so long it timed out, just kill the whole thing.
|
||||||
if(timeoutCheck._destroyed) return;
|
if(timeoutCheck._destroyed) return;
|
||||||
|
console.log('clearing timeout');
|
||||||
clearTimeout(timeoutCheck)
|
clearTimeout(timeoutCheck)
|
||||||
|
|
||||||
// Give MC a moment
|
// Give MC a moment
|
||||||
await sleep(1000);
|
// await sleep(1000);
|
||||||
|
|
||||||
|
let goBack = await this.goToReturn({where: chestBlock, reTry: true})
|
||||||
|
|
||||||
let isPutAway = await this.dumpToChest(chestBlock)
|
let isPutAway = await this.dumpToChest(chestBlock)
|
||||||
|
|
||||||
|
await goBack();
|
||||||
|
|
||||||
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.`);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
'test': {
|
||||||
|
desc: 'go away',
|
||||||
|
allowed: ['useless666'],
|
||||||
|
async function(from){
|
||||||
|
let chestBlock = findChestBySign(this, from);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,11 +21,16 @@ for(let name in conf.mc.bots){
|
|||||||
}
|
}
|
||||||
|
|
||||||
bot.on('onReady', async function(argument) {
|
bot.on('onReady', async function(argument) {
|
||||||
inventoryViewer(bot.bot);
|
// inventoryViewer(bot.bot);
|
||||||
await sleep(1000);
|
await sleep(1000);
|
||||||
bot.bot.setControlState('jump', true);
|
bot.bot.setControlState('jump', true);
|
||||||
|
console.log(bot.bot.entity);
|
||||||
setTimeout(()=> bot.bot.setControlState('jump', false), 5000)
|
setTimeout(()=> bot.bot.setControlState('jump', false), 5000)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// bot.on('message', function(...args){
|
||||||
|
// console.log('message | ', ...args)
|
||||||
|
// })
|
||||||
}
|
}
|
||||||
|
|
||||||
(async ()=>{
|
(async ()=>{
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
const mineflayer = require('mineflayer');
|
const mineflayer = require('mineflayer');
|
||||||
const minecraftData = require('minecraft-data');
|
const minecraftData = require('minecraft-data');
|
||||||
|
const { pathfinder, Movements, goals: { GoalNear } } = require('mineflayer-pathfinder');
|
||||||
const Vec3 = require('vec3');
|
const Vec3 = require('vec3');
|
||||||
const {sleep} = require('../utils');
|
const {sleep} = require('../utils');
|
||||||
|
|
||||||
@ -106,8 +107,11 @@ class CJbot{
|
|||||||
// server
|
// server
|
||||||
async __onReady(){try{
|
async __onReady(){try{
|
||||||
|
|
||||||
|
this.bot.loadPlugin(pathfinder);
|
||||||
this.mcData = minecraftData(this.bot.version);
|
this.mcData = minecraftData(this.bot.version);
|
||||||
|
this.defaultMove = new Movements(this.bot, this.mcData);
|
||||||
|
this.defaultMove.canDig = false
|
||||||
|
this.bot.pathfinder.setMovements(this.defaultMove);
|
||||||
|
|
||||||
// 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.
|
||||||
@ -306,6 +310,7 @@ class CJbot{
|
|||||||
await this.commands[cmd].function.call(this, from, ...parts);
|
await this.commands[cmd].function.call(this, from, ...parts);
|
||||||
}catch(error){
|
}catch(error){
|
||||||
this.whisper(from, `The command encountered an error.`);
|
this.whisper(from, `The command encountered an error.`);
|
||||||
|
this.whisper(from, `ERROR: ${error}`);
|
||||||
console.error(`Chat command error on ${cmd} from ${from}\n`, error);
|
console.error(`Chat command error on ${cmd} from ${from}\n`, error);
|
||||||
}
|
}
|
||||||
this.__unLockCommand();
|
this.__unLockCommand();
|
||||||
@ -337,6 +342,40 @@ class CJbot{
|
|||||||
throw new Error('Not supported block identifier');
|
throw new Error('Not supported block identifier');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async _goTo(block, range=2){
|
||||||
|
block = this.__blockOrVec(block);
|
||||||
|
|
||||||
|
return await this.bot.pathfinder.goto(new GoalNear(...block.position.toArray(), range));
|
||||||
|
}
|
||||||
|
|
||||||
|
goTo(options){
|
||||||
|
console.log('goTo options', options)
|
||||||
|
return new Promise(async(resolve, reject)=>{
|
||||||
|
|
||||||
|
let range = options.range || 2;
|
||||||
|
|
||||||
|
try{
|
||||||
|
await this._goTo(options.where, range)
|
||||||
|
return resolve();
|
||||||
|
}catch(error){
|
||||||
|
console.log('goTo error', error)
|
||||||
|
if(options.reTry) return reject('Action can not move to where')
|
||||||
|
await this._goTo(options, true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async goToReturn(options){
|
||||||
|
let here = this.bot.entity.position;
|
||||||
|
let hereYaw = this.bot.entity.yaw
|
||||||
|
await this.goTo(options);
|
||||||
|
return async () =>{
|
||||||
|
await this.goTo({where: here, range: 0}, true);
|
||||||
|
await sleep(500);
|
||||||
|
await this.bot.look(Math.floor(hereYaw), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async __nextContainerSlot(window, item) {
|
async __nextContainerSlot(window, item) {
|
||||||
let firstEmptySlot = false;
|
let firstEmptySlot = false;
|
||||||
@ -356,11 +395,28 @@ class CJbot{
|
|||||||
return firstEmptySlot;
|
return firstEmptySlot;
|
||||||
}
|
}
|
||||||
|
|
||||||
async dumpToChest(block, blockName, amount) {
|
async openContainer(block){
|
||||||
|
let count = 0;
|
||||||
block = this.__blockOrVec(block);
|
block = this.__blockOrVec(block);
|
||||||
|
|
||||||
this.bot.openContainer(block);
|
while(!this.bot.currentWindow){
|
||||||
let window = await this.once('windowOpen');
|
let window = this.bot.openContainer(block);
|
||||||
|
await sleep(1500);
|
||||||
|
if(this.bot.currentWindow?.title){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
this.bot.removeAllListeners('windowOpen');
|
||||||
|
|
||||||
|
if(count++ == 3) throw 'Block wont open';
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.bot.currentWindow;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
async dumpToChest(block, blockName, amount) {
|
||||||
|
|
||||||
|
let window = await this.openContainer(block);
|
||||||
|
|
||||||
let items = 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;
|
||||||
@ -369,8 +425,7 @@ class CJbot{
|
|||||||
});
|
});
|
||||||
|
|
||||||
for(let item of items){
|
for(let item of items){
|
||||||
console.log(`Trying to place ${item.name}`)
|
await sleep(500);
|
||||||
await sleep(100);
|
|
||||||
let currentSlot = Number(item.slot);
|
let currentSlot = Number(item.slot);
|
||||||
if(!window.slots[currentSlot]) continue;
|
if(!window.slots[currentSlot]) continue;
|
||||||
|
|
||||||
@ -381,18 +436,17 @@ class CJbot{
|
|||||||
// continue;
|
// continue;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
console.log('item', this.mcData.itemsByName[item.name])
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
console.log('transfer', await this.bot.transfer({
|
await this.bot.transfer({
|
||||||
window,
|
window,
|
||||||
itemType: this.mcData.itemsByName[item.name].id,
|
itemType: this.mcData.itemsByName[item.name].id,
|
||||||
sourceStart: currentSlot,
|
sourceStart: currentSlot,
|
||||||
sourceEnd: currentSlot+1,
|
sourceEnd: currentSlot+1,
|
||||||
destStart: 0,
|
destStart: 0,
|
||||||
destEnd: window.inventoryStart,
|
destEnd: window.inventoryStart-1,
|
||||||
count: amount || item.count,
|
count: amount || item.count,
|
||||||
}))
|
})
|
||||||
|
|
||||||
if(amount) amount -= item.count
|
if(amount) amount -= item.count
|
||||||
}catch(error){
|
}catch(error){
|
||||||
@ -401,7 +455,7 @@ class CJbot{
|
|||||||
// await this.bot.moveSlotItem(currentSlot, chestSlot);
|
// await this.bot.moveSlotItem(currentSlot, chestSlot);
|
||||||
}
|
}
|
||||||
|
|
||||||
await sleep(100);
|
await sleep(1000);
|
||||||
await this.bot.closeWindow(window);
|
await this.bot.closeWindow(window);
|
||||||
|
|
||||||
return amount ? amount : true;
|
return amount ? amount : true;
|
||||||
|
1925
nodejs/package-lock.json
generated
1925
nodejs/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user