<commit_before>package de.comeight.crystallogy.gui.bookOfKnowledge;

import java.util.LinkedList;

import de.comeight.crystallogy.gui.bookOfKnowledge.buttons.BookButtonCategory;
import de.comeight.crystallogy.gui.bookOfKnowledge.pages.GuiBookPage;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.client.config.GuiUtils;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class ScrollBarList {
	//-----------------------------------------------Variabeln:---------------------------------------------
	protected final Minecraft mc = Minecraft.getMinecraft();
	private GuiBookPage page;
	private long lastMouseEvent;
	protected Long mouseCooldownUntil = 0L;
	protected boolean shouldWaitForInput = true;
	
	protected int width;
	protected int height;
	protected int posX;
	protected int posY;
	
	protected final int entryHeigtht = 35;
	
	protected boolean scrollEnabeld = true;
	protected int scrollPos = 0;
	protected int hoverIndex = -1;
	
	protected LinkedList<BookButtonCategory> list = new LinkedList<BookButtonCategory>();
	
	protected final ResourceLocation BAR = new ResourceLocation("textures/gui/container/creative_inventory/tab_items.png");
	protected final ResourceLocation SCROLL = new ResourceLocation("textures/gui/container/creative_inventory/tabs.png");
	protected final int SCROLL_BAR_WIDTH = 10; 
	
	//-----------------------------------------------Constructor:-------------------------------------------
    public ScrollBarList(int width, int height, int posX, int posY, GuiBookPage page)
    {
    	this.page = page;
        this.width = width;
        this.height = height;
        this.posX = posX;
        this.posY = posY;
    }
	
	//-----------------------------------------------Set-, Get-Methoden:------------------------------------
    
    
    
	//-----------------------------------------------Sonstige Methoden:-------------------------------------
    public void drawScreen(int mouseX, int mouseY, int posX, int posY){
    	this.posX = posX;
        this.posY = posY;
    	
    	drawBackground(this.posX, this.posY);
    	shouldEnbaleScroll();
    	drawScrollBar(this.posX, this.posY);
    	drawEntrys(mouseX, mouseY);
    }
    
	protected void drawEntrys(int mouseX, int mouseY){
		int drawStratIndex;
    	int drawEndIndex;
    	if(scrollEnabeld){
    		drawStratIndex = scrollPos / entryHeigtht;
        	drawEndIndex = drawStratIndex + (height / entryHeigtht);
        	if(drawEndIndex >= list.size()){
        		drawEndIndex = list.size();
        	}
    	}
    	else{
    		drawStratIndex = 0;
        	drawEndIndex = list.size();
    	}
    	
    	
    	int relativeHoverIndex = getHoverIndex(mouseX - this.posX, mouseY - this.posY);
    	
    	hoverIndex = relativeHoverIndex;
    	if(hoverIndex != -1){
    		hoverIndex += drawStratIndex;
    	}
    	
    	for (int i = drawStratIndex; i < drawEndIndex; i++) {
    		if(list.get(i) != null){
    			if((i - drawStratIndex) == relativeHoverIndex){
    				drawEntry(i, true, this.posX, this.posY + ((i - drawStratIndex) * entryHeigtht));
    			}
    			else{
    				drawEntry(i, false, this.posX, this.posY + ((i - drawStratIndex) * entryHeigtht));
    			}
    		}
		}
	}
    
    protected void shouldEnbaleScroll(){
    	if((height / entryHeigtht) >= list.size()){
    		scrollEnabeld = false;
    	}
    	else{
    		scrollEnabeld = true;
    	}
    }
    
    protected int getHoverIndex(int mouseX, int mouseY){
    	if(mouseX < 0 || mouseY < 0 || mouseX > width - 10 || mouseY > height){
    		return -1;
    	}
    	return mouseY / entryHeigtht;
    }
    
    public void mouseReleased(int mouseX, int mouseY){
    	if(shouldWaitForInput){
    		lastMouseEvent = System.currentTimeMillis() + 100;
    		shouldWaitForInput = false;
    		return;
    	}
    	if(System.currentTimeMillis() < lastMouseEvent){
    		return;
    	}
    	if(hoverIndex >= 0){
			list.get(hoverIndex).onClicked(page);
		}
    }
    
    public void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) {
    	if(!scrollEnabeld || clickedMouseButton != 0){
    		return;
    	}
    	if(mouseX > posX + width || mouseX < posX + width - 10){<commit_msg>Fixed a crash related to index out of bounds<commit_after>package de.comeight.crystallogy.gui.bookOfKnowledge;

import java.util.LinkedList;

import de.comeight.crystallogy.gui.bookOfKnowledge.buttons.BookButtonCategory;
import de.comeight.crystallogy.gui.bookOfKnowledge.pages.GuiBookPage;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.client.config.GuiUtils;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class ScrollBarList {
	//-----------------------------------------------Variabeln:---------------------------------------------
	protected final Minecraft mc = Minecraft.getMinecraft();
	private GuiBookPage page;
	private long lastMouseEvent;
	protected Long mouseCooldownUntil = 0L;
	protected boolean shouldWaitForInput = true;
	
	protected int width;
	protected int height;
	protected int posX;
	protected int posY;
	
	protected final int entryHeigtht = 35;
	
	protected boolean scrollEnabeld = true;
	protected int scrollPos = 0;
	protected int hoverIndex = -1;
	
	protected LinkedList<BookButtonCategory> list = new LinkedList<BookButtonCategory>();
	
	protected final ResourceLocation BAR = new ResourceLocation("textures/gui/container/creative_inventory/tab_items.png");
	protected final ResourceLocation SCROLL = new ResourceLocation("textures/gui/container/creative_inventory/tabs.png");
	protected final int SCROLL_BAR_WIDTH = 10; 
	
	//-----------------------------------------------Constructor:-------------------------------------------
    public ScrollBarList(int width, int height, int posX, int posY, GuiBookPage page)
    {
    	this.page = page;
        this.width = width;
        this.height = height;
        this.posX = posX;
        this.posY = posY;
    }
	
	//-----------------------------------------------Set-, Get-Methoden:------------------------------------
    
    
    
	//-----------------------------------------------Sonstige Methoden:-------------------------------------
    public void drawScreen(int mouseX, int mouseY, int posX, int posY){
    	this.posX = posX;
        this.posY = posY;
    	
    	drawBackground(this.posX, this.posY);
    	shouldEnbaleScroll();
    	drawScrollBar(this.posX, this.posY);
    	drawEntrys(mouseX, mouseY);
    }
    
	protected void drawEntrys(int mouseX, int mouseY){
		int drawStratIndex;
    	int drawEndIndex;
    	if(scrollEnabeld){
    		drawStratIndex = scrollPos / entryHeigtht;
        	drawEndIndex = drawStratIndex + (height / entryHeigtht);
        	if(drawEndIndex >= list.size()){
        		drawEndIndex = list.size();
        	}
    	}
    	else{
    		drawStratIndex = 0;
        	drawEndIndex = list.size();
    	}
    	
    	
    	int relativeHoverIndex = getHoverIndex(mouseX - this.posX, mouseY - this.posY);
    	
    	hoverIndex = relativeHoverIndex;
    	if(hoverIndex != -1){
    		hoverIndex += drawStratIndex;
    	}
    	
    	for (int i = drawStratIndex; i < drawEndIndex; i++) {
    		if(list.get(i) != null){
    			if((i - drawStratIndex) == relativeHoverIndex){
    				drawEntry(i, true, this.posX, this.posY + ((i - drawStratIndex) * entryHeigtht));
    			}
    			else{
    				drawEntry(i, false, this.posX, this.posY + ((i - drawStratIndex) * entryHeigtht));
    			}
    		}
		}
	}
    
    protected void shouldEnbaleScroll(){
    	if((height / entryHeigtht) >= list.size()){
    		scrollEnabeld = false;
    	}
    	else{
    		scrollEnabeld = true;
    	}
    }
    
    protected int getHoverIndex(int mouseX, int mouseY){
    	if(mouseX < 0 || mouseY < 0 || mouseX > width - 10 || mouseY > height){
    		return -1;
    	}
    	return mouseY / entryHeigtht;
    }
    
    public void mouseReleased(int mouseX, int mouseY){
    	if(shouldWaitForInput){
    		lastMouseEvent = System.currentTimeMillis() + 100;
    		shouldWaitForInput = false;
    		return;
    	}
    	if(System.currentTimeMillis() < lastMouseEvent){
    		return;
    	}
    	if(hoverIndex >= 0 && hoverIndex > list.size()){
			list.get(hoverIndex).onClicked(page);
		}
    }
    
    public void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) {
    	if(!scrollEnabeld || clickedMouseButton != 0){
    		return;
    	}
    	if(mouseX > posX + width || mouseX < posX + width - 10){
{'fraction_non_alphanumeric': 0.17312122874382885, 'fraction_numerical': 0.004607789358200768, 'mean_word_length': 2.298118668596237, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 20, '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': '3232872', 'n_tokens_mistral': 2969, 'n_tokens_neox': 2848, 'n_words': 579}