Skip to content

Commit 1dac305

Browse files
committed
Added new helper methods for adding "copy to clipboard" text.
1 parent cc67d2c commit 1dac305

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Common/src/main/java/net/darkhax/bookshelf/api/util/TextHelper.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import net.darkhax.bookshelf.mixin.entity.AccessorEntity;
77
import net.minecraft.client.Minecraft;
88
import net.minecraft.client.resources.language.I18n;
9+
import net.minecraft.network.chat.ClickEvent;
910
import net.minecraft.network.chat.Component;
1011
import net.minecraft.network.chat.HoverEvent;
1112
import net.minecraft.network.chat.MutableComponent;
@@ -158,4 +159,14 @@ public static TranslatableComponent lookupTranslation(String key, BiFunction<Str
158159

159160
return fallback != null ? fallback.apply(key, args) : null;
160161
}
162+
163+
public static MutableComponent setCopyText(MutableComponent component, String copy) {
164+
165+
return component.withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, copy)));
166+
}
167+
168+
public static MutableComponent textWithCopy(String text) {
169+
170+
return new TextComponent(text).withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, text)));
171+
}
161172
}

0 commit comments

Comments
 (0)