use of net.minecraft.util.text.TextComponentString in project Binnie by ForestryMC.
the class ItemSoilMeter method onItemUse.
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
Block block = worldIn.getBlockState(pos).getBlock();
IGardeningManager gardening = BotanyCore.getGardening();
if (!gardening.isSoil(block)) {
pos = pos.down();
block = worldIn.getBlockState(pos).getBlock();
}
if (!gardening.isSoil(block)) {
pos = pos.down();
block = worldIn.getBlockState(pos).getBlock();
}
if (gardening.isSoil(block) && worldIn.isRemote) {
IBlockSoil soil = (IBlockSoil) block;
String info = I18N.localise("botany.soil.type") + ": " + EnumHelper.getLocalisedName(soil.getType(worldIn, pos), true) + ", " + TextFormatting.WHITE + I18N.localise("botany.moisture") + ": " + EnumHelper.getLocalisedName(soil.getMoisture(worldIn, pos), true) + ", " + TextFormatting.WHITE + I18N.localise("botany.ph") + ": " + EnumHelper.getLocalisedName(soil.getPH(worldIn, pos), true);
ITextComponent chat = new TextComponentString(info);
player.sendStatusMessage(chat, false);
}
return EnumActionResult.SUCCESS;
}
use of net.minecraft.util.text.TextComponentString in project ChatTweaks by blay09.
the class ChatView method addChatLine.
public ChatMessage addChatLine(ChatMessage chatLine) {
chatLine = chatLine.copy();
chatLines.add(chatLine);
if (chatLines.size() > MAX_MESSAGES) {
chatLines.remove(0);
}
try {
if (chatLine.getSender() == null) {
chatLine.setSender(subTextComponent(chatLine.getTextComponent(), lastMatcher.start("s"), lastMatcher.end("s")));
}
if (chatLine.getMessage() == null) {
chatLine.setMessage(subTextComponent(chatLine.getTextComponent(), lastMatcher.start("m"), lastMatcher.end("m")));
}
} catch (IllegalArgumentException ignored) {
if (chatLine.getMessage() == null) {
chatLine.setMessage(chatLine.getTextComponent());
}
}
ITextComponent source = chatLine.getTextComponent();
ITextComponent textComponent = chatLine.getTextComponent();
if (!builtOutputFormat.equals("$0")) {
textComponent = new TextComponentString("");
int last = 0;
Matcher matcher = groupPattern.matcher(builtOutputFormat);
while (matcher.find()) {
if (matcher.start() > last) {
textComponent.appendText(builtOutputFormat.substring(last, matcher.start()));
}
ITextComponent groupValue = null;
String namedGroup = matcher.group(2);
if (namedGroup != null) {
if (namedGroup.equals("s") && chatLine.getSender() != null) {
groupValue = chatLine.getSender();
} else if (namedGroup.equals("m") && chatLine.getMessage() != null) {
groupValue = chatLine.getMessage();
} else if (namedGroup.equals("t")) {
groupValue = new TextComponentString(ChatTweaksConfig.timestampFormat.format(new Date(chatLine.getTimestamp())));
groupValue.getStyle().setColor(TextFormatting.GRAY);
} else {
int groupStart = -1;
int groupEnd = -1;
try {
groupStart = lastMatcher.start(namedGroup);
groupEnd = lastMatcher.end(namedGroup);
} catch (IllegalArgumentException ignored) {
}
if (groupStart != -1 && groupEnd != -1) {
groupValue = subTextComponent(source, groupStart, groupEnd);
} else {
groupValue = chatLine.getOutputVar(namedGroup);
}
}
} else {
int group = Integer.parseInt(matcher.group(1));
if (group >= 0 && group <= lastMatcher.groupCount()) {
groupValue = subTextComponent(source, lastMatcher.start(group), lastMatcher.end(group));
}
}
if (groupValue == null) {
groupValue = new TextComponentString("missingno");
}
last = matcher.end();
textComponent.appendSibling(groupValue);
}
if (last < builtOutputFormat.length()) {
textComponent.appendText(builtOutputFormat.substring(last, builtOutputFormat.length()));
}
}
ITextComponent newComponent = null;
for (ITextComponent component : textComponent) {
if (component instanceof TextComponentString) {
String text = ((TextComponentString) component).getText();
if (text.length() > 1) {
int index = 0;
StringBuilder sb = new StringBuilder();
List<PositionedEmote> emotes = emoteScanner.scanForEmotes(text, null);
for (PositionedEmote emoteData : emotes) {
if (index < emoteData.getStart()) {
sb.append(text.substring(index, emoteData.getStart()));
}
int imageIndex = sb.length() + 1;
sb.append("\u00a7*");
for (int i = 0; i < emoteData.getEmote().getWidthInSpaces(); i++) {
sb.append(' ');
}
chatLine.addImage(new ChatImageEmote(imageIndex, emoteData.getEmote()));
index = emoteData.getEnd() + 1;
}
if (index < text.length()) {
sb.append(text.substring(index));
}
((TextComponentString) component).text = sb.toString();
}
if (text.length() > 0) {
if (newComponent == null) {
newComponent = new TextComponentString("");
newComponent.setStyle(textComponent.getStyle().createDeepCopy());
}
TextComponentString copyComponent = new TextComponentString(((TextComponentString) component).text);
copyComponent.setStyle(component.getStyle());
newComponent.appendSibling(copyComponent);
}
}
}
if (newComponent == null) {
newComponent = textComponent;
}
chatLine.setTextComponent(newComponent);
return chatLine;
}
use of net.minecraft.util.text.TextComponentString in project XNet by McJty.
the class ConnectorUpgradeItem method onItemUse.
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if (block == NetCableSetup.connectorBlock) {
if (!world.isRemote) {
TileEntity te = world.getTileEntity(pos);
if (te instanceof ConnectorTileEntity) {
NBTTagCompound tag = new NBTTagCompound();
te.writeToNBT(tag);
CableColor color = world.getBlockState(pos).getValue(GenericCableBlock.COLOR);
XNetBlobData blobData = XNetBlobData.getBlobData(world);
WorldBlob worldBlob = blobData.getWorldBlob(world);
ConsumerId consumer = worldBlob.getConsumerAt(pos);
((ConnectorBlock) block).unlinkBlock(world, pos);
world.setBlockState(pos, NetCableSetup.advancedConnectorBlock.getDefaultState().withProperty(GenericCableBlock.COLOR, color));
IBlockState blockState = world.getBlockState(pos);
((ConnectorBlock) blockState.getBlock()).createCableSegment(world, pos, consumer);
te = TileEntity.create(world, tag);
if (te != null) {
world.getChunkFromBlockCoords(pos).addTileEntity(te);
te.markDirty();
world.notifyBlockUpdate(pos, blockState, blockState, 3);
player.inventory.decrStackSize(player.inventory.currentItem, 1);
player.openContainer.detectAndSendChanges();
player.sendStatusMessage(new TextComponentString(TextFormatting.GREEN + "Connector was upgraded"), false);
} else {
player.sendStatusMessage(new TextComponentString(TextFormatting.RED + "Something went wrong during upgrade!"), false);
return EnumActionResult.FAIL;
}
}
}
return EnumActionResult.SUCCESS;
} else if (block == NetCableSetup.advancedConnectorBlock) {
if (!world.isRemote) {
player.sendStatusMessage(new TextComponentString(TextFormatting.YELLOW + "This connector is already advanced!"), false);
}
return EnumActionResult.SUCCESS;
} else {
if (!world.isRemote) {
player.sendStatusMessage(new TextComponentString(TextFormatting.RED + "Use this item on a connector to upgrade it!"), false);
}
return EnumActionResult.SUCCESS;
}
}
use of net.minecraft.util.text.TextComponentString in project RFToolsControl by McJty.
the class ProgramCommand method saveProgram.
private void saveProgram(ICommandSender sender, String arg, ItemStack item) {
ProgramCardInstance program = ProgramCardInstance.parseInstance(item);
String json = program.writeToJson();
// File file = new File("." + File.separator + "rftoolscontrol" + File.separator + arg);
File file = new File(arg);
if (file.exists()) {
file.delete();
}
try (PrintWriter writer = new PrintWriter(file)) {
writer.print(json);
} catch (FileNotFoundException e) {
ITextComponent component = new TextComponentString(TextFormatting.RED + "Error opening file for writing!");
if (sender instanceof EntityPlayer) {
((EntityPlayer) sender).sendStatusMessage(component, false);
} else {
sender.sendMessage(component);
}
return;
}
ITextComponent component = new TextComponentString("Saved program!");
if (sender instanceof EntityPlayer) {
((EntityPlayer) sender).sendStatusMessage(component, false);
} else {
sender.sendMessage(component);
}
}
use of net.minecraft.util.text.TextComponentString in project RFToolsControl by McJty.
the class ProgramCommand method loadProgram.
private void loadProgram(ICommandSender sender, String arg, ItemStack item) {
// File file = new File("." + File.separator + "rftoolscontrol" + File.separator + arg);
File file = new File(arg);
String json;
try (FileInputStream stream = new FileInputStream(file)) {
byte[] data = new byte[(int) file.length()];
stream.read(data);
json = new String(data, "UTF-8");
} catch (IOException e) {
ITextComponent component = new TextComponentString(TextFormatting.RED + "Error opening file for reading!");
if (sender instanceof EntityPlayer) {
((EntityPlayer) sender).sendStatusMessage(component, false);
} else {
sender.sendMessage(component);
}
return;
}
ProgramCardInstance program = ProgramCardInstance.readFromJson(json);
program.writeToNBT(item);
RFToolsCtrlMessages.INSTANCE.sendToServer(new PacketItemNBTToServer(item.getTagCompound()));
ITextComponent component = new TextComponentString("Loaded program!");
if (sender instanceof EntityPlayer) {
((EntityPlayer) sender).sendStatusMessage(component, false);
} else {
sender.sendMessage(component);
}
}
Aggregations