Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/test/externalTests/creative.js
Views: 789
const assert = require('assert')1const wait = require('util').promisify(setTimeout)2const SLOT = 3634module.exports = () => async (bot) => {5const Item = require('prismarine-item')(bot.registry)67const item1 = new Item(1, 1, 0)8const item2 = new Item(2, 1, 0)910const promise = bot.creative.setInventorySlot(SLOT, item2)1112try {13bot.creative.setInventorySlot(SLOT, item1)14} catch (err) {15assert.ok(err instanceof Error, 'The error has not been passed')16assert.ok(bot.inventory.slots[SLOT] == null)17}1819// setting a slot once works20await promise21assert.ok(bot.inventory.slots[SLOT] != null)22assert.ok(bot.inventory.slots[SLOT].type === item2.type)23// set the same item in the same slot again to ensure we don't hang24const returnValue = await Promise.race([25bot.creative.setInventorySlot(SLOT, item2),26(async () => {27await wait(5000) // after 5 seconds just fail the test28return 'Setting the same item in the same slot took too long'29})()30])31if (typeof returnValue === 'string') {32throw new Error(returnValue)33}34// setting that same slot again works35await bot.creative.setInventorySlot(SLOT, new Item(3, 1, 0))36assert.strictEqual(bot.inventory.slots[SLOT].type, 3)37// and again works38await bot.creative.setInventorySlot(SLOT, new Item(4, 1, 0))39assert.strictEqual(bot.inventory.slots[SLOT].type, 4)40// setting a slot to null41await bot.creative.setInventorySlot(SLOT, null)42assert.strictEqual(bot.inventory.slots[SLOT], null)43// clear slot44await bot.creative.setInventorySlot(SLOT, new Item(4, 1, 0))45assert.strictEqual(bot.inventory.slots[SLOT].type, 4)46await bot.creative.clearSlot(SLOT)47assert.strictEqual(bot.inventory.slots[SLOT], null)48// clear inventory49for (let i = 0; i < 9; i++) {50await bot.creative.setInventorySlot(36 + i, new Item(1, 1, 0))51}52assert.strictEqual(bot.inventory.slots.filter(item => item).length, 9)53await bot.creative.clearInventory()54assert.strictEqual(bot.inventory.slots.filter(item => item).length, 0)55}565758