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();
}
}
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);
}
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;
}
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;
}
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);
}
Aggregations