some JEI work. missing player inventory check
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package appeng.integration.modules.jei;
|
package appeng.integration.modules.jei;
|
||||||
|
|
||||||
|
import appeng.api.AEApi;
|
||||||
import appeng.api.storage.data.IAEItemStack;
|
import appeng.api.storage.data.IAEItemStack;
|
||||||
import appeng.api.storage.data.IItemList;
|
import appeng.api.storage.data.IItemList;
|
||||||
import appeng.container.AEBaseContainer;
|
import appeng.container.AEBaseContainer;
|
||||||
@@ -7,17 +8,22 @@ import appeng.core.sync.network.NetworkHandler;
|
|||||||
import appeng.core.sync.packets.PacketInventoryAction;
|
import appeng.core.sync.packets.PacketInventoryAction;
|
||||||
import appeng.helpers.InventoryAction;
|
import appeng.helpers.InventoryAction;
|
||||||
import appeng.util.item.AEItemStack;
|
import appeng.util.item.AEItemStack;
|
||||||
|
import com.google.common.base.Stopwatch;
|
||||||
import mezz.jei.api.gui.ITooltipCallback;
|
import mezz.jei.api.gui.ITooltipCallback;
|
||||||
import net.minecraft.inventory.Container;
|
import net.minecraft.inventory.Container;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.text.TextFormatting;
|
||||||
import net.minecraft.util.text.translation.I18n;
|
import net.minecraft.util.text.translation.I18n;
|
||||||
import org.lwjgl.input.Mouse;
|
import org.lwjgl.input.Mouse;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class CraftableCallBack implements ITooltipCallback<ItemStack> {
|
public class CraftableCallBack implements ITooltipCallback<ItemStack> {
|
||||||
private final IItemList<IAEItemStack> list;
|
private final IItemList<IAEItemStack> list;
|
||||||
private final Container container;
|
private final Container container;
|
||||||
|
private final Stopwatch lastClicked = Stopwatch.createStarted();
|
||||||
|
|
||||||
|
|
||||||
public CraftableCallBack(Container container, IItemList<IAEItemStack> ir) {
|
public CraftableCallBack(Container container, IItemList<IAEItemStack> ir) {
|
||||||
this.list = ir;
|
this.list = ir;
|
||||||
@@ -26,18 +32,27 @@ public class CraftableCallBack implements ITooltipCallback<ItemStack> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTooltip(int slotIndex, boolean input, ItemStack ingredient, List<String> tooltip) {
|
public void onTooltip(int slotIndex, boolean input, ItemStack ingredient, List<String> tooltip) {
|
||||||
|
if (!input) return;
|
||||||
if (list != null) {
|
if (list != null) {
|
||||||
AEItemStack stack = AEItemStack.fromItemStack(ingredient);
|
IAEItemStack found = list.findPrecise(AEItemStack.fromItemStack(ingredient));
|
||||||
if (list.findPrecise(stack) != null) {
|
if (found != null) {
|
||||||
tooltip.add(I18n.translateToLocalFormatted("gui.appliedenergistics2.Missing"));
|
if (found.getStackSize() == 0) {
|
||||||
tooltip.add(I18n.translateToLocalFormatted("gui.tooltips.appliedenergistics2.Craftable"));
|
String line = "§c[" + I18n.translateToLocalFormatted("gui.appliedenergistics2.Missing") + "]";
|
||||||
if (Mouse.isButtonDown(2)) {
|
tooltip.add(line);
|
||||||
((AEBaseContainer) container).setTargetStack(stack);
|
}
|
||||||
final PacketInventoryAction p = new PacketInventoryAction(InventoryAction.AUTO_CRAFT, container.getInventory().size(), 0);
|
if (found.isCraftable()) {
|
||||||
NetworkHandler.instance().sendToServer(p);
|
String line = "§1[" + I18n.translateToLocalFormatted("gui.tooltips.appliedenergistics2.Craftable") + "]";
|
||||||
|
tooltip.add(line);
|
||||||
|
if (Mouse.isButtonDown(2) && this.lastClicked.elapsed(TimeUnit.MILLISECONDS) > 200) {
|
||||||
|
this.lastClicked.reset().start();
|
||||||
|
((AEBaseContainer) container).setTargetStack(found);
|
||||||
|
final PacketInventoryAction p = new PacketInventoryAction(InventoryAction.AUTO_CRAFT, container.getInventory().size(), 0);
|
||||||
|
NetworkHandler.instance().sendToServer(p);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tooltip.add(I18n.translateToLocalFormatted("gui.appliedenergistics2.Missing"));
|
String line = "§c[" + I18n.translateToLocalFormatted("gui.appliedenergistics2.Missing") + "]";
|
||||||
|
tooltip.add(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package appeng.integration.modules.jei;
|
package appeng.integration.modules.jei;
|
||||||
|
|
||||||
|
import appeng.api.AEApi;
|
||||||
import appeng.api.config.FuzzyMode;
|
import appeng.api.config.FuzzyMode;
|
||||||
|
import appeng.api.storage.channels.IItemStorageChannel;
|
||||||
import appeng.api.storage.data.IAEItemStack;
|
import appeng.api.storage.data.IAEItemStack;
|
||||||
import appeng.api.storage.data.IItemList;
|
import appeng.api.storage.data.IItemList;
|
||||||
import appeng.client.gui.implementations.GuiCraftingTerm;
|
import appeng.client.gui.implementations.GuiCraftingTerm;
|
||||||
@@ -17,7 +19,10 @@ import net.minecraft.item.ItemStack;
|
|||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static mezz.jei.api.recipe.transfer.IRecipeTransferError.Type.USER_FACING;
|
import static mezz.jei.api.recipe.transfer.IRecipeTransferError.Type.USER_FACING;
|
||||||
|
|
||||||
@@ -33,15 +38,16 @@ public class JEIMissingItem implements IRecipeTransferError {
|
|||||||
IItemList<IAEItemStack> ir = g.getRepo().getList();
|
IItemList<IAEItemStack> ir = g.getRepo().getList();
|
||||||
boolean found;
|
boolean found;
|
||||||
this.errored = false;
|
this.errored = false;
|
||||||
|
|
||||||
recipeLayout.getItemStacks().addTooltipCallback(new CraftableCallBack(container, ir));
|
recipeLayout.getItemStacks().addTooltipCallback(new CraftableCallBack(container, ir));
|
||||||
|
|
||||||
|
IItemList<IAEItemStack> used = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
||||||
for (IGuiIngredient<?> i : recipeLayout.getItemStacks().getGuiIngredients().values()) {
|
for (IGuiIngredient<?> i : recipeLayout.getItemStacks().getGuiIngredients().values()) {
|
||||||
found = false;
|
found = false;
|
||||||
if (i.isInput() && i.getAllIngredients().size() > 0) {
|
if (i.isInput() && i.getAllIngredients().size() > 0) {
|
||||||
for (Object o : i.getAllIngredients()) {
|
List<?> allIngredients = i.getAllIngredients();
|
||||||
if (o instanceof ItemStack) {
|
for (Object allIngredient : allIngredients) {
|
||||||
ItemStack stack = (ItemStack) o;
|
if (allIngredient instanceof ItemStack) {
|
||||||
|
ItemStack stack = (ItemStack) allIngredient;
|
||||||
if (!stack.isEmpty()) {
|
if (!stack.isEmpty()) {
|
||||||
if (stack.getItem().isDamageable() || Platform.isGTDamageableItem(stack.getItem())) {
|
if (stack.getItem().isDamageable() || Platform.isGTDamageableItem(stack.getItem())) {
|
||||||
Collection<IAEItemStack> fuzzy = ir.findFuzzy(AEItemStack.fromItemStack(stack), FuzzyMode.IGNORE_ALL);
|
Collection<IAEItemStack> fuzzy = ir.findFuzzy(AEItemStack.fromItemStack(stack), FuzzyMode.IGNORE_ALL);
|
||||||
@@ -58,9 +64,12 @@ public class JEIMissingItem implements IRecipeTransferError {
|
|||||||
} else {
|
} else {
|
||||||
IAEItemStack ext = ir.findPrecise(AEItemStack.fromItemStack(stack));
|
IAEItemStack ext = ir.findPrecise(AEItemStack.fromItemStack(stack));
|
||||||
if (ext != null) {
|
if (ext != null) {
|
||||||
if (ext.getStackSize() > 0) {
|
IAEItemStack usedStack = used.findPrecise(ext);
|
||||||
|
if (ext.getStackSize() > 0 && (usedStack == null || ext.getStackSize() > usedStack.getStackSize())) {
|
||||||
|
used.add(ext.copy().setStackSize(1));
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
} else {
|
||||||
|
found = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -69,6 +78,7 @@ public class JEIMissingItem implements IRecipeTransferError {
|
|||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
this.errored = true;
|
this.errored = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -91,15 +101,19 @@ public class JEIMissingItem implements IRecipeTransferError {
|
|||||||
IItemList<IAEItemStack> ir = g.getRepo().getList();
|
IItemList<IAEItemStack> ir = g.getRepo().getList();
|
||||||
boolean found;
|
boolean found;
|
||||||
boolean craftable;
|
boolean craftable;
|
||||||
|
int currentSlot = 0;
|
||||||
this.errored = false;
|
this.errored = false;
|
||||||
|
IItemList<IAEItemStack> used = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
||||||
|
|
||||||
for (IGuiIngredient<?> i : recipeLayout.getItemStacks().getGuiIngredients().values()) {
|
for (IGuiIngredient<?> i : recipeLayout.getItemStacks().getGuiIngredients().values()) {
|
||||||
found = false;
|
found = false;
|
||||||
craftable = false;
|
craftable = false;
|
||||||
|
List<ItemStack> valid = new ArrayList<>();
|
||||||
if (i.isInput() && i.getAllIngredients().size() > 0) {
|
if (i.isInput() && i.getAllIngredients().size() > 0) {
|
||||||
for (Object o : i.getAllIngredients()) {
|
List<?> allIngredients = i.getAllIngredients();
|
||||||
if (o instanceof ItemStack) {
|
for (Object allIngredient : allIngredients) {
|
||||||
ItemStack stack = (ItemStack) o;
|
if (allIngredient instanceof ItemStack) {
|
||||||
|
ItemStack stack = (ItemStack) allIngredient;
|
||||||
if (!stack.isEmpty()) {
|
if (!stack.isEmpty()) {
|
||||||
if (stack.getItem().isDamageable() || Platform.isGTDamageableItem(stack.getItem())) {
|
if (stack.getItem().isDamageable() || Platform.isGTDamageableItem(stack.getItem())) {
|
||||||
Collection<IAEItemStack> fuzzy = ir.findFuzzy(AEItemStack.fromItemStack(stack), FuzzyMode.IGNORE_ALL);
|
Collection<IAEItemStack> fuzzy = ir.findFuzzy(AEItemStack.fromItemStack(stack), FuzzyMode.IGNORE_ALL);
|
||||||
@@ -108,6 +122,8 @@ public class JEIMissingItem implements IRecipeTransferError {
|
|||||||
if (itemStack.getStackSize() > 0) {
|
if (itemStack.getStackSize() > 0) {
|
||||||
if (itemStack.fuzzyComparison(AEItemStack.fromItemStack(stack), FuzzyMode.IGNORE_ALL)) {
|
if (itemStack.fuzzyComparison(AEItemStack.fromItemStack(stack), FuzzyMode.IGNORE_ALL)) {
|
||||||
found = true;
|
found = true;
|
||||||
|
used.add(itemStack.copy().setStackSize(1));
|
||||||
|
valid.addAll(fuzzy.stream().map(IAEItemStack::createItemStack).collect(Collectors.toList()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -120,29 +136,38 @@ public class JEIMissingItem implements IRecipeTransferError {
|
|||||||
} else {
|
} else {
|
||||||
IAEItemStack ext = ir.findPrecise(AEItemStack.fromItemStack(stack));
|
IAEItemStack ext = ir.findPrecise(AEItemStack.fromItemStack(stack));
|
||||||
if (ext != null) {
|
if (ext != null) {
|
||||||
if (ext.getStackSize() > 0) {
|
IAEItemStack usedStack = used.findPrecise(ext);
|
||||||
break;
|
if (ext.getStackSize() > 0 && (usedStack == null || usedStack.getStackSize() < ext.getStackSize())) {
|
||||||
} else {
|
used.add(ext.copy().setStackSize(1));
|
||||||
if (ext.isCraftable()) {
|
if (craftable) {
|
||||||
craftable = true;
|
valid.clear();
|
||||||
}
|
}
|
||||||
|
valid.add(ext.copy().setStackSize(1).createItemStack());
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
} else if (ext.isCraftable()) {
|
||||||
|
valid.add(ext.copy().setStackSize(1).createItemStack());
|
||||||
|
craftable = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
}
|
||||||
if (craftable) {
|
if (!found) {
|
||||||
i.drawHighlight(minecraft, new Color(0.0f, 0.0f, 1.0f, 0.4f), recipeX, recipeY);
|
if (craftable) {
|
||||||
} else {
|
i.drawHighlight(minecraft, new Color(0.0f, 0.0f, 1.0f, 0.4f), recipeX, recipeY);
|
||||||
i.drawHighlight(minecraft, new Color(1.0f, 0.0f, 0.0f, 0.4f), recipeX, recipeY);
|
recipeLayout.getItemStacks().set(currentSlot, valid);
|
||||||
}
|
|
||||||
this.errored = true;
|
|
||||||
} else {
|
} else {
|
||||||
this.errored = false;
|
i.drawHighlight(minecraft, new Color(1.0f, 0.0f, 0.0f, 0.4f), recipeX, recipeY);
|
||||||
}
|
}
|
||||||
|
this.errored = true;
|
||||||
|
} else {
|
||||||
|
recipeLayout.getItemStacks().set(currentSlot, valid);
|
||||||
|
this.errored = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
currentSlot++;
|
||||||
}
|
}
|
||||||
if (!this.errored) {
|
if (!this.errored) {
|
||||||
((RecipeLayout) recipeLayout).getRecipeTransferButton().init(Minecraft.getMinecraft().player.openContainer, Minecraft.getMinecraft().player);
|
((RecipeLayout) recipeLayout).getRecipeTransferButton().init(Minecraft.getMinecraft().player.openContainer, Minecraft.getMinecraft().player);
|
||||||
|
|||||||
Reference in New Issue
Block a user