Search in sources :

Example 81 with Text

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();
}
Also used : TextColor(net.minecraft.text.TextColor) Color(mathax.client.utils.render.color.Color) Text(net.minecraft.text.Text) TextColor(net.minecraft.text.TextColor)

Example 82 with Text

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);
}
Also used : Text(net.minecraft.text.Text)

Example 83 with Text

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;
}
Also used : Text(net.minecraft.text.Text) ItemStack(net.minecraft.item.ItemStack) Blackboard(dev.lambdaurora.aurorasdeco.Blackboard)

Example 84 with Text

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));
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) LiteralText(net.minecraft.text.LiteralText) TranslatableText(net.minecraft.text.TranslatableText) Text(net.minecraft.text.Text) ItemStack(net.minecraft.item.ItemStack) LiteralText(net.minecraft.text.LiteralText) Environment(net.fabricmc.api.Environment)

Example 85 with Text

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());
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) PlayerEntityMixinAccess(wraith.waystones.access.PlayerEntityMixinAccess) LiteralText(net.minecraft.text.LiteralText) TranslatableText(net.minecraft.text.TranslatableText) Text(net.minecraft.text.Text) ItemStack(net.minecraft.item.ItemStack) HashSet(java.util.HashSet) LiteralText(net.minecraft.text.LiteralText)

Aggregations

Text (net.minecraft.text.Text)108 LiteralText (net.minecraft.text.LiteralText)70 TranslatableText (net.minecraft.text.TranslatableText)35 Inject (org.spongepowered.asm.mixin.injection.Inject)14 ArrayList (java.util.ArrayList)13 ItemStack (net.minecraft.item.ItemStack)12 MinecraftClient (net.minecraft.client.MinecraftClient)11 MutableText (net.minecraft.text.MutableText)10 Formatting (net.minecraft.util.Formatting)10 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)9 List (java.util.List)7 ServerCommandSource (net.minecraft.server.command.ServerCommandSource)6 HoverEvent (net.minecraft.text.HoverEvent)6 TextColor (net.minecraft.text.TextColor)6 Mixin (org.spongepowered.asm.mixin.Mixin)6 At (org.spongepowered.asm.mixin.injection.At)6 ButtonWidget (net.minecraft.client.gui.widget.ButtonWidget)5 Redirect (org.spongepowered.asm.mixin.injection.Redirect)5 JsonObject (com.google.gson.JsonObject)4 GameProfile (com.mojang.authlib.GameProfile)4