<commit_before>package com.InfinityRaider.AgriCraft.gui;

import com.InfinityRaider.AgriCraft.handler.MutationHandler;
import com.InfinityRaider.AgriCraft.items.ItemJournal;
import com.InfinityRaider.AgriCraft.reference.Names;
import com.InfinityRaider.AgriCraft.reference.Reference;
import com.InfinityRaider.AgriCraft.utility.IOHelper;
import com.InfinityRaider.AgriCraft.utility.RenderHelper;
import com.InfinityRaider.AgriCraft.utility.SeedHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemSeeds;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class GuiJournal extends GuiScreen {
    //the gui textures
    public static final ResourceLocation textureBackground = new ResourceLocation(Reference.MOD_ID.toLowerCase(), "textures/gui/journal/GuiJournalBackground.png");
    public static final ResourceLocation textureFrontPage = new ResourceLocation(Reference.MOD_ID.toLowerCase(), "textures/gui/journal/GuiJournalFrontPage.png");
    public static final ResourceLocation textureTableOfContents = new ResourceLocation(Reference.MOD_ID.toLowerCase(), "textures/gui/journal/GuiJournalTableOfContents.png");
    public static final ResourceLocation textureIntroduction = new ResourceLocation(Reference.MOD_ID.toLowerCase(), "textures/gui/journal/GuiJournalIntroduction.png");
    public static final ResourceLocation textureSeedPage = new ResourceLocation(Reference.MOD_ID.toLowerCase(), "textures/gui/journal/GuiJournalSeedPage.png");
    //needed data
    protected EntityPlayer player;
    protected ItemStack[] discoveredSeeds;
    protected ItemStack[][] discoveredParents;
    protected ItemStack[] discoveredCoParents;
    protected ItemStack[] discoveredMutations;
    protected ItemStack[] fruits;
    //some gui properties and dimensions
    protected int currentPage = 0;
    protected final int standardPages = 3;
    private int xSize;
    private int ySize;
    private int guiLeft;
    private int guiTop;
    private final int black = 1644054;
    private int textStart;
    //the textures for a seed page
    protected IIcon[] plantIcons;
    protected IIcon seedIcon;
    protected IIcon[][] parentsIcons;
    protected IIcon[] coParentsIcons;
    protected IIcon[] mutationIcons;
    protected IIcon[] fruitIcons;
    //list of buttons
    protected List buttonList = new ArrayList();


    public GuiJournal(EntityPlayer player) {
        super();
        this.player = player;
        int pageWidth = 128;
        this.xSize = pageWidth *2;
        this.ySize = pageWidth *3/2;
    }

    //gets the array of discovered seeds
    private void setDataFromNBT() {
        if(this.player.getCurrentEquippedItem()!=null && this.player.getCurrentEquippedItem().stackSize>0 && this.player.getCurrentEquippedItem().getItem() instanceof ItemJournal && this.player.getCurrentEquippedItem().hasTagCompound()) {
            NBTTagCompound tag = this.player.getCurrentEquippedItem().getTagCompound();
            if(tag.hasKey(Names.NBT.discoveredSeeds)) {
                NBTTagList tagList = tag.getTagList(Names.NBT.discoveredSeeds, 10);      //10 for tagCompound
                this.discoveredSeeds = new ItemStack[tagList.tagCount()];
                for(int i=0;i<this.discoveredSeeds.length;i++) {
                    this.discoveredSeeds[i] = ItemStack.loadItemStackFromNBT(tagList.getCompoundTagAt(i));
                }

            }
            else {
                this.discoveredSeeds = new ItemStack[0];
            }
            if(tag.hasKey(Names.NBT.currentPage)) {
                this.currentPage = tag.getShort(Names.NBT.currentPage);
            }
        }
    }

    @Override
    protected void mouseClicked(int x, int y, int  rightClick) {
        boolean flipPage = false;
        //clicked for next page or previous page
        if(y>this.guiTop+172 && y<=this.guiTop+172+16 && rightClick==0) {
            if(x>this.guiLeft+221 && x<=this.guiLeft+221+16) {
                //next page
                if(this.currentPage<this.standardPages-1) {
                    this.currentPage = this.currentPage + 1;
                    flipPage = true;
                }
                else if(this.discoveredSeeds!=null && this.currentPage<this.discoveredSeeds.length+this.standardPages-1) {
                    this.currentPage = this.currentPage + 1;
                    flipPage = true;
                }
            }
            else if(x>this.guiLeft+19 && x<=this.guiLeft+19+16 && this.currentPage>0) {
                //prev page
                this.currentPage = this.currentPage-1;
                flipPage = true;
            }
        }
        else if(this.getSeedAtCoordinates(x, y)!=null && this.getSeedAtCoordinates(x,y).getItem()!=null) {
            ItemStack seed = this.getSeedAtCoordinates(x, y);
            int page = this.getPage(seed);
            this.currentPage = page>=0?page:this.currentPage;
            flipPage = true;
        }

        if(flipPage) {
            initPage(currentPage - standardPages);
        }
    }

    //initializes some values when the gui is opened
    @Override
    public void initGui() {
        super.initGui();
        //half of the screen size minus the gui size to centre the gui, the -16 is to ignore the players item bar
        this.guiLeft = (this.width - this.xSize)/2;
        this.guiTop = (this.height - 16 - this.ySize)/2;
        this.textStart = this.guiLeft + 29;
        //gets the discovered seeds
        this.setDataFromNBT();

    }

    //loads textures and initializes buttons
    private void initPage(int index) {
        this.buttonList = new ArrayList();
        if(currentPage>=standardPages) {
            getSeedTextures(index);
        }
    }

    //draws the gui
    @Override
    public void drawScreen(int x, int y, float opacity) {
        //draw the background
        this.drawBackground(0);
        //draw the contents of a page based on the current page
        switch(currentPage) {
            case 0: this.drawTitleScreen(); break;
            case 1: this.drawTableOfContents(); break;
            case 2: this.drawIntroduction(); break;
            default: this.drawSeedPage(currentPage - standardPages);
        }
        //draw the arrows if the mouse is hovering over the flip page area
        if(y>this.guiTop+172 && y<=this.guiTop+172+16) {
            Minecraft.getMinecraft().getTextureManager().bindTexture(textureBackground);
            GL11.glColor3f(1, 1, 1);
            GL11.glDisable(GL11.GL_LIGHTING);
            if(x>this.guiLeft+221 && x<=this.guiLeft+221+16) {
                drawTexturedModalRect(this.guiLeft+223, this.guiTop+178, 224, 239, 32, 17);
            }
            else if(x>this.guiLeft+19 && x<=this.guiLeft+19+16 && this.currentPage>0) {
                drawTexturedModalRect(this.guiLeft+1, this.guiTop+178, 0, 239, 32, 17);
            }
            GL11.glEnable(GL11.GL_LIGHTING);
        }
        //draws a tooltip if the mouse is hovering over an icon
        this.drawTooltip(x, y);
    }

    //draws a tooltip
    private void drawTooltip(int x, int y) {
        String[] tooltip = new String[1];
        //mutation tooltips
        if(this.currentPage>=this.standardPages) {
            //check if hovering over a seed
            ItemStack seed = getSeedAtCoordinates(x, y);
            if(seed!=null && seed.getItem()!=null) {<commit_msg>Hide table of contents page<commit_after>package com.InfinityRaider.AgriCraft.gui;

import com.InfinityRaider.AgriCraft.handler.MutationHandler;
import com.InfinityRaider.AgriCraft.items.ItemJournal;
import com.InfinityRaider.AgriCraft.reference.Names;
import com.InfinityRaider.AgriCraft.reference.Reference;
import com.InfinityRaider.AgriCraft.utility.IOHelper;
import com.InfinityRaider.AgriCraft.utility.RenderHelper;
import com.InfinityRaider.AgriCraft.utility.SeedHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemSeeds;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class GuiJournal extends GuiScreen {
    //the gui textures
    public static final ResourceLocation textureBackground = new ResourceLocation(Reference.MOD_ID.toLowerCase(), "textures/gui/journal/GuiJournalBackground.png");
    public static final ResourceLocation textureFrontPage = new ResourceLocation(Reference.MOD_ID.toLowerCase(), "textures/gui/journal/GuiJournalFrontPage.png");
    public static final ResourceLocation textureTableOfContents = new ResourceLocation(Reference.MOD_ID.toLowerCase(), "textures/gui/journal/GuiJournalTableOfContents.png");
    public static final ResourceLocation textureIntroduction = new ResourceLocation(Reference.MOD_ID.toLowerCase(), "textures/gui/journal/GuiJournalIntroduction.png");
    public static final ResourceLocation textureSeedPage = new ResourceLocation(Reference.MOD_ID.toLowerCase(), "textures/gui/journal/GuiJournalSeedPage.png");
    //needed data
    protected EntityPlayer player;
    protected ItemStack[] discoveredSeeds;
    protected ItemStack[][] discoveredParents;
    protected ItemStack[] discoveredCoParents;
    protected ItemStack[] discoveredMutations;
    protected ItemStack[] fruits;
    //some gui properties and dimensions
    protected int currentPage = 0;
    protected final int standardPages = 2;
    private int xSize;
    private int ySize;
    private int guiLeft;
    private int guiTop;
    private final int black = 1644054;
    private int textStart;
    //the textures for a seed page
    protected IIcon[] plantIcons;
    protected IIcon seedIcon;
    protected IIcon[][] parentsIcons;
    protected IIcon[] coParentsIcons;
    protected IIcon[] mutationIcons;
    protected IIcon[] fruitIcons;
    //list of buttons
    protected List buttonList = new ArrayList();


    public GuiJournal(EntityPlayer player) {
        super();
        this.player = player;
        int pageWidth = 128;
        this.xSize = pageWidth *2;
        this.ySize = pageWidth *3/2;
    }

    //gets the array of discovered seeds
    private void setDataFromNBT() {
        if(this.player.getCurrentEquippedItem()!=null && this.player.getCurrentEquippedItem().stackSize>0 && this.player.getCurrentEquippedItem().getItem() instanceof ItemJournal && this.player.getCurrentEquippedItem().hasTagCompound()) {
            NBTTagCompound tag = this.player.getCurrentEquippedItem().getTagCompound();
            if(tag.hasKey(Names.NBT.discoveredSeeds)) {
                NBTTagList tagList = tag.getTagList(Names.NBT.discoveredSeeds, 10);      //10 for tagCompound
                this.discoveredSeeds = new ItemStack[tagList.tagCount()];
                for(int i=0;i<this.discoveredSeeds.length;i++) {
                    this.discoveredSeeds[i] = ItemStack.loadItemStackFromNBT(tagList.getCompoundTagAt(i));
                }

            }
            else {
                this.discoveredSeeds = new ItemStack[0];
            }
            if(tag.hasKey(Names.NBT.currentPage)) {
                this.currentPage = tag.getShort(Names.NBT.currentPage);
            }
        }
    }

    @Override
    protected void mouseClicked(int x, int y, int  rightClick) {
        boolean flipPage = false;
        //clicked for next page or previous page
        if(y>this.guiTop+172 && y<=this.guiTop+172+16 && rightClick==0) {
            if(x>this.guiLeft+221 && x<=this.guiLeft+221+16) {
                //next page
                if(this.currentPage<this.standardPages-1) {
                    this.currentPage = this.currentPage + 1;
                    flipPage = true;
                }
                else if(this.discoveredSeeds!=null && this.currentPage<this.discoveredSeeds.length+this.standardPages-1) {
                    this.currentPage = this.currentPage + 1;
                    flipPage = true;
                }
            }
            else if(x>this.guiLeft+19 && x<=this.guiLeft+19+16 && this.currentPage>0) {
                //prev page
                this.currentPage = this.currentPage-1;
                flipPage = true;
            }
        }
        else if(this.getSeedAtCoordinates(x, y)!=null && this.getSeedAtCoordinates(x,y).getItem()!=null) {
            ItemStack seed = this.getSeedAtCoordinates(x, y);
            int page = this.getPage(seed);
            this.currentPage = page>=0?page:this.currentPage;
            flipPage = true;
        }

        if(flipPage) {
            initPage(currentPage - standardPages);
        }
    }

    //initializes some values when the gui is opened
    @Override
    public void initGui() {
        super.initGui();
        //half of the screen size minus the gui size to centre the gui, the -16 is to ignore the players item bar
        this.guiLeft = (this.width - this.xSize)/2;
        this.guiTop = (this.height - 16 - this.ySize)/2;
        this.textStart = this.guiLeft + 29;
        //gets the discovered seeds
        this.setDataFromNBT();

    }

    //loads textures and initializes buttons
    private void initPage(int index) {
        this.buttonList = new ArrayList();
        if(currentPage>=standardPages) {
            getSeedTextures(index);
        }
    }

    //draws the gui
    @Override
    public void drawScreen(int x, int y, float opacity) {
        //draw the background
        this.drawBackground(0);
        //draw the contents of a page based on the current page
        switch(currentPage) {
            case 0: this.drawTitleScreen(); break;
            //case 1: this.drawTableOfContents(); break;
            case 1: this.drawIntroduction(); break;
            default: this.drawSeedPage(currentPage - standardPages);
        }
        //draw the arrows if the mouse is hovering over the flip page area
        if(y>this.guiTop+172 && y<=this.guiTop+172+16) {
            Minecraft.getMinecraft().getTextureManager().bindTexture(textureBackground);
            GL11.glColor3f(1, 1, 1);
            GL11.glDisable(GL11.GL_LIGHTING);
            if(x>this.guiLeft+221 && x<=this.guiLeft+221+16) {
                drawTexturedModalRect(this.guiLeft+223, this.guiTop+178, 224, 239, 32, 17);
            }
            else if(x>this.guiLeft+19 && x<=this.guiLeft+19+16 && this.currentPage>0) {
                drawTexturedModalRect(this.guiLeft+1, this.guiTop+178, 0, 239, 32, 17);
            }
            GL11.glEnable(GL11.GL_LIGHTING);
        }
        //draws a tooltip if the mouse is hovering over an icon
        this.drawTooltip(x, y);
    }

    //draws a tooltip
    private void drawTooltip(int x, int y) {
        String[] tooltip = new String[1];
        //mutation tooltips
        if(this.currentPage>=this.standardPages) {
            //check if hovering over a seed
            ItemStack seed = getSeedAtCoordinates(x, y);
            if(seed!=null && seed.getItem()!=null) {
{'fraction_non_alphanumeric': 0.10257395313100269, 'fraction_numerical': 0.016903572800614674, 'mean_word_length': 2.6501519046506194, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4152793', 'n_tokens_mistral': 4714, 'n_tokens_neox': 4519, 'n_words': 984}