|
1 | 1 | const { Vec3 } = require('vec3')
|
2 | 2 | const assert = require('assert')
|
3 | 3 | const { once } = require('events')
|
| 4 | +const { onceWithCleanup } = require('../../lib/promise_utils') |
4 | 5 |
|
5 | 6 | module.exports = () => async (bot) => {
|
6 | 7 | const Item = require('prismarine-item')(bot.registry)
|
@@ -126,4 +127,59 @@ module.exports = () => async (bot) => {
|
126 | 127 |
|
127 | 128 | await withdrawBones(smallTrappedChestLocation, 1)
|
128 | 129 | await withdrawBones(largeTrappedChestLocations[0], 2)
|
| 130 | + |
| 131 | + const itemsWithStackSize = { |
| 132 | + 64: ['stone', 'grass'], |
| 133 | + 16: ['ender_pearl', 'egg'], |
| 134 | + 1: ['fishing_rod', 'bow'] |
| 135 | + } |
| 136 | + |
| 137 | + function getRandomStackableItem () { |
| 138 | + if (Math.random() < 0.75) { |
| 139 | + return itemsWithStackSize[64][~~(Math.random() * itemsWithStackSize[64].length)] |
| 140 | + } else { |
| 141 | + if (Math.random() < 0.5) { |
| 142 | + return itemsWithStackSize[16][~~(Math.random() * itemsWithStackSize[16].length)] |
| 143 | + } else { |
| 144 | + return itemsWithStackSize[1][~~(Math.random() * itemsWithStackSize[1].length)] |
| 145 | + } |
| 146 | + } |
| 147 | + } |
| 148 | + |
| 149 | + async function createRandomLayout (window, slotPopulationFactor) { |
| 150 | + await bot.test.becomeCreative() |
| 151 | + |
| 152 | + for (let slot = 0; slot < window.inventoryStart; slot++) { |
| 153 | + if (Math.random() < slotPopulationFactor) { |
| 154 | + const item = bot.registry.itemsByName[getRandomStackableItem()] |
| 155 | + bot.chat(`/give ${bot.username} ${item.name} ${Math.ceil(Math.random() * item.stackSize)}`) |
| 156 | + await onceWithCleanup(window, 'updateSlot', { checkCondition: (slot, oldItem, newItem) => slot === window.hotbarStart && newItem?.name === item.name }) |
| 157 | + |
| 158 | + // await bot.clickWindow(slot, 0, 2) |
| 159 | + await bot.moveSlotItem(window.hotbarStart, slot) |
| 160 | + } |
| 161 | + } |
| 162 | + |
| 163 | + await bot.test.becomeSurvival() |
| 164 | + } |
| 165 | + |
| 166 | + async function testMouseClick (window, clicks) { |
| 167 | + let iterations = 0 |
| 168 | + while (iterations++ < clicks) { |
| 169 | + await bot.clickWindow(~~(Math.random() * window.inventoryStart), 0, 0) |
| 170 | + } |
| 171 | + } |
| 172 | + |
| 173 | + function clearLargeChest () { |
| 174 | + bot.chat(`/setblock ${largeChestLocations[0].x} ${largeChestLocations[0].y} ${largeChestLocations[0].z} chest`) |
| 175 | + bot.chat(`/setblock ${largeChestLocations[1].x} ${largeChestLocations[1].y} ${largeChestLocations[1].z} chest`) |
| 176 | + } |
| 177 | + |
| 178 | + const window = await bot.openContainer(bot.blockAt(largeChestLocations[0])) |
| 179 | + await createRandomLayout(window, 0.95) |
| 180 | + |
| 181 | + await testMouseClick(window, 250) |
| 182 | + |
| 183 | + window.close() |
| 184 | + clearLargeChest() |
129 | 185 | }
|
0 commit comments