Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/plugins/anvil.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ function inject (bot) {
throw new Error('Not a anvil-like window: ' + JSON.stringify(anvil))
}

// 1.17+ raised the anvil custom-name limit from 35 to 50 characters
const nameLengthLimit = bot.supportFeature('anvilNameLengthIsFifty') ? 50 : 35

function err (name) {
anvil.close()
throw new Error(name)
Expand Down Expand Up @@ -43,7 +46,7 @@ function inject (bot) {
}

async function combine (itemOne, itemTwo, name) {
if (name?.length > 35) err('Name is too long.')
if (name?.length > nameLengthLimit) err('Name is too long.')
if (bot.supportFeature('useMCItemName')) {
bot._client.registerChannel('MC|ItemName', 'string')
}
Expand All @@ -70,7 +73,7 @@ function inject (bot) {
}

async function rename (item, name) {
if (name?.length > 35) err('Name is too long.')
if (name?.length > nameLengthLimit) err('Name is too long.')
if (bot.supportFeature('useMCItemName')) {
bot._client.registerChannel('MC|ItemName', 'string')
}
Expand Down
22 changes: 22 additions & 0 deletions test/externalTests/anvil.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,27 @@ module.exports = () => {
await bot.test.wait(1000)
})

addTest('rename with 40-char name on 1.17+', async (b, renameCost, renameName, Item, bot, makeBook, makeItem) => { // the name limit was raised to 50 in 1.17 (#3945)
if (!bot.supportFeature('anvilNameLengthIsFifty')) return // 1.16 and below: limit is still 35

bot.chat(`/clear ${bot.username}`)
await bot.test.becomeCreative()

await bot.test.setInventorySlot(36, makeItem({ type: bot.registry.itemsByName.diamond_sword.id }))

await bot.test.becomeSurvival()

const anvil = await bot.openAnvil(b)

const sword = anvil.findInventoryItem(bot.registry.itemsByName.diamond_sword.id)
const longName = 'a'.repeat(40)
await anvil.rename(sword, longName)
// test result
assert.strictEqual(anvil.slots[3].repairCost, renameCost())
assert.deepStrictEqual(anvil.slots[3].customName, renameName(longName))
anvil.close()
await bot.test.wait(1000)
})

return tests
}
Loading