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/placeEntity.js
Views: 789
const assert = require('assert')1const { Vec3 } = require('vec3')2const { once } = require('../../lib/promise_utils')34module.exports = (version) => {5async function runTest (bot, testFunction) {6await testFunction(bot)7}89const tests = []1011function addTest (name, f) {12tests[name] = bot => runTest(bot, f)13}1415addTest('place crystal', async (bot) => {16if (!bot.registry.itemsByName.end_crystal) return // unsupported17await bot.test.setBlock({ z: 1, relative: true, blockName: 'obsidian' })18await bot.test.awaitItemReceived(`/give ${bot.username} end_crystal`)19const crystal = await bot.placeEntity(bot.blockAt(bot.entity.position.offset(0, 0, 1)), new Vec3(0, 1, 0))20assert(crystal !== null)21let name = 'EnderCrystal'22if (bot.supportFeature('enderCrystalNameEndsInErNoCaps')) {23name = 'ender_crystal'24} else if (bot.supportFeature('entityNameLowerCaseNoUnderscore')) {25name = 'endercrystal'26} else if (bot.supportFeature('enderCrystalNameNoCapsWithUnderscore')) {27name = 'end_crystal'28}29const entity = bot.nearestEntity(o => o.name === name)30assert(entity?.name === name)31bot.attack(entity)32await once(bot, 'entityGone')33await bot.test.setBlock({ z: 1, blockName: 'air', relative: true })34})3536addTest('place boat', async (bot) => {37async function placeBlocksForTest (blockName) {38for (let z = -1; z >= -3; z--) {39const y = -140for (let x = -1; x <= 1; x++) {41await bot.test.setBlock({ x, y, z, blockName, relative: true })42}43}44}4546await placeBlocksForTest('water')47await bot.test.awaitItemReceived(`/give ${bot.username} ${bot.registry.oak_boat ? 'oak_boat' : 'boat'}`)48const boat = await bot.placeEntity(bot.blockAt(bot.entity.position.offset(0, -1, -2)), new Vec3(0, -1, 0))49assert(boat !== null)50const name = bot.supportFeature('entityNameUpperCaseNoUnderscore') ? 'Boat' : 'boat'51const entity = bot.nearestEntity(o => o.name === name)52assert(entity?.name === name)53await placeBlocksForTest('air')54bot.attack(entity)55await once(bot, 'entityGone')56})5758addTest('place summon egg', async (bot) => {59let command60if (bot.registry.isOlderThan('1.9')) {61command = '/give @p spawn_egg 1 54' // 1.862} else if (bot.registry.isOlderThan('1.11')) {63command = '/give @p spawn_egg 1 0 {EntityTag:{id:Zombie}}' // 1.9 / 1.1064} else if (bot.registry.isOlderThan('1.12')) {65command = '/give @p spawn_egg 1 0 {EntityTag:{id:minecraft:zombie}}' // 1.1166} else if (bot.registry.isOlderThan('1.13')) {67command = '/give @p spawn_egg 1 0 {EntityTag:{id:zombie}}' // 1.1268} else {69command = '/give @p zombie_spawn_egg 1' // >1.1270}71await bot.test.awaitItemReceived(command)72const zombie = await bot.placeEntity(bot.blockAt(bot.entity.position.offset(0, 0, 1)), new Vec3(0, 1, 0))73assert(zombie !== null)74const name = bot.supportFeature('entityNameUpperCaseNoUnderscore') ? 'Zombie' : 'zombie'75const entity = bot.nearestEntity(o => o.name === name)76assert(entity?.name === name)77bot.chat(`/kill @e[type=${name}]`) // use /kill instead of bot.attack() because it takes more than one hit to kill78await once(bot, 'entityGone')79})8081addTest('place armor stand', async (bot) => {82await bot.test.awaitItemReceived(`/give ${bot.username} armor_stand`)83const armorStand = await bot.placeEntity(bot.blockAt(bot.entity.position.offset(0, 0, 1)), new Vec3(0, 1, 0))84assert(armorStand !== null)85let name86if (bot.supportFeature('entityNameUpperCaseNoUnderscore')) {87name = 'ArmorStand'88} else if (bot.supportFeature('entityNameLowerCaseNoUnderscore')) {89name = 'armorstand'90} else {91name = 'armor_stand'92}93const entity = bot.nearestEntity(o => o.name === name)94assert(entity?.name === name)95bot.attack(entity)96await once(bot, 'entityGone')97})9899return tests100}101102103