Compare commits

..
1 Commits
Author SHA1 Message Date
slprime cfa2feab1c Highlight missing item in worktable (#22)
* highlight missing item in worktable

* fix crash without recipe
2022-06-29 22:59:03 +02:00
2 changed files with 85 additions and 12 deletions

No files matched your search

@@ -110,10 +110,37 @@ public abstract class RecipeUtil {
// in place of the ones in the saved crafting inventory.
// Check that the recipe it makes is the same as the currentRecipe.
InventoryCraftingForestry crafting = new InventoryCraftingForestry();
ItemStack[] stockCopy = ItemStackUtil.condenseStacks(availableItems);
final ItemStack[] ingregients = RecipeUtil.getCraftIngredients(recipeItems, availableItems);
for (int slot = 0; slot < ingregients.length; slot++) {
ItemStack recipeStack = ingregients[slot];
if (recipeStack == null && recipeItems[slot] != null) {
return null;
}
if (recipeStack == null) {
continue;
}
crafting.setInventorySlotContents(slot, recipeStack);
}
List<ItemStack> outputs = findMatchingRecipes(crafting, world);
if (!ItemStackUtil.containsItemStack(outputs, recipeOutput)) {
return null;
}
return crafting;
}
public static ItemStack[] getCraftIngredients(ItemStack[] recipeItems, ItemStack[] availableItems)
{
final ItemStack[] stockCopy = ItemStackUtil.condenseStacks(availableItems);
final ItemStack[] ingredients = new ItemStack[recipeItems.length];
for (int slot = 0; slot < recipeItems.length; slot++) {
ItemStack recipeStack = recipeItems[slot];
if (recipeStack == null) {
continue;
}
@@ -121,30 +148,26 @@ public abstract class RecipeUtil {
// Use crafting equivalent (not oredict) items first
for (ItemStack stockStack : stockCopy) {
if (stockStack.stackSize > 0 && ItemStackUtil.isCraftingEquivalent(recipeStack, stockStack, false, false)) {
ItemStack stack = ItemStackUtil.createSplitStack(stockStack, 1);
ingredients[slot] = ItemStackUtil.createSplitStack(stockStack, 1);
stockStack.stackSize--;
crafting.setInventorySlotContents(slot, stack);
break;
}
}
// Use oredict items if crafting equivalent items aren't available
if (crafting.getStackInSlot(slot) == null) {
if (ingredients[slot] == null) {
for (ItemStack stockStack : stockCopy) {
if (stockStack.stackSize > 0 && ItemStackUtil.isCraftingEquivalent(recipeStack, stockStack, true, true)) {
ItemStack stack = ItemStackUtil.createSplitStack(stockStack, 1);
ingredients[slot] = ItemStackUtil.createSplitStack(stockStack, 1);
stockStack.stackSize--;
crafting.setInventorySlotContents(slot, stack);
break;
}
}
}
}
List<ItemStack> outputs = findMatchingRecipes(crafting, world);
if (!ItemStackUtil.containsItemStack(outputs, recipeOutput)) {
return null;
}
return crafting;
return ingredients;
}
public static List<ItemStack> findMatchingRecipes(InventoryCrafting inventory, World world) {
@@ -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));