use of net.minecraft.util.text.ITextComponent in project MinecraftForge by MinecraftForge.
the class ForgeHooks method newChatWithLinks.
public static ITextComponent newChatWithLinks(String string, boolean allowMissingHeader) {
// Includes ipv4 and domain pattern
// Matches an ip (xx.xxx.xx.xxx) or a domain (something.com) with or
// without a protocol or path.
ITextComponent ichat = null;
Matcher matcher = URL_PATTERN.matcher(string);
int lastEnd = 0;
// Find all urls
while (matcher.find()) {
int start = matcher.start();
int end = matcher.end();
// Append the previous left overs.
String part = string.substring(lastEnd, start);
if (part.length() > 0) {
if (ichat == null)
ichat = new TextComponentString(part);
else
ichat.appendText(part);
}
lastEnd = end;
String url = string.substring(start, end);
ITextComponent link = new TextComponentString(url);
try {
// Add schema so client doesn't crash.
if ((new URI(url)).getScheme() == null) {
if (!allowMissingHeader) {
if (ichat == null)
ichat = new TextComponentString(url);
else
ichat.appendText(url);
continue;
}
url = "http://" + url;
}
} catch (URISyntaxException e) {
// Bad syntax bail out!
if (ichat == null)
ichat = new TextComponentString(url);
else
ichat.appendText(url);
continue;
}
// Set the click event and append the link.
ClickEvent click = new ClickEvent(ClickEvent.Action.OPEN_URL, url);
link.getStyle().setClickEvent(click);
link.getStyle().setUnderlined(true);
link.getStyle().setColor(TextFormatting.BLUE);
if (ichat == null)
ichat = link;
else
ichat.appendSibling(link);
}
// Append the rest of the message.
String end = string.substring(lastEnd);
if (ichat == null)
ichat = new TextComponentString(end);
else if (end.length() > 0)
ichat.appendText(string.substring(lastEnd));
return ichat;
}
use of net.minecraft.util.text.ITextComponent in project Overloaded by CJ-MC-Mods.
the class ItemMultiTool method leftClickOnBlockServer.
public void leftClickOnBlockServer(@Nonnull World world, @Nonnull EntityPlayerMP player, @Nonnull BlockPos pos) {
ItemStack itemStack = player.getHeldItem(EnumHand.MAIN_HAND);
if (itemStack.getItem() != this || world.isAirBlock(pos)) {
return;
}
player.setActiveHand(EnumHand.MAIN_HAND);
if (player.isSneaking()) {
NBTTagCompound tag = itemStack.getTagCompound();
if (tag == null) {
tag = new NBTTagCompound();
}
IBlockState state = world.getBlockState(pos);
Item item = Item.getItemFromBlock(state.getBlock());
ItemStack stackToPlace = new ItemStack(item, 1, state.getBlock().damageDropped(state));
NBTTagCompound blockTag = new NBTTagCompound();
stackToPlace.writeToNBT(blockTag);
tag.setTag("Item", blockTag);
itemStack.setTagCompound(tag);
ITextComponent component = stackToPlace.getTextComponent();
player.sendStatusMessage(new TextComponentString("Bound tool to ").appendSibling(component), true);
} else {
IEnergyStorage energy = itemStack.getCapability(ENERGY, null);
int efficiency = EnchantmentHelper.getEnchantmentLevel(Enchantments.EFFICIENCY, itemStack);
int unbreaking = EnchantmentHelper.getEnchantmentLevel(Enchantments.UNBREAKING, itemStack);
switch(breakAndUseEnergy(world, pos, energy, player, efficiency, unbreaking)) {
case FAIL_REMOVE:
player.sendStatusMessage(new TextComponentString("Unable to break block, reason unknown"), true);
break;
case FAIL_ENERGY:
player.sendStatusMessage(new TextComponentString("Unable to break block, not enough energy"), true);
break;
case FAIL_UNBREAKABLE:
player.sendStatusMessage(new TextComponentString("Block is unbreakable"), true);
break;
case SUCCESS:
break;
}
}
}
use of net.minecraft.util.text.ITextComponent 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));
}
use of net.minecraft.util.text.ITextComponent in project Railcraft by Railcraft.
the class OutputEntrySlot method getTooltip.
@Override
public List<String> getTooltip(int x, int y, Object[] data, int dataIndex) {
if (data[dataIndex] == null || stack(data, dataIndex) == null) {
return implementation.getTooltip(this, null);
}
List<String> tooltip = implementation.getTooltip(this, stack(data, dataIndex));
ICrusherCraftingManager.IOutputEntry outputEntry = (ICrusherCraftingManager.IOutputEntry) data[dataIndex];
for (ITextComponent line : outputEntry.getGenRule().getToolTip()) tooltip.add(line.getFormattedText());
return tooltip;
}
use of net.minecraft.util.text.ITextComponent in project SpongeCommon by SpongePowered.
the class MixinEntityPlayerMP method kick.
@Override
public void kick(Text message) {
final ITextComponent component = SpongeTexts.toComponent(message);
PlayerKickHelper.kickPlayer((EntityPlayerMP) (Object) this, component);
}
Aggregations