Search in sources :

Example 26 with Text

use of net.minecraft.text.Text in project meteor-client by MeteorDevelopment.

the class BetterTab method getPlayerName.

public Text getPlayerName(PlayerListEntry playerListEntry) {
    Text name;
    Color color = null;
    name = playerListEntry.getDisplayName();
    if (name == null)
        name = new LiteralText(playerListEntry.getProfile().getName());
    if (playerListEntry.getProfile().getId().toString().equals(mc.player.getGameProfile().getId().toString()) && self.get()) {
        color = selfColor.get();
    } else if (friends.get() && Friends.get().get(playerListEntry.getProfile().getName()) != null) {
        Friend friend = Friends.get().get(playerListEntry.getProfile().getName());
        if (friend != null)
            color = Friends.get().color;
    }
    if (color != null) {
        String nameString = name.getString();
        for (Formatting format : Formatting.values()) {
            if (format.isColor())
                nameString = nameString.replace(format.toString(), "");
        }
        name = new LiteralText(nameString).setStyle(name.getStyle().withColor(new TextColor(color.getPacked())));
    }
    return name;
}
Also used : Friend(meteordevelopment.meteorclient.systems.friends.Friend) Color(meteordevelopment.meteorclient.utils.render.color.Color) SettingColor(meteordevelopment.meteorclient.utils.render.color.SettingColor) TextColor(net.minecraft.text.TextColor) Formatting(net.minecraft.util.Formatting) LiteralText(net.minecraft.text.LiteralText) Text(net.minecraft.text.Text) TextColor(net.minecraft.text.TextColor) LiteralText(net.minecraft.text.LiteralText)

Example 27 with Text

use of net.minecraft.text.Text in project meteor-client by MeteorDevelopment.

the class Names method getSoundName.

public static String getSoundName(Identifier id) {
    return soundNames.computeIfAbsent(id, identifier -> {
        WeightedSoundSet soundSet = mc.getSoundManager().get(identifier);
        if (soundSet == null)
            return identifier.getPath();
        Text text = soundSet.getSubtitle();
        if (text == null)
            return identifier.getPath();
        return StringHelper.stripTextFormat(text.getString());
    });
}
Also used : WeightedSoundSet(net.minecraft.client.sound.WeightedSoundSet) TranslatableText(net.minecraft.text.TranslatableText) Text(net.minecraft.text.Text)

Example 28 with Text

use of net.minecraft.text.Text in project FZMM-Mod by Zailer43.

the class GenericCallback method copyItemName.

private boolean copyItemName(boolean copyStyle) {
    MinecraftClient mc = MinecraftClient.getInstance();
    ItemStack stack = InventoryUtils.getFocusedSlot();
    if (stack == null)
        return true;
    Text name = stack.hasCustomName() ? stack.getName() : stack.getItem().getName();
    if (copyStyle) {
        mc.keyboard.setClipboard(Text.Serializer.toJson(name));
    } else {
        mc.keyboard.setClipboard(name.getString());
    }
    return true;
}
Also used : MinecraftClient(net.minecraft.client.MinecraftClient) Text(net.minecraft.text.Text) ItemStack(net.minecraft.item.ItemStack)

Example 29 with Text

use of net.minecraft.text.Text in project tweakermore by Fallen-Breath.

the class ContainerFiller method process.

@Override
public boolean process(ClientPlayerEntity player, ContainerScreen<?> containerScreen, List<Slot> allSlots, List<Slot> playerInvSlots, List<Slot> containerInvSlots) {
    Slot bestSlot = null;
    long maxCount = TweakerMoreConfigs.AUTO_FILL_CONTAINER_THRESHOLD.getIntegerValue() - 1;
    for (Slot slot : playerInvSlots) if (slot.hasStack() && containerInvSlots.get(0).canInsert(slot.getStack())) {
        long cnt = playerInvSlots.stream().filter(slt -> InventoryUtils.areStacksEqual(slot.getStack(), slt.getStack())).count();
        if (cnt > maxCount) {
            maxCount = cnt;
            bestSlot = slot;
        } else if (cnt == maxCount && bestSlot != null && !InventoryUtils.areStacksEqual(slot.getStack(), bestSlot.getStack())) {
            bestSlot = null;
        }
    }
    if (bestSlot != null && !allSlots.isEmpty()) {
        Text stackName = bestSlot.getStack().getName();
        InventoryUtils.tryMoveStacks(bestSlot, containerScreen, true, true, false);
        long amount = containerInvSlots.stream().filter(Slot::hasStack).count(), total = containerInvSlots.size();
        boolean isFull = Container.calculateComparatorOutput(containerInvSlots.get(0).inventory) >= 15;
        String percentage = String.format("%s%d/%d%s", isFull ? Formatting.GREEN : Formatting.GOLD, amount, total, Formatting.RESET);
        InfoUtils.printActionbarMessage("tweakermore.config.tweakmAutoFillContainer.container_filled", containerScreen.getTitle(), stackName, percentage);
        return true;
    } else {
        InfoUtils.printActionbarMessage("tweakermore.config.tweakmAutoFillContainer.best_slot_not_found");
        return false;
    }
}
Also used : Slot(net.minecraft.container.Slot) Text(net.minecraft.text.Text)

Example 30 with Text

use of net.minecraft.text.Text in project tweakermore by Fallen-Breath.

the class SignTextCopier method copySignText.

public static boolean copySignText(KeyAction action, IKeybind key) {
    MinecraftClient mc = MinecraftClient.getInstance();
    if (mc.world != null && mc.crosshairTarget != null && mc.crosshairTarget.getType() == HitResult.Type.BLOCK) {
        BlockPos blockPos = ((BlockHitResult) mc.crosshairTarget).getBlockPos();
        BlockState blockState = mc.world.getBlockState(blockPos);
        if (blockState.getBlock() instanceof AbstractSignBlock) {
            BlockEntity blockEntity = mc.world.getBlockEntity(blockPos);
            if (blockEntity instanceof SignBlockEntity) {
                String text = Joiner.on("\n").join(Arrays.stream(((SignBlockEntity) blockEntity).text).map(Text::getString).collect(Collectors.toList()));
                text = StringUtils.strip(text);
                if (!text.isEmpty()) {
                    mc.keyboard.setClipboard(text);
                    InfoUtils.printActionbarMessage("tweakermore.config.copySignTextToClipBoard.sign_copied", blockState.getBlock().getName());
                } else {
                    InfoUtils.printActionbarMessage("tweakermore.config.copySignTextToClipBoard.empty_sign", blockState.getBlock().getName());
                }
                return true;
            }
        }
    }
    InfoUtils.printActionbarMessage("tweakermore.config.copySignTextToClipBoard.no_sign");
    return false;
}
Also used : BlockState(net.minecraft.block.BlockState) SignBlockEntity(net.minecraft.block.entity.SignBlockEntity) MinecraftClient(net.minecraft.client.MinecraftClient) BlockPos(net.minecraft.util.math.BlockPos) Text(net.minecraft.text.Text) BlockHitResult(net.minecraft.util.hit.BlockHitResult) AbstractSignBlock(net.minecraft.block.AbstractSignBlock) BlockEntity(net.minecraft.block.entity.BlockEntity) SignBlockEntity(net.minecraft.block.entity.SignBlockEntity)

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