|
3 | 3 | import codechicken.lib.gui.GuiDraw;
|
4 | 4 | import codechicken.nei.NEIServerUtils;
|
5 | 5 | import codechicken.nei.PositionedStack;
|
| 6 | +import codechicken.nei.guihook.GuiContainerManager; |
| 7 | +import codechicken.nei.recipe.GuiRecipe; |
6 | 8 | import com.djgiannuzz.thaumcraftneiplugin.items.ItemAspect;
|
7 | 9 | import com.djgiannuzz.thaumcraftneiplugin.nei.NEIHelper;
|
8 | 10 | import com.djgiannuzz.thaumcraftneiplugin.nei.recipehandler.CrucibleRecipeHandler;
|
9 | 11 | import java.awt.*;
|
10 |
| -import java.util.ArrayList; |
11 |
| -import java.util.Collection; |
12 |
| -import java.util.Collections; |
| 12 | +import java.util.*; |
13 | 13 | import java.util.List;
|
14 | 14 | import net.minecraft.client.Minecraft;
|
15 | 15 | import net.minecraft.client.resources.I18n;
|
16 | 16 | import net.minecraft.item.ItemStack;
|
17 | 17 | import net.minecraft.util.EnumChatFormatting;
|
| 18 | +import net.minecraft.util.StatCollector; |
18 | 19 | import org.lwjgl.opengl.GL11;
|
| 20 | +import ru.timeconqueror.tcneiadditions.util.GuiRecipeHelper; |
19 | 21 | import ru.timeconqueror.tcneiadditions.util.TCNAConfig;
|
20 | 22 | import ru.timeconqueror.tcneiadditions.util.TCUtil;
|
21 | 23 | import thaumcraft.api.ThaumcraftApi;
|
22 | 24 | import thaumcraft.api.aspects.AspectList;
|
23 | 25 | import thaumcraft.api.crafting.CrucibleRecipe;
|
| 26 | +import thaumcraft.api.research.ResearchCategories; |
| 27 | +import thaumcraft.api.research.ResearchItem; |
24 | 28 | import thaumcraft.client.lib.UtilsFX;
|
25 | 29 |
|
26 | 30 | public class TCNACrucibleRecipeHandler extends CrucibleRecipeHandler {
|
27 | 31 | private final String userName = Minecraft.getMinecraft().getSession().getUsername();
|
| 32 | + private int ySize; |
28 | 33 |
|
29 | 34 | @Override
|
30 | 35 | public void loadCraftingRecipes(String outputId, Object... results) {
|
@@ -109,27 +114,61 @@ public void drawExtras(int recipeIndex) {
|
109 | 114 |
|
110 | 115 | if (TCNAConfig.showResearchKey) {
|
111 | 116 | int y = 135;
|
112 |
| - String textToDraw = I18n.format("tcneiadditions.research.researchKey", recipe.researchKey); |
113 |
| - for (Object text : Minecraft.getMinecraft().fontRenderer.listFormattedStringToWidth(textToDraw, 162)) { |
| 117 | + String researchString = recipe.researchItem != null |
| 118 | + ? EnumChatFormatting.UNDERLINE |
| 119 | + + ResearchCategories.getCategoryName(recipe.researchItem.category) + " : " |
| 120 | + + recipe.researchItem.getName() |
| 121 | + : EnumChatFormatting.ITALIC + "null"; |
| 122 | + List listResearchString = |
| 123 | + Minecraft.getMinecraft().fontRenderer.listFormattedStringToWidth(researchString, 162); |
| 124 | + this.ySize = listResearchString.size() * 11; |
| 125 | + List<Object> list = new ArrayList<>(); |
| 126 | + list.add(StatCollector.translateToLocal("tcneiadditions.research.researchName") + ":"); |
| 127 | + list.addAll(listResearchString); |
| 128 | + for (Object text : list) { |
114 | 129 | GuiDraw.drawStringC((String) text, 82, y, Color.BLACK.getRGB(), false);
|
115 | 130 | y += 11;
|
116 | 131 | }
|
117 | 132 | }
|
118 | 133 | }
|
119 | 134 |
|
| 135 | + @Override |
| 136 | + public List<String> handleTooltip(GuiRecipe gui, List<String> list, int recipeIndex) { |
| 137 | + if (TCNAConfig.showResearchKey) { |
| 138 | + if (GuiContainerManager.shouldShowTooltip(gui) && list.size() == 0) { |
| 139 | + CrucibleCachedRecipe recipe = (CrucibleCachedRecipe) arecipes.get(recipeIndex); |
| 140 | + Rectangle rectangle = getResearchRect(gui, recipeIndex); |
| 141 | + Point mousePos = GuiDraw.getMousePosition(); |
| 142 | + if (rectangle.contains(mousePos)) { |
| 143 | + TCUtil.getResearchPrerequisites(list, recipe.researchItem); |
| 144 | + } |
| 145 | + } |
| 146 | + } |
| 147 | + return super.handleTooltip(gui, list, recipeIndex); |
| 148 | + } |
| 149 | + |
| 150 | + protected Rectangle getResearchRect(GuiRecipe gui, int recipeIndex) { |
| 151 | + Point offset = gui.getRecipePosition(recipeIndex); |
| 152 | + return new Rectangle( |
| 153 | + GuiRecipeHelper.getGuiLeft(gui) + offset.x + 2, |
| 154 | + GuiRecipeHelper.getGuiTop(gui) + offset.y + 146, |
| 155 | + GuiRecipeHelper.getXSize(gui) - 9, |
| 156 | + this.ySize); |
| 157 | + } |
| 158 | + |
120 | 159 | private class CrucibleCachedRecipe extends CachedRecipe {
|
121 | 160 | public List<PositionedStack> ingredients;
|
122 | 161 | public PositionedStack result;
|
123 | 162 | private AspectList aspects;
|
124 | 163 | private final boolean shouldShowRecipe;
|
125 |
| - private final String researchKey; |
| 164 | + private final ResearchItem researchItem; |
126 | 165 |
|
127 | 166 | public CrucibleCachedRecipe(CrucibleRecipe recipe, boolean shouldShowRecipe) {
|
128 | 167 | this.setIngredient(recipe.catalyst);
|
129 | 168 | this.setResult(recipe.getRecipeOutput());
|
130 | 169 | this.setAspectList(recipe.aspects);
|
131 | 170 | this.shouldShowRecipe = shouldShowRecipe;
|
132 |
| - this.researchKey = recipe.key != null ? recipe.key : EnumChatFormatting.ITALIC + "null"; |
| 171 | + this.researchItem = ResearchCategories.getResearch(recipe.key); |
133 | 172 | NEIHelper.addAspectsToIngredients(this.aspects, this.ingredients, 2);
|
134 | 173 | }
|
135 | 174 |
|
|
0 commit comments