Search in sources :

Example 21 with Style

use of net.minecraft.util.text.Style in project GregTech by GregTechCE.

the class CommandHand method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if (sender instanceof EntityPlayerMP) {
        EntityPlayerMP player = (EntityPlayerMP) sender;
        ItemStack stackInHand = player.inventory.getCurrentItem();
        if (stackInHand.isEmpty()) {
            throw new CommandException("gregtech.command.util.hand.no_item");
        }
        String registryName = stackInHand.getItem().getRegistryName().toString();
        ClickEvent itemNameEvent = new ClickEvent(Action.OPEN_URL, registryName);
        player.sendMessage(new TextComponentTranslation("gregtech.command.util.hand.item_id", registryName, stackInHand.getItemDamage()).setStyle(new Style().setClickEvent(itemNameEvent)));
        IElectricItem electricItem = stackInHand.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null);
        IFluidHandlerItem fluidHandlerItem = stackInHand.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
        if (electricItem != null) {
            player.sendMessage(new TextComponentTranslation("gregtech.command.util.hand.electric", electricItem.getCharge(), electricItem.getMaxCharge(), electricItem.getTier(), Boolean.toString(electricItem.canProvideChargeExternally())));
        }
        if (fluidHandlerItem != null) {
            for (IFluidTankProperties properties : fluidHandlerItem.getTankProperties()) {
                FluidStack contents = properties.getContents();
                String fluidName = contents == null ? "empty" : contents.getFluid().getName();
                ClickEvent fluidClickEvent = new ClickEvent(Action.OPEN_URL, fluidName);
                player.sendMessage(new TextComponentTranslation("gregtech.command.util.hand.fluid", fluidName, contents == null ? 0 : contents.amount, properties.getCapacity(), Boolean.toString(properties.canFill()), Boolean.toString(properties.canDrain())).setStyle(new Style().setClickEvent(fluidClickEvent)));
            }
        }
        if (stackInHand.getItem() instanceof MetaItem) {
            MetaItem<?> metaItem = (MetaItem<?>) stackInHand.getItem();
            MetaValueItem metaValueItem = metaItem.getItem(stackInHand);
            if (metaValueItem == null) {
                if (metaItem instanceof MaterialMetaItem) {
                    Material material = ((MaterialMetaItem) metaItem).getMaterial(stackInHand);
                    OrePrefix orePrefix = ((MaterialMetaItem) metaItem).getOrePrefix(stackInHand);
                    String oreDictName = new UnificationEntry(orePrefix, material).toString();
                    player.sendMessage(new TextComponentTranslation("gregtech.command.util.hand.material_meta_item", orePrefix, material).setStyle(new Style().setClickEvent(new ClickEvent(Action.OPEN_URL, oreDictName))));
                }
            } else {
                if (metaValueItem instanceof ToolMetaItem.MetaToolValueItem) {
                    IToolStats toolStats = ((MetaToolValueItem) metaValueItem).getToolStats();
                    player.sendMessage(new TextComponentTranslation("gregtech.command.util.hand.tool_stats", toolStats.getClass().getName()));
                }
                ClipboardUtil.copyToClipboard(player, metaValueItem.unlocalizedName);
                ClickEvent metaItemEvent = new ClickEvent(Action.OPEN_URL, metaValueItem.unlocalizedName);
                player.sendMessage(new TextComponentTranslation("gregtech.command.util.hand.meta_item", metaValueItem.unlocalizedName, metaValueItem).setStyle(new Style().setClickEvent(metaItemEvent)));
            }
        }
    } else {
        throw new CommandException("gregtech.command.util.hand.not_a_player");
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) IElectricItem(gregtech.api.capability.IElectricItem) MetaValueItem(gregtech.api.items.metaitem.MetaItem.MetaValueItem) MaterialMetaItem(gregtech.api.items.materialitem.MaterialMetaItem) MetaItem(gregtech.api.items.metaitem.MetaItem) ToolMetaItem(gregtech.api.items.toolitem.ToolMetaItem) FluidStack(net.minecraftforge.fluids.FluidStack) ClickEvent(net.minecraft.util.text.event.ClickEvent) OrePrefix(gregtech.api.unification.ore.OrePrefix) UnificationEntry(gregtech.api.unification.stack.UnificationEntry) Material(gregtech.api.unification.material.type.Material) MetaToolValueItem(gregtech.api.items.toolitem.ToolMetaItem.MetaToolValueItem) CommandException(net.minecraft.command.CommandException) IToolStats(gregtech.api.items.toolitem.IToolStats) MaterialMetaItem(gregtech.api.items.materialitem.MaterialMetaItem) IFluidTankProperties(net.minecraftforge.fluids.capability.IFluidTankProperties) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) Style(net.minecraft.util.text.Style) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack)

Example 22 with Style

use of net.minecraft.util.text.Style in project GregTech by GregTechCE.

the class MetaTileEntityLargeTurbine method addDisplayText.

@Override
protected void addDisplayText(List<ITextComponent> textList) {
    if (isStructureFormed()) {
        MetaTileEntityRotorHolder rotorHolder = getRotorHolder();
        FluidStack fuelStack = ((LargeTurbineWorkableHandler) workableHandler).getFuelStack();
        int fuelAmount = fuelStack == null ? 0 : fuelStack.amount;
        ITextComponent fuelName = new TextComponentTranslation(fuelAmount == 0 ? "gregtech.fluid.empty" : fuelStack.getUnlocalizedName());
        textList.add(new TextComponentTranslation("gregtech.multiblock.turbine.fuel_amount", fuelAmount, fuelName));
        if (rotorHolder.getRotorEfficiency() > 0.0) {
            textList.add(new TextComponentTranslation("gregtech.multiblock.turbine.rotor_speed", rotorHolder.getCurrentRotorSpeed(), rotorHolder.getMaxRotorSpeed()));
            textList.add(new TextComponentTranslation("gregtech.multiblock.turbine.rotor_efficiency", (int) (rotorHolder.getRotorEfficiency() * 100)));
            int rotorDurability = (int) (rotorHolder.getRotorDurability() * 100);
            if (rotorDurability > MIN_DURABILITY_TO_WARN) {
                textList.add(new TextComponentTranslation("gregtech.multiblock.turbine.rotor_durability", rotorDurability));
            } else {
                textList.add(new TextComponentTranslation("gregtech.multiblock.turbine.low_rotor_durability", MIN_DURABILITY_TO_WARN, rotorDurability).setStyle(new Style().setColor(TextFormatting.RED)));
            }
        }
        if (!isRotorFaceFree()) {
            textList.add(new TextComponentTranslation("gregtech.multiblock.turbine.obstructed").setStyle(new Style().setColor(TextFormatting.RED)));
        }
    }
    super.addDisplayText(textList);
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) FluidStack(net.minecraftforge.fluids.FluidStack) ITextComponent(net.minecraft.util.text.ITextComponent) Style(net.minecraft.util.text.Style) MetaTileEntityRotorHolder(gregtech.common.metatileentities.electric.multiblockpart.MetaTileEntityRotorHolder)

Example 23 with Style

use of net.minecraft.util.text.Style in project minecolonies by Minecolonies.

the class ListColoniesCommand method execute.

@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String... args) throws CommandException {
    int page = getIthArgument(args, 0, 1);
    final int abandonedSince = getIthArgument(args, 1, 0);
    final List<Colony> colonies;
    if (abandonedSince > 0) {
        colonies = ColonyManager.getColoniesAbandonedSince(abandonedSince);
    } else {
        colonies = ColonyManager.getColonies();
    }
    final int colonyCount = colonies.size();
    // check to see if we have to add one page to show the half page
    final int halfPage = (colonyCount % COLONIES_ON_PAGE == 0) ? 0 : 1;
    final int pageCount = ((colonyCount) / COLONIES_ON_PAGE) + halfPage;
    if (page < 1 || page > pageCount) {
        page = 1;
    }
    final int pageStartIndex = COLONIES_ON_PAGE * (page - 1);
    final int pageStopIndex = Math.min(COLONIES_ON_PAGE * page, colonyCount);
    final int prevPage = Math.max(0, page - 1);
    final int nextPage = Math.min(page + 1, (colonyCount / COLONIES_ON_PAGE) + halfPage);
    final List<Colony> coloniesPage;
    if (pageStartIndex < 0 || pageStartIndex >= colonyCount) {
        coloniesPage = new ArrayList<>();
    } else {
        coloniesPage = colonies.subList(pageStartIndex, pageStopIndex);
    }
    final ITextComponent headerLine = new TextComponentString(PAGE_TOP_LEFT + page + PAGE_TOP_MIDDLE + pageCount + PAGE_TOP_RIGHT);
    sender.sendMessage(headerLine);
    for (final Colony colony : coloniesPage) {
        sender.sendMessage(new TextComponentString(String.format(ID_AND_NAME_TEXT, colony.getID(), colony.getName())).setStyle(new Style().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format(COMMAND_COLONY_INFO, colony.getID())))));
        final BlockPos center = colony.getCenter();
        final ITextComponent teleport = new TextComponentString(COORDINATES_TEXT + String.format(COORDINATES_XYZ, center.getX(), center.getY(), center.getZ())).setStyle(new Style().setBold(true).setColor(TextFormatting.GOLD).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, TELEPORT_COMMAND + colony.getID())));
        sender.sendMessage(teleport);
    }
    final ITextComponent prevButton = new TextComponentString(PREV_PAGE).setStyle(new Style().setBold(true).setColor(TextFormatting.GOLD).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, LIST_COMMAND_SUGGESTED + prevPage)));
    final ITextComponent nextButton = new TextComponentString(NEXT_PAGE).setStyle(new Style().setBold(true).setColor(TextFormatting.GOLD).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, LIST_COMMAND_SUGGESTED + nextPage)));
    final ITextComponent beginLine = new TextComponentString(PAGE_LINE);
    final ITextComponent endLine = new TextComponentString(PAGE_LINE);
    sender.sendMessage(beginLine.appendSibling(prevButton).appendSibling(new TextComponentString(PAGE_LINE_DIVIDER)).appendSibling(nextButton).appendSibling(endLine));
}
Also used : ClickEvent(net.minecraft.util.text.event.ClickEvent) ITextComponent(net.minecraft.util.text.ITextComponent) Colony(com.minecolonies.coremod.colony.Colony) Style(net.minecraft.util.text.Style) BlockPos(net.minecraft.util.math.BlockPos) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 24 with Style

use of net.minecraft.util.text.Style in project SpongeCommon by SpongePowered.

the class MixinTextComponentBase method getLegacyFormattingBuilder.

private StringBuilder getLegacyFormattingBuilder() {
    StringBuilder builder = new StringBuilder();
    Style style = getStyle();
    apply(builder, COLOR_CHAR, defaultIfNull(style.getColor(), RESET));
    apply(builder, COLOR_CHAR, BOLD, style.getBold());
    apply(builder, COLOR_CHAR, ITALIC, style.getItalic());
    apply(builder, COLOR_CHAR, UNDERLINE, style.getUnderlined());
    apply(builder, COLOR_CHAR, STRIKETHROUGH, style.getStrikethrough());
    apply(builder, COLOR_CHAR, OBFUSCATED, style.getObfuscated());
    return builder;
}
Also used : ResolvedChatStyle(org.spongepowered.common.text.ResolvedChatStyle) TextStyle(org.spongepowered.api.text.format.TextStyle) Style(net.minecraft.util.text.Style)

Example 25 with Style

use of net.minecraft.util.text.Style in project SpongeCommon by SpongePowered.

the class MixinText method initializeComponent.

private ITextComponent initializeComponent() {
    if (this.component == null) {
        this.component = createComponent();
        Style style = this.component.getStyle();
        if (this.format.getColor() != TextColors.NONE) {
            style.setColor(((SpongeTextColor) this.format.getColor()).getHandle());
        }
        if (!this.format.getStyle().isEmpty()) {
            style.setBold(this.format.getStyle().isBold().orElse(null));
            style.setItalic(this.format.getStyle().isItalic().orElse(null));
            style.setUnderlined(this.format.getStyle().hasUnderline().orElse(null));
            style.setStrikethrough(this.format.getStyle().hasStrikethrough().orElse(null));
            style.setObfuscated(this.format.getStyle().isObfuscated().orElse(null));
        }
        if (this.clickAction.isPresent()) {
            style.setClickEvent(SpongeClickAction.getHandle(this.clickAction.get()));
        }
        if (this.hoverAction.isPresent()) {
            style.setHoverEvent(SpongeHoverAction.getHandle(this.hoverAction.get()));
        }
        if (this.shiftClickAction.isPresent()) {
            ShiftClickAction.InsertText insertion = (ShiftClickAction.InsertText) this.shiftClickAction.get();
            style.setInsertion(insertion.getResult());
        }
        for (Text child : this.children) {
            this.component.appendSibling(((IMixinText) child).toComponent());
        }
    }
    return this.component;
}
Also used : ShiftClickAction(org.spongepowered.api.text.action.ShiftClickAction) Style(net.minecraft.util.text.Style) IMixinText(org.spongepowered.common.interfaces.text.IMixinText) Text(org.spongepowered.api.text.Text)

Aggregations

Style (net.minecraft.util.text.Style)51 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)30 TextComponentString (net.minecraft.util.text.TextComponentString)21 ITextComponent (net.minecraft.util.text.ITextComponent)17 ClickEvent (net.minecraft.util.text.event.ClickEvent)10 BlockPos (net.minecraft.util.math.BlockPos)9 CommandException (net.minecraft.command.CommandException)7 EntityPlayer (net.minecraft.entity.player.EntityPlayer)4 ItemStack (net.minecraft.item.ItemStack)4 World (net.minecraft.world.World)4 Colony (com.minecolonies.coremod.colony.Colony)3 PlayerIdentifier (com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier)3 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)3 GameProfile (com.mojang.authlib.GameProfile)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 HoverEvent (net.minecraft.util.text.event.HoverEvent)2 Biome (net.minecraft.world.biome.Biome)2 FluidStack (net.minecraftforge.fluids.FluidStack)2