124批34续根治 停用态交还原版: 必须炸开(burstItem)但炸后彻底删MAX_STACK组件(unsetData不写16值)+updateInventory强清客户端缓存, 根治告示牌仍合64
Auto Release / build (push) Successful in 4m21s
Auto Release / build (push) Successful in 4m21s
This commit is contained in:
@@ -395,19 +395,40 @@ public class StackConfigManager implements Listener {
|
|||||||
* 彻底覆盖自定义组件,客户端协议层收到新值 → 合并受限到 vanillaMax。
|
* 彻底覆盖自定义组件,客户端协议层收到新值 → 合并受限到 vanillaMax。
|
||||||
* 兜底:若 meta 路径也失败(理论上不会),再尝试 unsetData 二次清除。
|
* 兜底:若 meta 路径也失败(理论上不会),再尝试 unsetData 二次清除。
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* ★ 124批34续根治(2026-11-20 用户明令「要炸开,但炸了不能再合并」):
|
||||||
|
* 交还原版 = 彻底【删掉】MAX_STACK_SIZE 组件(unsetData),不写任何组件值。
|
||||||
|
*
|
||||||
|
* 续33 旧做法 forceVanillaStackSize(item,16) 用 setItemMeta 显式写 16 —— 失败:
|
||||||
|
* 客户端协议层缓存的是「物品格」的旧组件值(64),服务端改 ItemStack 对象的组件值
|
||||||
|
* 不会让客户端已渲染那格重算 → 58+6 仍按缓存 64 合并。
|
||||||
|
*
|
||||||
|
* 正解:删组件(unsetData 把 MAX_STACK_SIZE 从 ItemStack.components 移除)→ 物品变成
|
||||||
|
* 「无组件」→ vanilla 合并逻辑读 Material.getMaxStackSize() 类型默认(告示牌 16 / 方块 64)。
|
||||||
|
* 配合 rescanPlayerInventory 末尾 updateInventory() 强制客户端全量重拉(清掉本地缓存的旧组件),
|
||||||
|
* 客户端拿到无组件物品 → 走 vanilla 默认上限 → 告示牌不可能合到 64。
|
||||||
|
*/
|
||||||
private void forceVanillaStackSize(ItemStack item, int vanillaMax) {
|
private void forceVanillaStackSize(ItemStack item, int vanillaMax) {
|
||||||
if (item == null || item.getType() == Material.AIR) return;
|
if (item == null || item.getType() == Material.AIR) return;
|
||||||
// 第一优先:setItemMeta 显式写 vanilla 默认值(覆盖自定义组件,客户端协议层同步新值)
|
// 彻底删组件(unsetData 为主,让物品回 vanilla 默认堆叠)
|
||||||
|
boolean unsetOk = false;
|
||||||
try {
|
try {
|
||||||
ItemMeta meta = item.getItemMeta();
|
Integer cur = item.getData(io.papermc.paper.datacomponent.DataComponentTypes.MAX_STACK_SIZE);
|
||||||
if (meta != null) {
|
if (cur != null) {
|
||||||
meta.setMaxStackSize(vanillaMax);
|
item.unsetData(io.papermc.paper.datacomponent.DataComponentTypes.MAX_STACK_SIZE);
|
||||||
item.setItemMeta(meta);
|
unsetOk = true;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {}
|
} catch (Exception ignored) {}
|
||||||
// 兜底:unsetData 二次清除(理论上不会走到这里)
|
// meta 路径兜底:旧组件写在 CustomData 时(unsetData 读不到才走这里)
|
||||||
try { item.unsetData(io.papermc.paper.datacomponent.DataComponentTypes.MAX_STACK_SIZE); } catch (Exception ignored) {}
|
if (!unsetOk) {
|
||||||
|
try {
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
if (meta != null && meta.getMaxStackSize() > 0) {
|
||||||
|
meta.setMaxStackSize(vanillaMax); // 仅 meta 兜底时写默认值(无组件路径不写值)
|
||||||
|
item.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
} catch (Exception ignored) {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -587,6 +608,7 @@ public class StackConfigManager implements Listener {
|
|||||||
*/
|
*/
|
||||||
private void rescanPlayerInventory(Player player, Inventory inv, String label) {
|
private void rescanPlayerInventory(Player player, Inventory inv, String label) {
|
||||||
int changed = 0;
|
int changed = 0;
|
||||||
|
boolean clientResyncNeeded = false; // ★ 124批34续根治:停用态删组件后需强制客户端重拉
|
||||||
try {
|
try {
|
||||||
ItemStack[] contents = inv.getContents();
|
ItemStack[] contents = inv.getContents();
|
||||||
if (contents == null) return;
|
if (contents == null) return;
|
||||||
@@ -605,15 +627,15 @@ public class StackConfigManager implements Listener {
|
|||||||
// 该物品在映射中仍有配置 → 走 applyStackSize 正常写目标 max。
|
// 该物品在映射中仍有配置 → 走 applyStackSize 正常写目标 max。
|
||||||
int cfgMax = getMaxStackSize(item.getType());
|
int cfgMax = getMaxStackSize(item.getType());
|
||||||
if (cfgMax <= 0) {
|
if (cfgMax <= 0) {
|
||||||
// ★ 续24(0信任模式):停用/映射被清空 → 已堆叠物品强制炸开到 vanilla 默认,
|
// ★ 124批34续根治(0信任模式,用户明令):停用/烂json 时已堆叠物品【必须炸开】
|
||||||
// 不依赖玩家手动拆。burstItem 内部统一处理:
|
// 到 vanilla 默认上限(burstItem),但炸开后要【删组件而非写 16 值】,
|
||||||
// 数量超默认 → 拆分到多个相邻空槽(每份≤默认)并 unsetData 交还原版;
|
// 并强制 updateInventory 清客户端缓存 —— 否则客户端缓存旧 64 组件值仍能合并。
|
||||||
// 数量未超 → 仅 unsetData 交还原版组件。无需先调 restoreDefaultStackSize
|
// 数量未超默认 → 删组件交还原版;超默认 → 拆到多槽每份≤vanilla + 删组件。
|
||||||
// (其 unsetData 返回 true 会短路 burstItem,导致 64 蛋仍是一格 64 不炸开)。
|
|
||||||
int burst = burstItem(inv, i, item);
|
int burst = burstItem(inv, i, item);
|
||||||
if (burst > 0) {
|
if (burst > 0 || stripCustomStackSize(item)) {
|
||||||
inv.setItem(i, item);
|
inv.setItem(i, item);
|
||||||
changed++;
|
changed++;
|
||||||
|
clientResyncNeeded = true; // 炸过/删过组件 → 需强制客户端重拉
|
||||||
}
|
}
|
||||||
} else if (applyStackSize(item)) {
|
} else if (applyStackSize(item)) {
|
||||||
inv.setItem(i, item);
|
inv.setItem(i, item);
|
||||||
@@ -624,9 +646,50 @@ public class StackConfigManager implements Listener {
|
|||||||
plugin.getLogger().warning("[物品堆叠] 补扫" + label + "异常: " + e.getMessage());
|
plugin.getLogger().warning("[物品堆叠] 补扫" + label + "异常: " + e.getMessage());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (changed > 0) {
|
// ★ 124批34续根治:停用态删过组件 → 强制客户端全量重拉(清掉本地缓存的旧 max 组件值)
|
||||||
plugin.getLogger().info("[物品堆叠] 补扫玩家 " + player.getName() + " 的" + label + ": " + changed + " 个物品已更新");
|
if (clientResyncNeeded) {
|
||||||
|
try { player.updateInventory(); } catch (Exception ignored) {}
|
||||||
}
|
}
|
||||||
|
if (changed > 0) {
|
||||||
|
plugin.getLogger().info("[物品堆叠] 补扫玩家 " + player.getName() + " 的" + label + ": " + changed
|
||||||
|
+ " 个物品已更新" + (clientResyncNeeded ? "(停用态已交还原版并强制客户端重拉)" : ""));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ★ 124批34续根治:删掉物品上的自定义 MAX_STACK_SIZE 数据组件(交还原版堆叠规则)。
|
||||||
|
* 与 forceVanillaStackSize「显式写 vanilla 默认值」不同:本方法只删组件不写值,
|
||||||
|
* 让物品回到「无组件」状态,vanilla 合并逻辑读类型默认(告示牌 16 / 方块 64),
|
||||||
|
* 配合 updateInventory 清客户端缓存,彻底杜绝「烂 json 停用后仍合 64」。
|
||||||
|
*
|
||||||
|
* @return true = 物品原本带自定义组件且已删除;false = 无组件/删除失败
|
||||||
|
*/
|
||||||
|
private boolean stripCustomStackSize(ItemStack item) {
|
||||||
|
if (item == null || item.getType() == Material.AIR) return false;
|
||||||
|
boolean had = false;
|
||||||
|
Integer cur;
|
||||||
|
try {
|
||||||
|
cur = item.getData(io.papermc.paper.datacomponent.DataComponentTypes.MAX_STACK_SIZE);
|
||||||
|
had = cur != null;
|
||||||
|
if (had) {
|
||||||
|
item.unsetData(io.papermc.paper.datacomponent.DataComponentTypes.MAX_STACK_SIZE);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// meta 路径兜底:旧组件写在 CustomData 时
|
||||||
|
try {
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
if (meta != null) {
|
||||||
|
int vanillaDefault = getVanillaMax(item.getType());
|
||||||
|
int mmax = meta.getMaxStackSize();
|
||||||
|
had = mmax > 0 && mmax != vanillaDefault;
|
||||||
|
if (had) {
|
||||||
|
meta.setMaxStackSize(vanillaDefault);
|
||||||
|
item.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception ignored) {}
|
||||||
|
}
|
||||||
|
return had;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user