Skip to content

全息浮空標籤 (MC 26.1.2)

本文件详细介绍 Minecraft 26.1.2Item Clumps 的全息浮空计数指示器系统及纯原版客户端名牌渲染機制。


📊 特性資訊框

属性技术规格
系统名称服务端全息名牌提供器
渲染策略原版原生自定义實體名牌 (setCustomName / setCustomNameVisible)
需要客户端模组?(100% 由原版未装模组客户端直接渲染)
標籤格式規範<物品名称> x<数量>(如 鑽石 x128橡木原木 x500
閾值規則当 $\text{count} > \text{maxStackSize}$ 时显示(如鵝卵石 $> 64$)
显示开关游戏規則item_clumps:render_labels(默认:true

🏷️ 浮空標籤在原版客户端上的渲染機制

Item Clumps 直接借用原版 Minecraft 自帶的實體自定义名牌系统:

                      ┌───────────────────────────────┐
                      │ Ground Item Stack Size Changes│
                      └───────────────┬───────────────┘


                      ┌───────────────────────────────┐
                      │  Is render_labels Enabled?    │
                      │  Does count > maxStackSize?   │
                      └───────────────┬───────────────┘

                     ┌────────────────┴────────────────┐
                     │ (Yes)                           │ (No)
                     ▼                                 ▼
       ┌───────────────────────────┐     ┌───────────────────────────┐
       │ Set Entity Custom Name    │     │ Clear Entity Custom Name  │
       │ setCustomName(name xCount)│     │ setCustomName(null)       │
       │ setCustomNameVisible(true)│     │ setCustomNameVisible(false│
       └─────────────┬─────────────┘     └───────────────────────────┘


       ┌───────────────────────────┐
       │ SyncedEntityData Packet   │
       │ Sent to all nearby clients│
       └─────────────┬─────────────┘


       ┌───────────────────────────┐
       │ Vanilla Client Renders    │
       │ Clean Floating Name Tag!  │
       └───────────────────────────┘

💻 真實源码实现参考

源自 Minecraft 26.1.2 的 ItemEntityMixin.java

java
private void item_clumps$updateVanillaNameTag() {
    if (this.level() == null || this.level().isClientSide()) return;
    ItemStack stack = this.getItem();
    if (stack.isEmpty()) {
        this.setCustomName(null);
        this.setCustomNameVisible(false);
        return;
    }

    int count = stack.getCount();
    int maxStack = stack.getMaxStackSize();
    if (DynamicGameRuleManager.getBoolean(this.level(), ItemClumpsFabric.RENDER_LABELS) && count > maxStack) {
        Component name = stack.getItemName().copy().append(" x" + count);
        if (!this.hasCustomName() || !this.getCustomName().getString().equals(name.getString())) {
            this.setCustomName(name);
            this.setCustomNameVisible(true);
        }
    } else {
        if (this.hasCustomName()) {
            this.setCustomName(null);
            this.setCustomNameVisible(false);
        }
    }
}

@Inject(method = "tick", at = @At("HEAD"))
private void item_clumps$onTick(CallbackInfo ci) {
    if (!this.level().isClientSide()) {
        this.item_clumps$updateVanillaNameTag();
    }
}

@Inject(method = "setItem", at = @At("TAIL"))
private void item_clumps$onSetItem(ItemStack itemStack, CallbackInfo ci) {
    if (!this.level().isClientSide()) {
        this.item_clumps$updateVanillaNameTag();
    }
}

🔗 相关文件 (MC 26.1.2)

Official documentation & web portal for Dasik Igaijinn mods.