update NEI version

This commit is contained in:
slprime committed 2025-03-27 15:55:43 +02:00
1 parent 46b4319bf6
commit 73614a286f
20 files changed
+644 -416

No files matched your search

@@ -15,11 +15,12 @@ import net.minecraftforge.oredict.OreDictionary;
import com.github.vfyjxf.nee.config.ItemCombination;
import com.github.vfyjxf.nee.config.NEEConfig;
import com.github.vfyjxf.nee.nei.NEEGuiOverlayButton.NEEItemOverlayState;
import com.github.vfyjxf.nee.nei.NEETerminalOverlayButton.NEEItemOverlayState;
import com.github.vfyjxf.nee.network.NEENetworkHandler;
import com.github.vfyjxf.nee.network.packet.PacketNEIPatternRecipe;
import com.github.vfyjxf.nee.processor.IRecipeProcessor;
import com.github.vfyjxf.nee.processor.RecipeProcessor;
import com.github.vfyjxf.nee.utils.GuiUtils;
import com.github.vfyjxf.nee.utils.Ingredient;
import com.github.vfyjxf.nee.utils.IngredientTracker;
import com.github.vfyjxf.nee.utils.ItemUtils;
@@ -27,11 +28,12 @@ import com.github.vfyjxf.nee.utils.ModIDs;
import com.glodblock.github.nei.FluidPatternTerminalRecipeTransferHandler;
import appeng.util.Platform;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
import codechicken.nei.api.IOverlayHandler;
import codechicken.nei.recipe.GuiOverlayButton;
import codechicken.nei.recipe.GuiOverlayButton.ItemOverlayState;
import codechicken.nei.recipe.GuiRecipe;
import codechicken.nei.recipe.GuiRecipeButton;
import codechicken.nei.recipe.IRecipeHandler;
import codechicken.nei.recipe.TemplateRecipeHandler;
import cpw.mods.fml.common.Loader;
@@ -45,20 +47,30 @@ public class NEEPatternTerminalHandler implements IOverlayHandler {
public static final String INPUT_KEY = "#";
public static final String OUTPUT_KEY = "Outputs";
public static Map<String, PositionedStack> ingredients = new HashMap<>();// Add the function of mouse wheel to
// switch materials
// Add the function of mouse wheel to switch materials
public static Map<String, PositionedStack> ingredients = new HashMap<>();
public static final NEEPatternTerminalHandler instance = new NEEPatternTerminalHandler();
private NEEPatternTerminalHandler() {}
@Override
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
NEENetworkHandler.getInstance().sendToServer(packRecipe(recipe, recipeIndex));
public void overlayRecipe(GuiContainer gui, IRecipeHandler handler, int recipeIndex, boolean shift) {
transferRecipe(gui, handler, recipeIndex, 1);
}
if (Loader.isModLoaded(ModIDs.FC)) {
fluidCraftOverlayRecipe(firstGui, recipe, recipeIndex, shift);
@Override
public int transferRecipe(GuiContainer gui, IRecipeHandler handler, int recipeIndex, int multiplier) {
multiplier = Math.max(1, multiplier);
NEENetworkHandler.getInstance().sendToServer(packRecipe(handler, recipeIndex, multiplier));
if (Loader.isModLoaded(ModIDs.FC) && GuiUtils.isFluidCraftPatternTermEx(gui)) {
fluidCraftOverlayRecipe(gui, handler, recipeIndex, multiplier);
}
return 0;
}
@Override
@@ -74,21 +86,21 @@ public class NEEPatternTerminalHandler implements IOverlayHandler {
}
@Optional.Method(modid = ModIDs.FC)
private void fluidCraftOverlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
FluidPatternTerminalRecipeTransferHandler.INSTANCE.overlayRecipe(firstGui, recipe, recipeIndex, shift);
private void fluidCraftOverlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex,
int multiplier) {
FluidPatternTerminalRecipeTransferHandler.INSTANCE.transferRecipe(firstGui, recipe, recipeIndex, multiplier);
}
private PacketNEIPatternRecipe packRecipe(IRecipeHandler recipe, int recipeIndex) {
private PacketNEIPatternRecipe packRecipe(IRecipeHandler recipe, int recipeIndex, int multiplier) {
if (isCraftingTableRecipe(recipe)) {
return packCraftingTableRecipe(recipe, recipeIndex);
} else {
return packProcessRecipe(recipe, recipeIndex);
return packProcessRecipe(recipe, recipeIndex, (int) multiplier);
}
}
private boolean isCraftingTableRecipe(IRecipeHandler recipe) {
if (recipe instanceof TemplateRecipeHandler) {
TemplateRecipeHandler templateRecipeHandler = (TemplateRecipeHandler) recipe;
if (recipe instanceof TemplateRecipeHandler templateRecipeHandler) {
String overlayIdentifier = templateRecipeHandler.getOverlayIdentifier();
return "crafting".equals(overlayIdentifier) || "crafting2x2".equals(overlayIdentifier);
} else {
@@ -96,7 +108,7 @@ public class NEEPatternTerminalHandler implements IOverlayHandler {
}
}
private PacketNEIPatternRecipe packProcessRecipe(IRecipeHandler recipe, int recipeIndex) {
private PacketNEIPatternRecipe packProcessRecipe(IRecipeHandler recipe, int recipeIndex, int multiplier) {
final NBTTagCompound recipeInputs = new NBTTagCompound();
final NBTTagCompound recipeOutputs = new NBTTagCompound();
String identifier = recipe instanceof TemplateRecipeHandler ? recipe.getOverlayIdentifier() : NULL_IDENTIFIER;
@@ -120,22 +132,24 @@ public class NEEPatternTerminalHandler implements IOverlayHandler {
recipe,
recipeIndex,
identifier);
NEEPatternTerminalHandler.ingredients.clear();
for (PositionedStack positionedStack : mergedInputs) {
ItemStack currentStack = positionedStack.items[0];
ItemStack currentStack = positionedStack.getFilteredPermutations().get(0);
ItemStack preferModItem = ItemUtils.getPreferModItem(positionedStack.items);
int stackSize = currentStack.stackSize;
if (preferModItem != null) {
currentStack = preferModItem;
currentStack.stackSize = positionedStack.items[0].stackSize;
currentStack.stackSize = stackSize;
}
for (ItemStack stack : positionedStack.items) {
if (Platform.isRecipePrioritized(stack)
|| ItemUtils.isPreferItems(stack, recipeProcessorId, identifier)) {
currentStack = stack.copy();
currentStack.stackSize = positionedStack.items[0].stackSize;
currentStack.stackSize = stackSize;
break;
}
}
@@ -154,7 +168,7 @@ public class NEEPatternTerminalHandler implements IOverlayHandler {
recipeInputs.setTag(
INPUT_KEY + inputIndex,
ItemUtils.writeItemStackToNBT(currentStack, new NBTTagCompound()));
ItemUtils.writeItemStackToNBT(currentStack, currentStack.stackSize * multiplier));
NEEPatternTerminalHandler.ingredients.put(INPUT_KEY + inputIndex, positionedStack);
inputIndex++;
}
@@ -176,7 +190,7 @@ public class NEEPatternTerminalHandler implements IOverlayHandler {
recipeOutputs.setTag(
OUTPUT_KEY + outputIndex,
ItemUtils.writeItemStackToNBT(outputStack, new NBTTagCompound()));
ItemUtils.writeItemStackToNBT(outputStack, outputStack.stackSize * multiplier));
outputIndex++;
}
@@ -193,7 +207,7 @@ public class NEEPatternTerminalHandler implements IOverlayHandler {
List<PositionedStack> mergedInputs = new ArrayList<>();
for (PositionedStack positionedStack : inputs) {
ItemStack currentStack = positionedStack.item;
ItemStack currentStack = positionedStack.getFilteredPermutations().get(0);
ItemCombination currentValue = ItemCombination.valueOf(NEEConfig.itemCombinationMode);
boolean find = false;
@@ -203,9 +217,10 @@ public class NEEPatternTerminalHandler implements IOverlayHandler {
if (currentValue == ItemCombination.ENABLED || isWhitelist) {
for (PositionedStack storedStack : mergedInputs) {
ItemStack firstStack = storedStack.items[0];
boolean areItemStackEqual = firstStack.isItemEqual(currentStack)
&& ItemStack.areItemStackTagsEqual(firstStack, currentStack);
ItemStack firstStack = storedStack.getFilteredPermutations().get(0);
boolean areItemStackEqual = NEIServerUtils
.areStacksSameTypeCraftingWithNBT(firstStack, currentStack);
if (areItemStackEqual
&& (firstStack.stackSize + currentStack.stackSize) <= firstStack.getMaxStackSize()) {
@@ -225,25 +240,25 @@ public class NEEPatternTerminalHandler implements IOverlayHandler {
}
private PacketNEIPatternRecipe packCraftingTableRecipe(IRecipeHandler recipe, int recipeIndex) {
final NBTTagCompound recipeInputs = new NBTTagCompound();
final List<PositionedStack> ingredients = recipe.getIngredientStacks(recipeIndex);
final NBTTagCompound recipeInputs = new NBTTagCompound();
NEEPatternTerminalHandler.ingredients.clear();
for (final PositionedStack positionedStack : ingredients) {
for (PositionedStack positionedStack : ingredients) {
final int col = (positionedStack.relx - 25) / 18;
final int row = (positionedStack.rely - 6) / 18;
int slotIndex = col + row * 3;
if (positionedStack.items != null && positionedStack.items.length > 0) {
final ItemStack[] currentStackList = positionedStack.items;
ItemStack stack = positionedStack.item;
positionedStack = positionedStack.copy();
ItemStack stack = positionedStack.getFilteredPermutations().get(0);
ItemStack preferModItem = ItemUtils.getPreferModItem(positionedStack.items);
if (preferModItem != null) {
stack = preferModItem;
}
for (ItemStack currentStack : currentStackList) {
for (ItemStack currentStack : positionedStack.items) {
if (Platform.isRecipePrioritized(currentStack) || ItemUtils.isPreferItems(currentStack)) {
stack = currentStack.copy();
}
@@ -255,7 +270,8 @@ public class NEEPatternTerminalHandler implements IOverlayHandler {
stack.setItemDamage(0);
}
recipeInputs.setTag(INPUT_KEY + slotIndex, ItemUtils.writeItemStackToNBT(stack, new NBTTagCompound()));
positionedStack.item = stack;
recipeInputs.setTag(INPUT_KEY + slotIndex, ItemUtils.writeItemStackToNBT(stack, stack.stackSize));
NEEPatternTerminalHandler.ingredients.put(INPUT_KEY + slotIndex, positionedStack);
}
@@ -265,11 +281,9 @@ public class NEEPatternTerminalHandler implements IOverlayHandler {
}
@SubscribeEvent
public void onActionPerformedEventPre(GuiOverlayButton.UpdateOverlayButtonsEvent.Post event) {
if (event.gui instanceof GuiRecipe && isGuiPatternTerm((GuiRecipe<?>) event.gui)) {
for (int i = 0; i < event.buttonList.size(); i++) {
event.buttonList.set(i, new NEEGuiOverlayButton(event.buttonList.get(i)));
}
public void onActionPerformedEventPre(GuiRecipeButton.UpdateRecipeButtonsEvent.Post event) {
if (event.gui instanceof GuiRecipe guiRecipe && isGuiPatternTerm(guiRecipe)) {
NEETerminalOverlayButton.updateRecipeButtons(guiRecipe, event.buttonList);
}
}