use of net.minecraft.text.Text in project Client by MatHax.
the class TextUtils method preOrderTraverse.
private static void preOrderTraverse(Text text, Stack<ColoredText> stack, List<ColoredText> coloredTexts) {
if (text == null)
return;
String textString = text.asString();
TextColor mcTextColor = text.getStyle().getColor();
Color textColor;
if (mcTextColor == null) {
if (stack.empty())
textColor = new Color(255, 255, 255);
else
textColor = stack.peek().getColor();
} else
textColor = new Color((text.getStyle().getColor().getRgb()) | 0xFF000000);
ColoredText coloredText = new ColoredText(textString, textColor);
coloredTexts.add(coloredText);
stack.push(coloredText);
for (Text child : text.getSiblings()) preOrderTraverse(child, stack, coloredTexts);
stack.pop();
}
use of net.minecraft.text.Text in project spark by lucko.
the class FabricCommandSender method sendMessage.
@Override
public void sendMessage(Component message) {
Text component = Text.Serializer.fromJson(GsonComponentSerializer.gson().serialize(message));
super.delegate.sendSystemMessage(component, NIL_UUID);
}
use of net.minecraft.text.Text in project AurorasDecorations by LambdAurora.
the class BlackboardCloneRecipe method craft.
@Override
public ItemStack craft(CraftingInventory inv) {
Blackboard blackboard = null;
ItemStack output = null;
Text customName = null;
for (int slot = 0; slot < inv.size(); ++slot) {
var craftStack = inv.getStack(slot);
if (!craftStack.isEmpty()) {
if (OUTPUT.test(craftStack) && !this.isInput(craftStack)) {
output = craftStack;
} else if (this.isInput(craftStack)) {
var nbt = BlockItem.getBlockEntityNbtFromStack(craftStack);
blackboard = Blackboard.fromNbt(nbt);
if (craftStack.hasCustomName())
customName = craftStack.getName();
}
}
}
var out = output.copy();
out.setCount(1);
var nbt = AuroraUtil.getOrCreateBlockEntityNbt(out, AurorasDecoRegistry.BLACKBOARD_BLOCK_ENTITY_TYPE);
blackboard.writeNbt(nbt);
if (customName != null)
out.setCustomName(customName);
return out;
}
use of net.minecraft.text.Text in project HWG by cybercat-mods.
the class GrenadeLauncherItem method appendTooltip.
@Environment(EnvType.CLIENT)
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) {
List<ItemStack> list = getProjectiles(stack);
if (isCharged(stack) && !list.isEmpty()) {
ItemStack itemStack = (ItemStack) list.get(0);
tooltip.add((new TranslatableText("Ammo")).append(" ").append(itemStack.toHoverableText()));
if (context.isAdvanced() && itemStack.getItem() == GRENADES) {
List<Text> list2 = Lists.newArrayList();
HWGItems.G_EMP.appendTooltip(itemStack, world, list2, context);
if (!list2.isEmpty()) {
for (int i = 0; i < list2.size(); ++i) {
list2.set(i, (new LiteralText(" ")).append((Text) list2.get(i)).formatted(Formatting.GRAY));
}
tooltip.addAll(list2);
}
}
}
tooltip.add(new TranslatableText("hwg.ammo.reloadgrenades").formatted(Formatting.ITALIC));
}
use of net.minecraft.text.Text in project FabricWaystones by LordDeatHunter.
the class ScrollOfInfiniteKnowledgeItem method use.
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
ItemStack stack = user.getStackInHand(hand);
if (Waystones.WAYSTONE_STORAGE == null) {
return TypedActionResult.fail(stack);
}
int learned = 0;
HashSet<String> toLearn = new HashSet<>();
for (String hash : Waystones.WAYSTONE_STORAGE.getAllHashes()) {
if (!((PlayerEntityMixinAccess) user).hasDiscoveredWaystone(hash)) {
var waystone = Waystones.WAYSTONE_STORAGE.getWaystoneEntity(hash);
if (waystone != null && waystone.getOwner() == null) {
waystone.setOwner(user);
}
toLearn.add(hash);
++learned;
}
}
Text text;
if (learned > 0) {
if (learned > 1) {
text = new TranslatableText("waystones.learned.infinite.multiple", new LiteralText(String.valueOf(learned)).styled(style -> style.withColor(TextColor.parse(new TranslatableText("waystones.learned.infinite.multiple.arg_color").getString()))));
} else {
text = new TranslatableText("waystones.learned.infinite.single");
}
((PlayerEntityMixinAccess) user).discoverWaystones(toLearn);
if (!user.isCreative() && Config.getInstance().consumeInfiniteScroll()) {
stack.decrement(1);
}
} else {
text = new TranslatableText("waystones.learned.infinite.none");
}
if (!world.isClient) {
user.sendMessage(text, false);
}
if (stack.isEmpty()) {
user.setStackInHand(hand, ItemStack.EMPTY);
}
stack = user.getStackInHand(hand);
return TypedActionResult.success(stack, world.isClient());
}
Aggregations