From 0ec108cfcba26308700b81f603c9d595b02a5d46 Mon Sep 17 00:00:00 2001 From: Xuxchloris <7482714452@qq.com> Date: Fri, 14 Aug 2026 19:48:21 +0000 Subject: [PATCH] fix(anvil): use 50-char name limit on 1.17+ The anvil custom-name limit was raised from 35 to 50 in Minecraft 1.17, but openAnvil still rejected names longer than 35 characters on every version. Use the anvilNameLengthIsFifty minecraft-data feature to pick the correct limit. Fixes #3945. Adds a version-gated external test that renames an item with a 40-char name on 1.17+ (skipped on 1.16 and below where 35 is still correct). --- lib/plugins/anvil.js | 7 +++++-- test/externalTests/anvil.js | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/plugins/anvil.js b/lib/plugins/anvil.js index 9675a3a419..978eb2a750 100644 --- a/lib/plugins/anvil.js +++ b/lib/plugins/anvil.js @@ -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) @@ -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') } @@ -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') } diff --git a/test/externalTests/anvil.js b/test/externalTests/anvil.js index 7ad1d7c932..24f6fcd222 100644 --- a/test/externalTests/anvil.js +++ b/test/externalTests/anvil.js @@ -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 }