Skip to content

Commit

Permalink
1.20 (#3088)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: extremeheat <[email protected]>
  • Loading branch information
3 people committed Jun 28, 2023
1 parent 9968c94 commit d0a1660
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 33 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
29 changes: 17 additions & 12 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export interface Bot extends TypedEmitter<BotEvents> {
force?: boolean
) => Promise<void>

updateSign: (block: Block, text: string) => void
updateSign: (block: Block, text: string, back?: boolean) => void

equip: (
item: Item | number,
Expand Down
4 changes: 3 additions & 1 deletion lib/plugins/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down Expand Up @@ -452,8 +452,10 @@ function inject (bot, { version, storageBuilder, hideErrors }) {
text4: lines[3] ?? ''
}
}

bot._client.write('update_sign', {
location: block.position,
isFrontText: !back,
...signData
})
}
Expand Down
4 changes: 2 additions & 2 deletions lib/version.js
Original file line number Diff line number Diff line change
@@ -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
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 5 additions & 2 deletions test/externalTests/commandBlock.js
Original file line number Diff line number Diff line change
@@ -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)}`
Expand All @@ -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)
}
13 changes: 3 additions & 10 deletions test/externalTests/sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,16 @@ 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')

setTimeout(() => {
// 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
Expand Down

0 comments on commit d0a1660

Please sign in to comment.