Skip to content

Commit

Permalink
1.19.3 (#2912)
Browse files Browse the repository at this point in the history
* Add 1.19.3 as a tested version

* Update dependency version

* Fix tests

* 1.19.3 fixes

* Fix lint

* Update minecraft-data version
  • Loading branch information
frej4189 authored Jan 28, 2023
1 parent 2086273 commit 83c0a33
Show file tree
Hide file tree
Showing 7 changed files with 265 additions and 138 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ jobs:
mcVersion: '1.19'
- javaVersion: 17
mcVersion: '1.19.2'
- javaVersion: 17
mcVersion: '1.19.3'
fail-fast: false

steps:
Expand Down
2 changes: 2 additions & 0 deletions lib/plugins/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ function inject (bot, options) {
salt: 0n,
argumentSignatures: [],
signedPreview: false,
messageCount: 0,
acknowledged: Buffer.alloc(3),
// 1.19.2 Chat Command packet also includes an array of last seen messages
previousMessages: []
})
Expand Down
181 changes: 125 additions & 56 deletions lib/plugins/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,14 @@ function inject (bot) {
entity.metadata = metadata
bot.emit('entityUpdate', entity)

const typeSlot = bot.supportFeature('itemsAreAlsoBlocks') ? 5 : 6
const typeSlot = (bot.supportFeature('itemsAreAlsoBlocks') ? 5 : 6) + (bot.supportFeature('entityMetadataHasLong') ? 1 : 0)
const slot = packet.metadata.find(e => e.type === typeSlot)
if (entity.name && (entity.name.toLowerCase() === 'item' || entity.name === 'item_stack') && slot) {
bot.emit('itemDrop', entity)
}

const pose = packet.metadata.find(e => e.type === 18)
const typePose = bot.supportFeature('entityMetadataHasLong') ? 19 : 18
const pose = packet.metadata.find(e => e.type === typePose)
if (pose && pose.value === 2) {
bot.emit('entitySleep', entity)
}
Expand Down Expand Up @@ -444,81 +445,149 @@ function inject (bot) {

bot._client.on('player_info', (packet) => {
// player list item(s)
for (const item of packet.data) {
let player = bot.uuidToUsername[item.UUID] ? bot.players[bot.uuidToUsername[item.UUID]] : null
if (packet.action === 0) {

if (bot.supportFeature('playerInfoActionIsBitfield')) {
for (const item of packet.data) {
let player = bot.uuidToUsername[item.uuid] ? bot.players[bot.uuidToUsername[item.uuid]] : null
let newPlayer = false

// New Player
if (!player) {
player = bot.players[item.name] = {
username: item.name,
ping: item.ping,
uuid: item.UUID,
displayName: new ChatMessage({ text: '', extra: [{ text: item.name }] }),
profileKeys: item.crypto
? {
publicKey: item.crypto.publicKey, // DER-encoded public key
signature: item.crypto.signature // Signature
}
: null
}
const obj = {
uuid: item.uuid
}

bot.uuidToUsername[item.UUID] = item.name
bot.emit('playerJoined', player)
newPlayer = true
} else {
// Just an Update
player.gamemode = item.gamemode
player.ping = item.ping
if (item.crypto) {
player.profileKeys = {
publicKey: item.crypto.publicKey,
signature: item.crypto.signature
}
}
if (!player) newPlayer = true

player = player || obj

if (packet.action & 1) {
obj.username = item.player.name
obj.displayName = player.displayName || new ChatMessage({ text: '', extra: [{ text: item.player.name }] })
}

if (packet.action & 4) {
obj.gamemode = item.gamemode
}

if (packet.action & 16) {
obj.ping = item.latency
}

if (item.displayName) {
player.displayName = new ChatMessage(JSON.parse(item.displayName))
obj.displayName = new ChatMessage(JSON.parse(item.displayName))
} else if (packet.action & 32) obj.displayName = new ChatMessage({ text: '', extra: [{ text: player.username || obj.username }] })

if (newPlayer) {
if (!obj.username) continue // Should be unreachable
player = bot.players[obj.username] = obj
bot.uuidToUsername[obj.uuid] = obj.username
} else {
Object.assign(player, obj)
}

const playerEntity = Object.values(bot.entities).find(e => e.type === 'player' && e.username === item.name)
const playerEntity = Object.values(bot.entities).find(e => e.type === 'player' && e.username === obj.username)
player.entity = playerEntity

if (playerEntity === bot.entity) {
bot.player = player
}

if (!newPlayer) {
bot.emit('playerUpdated', player)
}
} else if (player) {
if (packet.action === 1) {
player.gamemode = item.gamemode
} else if (packet.action === 2) {
player.ping = item.ping
} else if (packet.action === 3 && !item.displayName) {
player.displayName = new ChatMessage({ text: '', extra: [{ text: player.username }] })
} else if (packet.action === 3 && item.displayName) {
player.displayName = new ChatMessage(JSON.parse(item.displayName))
} else if (packet.action === 4) {
if (player.entity === bot.entity) continue

player.entity = null
delete bot.players[player.username]
delete bot.uuidToUsername[item.UUID]
bot.emit('playerLeft', player)
continue
if (newPlayer) {
bot.emit('playerJoined', player)
} else {
continue
bot.emit('playerUpdated', player)
}
}
} else {
for (const item of packet.data) {
let player = bot.uuidToUsername[item.UUID] ? bot.players[bot.uuidToUsername[item.UUID]] : null
if (packet.action === 0) {
let newPlayer = false

// New Player
if (!player) {
player = bot.players[item.name] = {
username: item.name,
ping: item.ping,
uuid: item.UUID,
displayName: new ChatMessage({ text: '', extra: [{ text: item.name }] }),
profileKeys: item.crypto
? {
publicKey: item.crypto.publicKey, // DER-encoded public key
signature: item.crypto.signature // Signature
}
: null
}

bot.uuidToUsername[item.UUID] = item.name
bot.emit('playerJoined', player)
newPlayer = true
} else {
// Just an Update
player.gamemode = item.gamemode
player.ping = item.ping
if (item.crypto) {
player.profileKeys = {
publicKey: item.crypto.publicKey,
signature: item.crypto.signature
}
}
}

if (item.displayName) {
player.displayName = new ChatMessage(JSON.parse(item.displayName))
}

const playerEntity = Object.values(bot.entities).find(e => e.type === 'player' && e.username === item.name)
player.entity = playerEntity

if (playerEntity === bot.entity) {
bot.player = player
}

bot.emit('playerUpdated', player)
if (!newPlayer) {
bot.emit('playerUpdated', player)
}
} else if (player) {
if (packet.action === 1) {
player.gamemode = item.gamemode
} else if (packet.action === 2) {
player.ping = item.ping
} else if (packet.action === 3 && !item.displayName) {
player.displayName = new ChatMessage({ text: '', extra: [{ text: player.username }] })
} else if (packet.action === 3 && item.displayName) {
player.displayName = new ChatMessage(JSON.parse(item.displayName))
} else if (packet.action === 4) {
if (player.entity === bot.entity) continue

player.entity = null
delete bot.players[player.username]
delete bot.uuidToUsername[item.UUID]
bot.emit('playerLeft', player)
continue
} else {
continue
}

bot.emit('playerUpdated', player)
}
}
}
})

// (1.19.3) player(s) leave the game
bot._client.on('player_remove', (packet) => {
for (const uuid of packet.players) {
const player = bot.uuidToUsername[uuid] ? bot.players[bot.uuidToUsername[uuid]] : null

if (player.entity === bot.entity) continue

player.entity = null
delete bot.players[player.username]
delete bot.uuidToUsername[uuid]
bot.emit('playerLeft', player)
}
})

// attaching to a vehicle
bot._client.on('attach_entity', (packet) => {
if (packet.entityId !== bot.entity.id) return
Expand Down
2 changes: 1 addition & 1 deletion 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']
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']
} // when updating testedVersions, make sure to update CI.yml
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"license": "MIT",
"dependencies": {
"minecraft-data": "^3.15.2",
"minecraft-data": "^3.26.0",
"minecraft-protocol": "^1.40.3",
"prismarine-biome": "^1.1.1",
"prismarine-block": "^1.13.1",
Expand Down
2 changes: 1 addition & 1 deletion test/externalTests/sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = () => async (bot) => {

let signItem = null
for (const name in bot.registry.itemsByName) {
if (name.includes('sign')) signItem = bot.registry.itemsByName[name]
if (name.includes('sign') && !name.includes('hanging')) signItem = bot.registry.itemsByName[name]
}
assert.notStrictEqual(signItem, null)

Expand Down
Loading

0 comments on commit 83c0a33

Please sign in to comment.