PrismarineJS / mineflayer

Create Minecraft bots with a powerful, stable, and high level JavaScript API.
https://prismarinejs.github.io/mineflayer/
MIT License
4.95k stars 904 forks source link

Bot.clickWindow not working in ShopGuiPlus plugin #824

Closed JungleDome closed 4 years ago

JungleDome commented 5 years ago

Versions

Detailed description of a question

Hi, I am facing issues trying to select/click on an item in chest shop gui. The plugin name is shop gui plus, basically it has three kind of input. Left click for buying item, right click for selling item, and middle mouse click for sell all item in inventory where left and right click will leads to another gui for choosing quantity. However, the problem I'm facing right now is I am able to select the main category menu using bot.clickWindow but when buying an item the bot.clickWindow does not interact with the gui. Do any of you knows how to fix this problem?

The things that I tried: 1) Checking whether the slot I'm selecting contains the item. 2) window.selectedItem does holds the value of the item. (which means the gui is working properly) 3) Prints error for bot.clickWindow but returned undefined. 4) Trying to select the item by equipping/swapping it to hand/inventory.

Code:

bot.on('windowOpen',function(window) {
    console.log("Selling sulphur");
    console.log(window.slots[12]);
    console.log(window.selectedItem);
    bot.clickWindow(12, 1, 0, (err) => {
        console.log(err);
    });
    console.log(window.selectedItem);
    console.log(window.slots[12]);
    bot.equip(window.selectedItem,"hand");
}

Output:

Selling sulphur
Item {
  type: 289,
  count: 1,
  metadata: 0,
  nbt: { type: 'compound', name: '', value: { display: [Object] } },
  name: 'gunpowder',
  displayName: 'Gunpowder',
  stackSize: 64,
  slot: 12 }
null
undefined
Item {
  type: 289,
  count: 1,
  metadata: 0,
  nbt: { type: 'compound', name: '', value: { display: [Object] } },
  name: 'gunpowder',
  displayName: 'Gunpowder',
  stackSize: 64 }
null
JungleDome commented 5 years ago

Are there any mod or plugins which I can get the client to server packets in order to determine the problem details?

rom1504 commented 5 years ago

You can use debug mode for this (see readme)

JungleDome commented 5 years ago

Vanilla Packet

client->server:play window_click :{"windowId":2,"slot":3,"mouseButton":0,"action":1,"mode":0,"item":{"blockId":42,"itemCount":1,"itemDamage":0,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§6* §eBuy: §c$§f1,260","§6* §eSell: §a$§f810","§8* §7Click with §8§nMMB§7 to sell all"]}}}}}}}}
client<-server:play.window_items :{"windowId":2,"items":[{"blockId":173,"itemCount":1,"itemDamage":0,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§6* §eBuy: §c$§f360","§6* §eSell: §a$§f135","§8* §7Click with §8§nMMB§7 to sell all"]}}}}}}},{"blockId":152,"itemCount":1,"itemDamage":0,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§6* §eBuy: §c$§f270","§6* §eSell: §a$§f180","§8* §7Click with §8§nMMB§7 to sell all"]}}}}}}},{"blockId":22,"itemCount":1,"itemDamage":0,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§6* §eBuy: §c$§f225","§6* §eSell: §a$§f180","§8* §7Click with §8§nMMB§7 to sell all"]}}}}}}},{"blockId":42,"itemCount":1,"itemDamage":0,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§6* §eBuy: §c$§f1,260","§6* §eSell: §a$§f810","§8* §7Click with §8§nMMB§7 to sell all"]}}}}}}},{"blockId":41,"itemCount":1,"itemDamage":0,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§6* §eBuy: §c$§f1,440","§6* §eSell: §a$§f900","§8* §7Click with §8§nMMB§7 to sell all"]}}}}}}},{"blockId":57,"itemCount":1,"itemDamage":0,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§6* §eBuy: §c$§f1,620","§6* §eSell: §a$§f990","§8* §7Click with §8§nMMB§7 to sell all"]}}}}}}},{"blockId":133,"itemCount":1,"itemDamage":0,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§6* §eBuy: §c$§f1,800","§6* §eSell: §a$§f1,080","§8* §7Click with §8§nMMB§7 to sell all"]}}}}}}},{"blockId":263,"itemCount":1,"itemDamage":0,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§6* §eBuy: §c$§f40","§6* §eSell: §a$§f15","§8* §7Click with §8§nMMB§7 to sell all"]}}}}}}},{"blockId":331,"itemCount":1,"itemDamage":0,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§6* §eBuy: §c$§f30","§6* §eSell: §a$§f20","§8* §7Click with §8§nMMB§7 to sell all"]}}}}}}},{"blockId":351,"itemCount":1,"itemDamage":4,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§6* §eBuy: §c$§f25","§6* §eSell: §a$§f20","§8* §7Click with §8§nMMB§7 to sell all"]}}}}}}},{"blockId":265,"itemCount":1,"itemDamage":0,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§6* §eBuy: §c$§f140","§6* §eSell: §a$§f90","§8* §7Click with §8§nMMB§7 to sell all"]}}}}}}},{"blockId":266,"itemCount":1,"itemDamage":0,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§6* §eBuy: §c$§f160","§6* §eSell: §a$§f100","§8* §7Click with §8§nMMB§7 to sell all"]}}}}}}},{"blockId":264,"itemCount":1,"itemDamage":0,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§6* §eBuy: §c$§f180","§6* §eSell: §a$§f110","§8* §7Click with §8§nMMB§7 to sell all"]}}}}}}},{"blockId":388,"itemCount":1,"itemDamage":0,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§6* §eBuy: §c$§f200","§6* §eSell: §a$§f120","§8* §7Click with §8§nMMB§7 to sell all"]}}}}}}},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":160,"itemCount":1,"itemDamage":13},{"blockId":160,"itemCount":1,"itemDamage":13},{"blockId":160,"itemCount":1,"itemDamage":13},{"blockId":160,"itemCount":1,"itemDamage":13},{"blockId":288,"itemCount":1,"itemDamage":0,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§7Click Here to Return"]}},"Name":{"type":"string","value":"§c§lGO§r §c§lBACK"}}}}}},{"blockId":160,"itemCount":1,"itemDamage":13},{"blockId":160,"itemCount":1,"itemDamage":13},{"blockId":160,"itemCount":1,"itemDamage":13},{"blockId":160,"itemCount":1,"itemDamage":13},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":276,"itemCount":1,"itemDamage":0,"nbtData":{"type":"compound","name":"","value":{"ench":{"type":"list","value":{"type":"compound","value":[{"lvl":{"type":"short","value":5},"id":{"type":"short","value":16}},{"lvl":{"type":"short","value":2},"id":{"type":"short","value":19}},{"lvl":{"type":"short","value":2},"id":{"type":"short","value":20}},{"lvl":{"type":"short","value":3},"id":{"type":"short","value":21}},{"lvl":{"type":"short","value":3},"id":{"type":"short","value":22}},{"lvl":{"type":"short","value":3},"id":{"type":"short","value":34}},{"lvl":{"type":"short","value":1},"id":{"type":"short","value":70}}]}},"RepairCost":{"type":"int","value":63},"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§7Wither III","§7Nutrition III","§7DoubleDamage III","§7Execute V","§7Trap II","§7Rage III","§7SlowMo III","§7Confusion IV","§7FastTurn II","§7SkillSwipe V","§7Slice II","§7Inquisitive V","§7Blindness II","§7LifeSteal V","§7Headless V","§7Vampire V","§7Snare III","§7Disarmer III"]}}}}}}},{"blockId":278,"itemCount":1,"itemDamage":139,"nbtData":{"type":"compound","name":"","value":{"ench":{"type":"list","value":{"type":"compound","value":[{"lvl":{"type":"short","value":5},"id":{"type":"short","value":32}},{"lvl":{"type":"short","value":3},"id":{"type":"short","value":34}},{"lvl":{"type":"short","value":3},"id":{"type":"short","value":35}}]}},"RepairCost":{"type":"int","value":7}}}},{"blockId":279,"itemCount":1,"itemDamage":40},{"blockId":326,"itemCount":1,"itemDamage":0},{"blockId":95,"itemCount":1,"itemDamage":0},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1}]}
client<-server:play.set_slot :{"windowId":-1,"slot":-1,"item":{"blockId":-1}}
client<-server:play.open_window :{"windowId":3,"inventoryType":"minecraft:container","windowTitle":"{\"text\":\"§2Buying Iron Block\"}","slotCount":54}

Mineflayer Packet

client->server:play window_click :{"windowId":2,"slot":3,"mouseButton":0,"action":1,"mode":0,"item":{"blockId":42,"itemCount":1,"itemDamage":0,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§6* §eBuy: §c$§f1,260","§6* §eSell: §a$§f810","§8* §7Click with §8§nMMB§7 to sell all"]}}}}}}}}
client<-server:play.window_items :{"windowId":2,"items":[{"blockId":173,"itemCount":1,"itemDamage":0,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§6* §eBuy: §c$§f360","§6* §eSell: §a$§f135","§8* §7Click with §8§nMMB§7 to sell all"]}}}}}}},{"blockId":152,"itemCount":1,"itemDamage":0,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§6* §eBuy: §c$§f270","§6* §eSell: §a$§f180","§8* §7Click with §8§nMMB§7 to sell all"]}}}}}}},{"blockId":22,"itemCount":1,"itemDamage":0,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§6* §eBuy: §c$§f225","§6* §eSell: §a$§f180","§8* §7Click with §8§nMMB§7 to sell all"]}}}}}}},{"blockId":42,"itemCount":1,"itemDamage":0,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§6* §eBuy: §c$§f1,260","§6* §eSell: §a$§f810","§8* §7Click with §8§nMMB§7 to sell all"]}}}}}}},{"blockId":41,"itemCount":1,"itemDamage":0,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§6* §eBuy: §c$§f1,440","§6* §eSell: §a$§f900","§8* §7Click with §8§nMMB§7 to sell all"]}}}}}}},{"blockId":57,"itemCount":1,"itemDamage":0,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§6* §eBuy: §c$§f1,620","§6* §eSell: §a$§f990","§8* §7Click with §8§nMMB§7 to sell all"]}}}}}}},{"blockId":133,"itemCount":1,"itemDamage":0,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§6* §eBuy: §c$§f1,800","§6* §eSell: §a$§f1,080","§8* §7Click with §8§nMMB§7 to sell all"]}}}}}}},{"blockId":263,"itemCount":1,"itemDamage":0,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§6* §eBuy: §c$§f40","§6* §eSell: §a$§f15","§8* §7Click with §8§nMMB§7 to sell all"]}}}}}}},{"blockId":331,"itemCount":1,"itemDamage":0,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§6* §eBuy: §c$§f30","§6* §eSell: §a$§f20","§8* §7Click with §8§nMMB§7 to sell all"]}}}}}}},{"blockId":351,"itemCount":1,"itemDamage":4,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§6* §eBuy: §c$§f25","§6* §eSell: §a$§f20","§8* §7Click with §8§nMMB§7 to sell all"]}}}}}}},{"blockId":265,"itemCount":1,"itemDamage":0,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§6* §eBuy: §c$§f140","§6* §eSell: §a$§f90","§8* §7Click with §8§nMMB§7 to sell all"]}}}}}}},{"blockId":266,"itemCount":1,"itemDamage":0,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§6* §eBuy: §c$§f160","§6* §eSell: §a$§f100","§8* §7Click with §8§nMMB§7 to sell all"]}}}}}}},{"blockId":264,"itemCount":1,"itemDamage":0,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§6* §eBuy: §c$§f180","§6* §eSell: §a$§f110","§8* §7Click with §8§nMMB§7 to sell all"]}}}}}}},{"blockId":388,"itemCount":1,"itemDamage":0,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§6* §eBuy: §c$§f200","§6* §eSell: §a$§f120","§8* §7Click with §8§nMMB§7 to sell all"]}}}}}}},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":160,"itemCount":1,"itemDamage":13},{"blockId":160,"itemCount":1,"itemDamage":13},{"blockId":160,"itemCount":1,"itemDamage":13},{"blockId":160,"itemCount":1,"itemDamage":13},{"blockId":288,"itemCount":1,"itemDamage":0,"nbtData":{"type":"compound","name":"","value":{"display":{"type":"compound","value":{"Lore":{"type":"list","value":{"type":"string","value":["§7Click Here to Return"]}},"Name":{"type":"string","value":"§c§lGO§r §c§lBACK"}}}}}},{"blockId":160,"itemCount":1,"itemDamage":13},{"blockId":160,"itemCount":1,"itemDamage":13},{"blockId":160,"itemCount":1,"itemDamage":13},{"blockId":160,"itemCount":1,"itemDamage":13},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1},{"blockId":-1}]}
client<-server:play.set_slot :{"windowId":-1,"slot":-1,"item":{"blockId":-1}}

Do you have any idea what might cause the server not to open a new window? Could it be the reaction is too fast or some packet not formed correctly?

hexatester commented 4 years ago

What if you close the window first, then bot.equip(window.selectedItem,"hand");

JungleDome commented 4 years ago

Sorry to say that, I discontinued this project.