Skip to content

Commit

Permalink
Add vanilla-named methods to TextWrapper, as well as some additional …
Browse files Browse the repository at this point in the history
…helpers
  • Loading branch information
MaxNeedsSnacks committed Feb 5, 2024
1 parent ab4aabd commit 3f481aa
Showing 1 changed file with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.ComponentContents;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.contents.ScoreContents;
import net.minecraft.network.chat.contents.SelectorContents;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.GsonHelper;
import org.jetbrains.annotations.Nullable;
Expand All @@ -22,6 +24,7 @@
import java.util.Collection;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

@Info("The hub for all things text components. Format text to your hearts content!")
public class TextWrapper {
Expand Down Expand Up @@ -180,6 +183,11 @@ public static MutableComponent join(MutableComponent separator, Iterable<? exten
return joined;
}

@Info("Returns an empty component")
public static MutableComponent empty() {
return Component.empty();
}

@Info("Joins all components")
public static MutableComponent join(Component... texts) {
return join(Component.empty(), Arrays.asList(texts));
Expand All @@ -190,21 +198,51 @@ public static MutableComponent string(String text) {
return Component.literal(text);
}

@Info("Returns a plain component of the input")
public static MutableComponent literal(String text) {
return Component.literal(text);
}

@Info("Returns a translatable component of the input key")
public static MutableComponent translate(String key) {
return Component.translatable(key, new Object[0]);
return Component.translatable(key);
}

@Info("Returns a translatable component of the input key, with args of the objects")
public static MutableComponent translate(String key, Object... objects) {
return Component.translatable(key, objects);
}

@Info("Returns a translatable component of the input key")
public static MutableComponent translatable(String key) {
return Component.translatable(key);
}

@Info("Returns a translatable component of the input key, with args of the objects")
public static MutableComponent translatable(String key, Object... objects) {
return Component.translatable(key, objects);
}

@Info("Returns a keybinding component of the input keybinding descriptor")
public static MutableComponent keybind(String keybind) {
return Component.keybind(keybind);
}

@Info("Returns a score component of the input objective, for the provided selector")
public static MutableComponent score(String selector, String objective) {
return MutableComponent.create(new ScoreContents(selector, objective));
}

@Info("Returns a component displaying all entities matching the input selector")
public static MutableComponent selector(String selector) {
return MutableComponent.create(new SelectorContents(selector, Optional.empty()));
}

@Info("Returns a component displaying all entities matching the input selector, with a custom separator")
public static MutableComponent selector(String selector, Component separator) {
return MutableComponent.create(new SelectorContents(selector, Optional.of(separator)));
}

@Info("Returns a component of the input, colored black")
public static MutableComponent black(Object text) {
return of(text).kjs$black();
Expand Down

0 comments on commit 3f481aa

Please sign in to comment.