mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-10-26 14:24:07 +00:00
Create normalizeRecipeQueryStack (#772)
Co-authored-by: Martin Robertz <dream-master@gmx.net>
This commit is contained in:
1 parent
adc5a5df16
commit
ef8a7d8bd5
5 files changed
+46
-34
No files matched your search
@@ -18,6 +18,10 @@ public interface IStackStringifyHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
default ItemStack normalizeRecipeQueryStack(ItemStack stack) {
|
||||
return null;
|
||||
}
|
||||
|
||||
default void pauseItemDamageSound(boolean pause) {}
|
||||
|
||||
}
|
||||
@@ -20,7 +20,6 @@ import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.bookmark.BookmarksGridSlot;
|
||||
import codechicken.nei.recipe.Recipe.RecipeId;
|
||||
import codechicken.nei.recipe.stackinfo.GTFluidStackStringifyHandler;
|
||||
|
||||
public class GuiCraftingRecipe extends GuiRecipe<ICraftingHandler> {
|
||||
|
||||
@@ -36,10 +35,13 @@ public class GuiCraftingRecipe extends GuiRecipe<ICraftingHandler> {
|
||||
final Minecraft mc = NEIClientUtils.mc();
|
||||
final RecipeId recipeId;
|
||||
|
||||
if ("item".equals(outputId)) {
|
||||
for (int i = 0; i < results.length; i++) {
|
||||
results[i] = normalizeItemStack((ItemStack) results[i]);
|
||||
for (int i = 0; i < results.length; i++) {
|
||||
if (results[i] instanceof ItemStack stack) {
|
||||
results[i] = StackInfo.normalizeRecipeQueryStack(stack.copy());
|
||||
}
|
||||
}
|
||||
|
||||
if ("item".equals(outputId)) {
|
||||
recipeId = getRecipeId(mc.currentScreen, (ItemStack) results[0]);
|
||||
} else if ("recipeId".equals(outputId)) {
|
||||
recipeId = (RecipeId) results[1];
|
||||
@@ -105,13 +107,6 @@ public class GuiCraftingRecipe extends GuiRecipe<ICraftingHandler> {
|
||||
return GuiRecipeTab.getHandlerInfo(handler).getHandlerName();
|
||||
}
|
||||
|
||||
private static ItemStack normalizeItemStack(ItemStack stack) {
|
||||
GTFluidStackStringifyHandler.replaceAE2FCFluidDrop = true;
|
||||
stack = StackInfo.loadFromNBT(StackInfo.itemStackToNBT(stack));
|
||||
GTFluidStackStringifyHandler.replaceAE2FCFluidDrop = false;
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static RecipeId getRecipeId(GuiScreen gui, ItemStack stackover) {
|
||||
|
||||
if (gui instanceof GuiRecipe guiRecipe) {
|
||||
|
||||
@@ -12,7 +12,6 @@ import codechicken.nei.ItemPanels;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.recipe.Recipe.RecipeId;
|
||||
import codechicken.nei.recipe.stackinfo.GTFluidStackStringifyHandler;
|
||||
|
||||
public class GuiUsageRecipe extends GuiRecipe<IUsageHandler> {
|
||||
|
||||
@@ -22,9 +21,9 @@ public class GuiUsageRecipe extends GuiRecipe<IUsageHandler> {
|
||||
|
||||
public static boolean openRecipeGui(String inputId, Object... ingredients) {
|
||||
|
||||
if ("item".equals(inputId)) {
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
ingredients[i] = normalizeItemStack((ItemStack) ingredients[i]);
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
if (ingredients[i] instanceof ItemStack stack) {
|
||||
ingredients[i] = StackInfo.normalizeRecipeQueryStack(stack.copy());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,13 +65,6 @@ public class GuiUsageRecipe extends GuiRecipe<IUsageHandler> {
|
||||
return recipeQuery.runWithProfiling(NEIClientUtils.translate("recipe.concurrent.usage"));
|
||||
}
|
||||
|
||||
private static ItemStack normalizeItemStack(ItemStack stack) {
|
||||
GTFluidStackStringifyHandler.replaceAE2FCFluidDrop = true;
|
||||
stack = StackInfo.loadFromNBT(StackInfo.itemStackToNBT(stack));
|
||||
GTFluidStackStringifyHandler.replaceAE2FCFluidDrop = false;
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static void registerUsageHandler(IUsageHandler handler) {
|
||||
final String handlerId = handler.getHandlerId();
|
||||
|
||||
|
||||
@@ -76,6 +76,16 @@ public class StackInfo {
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static ItemStack normalizeRecipeQueryStack(ItemStack stack) {
|
||||
ItemStack result = null;
|
||||
|
||||
for (int i = stackStringifyHandlers.size() - 1; i >= 0 && result == null; i--) {
|
||||
result = stackStringifyHandlers.get(i).normalizeRecipeQueryStack(stack);
|
||||
}
|
||||
|
||||
return result == null ? stack : result;
|
||||
}
|
||||
|
||||
public static void pauseItemDamageSound(boolean pause) {
|
||||
if (isPausedItemDamageSound != (isPausedItemDamageSound = pause)) {
|
||||
for (IStackStringifyHandler handler : stackStringifyHandlers) {
|
||||
|
||||
@@ -19,9 +19,8 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler {
|
||||
protected static Class<?> itemFluidDisplay = null;
|
||||
protected static Method getFluidDisplayStack = null;
|
||||
protected static Method getFluidFromDisplayStack = null;
|
||||
public static boolean replaceAE2FCFluidDrop = false;
|
||||
private static Class<?> gtMetaGeneratedTool = null;
|
||||
private static Field playSound = null;
|
||||
protected static Class<?> gtMetaGeneratedTool = null;
|
||||
protected static Field playSound = null;
|
||||
|
||||
static {
|
||||
try {
|
||||
@@ -48,7 +47,7 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler {
|
||||
|
||||
public NBTTagCompound convertItemStackToNBT(ItemStack stack, boolean saveStackSize) {
|
||||
|
||||
if (replaceAE2FCFluidDrop || stack.getItem() != GameRegistry.findItem("ae2fc", "fluid_drop")) {
|
||||
if (stack.getItem() != GameRegistry.findItem("ae2fc", "fluid_drop")) {
|
||||
final FluidStack fluidStack = getFluid(stack);
|
||||
|
||||
if (fluidStack != null) {
|
||||
@@ -69,14 +68,11 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler {
|
||||
final Fluid fluid = FluidRegistry.getFluid(fluidName);
|
||||
final int amount = nbtTag.getInteger("Count");
|
||||
|
||||
try {
|
||||
final Object obj = getFluidDisplayStack.invoke(null, new FluidStack(fluid, amount), true);
|
||||
|
||||
if (obj != null) {
|
||||
return (ItemStack) obj;
|
||||
}
|
||||
|
||||
} catch (Exception e) {}
|
||||
if (fluid != null) {
|
||||
try {
|
||||
return (ItemStack) getFluidDisplayStack.invoke(null, new FluidStack(fluid, amount), true);
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -114,6 +110,21 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ItemStack normalizeRecipeQueryStack(ItemStack stack) {
|
||||
|
||||
if (stack.getItem() == GameRegistry.findItem("ae2fc", "fluid_drop")) {
|
||||
final FluidStack fluidStack = getFluid(stack);
|
||||
|
||||
if (fluidStack != null) {
|
||||
try {
|
||||
return (ItemStack) getFluidDisplayStack.invoke(null, fluidStack, true);
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pauseItemDamageSound(boolean pause) {
|
||||
if (playSound != null) {
|
||||
|
||||
Reference in new issue
Block a user