Search in sources :

Example 21 with ITextComponent

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

the class EntityCitizen method setLatestStatus.

/**
 * Set the latest status of the citizen and clear the existing status
 *
 * @param status the new status to set.
 */
public void setLatestStatus(final ITextComponent... status) {
    boolean hasChanged = false;
    for (int i = 0; i < latestStatus.length; i++) {
        final ITextComponent newStatus;
        if (i >= status.length) {
            newStatus = null;
        } else {
            newStatus = status[i];
        }
        if (!Objects.equals(latestStatus[i], newStatus)) {
            latestStatus[i] = newStatus;
            hasChanged = true;
        }
    }
    if (hasChanged) {
        citizenData.markDirty();
    }
}
Also used : ITextComponent(net.minecraft.util.text.ITextComponent)

Example 22 with ITextComponent

use of net.minecraft.util.text.ITextComponent in project Minestuck by mraof.

the class EntityConsort method processInteract.

@Override
protected boolean processInteract(EntityPlayer player, EnumHand hand) {
    if (this.isEntityAlive() && !player.isSneaking()) {
        if (!world.isRemote) {
            if (message == null) {
                message = ConsortDialogue.getRandomMessage(this, player);
                messageTicksLeft = 24000 + world.rand.nextInt(24000);
                messageData = new NBTTagCompound();
            }
            // TODO Make sure to catch any issues here
            ITextComponent text = message.getMessage(this, player);
            if (text != null)
                player.sendMessage(text);
        }
        return true;
    } else
        return super.processInteract(player, hand);
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ITextComponent(net.minecraft.util.text.ITextComponent)

Example 23 with ITextComponent

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

the class LanguageHandler method buildChatComponent.

private static ITextComponent buildChatComponent(final String key, final Object... message) {
    TextComponentTranslation translation = null;
    int onlyArgsUntil = 0;
    for (final Object object : message) {
        if (object instanceof ITextComponent) {
            if (onlyArgsUntil == 0) {
                onlyArgsUntil = -1;
            }
            break;
        }
        onlyArgsUntil++;
    }
    if (onlyArgsUntil >= 0) {
        final Object[] args = new Object[onlyArgsUntil];
        System.arraycopy(message, 0, args, 0, onlyArgsUntil);
        translation = new TextComponentTranslation(key, args);
    }
    for (final Object object : message) {
        if (translation == null) {
            if (object instanceof ITextComponent) {
                translation = new TextComponentTranslation(key);
            } else {
                translation = new TextComponentTranslation(key, object);
                continue;
            }
        }
        if (object instanceof ITextComponent) {
            translation.appendSibling((ITextComponent) object);
        } else if (object instanceof String) {
            boolean isInArgs = false;
            for (final Object obj : translation.getFormatArgs()) {
                if (obj.equals(object)) {
                    isInArgs = true;
                    break;
                }
            }
            if (!isInArgs) {
                translation.appendText((String) object);
            }
        }
    }
    if (translation == null) {
        translation = new TextComponentTranslation(key);
    }
    return translation;
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) ITextComponent(net.minecraft.util.text.ITextComponent)

Example 24 with ITextComponent

use of net.minecraft.util.text.ITextComponent in project SpongeForge by SpongePowered.

the class SpongeForgeEventFactory method createServerChatEvent.

// Server events
private static ServerChatEvent createServerChatEvent(Event event) {
    MessageChannelEvent.Chat spongeEvent = (MessageChannelEvent.Chat) event;
    Optional<Player> player = spongeEvent.getCause().first(Player.class);
    if (!player.isPresent()) {
        return null;
    }
    Text spongeText = spongeEvent.getOriginalMessage();
    ITextComponent component = SpongeTexts.toComponent(spongeText);
    if (!(component instanceof TextComponentTranslation)) {
        component = new TextComponentTranslation("%s", component);
    }
    // Using toPlain here is fine, since the raw message from the client
    // can't have formatting.
    ServerChatEvent forgeEvent = new ServerChatEvent((EntityPlayerMP) player.get(), spongeEvent.getOriginalMessage().toPlain(), (TextComponentTranslation) component);
    ((IMixinInitCause) forgeEvent).initCause(spongeEvent.getCause());
    return forgeEvent;
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) EntityPlayer(net.minecraft.entity.player.EntityPlayer) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) MessageChannelEvent(org.spongepowered.api.event.message.MessageChannelEvent) ITextComponent(net.minecraft.util.text.ITextComponent) IMixinInitCause(org.spongepowered.common.interfaces.IMixinInitCause) Text(org.spongepowered.api.text.Text) ServerChatEvent(net.minecraftforge.event.ServerChatEvent)

Example 25 with ITextComponent

use of net.minecraft.util.text.ITextComponent in project SpongeForge by SpongePowered.

the class SpongeForgeEventFactory method createMessageChannelEventChat.

public static MessageChannelEvent.Chat createMessageChannelEventChat(ServerChatEvent forgeEvent) {
    final ITextComponent forgeComponent = forgeEvent.getComponent();
    final MessageFormatter formatter = new MessageFormatter();
    MessageChannel channel;
    Text[] chat = SpongeTexts.splitChatMessage((TextComponentTranslation) forgeComponent);
    if (chat[1] == null) {
        // Move content from head part to body part
        chat[1] = chat[0] != null ? chat[0] : SpongeTexts.toText(forgeComponent);
        chat[0] = null;
    }
    if (chat[0] != null) {
        formatter.getHeader().add(new DefaultHeaderApplier(chat[0]));
    }
    formatter.getBody().add(new DefaultBodyApplier(chat[1]));
    Text rawSpongeMessage = Text.of(forgeEvent.getMessage());
    MessageChannel originalChannel = channel = ((Player) forgeEvent.getPlayer()).getMessageChannel();
    Sponge.getCauseStackManager().pushCause(forgeEvent.getPlayer());
    return SpongeEventFactory.createMessageChannelEventChat(Sponge.getCauseStackManager().getCurrentCause(), originalChannel, Optional.ofNullable(channel), formatter, rawSpongeMessage, false);
}
Also used : MessageChannel(org.spongepowered.api.text.channel.MessageChannel) DefaultHeaderApplier(org.spongepowered.api.event.message.MessageEvent.DefaultHeaderApplier) ITextComponent(net.minecraft.util.text.ITextComponent) DefaultBodyApplier(org.spongepowered.api.event.message.MessageEvent.DefaultBodyApplier) Text(org.spongepowered.api.text.Text) MessageFormatter(org.spongepowered.api.event.message.MessageEvent.MessageFormatter)

Aggregations

ITextComponent (net.minecraft.util.text.ITextComponent)96 TextComponentString (net.minecraft.util.text.TextComponentString)54 EntityPlayer (net.minecraft.entity.player.EntityPlayer)26 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)25 ClickEvent (net.minecraft.util.text.event.ClickEvent)16 ItemStack (net.minecraft.item.ItemStack)11 Style (net.minecraft.util.text.Style)8 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)8 HoverEvent (net.minecraft.util.text.event.HoverEvent)7 World (net.minecraft.world.World)7 ArrayList (java.util.ArrayList)6 BlockPos (net.minecraft.util.math.BlockPos)6 DimensionInformation (mcjty.rftoolsdim.dimensions.DimensionInformation)5 RfToolsDimensionManager (mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)5 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)5 Minecraft (net.minecraft.client.Minecraft)4 Text (org.spongepowered.api.text.Text)4 MagicBook (cavern.magic.MagicBook)3 SpecialMagic (cavern.magic.SpecialMagic)3 Matcher (java.util.regex.Matcher)3