From d0a1660521a1e6ce62f5da9d19c754ef48d89d7f Mon Sep 17 00:00:00 2001 From: PondWader <66561610+PondWader@users.noreply.github.com> Date: Wed, 28 Jun 2023 21:39:39 +0100 Subject: [PATCH] 1.20 (#3088) * 1.20 * Node 18 for tests * Actually use node 18 * Make command block test more reliable * Revert node 18 + place block change * Update sign test for prismarine-block changes * Update docs * Update package.json * Fix lint * Update ci.yml * sign `isFrontText` => `back` flag, remove removeAllListeners in tests * lint * Only test 1.20.1 and not 1.20 * Update package.json * Prismarine-block no longer returns empty trailing lines * Just trim end of sign text when checking it * use onceWithCleanUp for commandBlock test --------- Co-authored-by: Romain Beaumont Co-authored-by: extremeheat --- .github/workflows/ci.yml | 2 ++ docs/api.md | 29 +++++++++++++++++------------ index.d.ts | 2 +- lib/plugins/blocks.js | 4 +++- lib/version.js | 4 ++-- package.json | 10 +++++----- test/externalTests/commandBlock.js | 7 +++++-- test/externalTests/sign.js | 13 +++---------- 8 files changed, 38 insertions(+), 33 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 859675833..1fcc96f84 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,6 +37,8 @@ jobs: mcVersion: '1.19.3' - javaVersion: 17 mcVersion: '1.19.4' + - javaVersion: 17 + mcVersion: '1.20.1' fail-fast: false steps: diff --git a/docs/api.md b/docs/api.md index c0db3532a..e14046ac9 100644 --- a/docs/api.md +++ b/docs/api.md @@ -422,21 +422,26 @@ The skin data is stored in the `skinData` property of the player object, if pres See [prismarine-block](https://github.com/PrismarineJS/prismarine-block) -Also `block.blockEntity` is additional field with block entity data as `Object` +Also `block.blockEntity` is additional field with block entity data as `Object`. The data in this varies between versions. ```js -// sign.blockEntity +// sign.blockEntity example from 1.19 { - x: -53, - y: 88, - z: 66, - id: 'minecraft:sign', // 'Sign' in 1.10 - Text1: { toString: Function }, // ChatMessage object - Text2: { toString: Function }, // ChatMessage object - Text3: { toString: Function }, // ChatMessage object - Text4: { toString: Function } // ChatMessage object + GlowingText: 0, // 0 for false, 1 for true + Color: 'black', + Text1: '{"text":"1"}', + Text2: '{"text":"2"}', + Text3: '{"text":"3"}', + Text4: '{"text":"4"}' } ``` +Note if you want to get a sign's plain text, you can use [`block.getSignText()`](https://github.com/PrismarineJS/prismarine-block/blob/master/doc/API.md#sign) instead of unstable blockEntity data. +```java +> block = bot.blockAt(new Vec3(0, 60, 0)) // assuming a sign is here +> block.getSignText() +[ "Front text\nHello world", "Back text\nHello world" ] +``` + ### Biome See [prismarine-biome](https://github.com/PrismarineJS/prismarine-biome) @@ -1803,9 +1808,9 @@ Set the direction your head is facing. are looking, such as for dropping items or shooting arrows. This is not needed for client-side calculation such as walking direction. -#### bot.updateSign(block, text) +#### bot.updateSign(block, text, back = false) -Changes the text on the sign. +Changes the text on the sign. On Minecraft 1.20 and newer, a truthy `back` will try setting the text on the back of a sign (only visible if not attached to a wall). #### bot.equip(item, destination) diff --git a/index.d.ts b/index.d.ts index 519f21969..d73e962e1 100644 --- a/index.d.ts +++ b/index.d.ts @@ -275,7 +275,7 @@ export interface Bot extends TypedEmitter { force?: boolean ) => Promise - updateSign: (block: Block, text: string) => void + updateSign: (block: Block, text: string, back?: boolean) => void equip: ( item: Item | number, diff --git a/lib/plugins/blocks.js b/lib/plugins/blocks.js index 3a5dfb4a2..512bd2186 100644 --- a/lib/plugins/blocks.js +++ b/lib/plugins/blocks.js @@ -423,7 +423,7 @@ function inject (bot, { version, storageBuilder, hideErrors }) { } }) - bot.updateSign = (block, text) => { + bot.updateSign = (block, text, back = false) => { const lines = text.split('\n') if (lines.length > 4) { bot.emit('error', new Error('too many lines for sign text')) @@ -452,8 +452,10 @@ function inject (bot, { version, storageBuilder, hideErrors }) { text4: lines[3] ?? '' } } + bot._client.write('update_sign', { location: block.position, + isFrontText: !back, ...signData }) } diff --git a/lib/version.js b/lib/version.js index 2c700008e..ff89aed2f 100644 --- a/lib/version.js +++ b/lib/version.js @@ -1,4 +1,4 @@ module.exports = { - supportedVersions: ['1.8', '1.9', '1.10', '1.11', '1.12', '1.13', '1.14', '1.15', '1.16', '1.17', '1.18', '1.19'], - testedVersions: ['1.8.8', '1.9.4', '1.10.2', '1.11.2', '1.12.2', '1.13.2', '1.14.4', '1.15.2', '1.16.5', '1.17.1', '1.18.2', '1.19', '1.19.2', '1.19.3', '1.19.4'] + supportedVersions: ['1.8', '1.9', '1.10', '1.11', '1.12', '1.13', '1.14', '1.15', '1.16', '1.17', '1.18', '1.19', '1.20'], + testedVersions: ['1.8.8', '1.9.4', '1.10.2', '1.11.2', '1.12.2', '1.13.2', '1.14.4', '1.15.2', '1.16.5', '1.17.1', '1.18.2', '1.19', '1.19.2', '1.19.3', '1.19.4', '1.20.1'] } // when updating testedVersions, make sure to update CI.yml diff --git a/package.json b/package.json index 289eb0bc4..2042fc34c 100644 --- a/package.json +++ b/package.json @@ -21,16 +21,16 @@ }, "license": "MIT", "dependencies": { - "minecraft-data": "^3.26.0", - "minecraft-protocol": "^1.42.0", + "minecraft-data": "^3.37.0", + "minecraft-protocol": "^1.43.1", "prismarine-biome": "^1.1.1", - "prismarine-block": "^1.13.1", + "prismarine-block": "^1.17.0", "prismarine-chat": "^1.7.1", - "prismarine-chunk": "^1.32.0", + "prismarine-chunk": "^1.34.0", "prismarine-entity": "^2.2.0", "prismarine-item": "^1.12.1", "prismarine-nbt": "^2.0.0", - "prismarine-physics": "^1.3.1", + "prismarine-physics": "^1.7.0", "prismarine-recipe": "^1.3.0", "prismarine-registry": "^1.5.0", "prismarine-windows": "^2.5.0", diff --git a/test/externalTests/commandBlock.js b/test/externalTests/commandBlock.js index b46ddc64e..c47234dd6 100644 --- a/test/externalTests/commandBlock.js +++ b/test/externalTests/commandBlock.js @@ -1,6 +1,7 @@ const assert = require('assert') const { once } = require('events') const { Vec3 } = require('vec3') +const { onceWithCleanup } = require('../../lib/promise_utils') module.exports = () => async (bot) => { const command = `/say ${Math.floor(Math.random() * 1000)}` @@ -13,7 +14,9 @@ module.exports = () => async (bot) => { await p bot.setCommandBlock(commandBlockPos, command, false) - const [message] = await once(bot, 'message') + const [message] = await onceWithCleanup(bot, 'message', { + timeout: 5000, + checkCondition: (message) => message.json.with[0] === command + }) assert(message.json.translate === 'advMode.setCommand.success') - assert(message.json.with[0] === command) } diff --git a/test/externalTests/sign.js b/test/externalTests/sign.js index c194a3acf..27c35d24f 100644 --- a/test/externalTests/sign.js +++ b/test/externalTests/sign.js @@ -11,8 +11,8 @@ module.exports = () => async (bot) => { } assert.notStrictEqual(signItem, null) - const p = new Promise((resolve, reject) => { - bot._client.on('open_sign_entity', (packet) => { + const p = new Promise((resolve) => { + bot._client.once('open_sign_entity', (packet) => { const sign = bot.blockAt(new Vec3(packet.location)) bot.updateSign(sign, '1\n2\n3\n') @@ -20,14 +20,7 @@ module.exports = () => async (bot) => { // Get updated sign const sign = bot.blockAt(bot.entity.position) - assert.strictEqual(sign.signText, '1\n2\n3\n') - - if (sign.blockEntity && sign.blockEntity.Text1) { - assert.strictEqual(sign.blockEntity.Text1.toString(), '1') - assert.strictEqual(sign.blockEntity.Text2.toString(), '2') - assert.strictEqual(sign.blockEntity.Text3.toString(), '3') - assert.strictEqual(sign.blockEntity.Text4.toString(), '') - } + assert.strictEqual(sign.signText.trimEnd(), '1\n2\n3') if (sign.blockEntity) { // Check block update