<commit_before>package com.creativemd.creativecore.common.gui.controls.container;

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

import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;

import com.creativemd.creativecore.client.rendering.RenderHelper2D;
import com.creativemd.creativecore.common.container.slot.SlotControl;
import com.creativemd.creativecore.common.container.slot.SlotInput;
import com.creativemd.creativecore.common.container.slot.SlotOutput;
import com.creativemd.creativecore.common.gui.GuiContainerSub;
import com.creativemd.creativecore.common.gui.SubGui;
import com.creativemd.creativecore.common.gui.controls.GuiControl;

public class GuiSlotControl extends GuiControl{
	
	public SlotControl slot;
	
	public GuiSlotControl(int x, int y, SlotControl slot) {
		super(slot.slot.inventory.getInventoryName() + slot.slot.slotNumber, x, y, 18, 18);
		this.slot = slot;
	}
	
	@Override
	public void drawControl(FontRenderer renderer) {
		GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
		mc.getTextureManager().bindTexture(GuiContainerSub.background);
		RenderHelper2D.drawTexturedModalRect(0, 0, 176, 0, 18, 18);
		
		ItemStack stack = slot.slot.getStack();
		
		ItemStack newStack = null;
		if(isDragged() && stackSize.length > 1){
			updateHandStack();
			newStack = getItemStackByIndex(index);
		}else if(startSlot != null){
			updateStackSize();
			newStack = startSlot.getItemStackByIndex(index);
		}
		
		if(newStack != null)
		{
			if(stack != null)
				newStack.stackSize += stack.stackSize;
			stack = newStack;
		}
		
		if(slot.slot instanceof SlotInput)
		{
			ItemStack backgroundStack = null;
			if(((SlotInput)slot.slot).input != null)
				backgroundStack = ((SlotInput)slot.slot).input.getItemStack(1);
			
			if(backgroundStack != null)
			{
				//GL11.glPushMatrix();
				//GL11.glColor4d(1, 1, 1, 0.2);
				//GL11.glEnable(GL11.GL_BLEND);
				//GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
				//GL11.glPushMatrix();
				//GL11.glPushClientAttrib(GL11.GL_COLOR_BUFFER_BIT);
				GL11.glColor4d(1, 1, 1, 0.5);
				SubGui.itemRender.renderWithColor = false;
				drawItemStack(backgroundStack, renderer);
				SubGui.itemRender.renderWithColor = true;
				//GL11.glPopClientAttrib();
				//GL11.glPopMatrix();
				//GL11.glDisable(GL11.GL_BLEND);
				//GL11.glPopMatrix();
			}
		}
		
		if(stack != null)
		{
			GL11.glPushMatrix();
			drawItemStack(stack, renderer);
			GL11.glPopMatrix();
		}
		
		if(isMouseOver() || startSlot != null || isDragged())
		{
			GL11.glDisable(GL11.GL_LIGHTING);
			GL11.glDisable(GL11.GL_DEPTH_TEST);
			GL11.glColorMask(true, true, true, false);
			RenderHelper2D.drawGradientRect(1, 1, 17, 17, -2130706433, -2130706433);
			GL11.glColorMask(true, true, true, true);
			//GL11.glEnable(GL11.GL_LIGHTING);
			//GL11.glEnable(GL11.GL_DEPTH_TEST);
		}
		
		GL11.glDisable(GL11.GL_LIGHTING);
		GL11.glDisable(GL11.GL_DEPTH_TEST);
        //RenderHelper.enableStandardItemLighting();
	}
	
	public void drawItemStack(ItemStack stack, FontRenderer renderer)
	{
		try
		{
			GL11.glTranslated(8, 8, 0);
			GL11.glRotated(-rotation, 0, 0, 1);
			GL11.glTranslated(-8, -8, 0);
			GL11.glEnable(GL11.GL_ALPHA_TEST);
            GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
            GL11.glEnable(GL11.GL_BLEND);
            GL11.glEnable(GL11.GL_DEPTH_TEST);
            OpenGlHelper.glBlendFunc(770, 771, 1, 0);
            RenderHelper.enableGUIStandardItemLighting();
			//GL11.glPushMatrix();
			GL11.glEnable(GL12.GL_RESCALE_NORMAL);
	        
			GL11.glEnable(GL11.GL_LIGHTING);
			//GL11.glEnable(GL11.GL_LIGHTING);
			//RenderHelper.enableStandardItemLighting();
			//GL11.glTranslatef(0.0F, 0.0F, 32.0F);
			SubGui.itemRender.zLevel = 200.0F;
			FontRenderer font = null;
			if (slot.slot.getStack() != null)
				font = slot.slot.getStack().getItem().getFontRenderer(stack);
			if(font == null)
				font = renderer;
			SubGui.itemRender.renderItemAndEffectIntoGUI(font, mc.getTextureManager(), stack, 1, 1);
			String textStack = null;
			if (stack.stackSize == 0)
			{
				textStack = "" + EnumChatFormatting.YELLOW + "0";
			}
			SubGui.itemRender.renderItemOverlayIntoGUI(font, mc.getTextureManager(), stack, 1, 1, textStack);
			SubGui.itemRender.zLevel = 0.0F;
		}catch(Exception e){
			SubGui.itemRender.zLevel = 100.0F;
            
        	ResourceLocation resourcelocation = mc.renderEngine.getResourceLocation(1);
            IIcon icon = ((TextureMap)mc.getTextureManager().getTexture(resourcelocation)).getAtlasSprite("missingno");
            Minecraft.getMinecraft().renderEngine.bindTexture(resourcelocation);
            
        	SubGui.itemRender.renderIcon(1, 1, icon, 16, 16);

        	SubGui.itemRender.zLevel = 0.0F;
		}
	}
	
	@Override
	public ArrayList<String> getTooltip()
	{
		ArrayList<String> tips = new ArrayList<String>();
		if(slot.slot.getHasStack() && parent.container.player.inventory.getItemStack() == null)
		{
			List list = null;
			try{
				list = slot.slot.getStack().getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips);
		
		        for (int k = 0; k < list.size(); ++k)
		        {
		            if (k == 0)
		            {
		                list.set(k, slot.slot.getStack().getRarity().rarityColor + (String)list.get(k));
		            }
		            else
		            {
		                list.set(k, EnumChatFormatting.GRAY + (String)list.get(k));
		            }
		            tips.add((String) list.get(k));
		        }
			}catch (Exception e){
				ItemStack stack = slot.slot.getStack();
				tips.add(Item.itemRegistry.getNameForObject(stack.getItem()));
				tips.add("Damage: " + stack.getItemDamage());
				tips.add("NBT: " + (stack.stackTagCompound == null ? "null" : stack.stackTagCompound.toString()));
			}
		}
		return tips;
	}
	
	@Override
	public boolean onKeyPressed(char character, int key)
	{
		if(key == mc.gameSettings.keyBindDrop.getKeyCode() && isMouseOver())
		{
			NBTTagCompound nbt = new NBTTagCompound();
			nbt.setBoolean("ctrl", GuiScreen.isCtrlKeyDown());
			slot.sendNBTUpdate(2, nbt);
			return true;
		}
		return false;
	}
	
	@Override
	public boolean mouseScrolled(int posX, int posY, int scrolled){
		sendClickedPacket(3, scrolled);
		return true;
	}
	
	public void sendClickedPacket(int button, int scrolled)
	{
		NBTTagCompound nbt = new NBTTagCompound();<commit_msg>Fixed crashing if itemstack has an invalid Item<commit_after>package com.creativemd.creativecore.common.gui.controls.container;

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

import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;

import com.creativemd.creativecore.client.rendering.RenderHelper2D;
import com.creativemd.creativecore.common.container.slot.SlotControl;
import com.creativemd.creativecore.common.container.slot.SlotInput;
import com.creativemd.creativecore.common.container.slot.SlotOutput;
import com.creativemd.creativecore.common.gui.GuiContainerSub;
import com.creativemd.creativecore.common.gui.SubGui;
import com.creativemd.creativecore.common.gui.controls.GuiControl;

public class GuiSlotControl extends GuiControl{
	
	public SlotControl slot;
	
	public GuiSlotControl(int x, int y, SlotControl slot) {
		super(slot.slot.inventory.getInventoryName() + slot.slot.slotNumber, x, y, 18, 18);
		this.slot = slot;
	}
	
	@Override
	public void drawControl(FontRenderer renderer) {
		GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
		mc.getTextureManager().bindTexture(GuiContainerSub.background);
		RenderHelper2D.drawTexturedModalRect(0, 0, 176, 0, 18, 18);
		
		ItemStack stack = slot.slot.getStack();
		
		ItemStack newStack = null;
		if(isDragged() && stackSize.length > 1){
			updateHandStack();
			newStack = getItemStackByIndex(index);
		}else if(startSlot != null){
			updateStackSize();
			newStack = startSlot.getItemStackByIndex(index);
		}
		
		if(newStack != null)
		{
			if(stack != null)
				newStack.stackSize += stack.stackSize;
			stack = newStack;
		}
		
		if(slot.slot instanceof SlotInput)
		{
			ItemStack backgroundStack = null;
			if(((SlotInput)slot.slot).input != null)
				backgroundStack = ((SlotInput)slot.slot).input.getItemStack(1);
			
			if(backgroundStack != null)
			{
				//GL11.glPushMatrix();
				//GL11.glColor4d(1, 1, 1, 0.2);
				//GL11.glEnable(GL11.GL_BLEND);
				//GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
				//GL11.glPushMatrix();
				//GL11.glPushClientAttrib(GL11.GL_COLOR_BUFFER_BIT);
				GL11.glColor4d(1, 1, 1, 0.5);
				SubGui.itemRender.renderWithColor = false;
				drawItemStack(backgroundStack, renderer);
				SubGui.itemRender.renderWithColor = true;
				//GL11.glPopClientAttrib();
				//GL11.glPopMatrix();
				//GL11.glDisable(GL11.GL_BLEND);
				//GL11.glPopMatrix();
			}
		}
		
		if(stack != null)
		{
			GL11.glPushMatrix();
			drawItemStack(stack, renderer);
			GL11.glPopMatrix();
		}
		
		if(isMouseOver() || startSlot != null || isDragged())
		{
			GL11.glDisable(GL11.GL_LIGHTING);
			GL11.glDisable(GL11.GL_DEPTH_TEST);
			GL11.glColorMask(true, true, true, false);
			RenderHelper2D.drawGradientRect(1, 1, 17, 17, -2130706433, -2130706433);
			GL11.glColorMask(true, true, true, true);
			//GL11.glEnable(GL11.GL_LIGHTING);
			//GL11.glEnable(GL11.GL_DEPTH_TEST);
		}
		
		GL11.glDisable(GL11.GL_LIGHTING);
		GL11.glDisable(GL11.GL_DEPTH_TEST);
        //RenderHelper.enableStandardItemLighting();
	}
	
	public void drawItemStack(ItemStack stack, FontRenderer renderer)
	{
		try
		{
			GL11.glTranslated(8, 8, 0);
			GL11.glRotated(-rotation, 0, 0, 1);
			GL11.glTranslated(-8, -8, 0);
			GL11.glEnable(GL11.GL_ALPHA_TEST);
            GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
            GL11.glEnable(GL11.GL_BLEND);
            GL11.glEnable(GL11.GL_DEPTH_TEST);
            OpenGlHelper.glBlendFunc(770, 771, 1, 0);
            RenderHelper.enableGUIStandardItemLighting();
			//GL11.glPushMatrix();
			GL11.glEnable(GL12.GL_RESCALE_NORMAL);
	        
			GL11.glEnable(GL11.GL_LIGHTING);
			//GL11.glEnable(GL11.GL_LIGHTING);
			//RenderHelper.enableStandardItemLighting();
			//GL11.glTranslatef(0.0F, 0.0F, 32.0F);
			SubGui.itemRender.zLevel = 200.0F;
			FontRenderer font = null;
			if (slot.slot.getStack() != null)
				font = slot.slot.getStack().getItem().getFontRenderer(stack);
			if(font == null)
				font = renderer;
			SubGui.itemRender.renderItemAndEffectIntoGUI(font, mc.getTextureManager(), stack, 1, 1);
			String textStack = null;
			if (stack.stackSize == 0)
			{
				textStack = "" + EnumChatFormatting.YELLOW + "0";
			}
			SubGui.itemRender.renderItemOverlayIntoGUI(font, mc.getTextureManager(), stack, 1, 1, textStack);
			SubGui.itemRender.zLevel = 0.0F;
		}catch(Exception e){
			SubGui.itemRender.zLevel = 100.0F;
            
        	ResourceLocation resourcelocation = mc.renderEngine.getResourceLocation(1);
            IIcon icon = ((TextureMap)mc.getTextureManager().getTexture(resourcelocation)).getAtlasSprite("missingno");
            Minecraft.getMinecraft().renderEngine.bindTexture(resourcelocation);
            
        	SubGui.itemRender.renderIcon(1, 1, icon, 16, 16);

        	SubGui.itemRender.zLevel = 0.0F;
		}
	}
	
	@Override
	public ArrayList<String> getTooltip()
	{
		ArrayList<String> tips = new ArrayList<String>();
		if(slot.slot.getHasStack() && parent.container.player.inventory.getItemStack() == null)
		{
			List list = null;
			try{
				list = slot.slot.getStack().getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips);
		
		        for (int k = 0; k < list.size(); ++k)
		        {
		            if (k == 0)
		            {
		                list.set(k, slot.slot.getStack().getRarity().rarityColor + (String)list.get(k));
		            }
		            else
		            {
		                list.set(k, EnumChatFormatting.GRAY + (String)list.get(k));
		            }
		            tips.add((String) list.get(k));
		        }
			}catch (Exception e){
				ItemStack stack = slot.slot.getStack();
				try{
					tips.add(Item.itemRegistry.getNameForObject(stack.getItem()));
					tips.add("Damage: " + stack.getItemDamage());
					tips.add("NBT: " + (stack.stackTagCompound == null ? "null" : stack.stackTagCompound.toString()));
				}catch(Exception e2){
					tips.add("<ERRORED>");
				}
			}
		}
		return tips;
	}
	
	@Override
	public boolean onKeyPressed(char character, int key)
	{
		if(key == mc.gameSettings.keyBindDrop.getKeyCode() && isMouseOver())
		{
			NBTTagCompound nbt = new NBTTagCompound();
			nbt.setBoolean("ctrl", GuiScreen.isCtrlKeyDown());
			slot.sendNBTUpdate(2, nbt);
			return true;
		}
		return false;
	}
	
	@Override
	public boolean mouseScrolled(int posX, int posY, int scrolled){
		sendClickedPacket(3, scrolled);
		return true;
	}
	
	public void sendClickedPacket(int button, int scrolled)
	{
		NBTTagCompound nbt = new NBTTagCompound();
{'fraction_non_alphanumeric': 0.13405848283655883, 'fraction_numerical': 0.032419833309789516, 'mean_word_length': 3.621083550913838, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '4745021', 'n_tokens_mistral': 5786, 'n_tokens_neox': 4985, 'n_words': 760}