package org.cyclops.integrateddynamics.core.client.gui.container;

import com.google.common.collect.Lists;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting;
import org.cyclops.cyclopscore.client.gui.container.ContainerScreenExtended;
import org.cyclops.cyclopscore.client.gui.image.Images;
import org.cyclops.cyclopscore.helper.L10NHelpers;
import org.cyclops.cyclopscore.helper.StringHelpers;

import java.util.List;
import java.util.stream.Collectors;

/**
 * A component for displaying errors.
 * @author rubensworks
 */
public class DisplayErrorsComponent {

    public void drawForeground(List<ITextComponent> errors, int errorX, int errorY, int mouseX, int mouseY, ContainerScreenExtended<?> gui, int guiLeft, int guiTop) {
        if(!errors.isEmpty()) {
            if(gui.isPointInRegion(errorX, errorY, Images.ERROR.getSheetWidth(), Images.ERROR.getSheetHeight(), mouseX, mouseY)) {
                List<ITextComponent> lines = Lists.newLinkedList();
                for(ITextComponent error : errors) {
                    lines.addAll(StringHelpers.splitLines(error.getFormattedText(), L10NHelpers.MAX_TOOLTIP_LINE_LENGTH,
                            TextFormatting.RED.toString())
                            .stream()
                            .map(StringTextComponent::new)
                            .collect(Collectors.toList()));
                }
                gui.drawTooltip(lines, mouseX - guiLeft, mouseY - guiTop);
            }
        }
    }

    public void drawBackground(List<ITextComponent> errors, int errorX, int errorY, int okX, int okY, ContainerScreenExtended<?> gui, int guiLeft, int guiTop, boolean okCondition) {
        // Render error symbol
        if(!errors.isEmpty()) {
            Images.ERROR.draw(gui, guiLeft + errorX, guiTop + errorY);
        } else if(okCondition) {
            Images.OK.draw(gui, guiLeft + okX, guiTop + okY);
        }
    }

}

@@ -484,16 +484,50 @@
 lpers;%0A%0A
+import javax.annotation.Nullable;%0A
 import j
@@ -541,16 +541,16 @@
 l.List;%0A
-
 import j
@@ -713,24 +713,34 @@
 wForeground(
+@Nullable 
 List%3CITextCo
@@ -866,32 +866,50 @@
 p) %7B%0A        if(
+errors != null && 
 !errors.isEmpty(
@@ -1657,16 +1657,26 @@
 kground(
+@Nullable 
 List%3CITe
@@ -1860,16 +1860,34 @@
      if(
+errors != null && 
 !errors.

Fix display panel crash when errors field is null