<commit_before>package com.creativemd.littletiles.common.gui;

import java.util.ArrayList;

import com.creativemd.creativecore.common.utils.mc.ColorUtils;
import com.creativemd.creativecore.gui.GuiRenderHelper;
import com.creativemd.creativecore.gui.container.SubGui;
import com.creativemd.creativecore.gui.controls.gui.GuiButton;
import com.creativemd.creativecore.gui.controls.gui.GuiLabel;
import com.creativemd.creativecore.gui.controls.gui.custom.GuiItemListBox;
import com.creativemd.littletiles.common.action.LittleAction;
import com.creativemd.littletiles.common.action.block.NotEnoughIngredientsException;
import com.creativemd.littletiles.common.action.block.NotEnoughIngredientsException.NotEnoughVolumeExcepion;
import com.creativemd.littletiles.common.container.SubContainerWorkbench;
import com.creativemd.littletiles.common.ingredients.BlockIngredient;
import com.creativemd.littletiles.common.ingredients.BlockIngredient.BlockIngredients;
import com.creativemd.littletiles.common.ingredients.ColorUnit;
import com.creativemd.littletiles.common.items.ItemRecipe;
import com.creativemd.littletiles.common.items.ItemRecipeAdvanced;
import com.creativemd.littletiles.common.tiles.preview.LittlePreviews;
import com.creativemd.littletiles.common.tiles.preview.LittleTilePreview;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;

public class SubGuiWorkbench extends SubGui {
	
	public SubGuiWorkbench() {
		super(200, 200);
	}
	
	@Override
	public void createControls() {
		controls.add(new GuiLabel("->", 25, 6));
		controls.add(new GuiButton("Craft", 70, 3, 40) {
			
			@Override
			public void onClicked(int x, int y, int button) {
				ItemStack stack1 = ((SubContainerWorkbench) container).basic.getStackInSlot(0);
				ItemStack stack2 = ((SubContainerWorkbench) container).basic.getStackInSlot(1);
				
				GuiItemListBox listBox = (GuiItemListBox) get("missing");
				GuiLabel label = (GuiLabel) get("label");
				label.caption = "";
				listBox.clear();
				
				if (!stack1.isEmpty()) {
					if (stack1.getItem() instanceof ItemRecipe || stack1.getItem() instanceof ItemRecipeAdvanced) {
						LittlePreviews previews = LittleTilePreview.getPreview(stack1);
						
						EntityPlayer player = getPlayer();
						
						ColorUnit color = new ColorUnit();
						BlockIngredients ingredients = new BlockIngredients();
						for (LittleTilePreview preview : previews) {
							if (preview.canBeConvertedToBlockEntry()) {
								ingredients.addIngredient(preview.getBlockIngredient(previews.context));
								color.addColorUnit(ColorUnit.getColors(previews.context, preview));
							}
						}
						try {
							if (LittleAction.drainIngredients(player, ingredients, color)) {
								sendPacketToServer(new NBTTagCompound());
							}
						} catch (NotEnoughIngredientsException e) {
							if (e instanceof NotEnoughVolumeExcepion) {
								for (BlockIngredient ingredient : ingredients.getIngredients()) {
									listBox.add(ingredient.value > 1 ? ingredient.value + " blocks" : (int) (ingredient.value * previews.context.maxTilesPerBlock) + " pixels", ingredient.getItemStack());
								}
							} else {
								label.caption = e.getLocalizedMessage();
								label.width = GuiRenderHelper.instance.getStringWidth(label.caption) + label.getContentOffset() * 2;
							}
						}
						
					} else {
						sendPacketToServer(new NBTTagCompound());
					}<commit_msg>Fixed workbench not displaying missing colors correctly<commit_after>package com.creativemd.littletiles.common.gui;

import java.util.ArrayList;

import com.creativemd.creativecore.common.utils.mc.ColorUtils;
import com.creativemd.creativecore.gui.GuiRenderHelper;
import com.creativemd.creativecore.gui.container.SubGui;
import com.creativemd.creativecore.gui.controls.gui.GuiButton;
import com.creativemd.creativecore.gui.controls.gui.GuiLabel;
import com.creativemd.creativecore.gui.controls.gui.custom.GuiItemListBox;
import com.creativemd.littletiles.common.action.LittleAction;
import com.creativemd.littletiles.common.action.block.NotEnoughIngredientsException;
import com.creativemd.littletiles.common.action.block.NotEnoughIngredientsException.NotEnoughColorException;
import com.creativemd.littletiles.common.action.block.NotEnoughIngredientsException.NotEnoughVolumeExcepion;
import com.creativemd.littletiles.common.container.SubContainerWorkbench;
import com.creativemd.littletiles.common.ingredients.BlockIngredient;
import com.creativemd.littletiles.common.ingredients.BlockIngredient.BlockIngredients;
import com.creativemd.littletiles.common.ingredients.ColorUnit;
import com.creativemd.littletiles.common.items.ItemRecipe;
import com.creativemd.littletiles.common.items.ItemRecipeAdvanced;
import com.creativemd.littletiles.common.tiles.preview.LittlePreviews;
import com.creativemd.littletiles.common.tiles.preview.LittleTilePreview;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;

public class SubGuiWorkbench extends SubGui {
	
	public SubGuiWorkbench() {
		super(200, 200);
	}
	
	@Override
	public void createControls() {
		controls.add(new GuiLabel("->", 25, 6));
		controls.add(new GuiButton("Craft", 70, 3, 40) {
			
			@Override
			public void onClicked(int x, int y, int button) {
				ItemStack stack1 = ((SubContainerWorkbench) container).basic.getStackInSlot(0);
				ItemStack stack2 = ((SubContainerWorkbench) container).basic.getStackInSlot(1);
				
				GuiItemListBox listBox = (GuiItemListBox) get("missing");
				GuiLabel label = (GuiLabel) get("label");
				label.caption = "";
				listBox.clear();
				
				if (!stack1.isEmpty()) {
					if (stack1.getItem() instanceof ItemRecipe || stack1.getItem() instanceof ItemRecipeAdvanced) {
						LittlePreviews previews = LittleTilePreview.getPreview(stack1);
						
						EntityPlayer player = getPlayer();
						
						ColorUnit color = new ColorUnit();
						BlockIngredients ingredients = new BlockIngredients();
						for (LittleTilePreview preview : previews) {
							if (preview.canBeConvertedToBlockEntry()) {
								ingredients.addIngredient(preview.getBlockIngredient(previews.context));
								color.addColorUnit(ColorUnit.getColors(previews.context, preview));
							}
						}
						try {
							if (LittleAction.drainIngredients(player, ingredients, color)) {
								sendPacketToServer(new NBTTagCompound());
							}
						} catch (NotEnoughIngredientsException e) {
							if (e instanceof NotEnoughVolumeExcepion) {
								for (BlockIngredient ingredient : ingredients.getIngredients()) {
									listBox.add(ingredient.value > 1 ? ingredient.value + " blocks" : (int) (ingredient.value * previews.context.maxTilesPerBlock) + " pixels", ingredient.getItemStack());
								}
							} else if (e instanceof NotEnoughColorException) {
								ColorUnit unit = ((NotEnoughColorException) e).missing;
								if (unit.BLACK > 0)
									listBox.add(unit.getBlackDescription(), ItemStack.EMPTY);
								if (unit.CYAN > 0)
									listBox.add(unit.getCyanDescription(), ItemStack.EMPTY);
								if (unit.MAGENTA > 0)
									listBox.add(unit.getMagentaDescription(), ItemStack.EMPTY);
								if (unit.YELLOW > 0)
									listBox.add(unit.getYellowDescription(), ItemStack.EMPTY);
							} else {
								label.caption = e.getLocalizedMessage();
								label.width = GuiRenderHelper.instance.getStringWidth(label.caption) + label.getContentOffset() * 2;
							}
						}
						
					} else {
						sendPacketToServer(new NBTTagCompound());
					}
{'fraction_non_alphanumeric': 0.10772063659081942, 'fraction_numerical': 0.006839405497829804, 'mean_word_length': 4.339887640449438, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '2498903', 'n_tokens_mistral': 2914, 'n_tokens_neox': 2332, 'n_words': 361}