add tooltip callback. Paint craftables in blue. middle click to craft
from JEI
This commit is contained in:
@@ -23,6 +23,7 @@ import appeng.api.config.ActionItems;
|
|||||||
import appeng.api.config.Settings;
|
import appeng.api.config.Settings;
|
||||||
import appeng.api.storage.ITerminalHost;
|
import appeng.api.storage.ITerminalHost;
|
||||||
import appeng.client.gui.widgets.GuiImgButton;
|
import appeng.client.gui.widgets.GuiImgButton;
|
||||||
|
import appeng.client.me.ItemRepo;
|
||||||
import appeng.container.implementations.ContainerCraftingTerm;
|
import appeng.container.implementations.ContainerCraftingTerm;
|
||||||
import appeng.container.slot.SlotCraftingMatrix;
|
import appeng.container.slot.SlotCraftingMatrix;
|
||||||
import appeng.core.localization.GuiText;
|
import appeng.core.localization.GuiText;
|
||||||
@@ -81,4 +82,8 @@ public class GuiCraftingTerm extends GuiMEMonitorable {
|
|||||||
protected String getBackground() {
|
protected String getBackground() {
|
||||||
return "guis/crafting.png";
|
return "guis/crafting.png";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ItemRepo getRepo() {
|
||||||
|
return this.repo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfi
|
|||||||
private static int craftingGridOffsetY;
|
private static int craftingGridOffsetY;
|
||||||
|
|
||||||
private static String memoryText = "";
|
private static String memoryText = "";
|
||||||
private final ItemRepo repo;
|
protected final ItemRepo repo;
|
||||||
private final int offsetX = 9;
|
private final int offsetX = 9;
|
||||||
private final int lowerTextureOffset = 0;
|
private final int lowerTextureOffset = 0;
|
||||||
private final IConfigManager configSrc;
|
private final IConfigManager configSrc;
|
||||||
|
|||||||
@@ -268,4 +268,8 @@ public class ItemRepo {
|
|||||||
this.updateJEI(this.searchString);
|
this.updateJEI(this.searchString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IItemList<IAEItemStack> getList() {
|
||||||
|
return list;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import appeng.container.slot.SlotCraftingTerm;
|
|||||||
import appeng.helpers.IContainerCraftingPacket;
|
import appeng.helpers.IContainerCraftingPacket;
|
||||||
import appeng.parts.reporting.PartCraftingTerminal;
|
import appeng.parts.reporting.PartCraftingTerminal;
|
||||||
import appeng.tile.inventory.AppEngInternalInventory;
|
import appeng.tile.inventory.AppEngInternalInventory;
|
||||||
|
import appeng.util.IConfigManagerHost;
|
||||||
import appeng.util.inv.IAEAppEngInventory;
|
import appeng.util.inv.IAEAppEngInventory;
|
||||||
import appeng.util.inv.InvOperation;
|
import appeng.util.inv.InvOperation;
|
||||||
import appeng.util.inv.WrapperInvItemHandler;
|
import appeng.util.inv.WrapperInvItemHandler;
|
||||||
@@ -119,4 +120,8 @@ public class ContainerCraftingTerm extends ContainerMEMonitorable implements IAE
|
|||||||
public IRecipe getCurrentRecipe() {
|
public IRecipe getCurrentRecipe() {
|
||||||
return this.currentRecipe;
|
return this.currentRecipe;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IConfigManagerHost getGui() {
|
||||||
|
return super.getGui();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa
|
|||||||
|
|
||||||
private final SlotRestrictedInput[] cellView = new SlotRestrictedInput[5];
|
private final SlotRestrictedInput[] cellView = new SlotRestrictedInput[5];
|
||||||
private final IMEMonitor<IAEItemStack> monitor;
|
private final IMEMonitor<IAEItemStack> monitor;
|
||||||
private final IItemList<IAEItemStack> items = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
public final IItemList<IAEItemStack> items = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
||||||
private final IConfigManager clientCM;
|
private final IConfigManager clientCM;
|
||||||
private final ITerminalHost host;
|
private final ITerminalHost host;
|
||||||
@GuiSync(99)
|
@GuiSync(99)
|
||||||
@@ -357,7 +357,7 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa
|
|||||||
this.hasPower = isPowered;
|
this.hasPower = isPowered;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IConfigManagerHost getGui() {
|
protected IConfigManagerHost getGui() {
|
||||||
return this.gui;
|
return this.gui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,15 @@ import appeng.api.storage.data.IAEItemStack;
|
|||||||
import appeng.api.storage.data.IItemList;
|
import appeng.api.storage.data.IItemList;
|
||||||
import appeng.container.ContainerNull;
|
import appeng.container.ContainerNull;
|
||||||
import appeng.container.guisync.GuiSync;
|
import appeng.container.guisync.GuiSync;
|
||||||
import appeng.container.slot.*;
|
import appeng.container.slot.AppEngSlot;
|
||||||
|
import appeng.container.slot.IOptionalSlotHost;
|
||||||
|
import appeng.container.slot.OptionalSlotFake;
|
||||||
|
import appeng.container.slot.SlotFakeCraftingMatrix;
|
||||||
|
import appeng.container.slot.SlotPatternOutputs;
|
||||||
|
import appeng.container.slot.SlotPatternTerm;
|
||||||
|
import appeng.container.slot.SlotPlayerHotBar;
|
||||||
|
import appeng.container.slot.SlotPlayerInv;
|
||||||
|
import appeng.container.slot.SlotRestrictedInput;
|
||||||
import appeng.core.sync.packets.PacketPatternSlot;
|
import appeng.core.sync.packets.PacketPatternSlot;
|
||||||
import appeng.helpers.IContainerCraftingPacket;
|
import appeng.helpers.IContainerCraftingPacket;
|
||||||
import appeng.items.storage.ItemViewCell;
|
import appeng.items.storage.ItemViewCell;
|
||||||
@@ -46,7 +54,11 @@ import appeng.util.item.AEItemStack;
|
|||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.entity.player.InventoryPlayer;
|
import net.minecraft.entity.player.InventoryPlayer;
|
||||||
import net.minecraft.inventory.*;
|
import net.minecraft.inventory.IContainerListener;
|
||||||
|
import net.minecraft.inventory.InventoryCraftResult;
|
||||||
|
import net.minecraft.inventory.InventoryCrafting;
|
||||||
|
import net.minecraft.inventory.Slot;
|
||||||
|
import net.minecraft.inventory.SlotCrafting;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.crafting.CraftingManager;
|
import net.minecraft.item.crafting.CraftingManager;
|
||||||
import net.minecraft.item.crafting.IRecipe;
|
import net.minecraft.item.crafting.IRecipe;
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package appeng.integration.modules.jei;
|
||||||
|
|
||||||
|
import appeng.api.storage.data.IAEItemStack;
|
||||||
|
import appeng.api.storage.data.IItemList;
|
||||||
|
import appeng.container.AEBaseContainer;
|
||||||
|
import appeng.core.sync.network.NetworkHandler;
|
||||||
|
import appeng.core.sync.packets.PacketInventoryAction;
|
||||||
|
import appeng.helpers.InventoryAction;
|
||||||
|
import appeng.util.item.AEItemStack;
|
||||||
|
import mezz.jei.api.gui.ITooltipCallback;
|
||||||
|
import net.minecraft.inventory.Container;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.text.translation.I18n;
|
||||||
|
import org.lwjgl.input.Mouse;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CraftableCallBack implements ITooltipCallback<ItemStack> {
|
||||||
|
private final IItemList<IAEItemStack> list;
|
||||||
|
private final Container container;
|
||||||
|
|
||||||
|
public CraftableCallBack(Container container, IItemList<IAEItemStack> ir) {
|
||||||
|
this.list = ir;
|
||||||
|
this.container = container;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTooltip(int slotIndex, boolean input, ItemStack ingredient, List<String> tooltip) {
|
||||||
|
if (list != null) {
|
||||||
|
AEItemStack stack = AEItemStack.fromItemStack(ingredient);
|
||||||
|
if (list.findPrecise(stack) != null) {
|
||||||
|
tooltip.add(I18n.translateToLocalFormatted("gui.tooltips.appliedenergistics2.Craftable"));
|
||||||
|
if (Mouse.isButtonDown(2)) {
|
||||||
|
((AEBaseContainer) container).setTargetStack(stack);
|
||||||
|
final PacketInventoryAction p = new PacketInventoryAction(InventoryAction.AUTO_CRAFT, container.getInventory().size(), 0);
|
||||||
|
NetworkHandler.instance().sendToServer(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,19 +1,81 @@
|
|||||||
package appeng.integration.modules.jei;
|
package appeng.integration.modules.jei;
|
||||||
|
|
||||||
|
import appeng.api.config.FuzzyMode;
|
||||||
|
import appeng.api.storage.data.IAEItemStack;
|
||||||
|
import appeng.api.storage.data.IItemList;
|
||||||
|
import appeng.client.gui.implementations.GuiCraftingTerm;
|
||||||
|
import appeng.client.gui.implementations.GuiPatternTerm;
|
||||||
|
import appeng.container.implementations.ContainerCraftingTerm;
|
||||||
import appeng.container.implementations.ContainerPatternTerm;
|
import appeng.container.implementations.ContainerPatternTerm;
|
||||||
|
import appeng.util.Platform;
|
||||||
|
import appeng.util.item.AEItemStack;
|
||||||
import mezz.jei.api.gui.IGuiIngredient;
|
import mezz.jei.api.gui.IGuiIngredient;
|
||||||
import mezz.jei.api.gui.IRecipeLayout;
|
import mezz.jei.api.gui.IRecipeLayout;
|
||||||
import mezz.jei.api.recipe.transfer.IRecipeTransferError;
|
import mezz.jei.api.recipe.transfer.IRecipeTransferError;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.inventory.Container;
|
import net.minecraft.inventory.Container;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
import static mezz.jei.api.recipe.transfer.IRecipeTransferError.Type.USER_FACING;
|
import static mezz.jei.api.recipe.transfer.IRecipeTransferError.Type.USER_FACING;
|
||||||
|
|
||||||
public class JEIMissingItem implements IRecipeTransferError {
|
public class JEIMissingItem implements IRecipeTransferError {
|
||||||
|
|
||||||
|
private boolean errored;
|
||||||
|
|
||||||
|
JEIMissingItem(Container container, @Nonnull IRecipeLayout recipeLayout) {
|
||||||
|
if (container instanceof ContainerCraftingTerm) {
|
||||||
|
ContainerCraftingTerm craftingTerm = (ContainerCraftingTerm) container;
|
||||||
|
GuiCraftingTerm g = (GuiCraftingTerm) craftingTerm.getGui();
|
||||||
|
|
||||||
|
IItemList<IAEItemStack> ir = g.getRepo().getList();
|
||||||
|
boolean found;
|
||||||
|
this.errored = false;
|
||||||
|
|
||||||
|
recipeLayout.getItemStacks().addTooltipCallback(new CraftableCallBack(container, ir));
|
||||||
|
|
||||||
|
for (IGuiIngredient<?> i : recipeLayout.getItemStacks().getGuiIngredients().values()) {
|
||||||
|
found = false;
|
||||||
|
if (i.isInput() && i.getAllIngredients().size() > 0) {
|
||||||
|
for (Object o : i.getAllIngredients()) {
|
||||||
|
if (o instanceof ItemStack) {
|
||||||
|
ItemStack stack = (ItemStack) o;
|
||||||
|
if (!stack.isEmpty()) {
|
||||||
|
if (stack.getItem().isDamageable() || Platform.isGTDamageableItem(stack.getItem())) {
|
||||||
|
Collection<IAEItemStack> fuzzy = ir.findFuzzy(AEItemStack.fromItemStack(stack), FuzzyMode.IGNORE_ALL);
|
||||||
|
if (fuzzy.size() > 0) {
|
||||||
|
for (IAEItemStack itemStack : fuzzy) {
|
||||||
|
if (itemStack.getStackSize() > 0) {
|
||||||
|
if (itemStack.isSameType(stack)) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
IAEItemStack ext = ir.findPrecise(AEItemStack.fromItemStack(stack));
|
||||||
|
if (ext != null) {
|
||||||
|
if (ext.getStackSize() > 0) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
this.errored = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Type getType() {
|
public Type getType() {
|
||||||
@@ -23,10 +85,70 @@ public class JEIMissingItem implements IRecipeTransferError {
|
|||||||
@Override
|
@Override
|
||||||
public void showError(Minecraft minecraft, int mouseX, int mouseY, @Nonnull IRecipeLayout recipeLayout, int recipeX, int recipeY) {
|
public void showError(Minecraft minecraft, int mouseX, int mouseY, @Nonnull IRecipeLayout recipeLayout, int recipeX, int recipeY) {
|
||||||
Container c = minecraft.player.openContainer;
|
Container c = minecraft.player.openContainer;
|
||||||
if (c instanceof ContainerPatternTerm) {
|
if (c instanceof ContainerCraftingTerm) {
|
||||||
|
ContainerCraftingTerm craftingTerm = (ContainerCraftingTerm) c;
|
||||||
|
GuiCraftingTerm g = (GuiCraftingTerm) craftingTerm.getGui();
|
||||||
|
|
||||||
|
IItemList<IAEItemStack> ir = g.getRepo().getList();
|
||||||
|
boolean found;
|
||||||
|
boolean craftable;
|
||||||
|
this.errored = false;
|
||||||
|
|
||||||
for (IGuiIngredient<?> i : recipeLayout.getItemStacks().getGuiIngredients().values()) {
|
for (IGuiIngredient<?> i : recipeLayout.getItemStacks().getGuiIngredients().values()) {
|
||||||
i.drawHighlight(minecraft, new Color(1.0f, 0.0f, 0.0f, 0.4f), recipeX, recipeY);
|
found = false;
|
||||||
|
craftable = false;
|
||||||
|
if (i.isInput() && i.getAllIngredients().size() > 0) {
|
||||||
|
for (Object o : i.getAllIngredients()) {
|
||||||
|
if (o instanceof ItemStack) {
|
||||||
|
ItemStack stack = (ItemStack) o;
|
||||||
|
if (!stack.isEmpty()) {
|
||||||
|
if (stack.getItem().isDamageable() || Platform.isGTDamageableItem(stack.getItem())) {
|
||||||
|
Collection<IAEItemStack> fuzzy = ir.findFuzzy(AEItemStack.fromItemStack(stack), FuzzyMode.IGNORE_ALL);
|
||||||
|
if (fuzzy.size() > 0) {
|
||||||
|
for (IAEItemStack itemStack : fuzzy) {
|
||||||
|
if (itemStack.getStackSize() > 0) {
|
||||||
|
if (itemStack.fuzzyComparison(AEItemStack.fromItemStack(stack), FuzzyMode.IGNORE_ALL)) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (itemStack.isCraftable()) {
|
||||||
|
craftable = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
IAEItemStack ext = ir.findPrecise(AEItemStack.fromItemStack(stack));
|
||||||
|
if (ext != null) {
|
||||||
|
if (ext.getStackSize() > 0) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
if (ext.isCraftable()) {
|
||||||
|
craftable = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
if (craftable) {
|
||||||
|
i.drawHighlight(minecraft, new Color(0.0f, 0.0f, 1.0f, 0.4f), recipeX, recipeY);
|
||||||
|
} else {
|
||||||
|
i.drawHighlight(minecraft, new Color(1.0f, 0.0f, 0.0f, 0.4f), recipeX, recipeY);
|
||||||
|
}
|
||||||
|
this.errored = true;
|
||||||
|
} else {
|
||||||
|
this.errored = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean errored() {
|
||||||
|
return this.errored;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
package appeng.integration.modules.jei;
|
package appeng.integration.modules.jei;
|
||||||
|
|
||||||
|
|
||||||
|
import appeng.container.implementations.ContainerCraftingTerm;
|
||||||
import appeng.container.implementations.ContainerPatternTerm;
|
import appeng.container.implementations.ContainerPatternTerm;
|
||||||
import appeng.container.slot.SlotCraftingMatrix;
|
import appeng.container.slot.SlotCraftingMatrix;
|
||||||
import appeng.container.slot.SlotFakeCraftingMatrix;
|
import appeng.container.slot.SlotFakeCraftingMatrix;
|
||||||
@@ -70,8 +71,10 @@ class RecipeTransferHandler<T extends Container> implements IRecipeTransferHandl
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!doTransfer) {
|
if (!doTransfer) {
|
||||||
if (recipeType.equals(VanillaRecipeCategoryUid.CRAFTING)) {
|
if (container instanceof ContainerCraftingTerm && recipeType.equals(VanillaRecipeCategoryUid.CRAFTING)) {
|
||||||
return new JEIMissingItem();
|
JEIMissingItem error = new JEIMissingItem(container, recipeLayout);
|
||||||
|
if (error.errored())
|
||||||
|
return error;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user