LoginSignup
0
0

More than 5 years have passed since last update.

文字に色を付ける

Posted at

概要

チャットやアイテムの文字に色を付ける方法です。

バニラの金リンゴみたいなアイテムが作成できるようになります。

使い方

com.mojang.realmsclient.guiパッケージのChatFormattingを使用します。

ChatFormatting.色 で、色の取得が出来るので、それを色を変更したい文字の前にくっつけます。

ItemHogeHoge.java

public class ItemHogeHoge extends Item {

    public String getItemStackDisplayName(ItemStack stack)
    {
        String origin = super.getItemStackDisplayName(stack);
        return ChatFormatting.GOLD + origin;
    }

}

このソースではItemの名前の色をゴールドに変更します。

実行結果

無cc題.png

※名前やテクスチャ、jsonは別で指定しています

おまけ

ChatFormattingクラスは、バニラに元からある仕組みを利用しやすくしたUtilクラスなだけなので、
文字の前に§6と書いたりしても色の変更は出来ます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0