第124批续34: restoreDefaultStackSize 改用 forceVanillaStackSize
Auto Release / build (push) Successful in 2m7s
Auto Release / build (push) Successful in 2m7s
烂 JSON 时 clearAll→rescanOnlinePlayers→restoreDefaultStackSize 用 unsetData 清组件, 但 unsetData 只「标记删除」,客户端仍缓存旧值(MAX_STACK_SIZE=64),告示牌/鸡蛋 仍能堆到 64(续33 已证明)。 修复:restoreDefaultStackSize 改用 forceVanillaStackSize(显式写 Material.getMaxStackSize(),告示牌→16,鸡蛋→16),与 burstItem 路径一致。 同时包含第125批续6(Dialog afterAction NONE→CLOSE)。
This commit is contained in:
@@ -957,41 +957,26 @@ public class StackConfigManager implements Listener {
|
|||||||
* @return true = 确实做了还原;false = 该物品本就无自定义组件
|
* @return true = 确实做了还原;false = 该物品本就无自定义组件
|
||||||
*/
|
*/
|
||||||
private boolean restoreDefaultStackSize(ItemStack item) {
|
private boolean restoreDefaultStackSize(ItemStack item) {
|
||||||
|
if (item == null || item.getType() == Material.AIR) return false;
|
||||||
Integer current = null;
|
Integer current = null;
|
||||||
boolean hasComponent = false;
|
boolean hasComponent = false;
|
||||||
try {
|
try {
|
||||||
current = item.getData(io.papermc.paper.datacomponent.DataComponentTypes.MAX_STACK_SIZE);
|
current = item.getData(io.papermc.paper.datacomponent.DataComponentTypes.MAX_STACK_SIZE);
|
||||||
hasComponent = current != null;
|
hasComponent = current != null;
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
// 无 setData 能力 → 看 meta
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
if (meta != null && meta.getMaxStackSize() > 0) {
|
if (meta != null && meta.getMaxStackSize() > 0) {
|
||||||
hasComponent = true;
|
hasComponent = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!hasComponent) return false;
|
if (!hasComponent) return false;
|
||||||
// ★ 续16-遗留7(交还原版,2026-11-14 用户口径「配置损坏就交还MC原版堆叠逻辑,插件不管」):
|
// ★ 续33(2026-11-18):改用 forceVanillaStackSize 显式写 vanilla 默认值。
|
||||||
// 旧逻辑把 def 写死 64(setData(MAX_STACK_SIZE, 64))——但告示牌/旗帜 vanilla 默认上限
|
// unsetData 只「标记删除」,客户端协议层仍缓存旧值(MAX_STACK_SIZE=64),
|
||||||
// 其实是 16(不是 64),鸡蛋/不死图腾才是 64。写死 64 会让告示牌 max 从 16 被抬到 64,
|
// 告示牌/鸡蛋仍能堆到 64。forceVanillaStackSize 用 setItemMeta+setMaxStackSize
|
||||||
// 「交还原版」交还失败(仍能堆到 64 而非原版 16)。
|
// 显式写 Material.getMaxStackSize()(告示牌→16,鸡蛋→16),彻底覆盖自定义组件。
|
||||||
// 改为 resetData(MAX_STACK_SIZE):Paper 26.x 官方「重置为类型默认值」API,
|
int vanillaMax = item.getType().getMaxStackSize();
|
||||||
// 把物品 max_stack_size 组件重置回该 Material 的 vanilla 默认(告示牌→16,鸡蛋→64)。
|
forceVanillaStackSize(item, vanillaMax);
|
||||||
// 等价于 unsetData 但更明确表达「还原为原生默认」语义。
|
return true;
|
||||||
// ★ 续24-A(2026-11-18):改用 unsetData 替代 resetData。
|
|
||||||
// resetData 用 Material.getDefaultData(MAX_STACK_SIZE) 作为"默认值",
|
|
||||||
// 但 Paper 的 getDefaultData 对鸡蛋返回 64(非 vanilla 的 16),导致"交还原版"交还失败。
|
|
||||||
// unsetData 彻底删除组件,vanilla 协议层用该物品的原生默认堆叠上限(鸡蛋→16,告示牌→16)。
|
|
||||||
try {
|
|
||||||
item.unsetData(io.papermc.paper.datacomponent.DataComponentTypes.MAX_STACK_SIZE);
|
|
||||||
return true;
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
// unsetData 失败(旧 Paper 无此能力)→ 兜底 resetData
|
|
||||||
try {
|
|
||||||
item.unsetData(io.papermc.paper.datacomponent.DataComponentTypes.MAX_STACK_SIZE);
|
|
||||||
return true;
|
|
||||||
} catch (Exception ignored2) {}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===================== 事件监听 =====================
|
// ===================== 事件监听 =====================
|
||||||
|
|||||||
Reference in New Issue
Block a user