Highlight missing item in worktable (#22)

* highlight missing item in worktable

* fix crash without recipe
This commit is contained in:
slprime authored and GitHub committed 2022-06-29 22:59:03 +02:00
1 parent 06baad945a
commit cfa2feab1c
2 files changed
+85 -12

No files matched your search

@@ -12,18 +12,25 @@ package forestry.factory.gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import forestry.core.config.Constants;
import forestry.core.gui.GuiForestryTitled;
import forestry.core.gui.buttons.GuiBetterButton;
import forestry.core.gui.buttons.StandardButtonTextureSets;
import forestry.core.network.packets.PacketGuiSelectRequest;
import forestry.core.proxy.Proxies;
import forestry.core.recipes.RecipeUtil;
import forestry.core.utils.InventoryUtil;
import forestry.factory.gui.widgets.ClearWorktable;
import forestry.factory.gui.widgets.MemorizedRecipeSlot;
import forestry.factory.inventory.InventoryGhostCrafting;
import forestry.factory.recipes.MemorizedRecipe;
import forestry.factory.recipes.RecipeMemory;
import forestry.factory.tiles.TileWorktable;
import org.lwjgl.opengl.GL11;
public class GuiWorktable extends GuiForestryTitled<ContainerWorktable, TileWorktable> {
private static final int SPACING = 18;
private boolean hasRecipeConflict = false;
@@ -62,6 +69,49 @@ public class GuiWorktable extends GuiForestryTitled<ContainerWorktable, TileWork
}
}
@Override
public void drawScreen(int mouseX, int mouseY, float parTicks)
{
super.drawScreen(mouseX, mouseY, parTicks);
final Slot itemSlot = (Slot) inventorySlots.inventorySlots.get(54 + InventoryGhostCrafting.SLOT_CRAFTING_RESULT);
if (
func_146978_c(itemSlot.xDisplayPosition, itemSlot.yDisplayPosition, 16, 16, mouseX, mouseY) &&
!inventory.canTakeStack(InventoryGhostCrafting.SLOT_CRAFTING_RESULT)
) {
final MemorizedRecipe recipe = inventory.getCurrentRecipe();
if (recipe != null) {
final ItemStack[] recipeItems = InventoryUtil.getStacks(recipe.getCraftMatrix());
final ItemStack[] availableItems = InventoryUtil.getStacks(inventory);
final ItemStack[] ingregients = RecipeUtil.getCraftIngredients(recipeItems, availableItems);
for (int slot = 0; slot < ingregients.length; slot++) {
if (ingregients[slot] == null && recipeItems[slot] != null) {
renderSlotOverlay((Slot) inventorySlots.inventorySlots.get(54 + slot));
}
}
}
}
}
private void renderSlotOverlay(final Slot slot) {
final int left = guiLeft + slot.xDisplayPosition;
final int top = guiTop + slot.yDisplayPosition;
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glTranslatef(0, 0, 150);
drawRect(left, top, left + 16, top + 16, 0x88ff0000);
GL11.glTranslatef(0, 0, -150);
GL11.glEnable(GL11.GL_LIGHTING);
}
@SuppressWarnings("unchecked")
private void addButtons() {
buttonList.add(new GuiBetterButton(0, guiLeft + 76, guiTop + 56, StandardButtonTextureSets.LEFT_BUTTON_SMALL));