Search in sources :

Example 91 with TextComponentString

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;
}
Also used : IBlockSoil(binnie.botany.api.gardening.IBlockSoil) ITextComponent(net.minecraft.util.text.ITextComponent) Block(net.minecraft.block.Block) TextComponentString(net.minecraft.util.text.TextComponentString) IGardeningManager(binnie.botany.api.gardening.IGardeningManager) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 92 with TextComponentString

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;
}
Also used : Matcher(java.util.regex.Matcher) ITextComponent(net.minecraft.util.text.ITextComponent) TextComponentString(net.minecraft.util.text.TextComponentString) PositionedEmote(net.blay09.mods.chattweaks.chat.emotes.PositionedEmote) ChatImageEmote(net.blay09.mods.chattweaks.image.ChatImageEmote) Date(java.util.Date) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 93 with TextComponentString

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;
    }
}
Also used : ConnectorTileEntity(mcjty.xnet.blocks.cables.ConnectorTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) XNetBlobData(mcjty.xnet.multiblock.XNetBlobData) ConnectorTileEntity(mcjty.xnet.blocks.cables.ConnectorTileEntity) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ConsumerId(mcjty.xnet.api.keys.ConsumerId) GenericCableBlock(mcjty.xnet.blocks.generic.GenericCableBlock) Block(net.minecraft.block.Block) ConnectorBlock(mcjty.xnet.blocks.cables.ConnectorBlock) WorldBlob(mcjty.xnet.multiblock.WorldBlob) CableColor(mcjty.xnet.blocks.generic.CableColor) ConnectorBlock(mcjty.xnet.blocks.cables.ConnectorBlock) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 94 with TextComponentString

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);
    }
}
Also used : ProgramCardInstance(mcjty.rftoolscontrol.logic.grid.ProgramCardInstance) ITextComponent(net.minecraft.util.text.ITextComponent) EntityPlayer(net.minecraft.entity.player.EntityPlayer) TextComponentString(net.minecraft.util.text.TextComponentString) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 95 with TextComponentString

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);
    }
}
Also used : ProgramCardInstance(mcjty.rftoolscontrol.logic.grid.ProgramCardInstance) ITextComponent(net.minecraft.util.text.ITextComponent) EntityPlayer(net.minecraft.entity.player.EntityPlayer) TextComponentString(net.minecraft.util.text.TextComponentString) PacketItemNBTToServer(mcjty.rftoolscontrol.network.PacketItemNBTToServer) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

TextComponentString (net.minecraft.util.text.TextComponentString)343 EntityPlayer (net.minecraft.entity.player.EntityPlayer)79 ItemStack (net.minecraft.item.ItemStack)68 BlockPos (net.minecraft.util.math.BlockPos)60 ITextComponent (net.minecraft.util.text.ITextComponent)48 TileEntity (net.minecraft.tileentity.TileEntity)41 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)35 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)32 Colony (com.minecolonies.coremod.colony.Colony)26 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)26 IBlockState (net.minecraft.block.state.IBlockState)23 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)21 Style (net.minecraft.util.text.Style)21 IColony (com.minecolonies.api.colony.IColony)19 ClickEvent (net.minecraft.util.text.event.ClickEvent)19 Entity (net.minecraft.entity.Entity)18 Block (net.minecraft.block.Block)17 World (net.minecraft.world.World)17 ArrayList (java.util.ArrayList)16 ActionResult (net.minecraft.util.ActionResult)13