Simplify some code

This commit is contained in:
vfyjxf committed 2021-12-19 01:20:51 +08:00
1 parent 9963789272
commit 7ccf1b0767
28 files changed
+395 -326

No files matched your search

@@ -50,9 +50,10 @@ public class NEINeeConfig implements IConfigureNEI {
);
Set<String> identifiers = new HashSet<>(defaultIdentifiers);
for (IRecipeProcessor processor : RecipeProcessor.recipeProcessors) {
identifiers.addAll(processor.getAllOverlayIdentifier());
}
RecipeProcessor.recipeProcessors
.stream()
.map(IRecipeProcessor::getAllOverlayIdentifier)
.forEach(identifiers::addAll);
for (String ident : identifiers) {
API.registerGuiOverlay(GuiPatternTerm.class, ident);
@@ -103,15 +104,16 @@ public class NEINeeConfig implements IConfigureNEI {
}
if (controllerIndex > 0) {
GuiContainerManager.inputHandlers.remove(controllerIndex);
GuiContainerManager.inputHandlers.add(controllerIndex, new NEIController() {
@Override
public boolean mouseScrolled(GuiContainer gui, int mouseX, int mouseY, int scrolled) {
if (transferBlacklist.contains(gui.getClass())) {
return false;
}
return super.mouseScrolled(gui, mouseX, mouseY, scrolled);
}
});
GuiContainerManager.inputHandlers.add(controllerIndex,
new NEIController() {
@Override
public boolean mouseScrolled(GuiContainer gui, int mouseX, int mouseY, int scrolled) {
if (transferBlacklist.contains(gui.getClass())) {
return false;
}
return super.mouseScrolled(gui, mouseX, mouseY, scrolled);
}
});
NotEnoughEnergistics.logger.info("NEIController replaced success");
}
}
@@ -51,7 +51,7 @@ public class GuiHandler implements INEIGuiHandler {
if (dWheel != 0 && (isPatternTerm || isInterface)) {
int x = Mouse.getEventX() * mc.currentScreen.width / mc.displayWidth;
int y = mc.currentScreen.height - Mouse.getEventY() * mc.currentScreen.height / mc.displayHeight - 1;
Slot currentSlot = GuiUtils.getSlotUnderMouse((GuiContainer) mc.currentScreen, x, y);
Slot currentSlot = ((GuiContainer) mc.currentScreen).getSlotAtPosition(x, y);
if (currentSlot instanceof SlotFake && currentSlot.getHasStack()) {
//try to change current itemstack to next ingredient;
if (Keyboard.isKeyDown(NEIClientConfig.getKeyBinding("nee.ingredient")) && GuiUtils.isCraftingSlot(currentSlot)) {
@@ -156,14 +156,15 @@ public class GuiHandler implements INEIGuiHandler {
@Override
public boolean handleDragNDrop(GuiContainer gui, int mouseX, int mouseY, ItemStack draggedStack, int button) {
if (gui instanceof AEBaseGui) {
if (button != 2) {
Slot currentSlot = GuiUtils.getSlotUnderMouse(gui, mouseX, mouseY);
if (button != 2 && draggedStack != null) {
Slot currentSlot = gui.getSlotAtPosition(mouseX, mouseY);
if (currentSlot instanceof SlotFake && ((SlotFake) currentSlot).isEnabled()) {
List<Integer> slots = new ArrayList<>();
slots.add(currentSlot.slotNumber);
ItemStack copyStack = draggedStack.copy();
copyStack.stackSize = useStackSizeFromNEI ? draggedStack.stackSize : draggedStackDefaultSize;
NEENetworkHandler.getInstance().sendToServer(new PacketSlotStackChange(copyStack, slots));
draggedStack.stackSize = 0;
return true;
}
}
@@ -14,7 +14,9 @@ import com.github.vfyjxf.nee.utils.IngredientTracker;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.ReflectionHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.*;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import net.minecraft.inventory.Slot;
@@ -32,6 +34,9 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Please note the difference between the GTNH NEI and the official NEI
*/
public class NEEContainerDrawHandler implements IContainerDrawHandler {
public static NEEContainerDrawHandler instance = new NEEContainerDrawHandler();
@@ -39,6 +44,7 @@ public class NEEContainerDrawHandler implements IContainerDrawHandler {
private Field overlayButtonsField;
private Method recipesPerPageMethod;
private boolean drawRequestTooltip;
private boolean drawMissingTooltip;
private boolean drawCraftableTooltip;
private boolean isGtnhNei;
@@ -105,7 +111,11 @@ public class NEEContainerDrawHandler implements IContainerDrawHandler {
e.printStackTrace();
}
} else {
overlayButtons = new ArrayList<>(Arrays.asList(guiRecipe.overlay1, guiRecipe.overlay2));
overlayButtons = new ArrayList<>();
GuiButton overlay1 = ReflectionHelper.getPrivateValue(GuiRecipe.class,guiRecipe,"overlay1");
GuiButton overlay2 = ReflectionHelper.getPrivateValue(GuiRecipe.class,guiRecipe,"overlay2");
overlayButtons.add(overlay1);
overlayButtons.add(overlay2);
}
if (overlayButtons != null) {
@@ -144,6 +154,7 @@ public class NEEContainerDrawHandler implements IContainerDrawHandler {
Gui.drawRect(slot.xDisplayPosition, slot.yDisplayPosition,
slot.xDisplayPosition + 16, slot.yDisplayPosition + 16,
new Color(1.0f, 0.0f, 0.0f, 0.4f).getRGB());
this.drawMissingTooltip = true;
}
}
}
@@ -168,7 +179,11 @@ public class NEEContainerDrawHandler implements IContainerDrawHandler {
e.printStackTrace();
}
} else {
overlayButtons = new ArrayList<>(Arrays.asList(guiRecipe.overlay1, guiRecipe.overlay2));
overlayButtons = new ArrayList<>();
GuiButton overlay1 = ReflectionHelper.getPrivateValue(GuiRecipe.class,guiRecipe,"overlay1");
GuiButton overlay2 = ReflectionHelper.getPrivateValue(GuiRecipe.class,guiRecipe,"overlay2");
overlayButtons.add(overlay1);
overlayButtons.add(overlay2);
}
if (overlayButtons != null) {
for (GuiButton button : overlayButtons) {
@@ -176,6 +191,7 @@ public class NEEContainerDrawHandler implements IContainerDrawHandler {
drawCraftingHelperTooltip(guiRecipe, event.mouseX, event.mouseY);
this.drawCraftableTooltip = false;
this.drawRequestTooltip = false;
this.drawMissingTooltip = false;
}
}
}
@@ -186,25 +202,22 @@ public class NEEContainerDrawHandler implements IContainerDrawHandler {
private void drawCraftingHelperTooltip(GuiRecipe guiRecipe, int mouseX, int mouseY) {
List<String> tooltips = new ArrayList<>();
boolean isCraftingTerm = guiRecipe.firstGui instanceof GuiCraftingTerm || GuiUtils.isGuiWirelessCrafting(guiRecipe.firstGui);
if (this.drawRequestTooltip && isCraftingTerm) {
tooltips.add(String.format("%s" + EnumChatFormatting.GRAY + " + " +
EnumChatFormatting.BLUE + I18n.format("neenergistics.gui.tooltip.helper.crafting"),
EnumChatFormatting.YELLOW + Keyboard.getKeyName(NEIClientConfig.getKeyBinding("nee.preview"))));
if (isCraftingTerm) {
if(this.drawRequestTooltip) {
tooltips.add(String.format("%s" + EnumChatFormatting.GRAY + " + " +
EnumChatFormatting.BLUE + I18n.format("neenergistics.gui.tooltip.helper.crafting"),
EnumChatFormatting.YELLOW + Keyboard.getKeyName(NEIClientConfig.getKeyBinding("nee.preview"))));
}
if(this.drawMissingTooltip){
tooltips.add(EnumChatFormatting.RED + I18n.format("neenergistics.gui.tooltip.missing"));
}
}
boolean isPatternTerm = guiRecipe.firstGui instanceof GuiPatternTerm || GuiUtils.isPatternTermExGui(guiRecipe.firstGui);
if (this.drawCraftableTooltip && isPatternTerm) {
tooltips.add(EnumChatFormatting.BLUE + I18n.format("neenergistics.gui.tooltip.helper.pattern"));
}
try {
ReflectionHelper.findMethod(GuiScreen.class, guiRecipe,
new String[]{"drawHoveringText"},
List.class,
int.class,
int.class,
FontRenderer.class).invoke(guiRecipe, tooltips, mouseX, mouseY, Minecraft.getMinecraft().fontRenderer);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
//drawHoveringText
guiRecipe.func_146283_a(tooltips, mouseX, mouseY);
}
@SuppressWarnings("unchecked")
@@ -214,7 +227,11 @@ public class NEEContainerDrawHandler implements IContainerDrawHandler {
//check stacks in player's inventory and crafting grid
List<ItemStack> inventoryStacks = new ArrayList<>();
for (Slot slot : (List<Slot>) firstGui.inventorySlots.inventorySlots) {
boolean canGetStack = slot != null && slot.getHasStack() && slot.getStack().stackSize > 0 && slot.isItemValid(slot.getStack()) && slot.canTakeStack(Minecraft.getMinecraft().thePlayer);
boolean canGetStack = slot != null &&
slot.getHasStack() &&
slot.getStack().stackSize > 0 &&
slot.isItemValid(slot.getStack()) &&
slot.canTakeStack(Minecraft.getMinecraft().thePlayer);
if (canGetStack) {
inventoryStacks.add(slot.getStack().copy());
}
@@ -58,71 +58,74 @@ public class NEECraftingHandler implements IOverlayHandler {
int outputIndex = 0;
//get all recipe inputs and other stacks,use first item
for (IRecipeProcessor processor : RecipeProcessor.recipeProcessors) {
List<PositionedStack> inputs = processor.getRecipeInput(recipe, recipeIndex, identifier);
List<PositionedStack> outputs = processor.getRecipeOutput(recipe, recipeIndex, identifier);
String recipeProcessorId = processor.getRecipeProcessorId();
List<PositionedStack> tInputs = new ArrayList<>();
if (processor.getAllOverlayIdentifier().contains(identifier)) {
List<PositionedStack> inputs = processor.getRecipeInput(recipe, recipeIndex, identifier);
List<PositionedStack> outputs = processor.getRecipeOutput(recipe, recipeIndex, identifier);
String recipeProcessorId = processor.getRecipeProcessorId();
List<PositionedStack> tInputs = new ArrayList<>();
if (inputs != null && outputs != null) {
if (!inputs.isEmpty() && !outputs.isEmpty()) {
for (PositionedStack positionedStack : inputs) {
ItemStack currentStack = positionedStack.items[0];
boolean find = false;
for (PositionedStack storedStack : tInputs) {
ItemStack firstStack = storedStack.items[0];
boolean areItemStackEqual = firstStack.isItemEqual(currentStack) && ItemStack.areItemStackTagsEqual(firstStack, currentStack);
if (areItemStackEqual && (firstStack.stackSize + currentStack.stackSize) <= firstStack.getMaxStackSize()) {
find = true;
storedStack.items[0].stackSize = firstStack.stackSize + currentStack.stackSize;
for (PositionedStack positionedStack : inputs) {
ItemStack currentStack = positionedStack.items[0];
boolean find = false;
for (PositionedStack storedStack : tInputs) {
ItemStack firstStack = storedStack.items[0];
boolean areItemStackEqual = firstStack.isItemEqual(currentStack) && ItemStack.areItemStackTagsEqual(firstStack, currentStack);
if (areItemStackEqual && (firstStack.stackSize + currentStack.stackSize) <= firstStack.getMaxStackSize()) {
find = true;
storedStack.items[0].stackSize = firstStack.stackSize + currentStack.stackSize;
}
}
if (!find) {
tInputs.add(positionedStack.copy());
}
}
if (!find) {
tInputs.add(positionedStack.copy());
}
}
for (PositionedStack positionedStack : tInputs) {
ItemStack currentStack = positionedStack.items[0];
ItemStack preferModItem = ItemUtils.getPreferModItem(positionedStack.items);
for (PositionedStack positionedStack : tInputs) {
ItemStack currentStack = positionedStack.items[0];
ItemStack preferModItem = ItemUtils.getPreferModItem(positionedStack.items);
if (preferModItem != null) {
currentStack = preferModItem;
currentStack.stackSize = positionedStack.items[0].stackSize;
}
for (ItemStack stack : positionedStack.items) {
if (Platform.isRecipePrioritized(stack) || ItemUtils.isPreferItems(stack, recipeProcessorId, identifier)) {
currentStack = stack.copy();
if (preferModItem != null) {
currentStack = preferModItem;
currentStack.stackSize = positionedStack.items[0].stackSize;
break;
}
}
if (ItemUtils.isInBlackList(currentStack, recipeProcessorId, identifier)) {
continue;
for (ItemStack stack : positionedStack.items) {
if (Platform.isRecipePrioritized(stack) || ItemUtils.isPreferItems(stack, recipeProcessorId, identifier)) {
currentStack = stack.copy();
currentStack.stackSize = positionedStack.items[0].stackSize;
break;
}
}
if (ItemUtils.isInBlackList(currentStack, recipeProcessorId, identifier)) {
continue;
}
//Fix ItemStack with wrong meta
if (currentStack.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
currentStack.setItemDamage(0);
}
recipeInputs.setTag("#" + inputIndex, currentStack.writeToNBT(new NBTTagCompound()));
NEECraftingHandler.ingredients.put("input" + inputIndex, positionedStack);
inputIndex++;
}
//Fix ItemStack with wrong meta
if (currentStack.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
currentStack.setItemDamage(0);
for (PositionedStack positionedStack : outputs) {
if (outputIndex >= 4 || positionedStack == null || positionedStack.item == null) {
continue;
}
ItemStack outputStack = positionedStack.item.copy();
//Fix ItemStack with wrong meta(maybe ?)
if (outputStack.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
outputStack.setItemDamage(0);
}
recipeOutputs.setTag(OUTPUT_KEY + outputIndex, outputStack.writeToNBT(new NBTTagCompound()));
outputIndex++;
}
recipeInputs.setTag("#" + inputIndex, currentStack.writeToNBT(new NBTTagCompound()));
NEECraftingHandler.ingredients.put("input" + inputIndex, positionedStack);
inputIndex++;
}
for (PositionedStack positionedStack : outputs) {
if (outputIndex >= 4 || positionedStack == null || positionedStack.item == null) {
continue;
}
ItemStack outputStack = positionedStack.item.copy();
//Fix ItemStack with wrong meta(maybe ?)
if (outputStack.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
outputStack.setItemDamage(0);
}
recipeOutputs.setTag(OUTPUT_KEY + outputIndex, outputStack.writeToNBT(new NBTTagCompound()));
outputIndex++;
break;
}
}
}
@@ -213,7 +213,11 @@ public class NEECraftingHelper implements IOverlayHandler {
isGtnhNei = false;
}
if (!isGtnhNei) {
overlayButtons = new ArrayList<>(Arrays.asList(guiRecipe.overlay1, guiRecipe.overlay2));
overlayButtons = new ArrayList<>();
GuiButton overlay1 = ReflectionHelper.getPrivateValue(GuiRecipe.class,guiRecipe,"overlay1");
GuiButton overlay2 = ReflectionHelper.getPrivateValue(GuiRecipe.class,guiRecipe,"overlay2");
overlayButtons.add(overlay1);
overlayButtons.add(overlay2);
}
if (event.button.id >= OVERLAY_BUTTON_ID_START && event.button.id < OVERLAY_BUTTON_ID_START + overlayButtons.size()) {
boolean isPatternTerm = guiRecipe.firstGui instanceof GuiPatternTerm || GuiUtils.isPatternTermExGui(guiRecipe.firstGui);
@@ -3,9 +3,11 @@ package com.github.vfyjxf.nee.processor;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.IRecipeHandler;
import javax.annotation.Nonnull;
import java.util.*;
public class AvaritiaRecipeProcessor implements IRecipeProcessor {
@Nonnull
@Override
public Set<String> getAllOverlayIdentifier() {
return new HashSet<>(Arrays.asList(
@@ -13,30 +15,31 @@ public class AvaritiaRecipeProcessor implements IRecipeProcessor {
));
}
@Nonnull
@Override
public String getRecipeProcessorId() {
return "Avaritia";
}
@Nonnull
@Override
public List<PositionedStack> getRecipeInput(IRecipeHandler recipe, int recipeIndex, String identifier) {
for (String ident : getAllOverlayIdentifier()) {
if (ident.equals(identifier)) {
return new ArrayList<>(recipe.getIngredientStacks(recipeIndex));
}
List<PositionedStack> recipeInputs = new ArrayList<>();
if (this.getAllOverlayIdentifier().contains(identifier)) {
recipeInputs.addAll(recipe.getIngredientStacks(recipeIndex));
return recipeInputs;
}
return null;
return recipeInputs;
}
@Nonnull
@Override
public List<PositionedStack> getRecipeOutput(IRecipeHandler recipe, int recipeIndex, String identifier) {
for (String ident : getAllOverlayIdentifier()) {
if (ident.equals(identifier)) {
List<PositionedStack> recipeOutput = new ArrayList<>();
recipeOutput.add(recipe.getResultStack(recipeIndex));
return recipeOutput;
}
List<PositionedStack> recipeOutput = new ArrayList<>();
if (this.getAllOverlayIdentifier().contains(identifier)) {
recipeOutput.add(recipe.getResultStack(recipeIndex));
return recipeOutput;
}
return null;
return recipeOutput;
}
}
@@ -3,12 +3,14 @@ package com.github.vfyjxf.nee.processor;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.IRecipeHandler;
import javax.annotation.Nonnull;
import java.util.*;
/**
* @author vfyjxf
*/
public class BloodMagicRecipeProcessor implements IRecipeProcessor {
@Nonnull
@Override
public Set<String> getAllOverlayIdentifier() {
return new HashSet<>(Arrays.asList(
@@ -19,30 +21,31 @@ public class BloodMagicRecipeProcessor implements IRecipeProcessor {
));
}
@Nonnull
@Override
public String getRecipeProcessorId() {
return "BloodMagic";
}
@Nonnull
@Override
public List<PositionedStack> getRecipeInput(IRecipeHandler recipe, int recipeIndex, String identifier) {
for (String ident : getAllOverlayIdentifier()) {
if (ident.equals(identifier)) {
return new ArrayList<>(recipe.getIngredientStacks(recipeIndex));
}
List<PositionedStack> recipeInputs = new ArrayList<>();
if (this.getAllOverlayIdentifier().contains(identifier)) {
recipeInputs.addAll(recipe.getIngredientStacks(recipeIndex));
return recipeInputs;
}
return null;
return recipeInputs;
}
@Nonnull
@Override
public List<PositionedStack> getRecipeOutput(IRecipeHandler recipe, int recipeIndex, String identifier) {
for (String ident : getAllOverlayIdentifier()) {
if (ident.equals(identifier)) {
List<PositionedStack> recipeOutputs = new ArrayList<>();
recipeOutputs.add(recipe.getResultStack(recipeIndex));
return recipeOutputs;
}
List<PositionedStack> recipeOutputs = new ArrayList<>();
if (this.getAllOverlayIdentifier().contains(identifier)) {
recipeOutputs.add(recipe.getResultStack(recipeIndex));
return recipeOutputs;
}
return null;
return recipeOutputs;
}
}
@@ -5,6 +5,8 @@ import buildcraft.compat.nei.RecipeHandlerIntegrationTable;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.IRecipeHandler;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -13,11 +15,13 @@ import java.util.List;
*/
public class BuildCraftRecipeProcessor implements IRecipeProcessor {
@Nonnull
@Override
public String getRecipeProcessorId() {
return "BuildCraft";
}
@Nonnull
@Override
public List<PositionedStack> getRecipeInput(IRecipeHandler recipe, int recipeIndex, String identifier) {
if (recipe instanceof RecipeHandlerAssemblyTable) {
@@ -25,9 +29,10 @@ public class BuildCraftRecipeProcessor implements IRecipeProcessor {
} else if (recipe instanceof RecipeHandlerIntegrationTable) {
return handlerIntegrationTableRecipe((RecipeHandlerIntegrationTable) recipe, recipeIndex, true);
}
return null;
return new ArrayList<>();
}
@Nonnull
@Override
public List<PositionedStack> getRecipeOutput(IRecipeHandler recipe, int recipeIndex, String identifier) {
if (recipe instanceof RecipeHandlerAssemblyTable) {
@@ -35,7 +40,7 @@ public class BuildCraftRecipeProcessor implements IRecipeProcessor {
} else if (recipe instanceof RecipeHandlerIntegrationTable) {
return handlerIntegrationTableRecipe((RecipeHandlerIntegrationTable) recipe, recipeIndex, false);
}
return null;
return new ArrayList<>();
}
private List<PositionedStack> handlerAssemblyTableRecipe(RecipeHandlerAssemblyTable recipe, int recipeIndex, boolean getInput) {
@@ -4,9 +4,11 @@ import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.IRecipeHandler;
import crazypants.enderio.nei.SagMillRecipeHandler;
import javax.annotation.Nonnull;
import java.util.*;
public class EnderIORecipeProcessor implements IRecipeProcessor {
@Nonnull
@Override
public Set<String> getAllOverlayIdentifier() {
return new HashSet<>(Arrays.asList(
@@ -15,38 +17,40 @@ public class EnderIORecipeProcessor implements IRecipeProcessor {
));
}
@Nonnull
@Override
public String getRecipeProcessorId() {
return "EnderIO";
}
@Nonnull
@Override
public List<PositionedStack> getRecipeInput(IRecipeHandler recipe, int recipeIndex, String identifier) {
for (String ident : getAllOverlayIdentifier()) {
if (ident.equals(identifier)) {
return new ArrayList<>(recipe.getIngredientStacks(recipeIndex));
}
}
return null;
List<PositionedStack> recipeInputs = new ArrayList<>();
if (this.getAllOverlayIdentifier().contains(identifier)) {
recipeInputs.addAll(recipe.getIngredientStacks(recipeIndex));
return recipeInputs;
}
return recipeInputs;
}
@Nonnull
@Override
public List<PositionedStack> getRecipeOutput(IRecipeHandler recipe, int recipeIndex, String identifier) {
if(identifier!=null) {
for (String ident : getAllOverlayIdentifier()) {
if (ident.equals(identifier)) {
List<PositionedStack> recipeOutputs = new ArrayList<>();
recipeOutputs.add(recipe.getResultStack(recipeIndex));
recipeOutputs.addAll(recipe.getOtherStacks(recipeIndex));
//remove output if it's chance != 1
if(recipe instanceof SagMillRecipeHandler){
SagMillRecipeHandler.MillRecipe millRecipe = (SagMillRecipeHandler.MillRecipe) ((SagMillRecipeHandler) recipe).arecipes.get(recipeIndex);
recipeOutputs.removeIf(positionedStack -> millRecipe.getChanceForOutput(positionedStack.item) != 1.0F);
}
return recipeOutputs;
List<PositionedStack> recipeOutputs = new ArrayList<>();
if (identifier != null) {
if (this.getAllOverlayIdentifier().contains(identifier)) {
recipeOutputs.add(recipe.getResultStack(recipeIndex));
recipeOutputs.addAll(recipe.getOtherStacks(recipeIndex));
//remove output if it's chance != 1
if (recipe instanceof SagMillRecipeHandler) {
SagMillRecipeHandler.MillRecipe millRecipe = (SagMillRecipeHandler.MillRecipe) ((SagMillRecipeHandler) recipe).arecipes.get(recipeIndex);
recipeOutputs.removeIf(positionedStack -> millRecipe.getChanceForOutput(positionedStack.item) != 1.0F);
}
return recipeOutputs;
}
}
return null;
return recipeOutputs;
}
}
@@ -4,17 +4,20 @@ import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.IRecipeHandler;
import forestry.factory.recipes.nei.*;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class ForestryRecipeProcessor implements IRecipeProcessor {
@Nonnull
@Override
public String getRecipeProcessorId() {
return "Forestry";
}
@Nonnull
@Override
public List<PositionedStack> getRecipeInput(IRecipeHandler recipe, int recipeIndex, String identifier) {
if (recipe instanceof NEIHandlerBottler) {
@@ -42,9 +45,10 @@ public class ForestryRecipeProcessor implements IRecipeProcessor {
return squeezerHandler((NEIHandlerSqueezer) recipe, recipeIndex, true);
}
return null;
return new ArrayList<>();
}
@Nonnull
@Override
public List<PositionedStack> getRecipeOutput(IRecipeHandler recipe, int recipeIndex, String identifier) {
if (recipe instanceof NEIHandlerBottler) {
@@ -72,7 +76,7 @@ public class ForestryRecipeProcessor implements IRecipeProcessor {
return squeezerHandler((NEIHandlerSqueezer) recipe, recipeIndex, false);
}
return null;
return new ArrayList<>();
}
private List<PositionedStack> bottlerHandler(NEIHandlerBottler base, int recipeIndex, boolean getInput) {
@@ -93,7 +97,7 @@ public class ForestryRecipeProcessor implements IRecipeProcessor {
return getInput ? recipeInput : Collections.singletonList(base.getResultStack(recipeIndex));
}
//Fermenter doesn't support, because it doesn't has a item output
//Fermenter doesn't support, because it doesn't have an item output
private List<PositionedStack> moistenerHandler(NEIHandlerMoistener base, int recipeIndex, boolean getInput) {
List<PositionedStack> recipeInput = new ArrayList<>(base.getIngredientStacks(recipeIndex));
@@ -4,12 +4,14 @@ import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.IRecipeHandler;
import gregtech.api.util.GTPP_Recipe;
import javax.annotation.Nonnull;
import java.util.*;
/**
* @author vfyjxf
*/
public class GTPPRecipeProcessor implements IRecipeProcessor {
@Nonnull
@Override
public Set<String> getAllOverlayIdentifier() {
HashSet<String> identifiers = new HashSet<>(Collections.singletonList("GTPP_Decayables"));
@@ -23,32 +25,33 @@ public class GTPPRecipeProcessor implements IRecipeProcessor {
return identifiers;
}
@Nonnull
@Override
public String getRecipeProcessorId() {
return "GT++";
}
@Nonnull
@Override
public List<PositionedStack> getRecipeInput(IRecipeHandler recipe, int recipeIndex, String identifier) {
for (String ident : getAllOverlayIdentifier()) {
if (ident.equals(identifier)) {
List<PositionedStack> recipeInputs = new ArrayList<>(recipe.getIngredientStacks(recipeIndex));
recipeInputs.removeIf(positionedStack -> GregTech5RecipeProcessor.getFluidFromDisplayStack(positionedStack.items[0]) != null || positionedStack.item.stackSize == 0);
return recipeInputs;
}
List<PositionedStack> recipeInputs = new ArrayList<>();
if (this.getAllOverlayIdentifier().contains(identifier)) {
recipeInputs.addAll(recipe.getIngredientStacks(recipeIndex));
recipeInputs.removeIf(positionedStack -> GregTech5RecipeProcessor.getFluidFromDisplayStack(positionedStack.items[0]) != null || positionedStack.item.stackSize == 0);
return recipeInputs;
}
return null;
return recipeInputs;
}
@Nonnull
@Override
public List<PositionedStack> getRecipeOutput(IRecipeHandler recipe, int recipeIndex, String identifier) {
for (String ident : getAllOverlayIdentifier()) {
if (ident.equals(identifier)) {
List<PositionedStack> recipeOutputs = new ArrayList<>(recipe.getOtherStacks(recipeIndex));
recipeOutputs.removeIf(positionedStack -> GregTech5RecipeProcessor.getFluidFromDisplayStack(positionedStack.items[0]) != null);
return recipeOutputs;
}
List<PositionedStack> recipeOutputs = new ArrayList<>();
if (this.getAllOverlayIdentifier().contains(identifier)) {
recipeOutputs.addAll(recipe.getOtherStacks(recipeIndex));
recipeOutputs.removeIf(positionedStack -> GregTech5RecipeProcessor.getFluidFromDisplayStack(positionedStack.items[0]) != null);
return recipeOutputs;
}
return null;
return recipeOutputs;
}
}
@@ -10,6 +10,7 @@ import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -35,6 +36,7 @@ public class GregTech5RecipeProcessor implements IRecipeProcessor {
gtAssLineClz = gtAL;
}
@Nonnull
@Override
public Set<String> getAllOverlayIdentifier() {
@@ -48,16 +50,18 @@ public class GregTech5RecipeProcessor implements IRecipeProcessor {
return identifiers;
}
@Nonnull
@Override
public String getRecipeProcessorId() {
return "GregTech5";
}
@Nonnull
@Override
public List<PositionedStack> getRecipeInput(IRecipeHandler recipe, int recipeIndex, String identifier) {
List<PositionedStack> recipeInputs = new ArrayList<>();
if (gtDefaultClz.isInstance(recipe) || gtAssLineClz.isInstance(recipe)) {
List<PositionedStack> recipeInputs = new ArrayList<>(recipe.getIngredientStacks(recipeIndex));
recipeInputs.addAll(recipe.getIngredientStacks(recipeIndex));
recipeInputs.removeIf(positionedStack -> getFluidFromDisplayStack(positionedStack.items[0]) != null || positionedStack.item.stackSize == 0);
if (!recipeInputs.isEmpty()) {
ItemStack specialItem = recipeInputs.get(recipeInputs.size() - 1).items[0];
@@ -66,20 +70,22 @@ public class GregTech5RecipeProcessor implements IRecipeProcessor {
}
return recipeInputs;
}
return null;
return recipeInputs;
}
@Nonnull
@Override
public List<PositionedStack> getRecipeOutput(IRecipeHandler recipe, int recipeIndex, String identifier) {
List<PositionedStack> recipeOutputs = new ArrayList<>();
if (gtDefaultClz.isInstance(recipe) || gtAssLineClz.isInstance(recipe)) {
List<PositionedStack> recipeOutputs = new ArrayList<>(recipe.getOtherStacks(recipeIndex));
recipeOutputs.addAll(recipe.getOtherStacks(recipeIndex));
recipeOutputs.removeIf(positionedStack -> getFluidFromDisplayStack(positionedStack.items[0]) != null);
//remove output if it's chance != 10000
recipeOutputs.removeIf(stack -> stack instanceof FixedPositionedStack && !(((FixedPositionedStack) stack).mChance == 10000 || ((FixedPositionedStack) stack).mChance <= 0));
return recipeOutputs;
}
return null;
return recipeOutputs;
}
/**
@@ -95,6 +101,7 @@ public class GregTech5RecipeProcessor implements IRecipeProcessor {
Fluid tFluid = FluidRegistry.getFluid(ItemList.Display_Fluid.getItem().getDamage(aDisplayStack));
return new FluidStack(tFluid, (int) aDisplayStack.getTagCompound().getLong("mFluidDisplayAmount"));
}
public static boolean isStackValid(Object aStack) {
return (aStack instanceof ItemStack) && ((ItemStack) aStack).getItem() != null && ((ItemStack) aStack).stackSize >= 0;
}
@@ -9,6 +9,7 @@ import gregapi.data.FL;
import gregapi.recipes.Recipe;
import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashSet;
@@ -19,6 +20,7 @@ import java.util.Set;
* @author vfyjxf
*/
public class GregTech6RecipeProcessor implements IRecipeProcessor {
@Nonnull
@Override
public Set<String> getAllOverlayIdentifier() {
Set<String> identifiers = new HashSet<>();
@@ -30,54 +32,55 @@ public class GregTech6RecipeProcessor implements IRecipeProcessor {
return identifiers;
}
@Nonnull
@Override
public String getRecipeProcessorId() {
return "GregTech6";
}
@Nonnull
@Override
public List<PositionedStack> getRecipeInput(IRecipeHandler recipe, int recipeIndex, String identifier) {
for (String ident : getAllOverlayIdentifier()) {
if (ident.equals(identifier)) {
List<PositionedStack> recipeInputs = new ArrayList<>(recipe.getIngredientStacks(recipeIndex));
//remove fluid
recipeInputs.removeIf(positionedStack -> FL.getFluid(positionedStack.item, true) != null || positionedStack.item.stackSize == 0);
//try to remove machine
if (recipe instanceof NEI_RecipeMap) {
Field mRecipeMapField = ReflectionHelper.findField(NEI_RecipeMap.class, "mRecipeMap");
Recipe.RecipeMap mRecipeMap = null;
try {
mRecipeMap = (Recipe.RecipeMap) mRecipeMapField.get(recipe);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
if (mRecipeMap != null) {
ItemStack lastItem = (recipeInputs.get(recipeInputs.size() - 1)).items[0];
for (ItemStack stack : mRecipeMap.mRecipeMachineList) {
if (ItemStack.areItemStackTagsEqual(lastItem, stack)) {
recipeInputs.remove(recipeInputs.size() - 1);
break;
}
List<PositionedStack> recipeInputs = new ArrayList<>();
if (this.getAllOverlayIdentifier().contains(identifier)) {
recipeInputs.addAll(recipe.getIngredientStacks(recipeIndex));
//remove fluid
recipeInputs.removeIf(positionedStack -> FL.getFluid(positionedStack.item, true) != null || positionedStack.item.stackSize == 0);
//try to remove machine
if (recipe instanceof NEI_RecipeMap) {
Field mRecipeMapField = ReflectionHelper.findField(NEI_RecipeMap.class, "mRecipeMap");
Recipe.RecipeMap mRecipeMap = null;
try {
mRecipeMap = (Recipe.RecipeMap) mRecipeMapField.get(recipe);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
if (mRecipeMap != null) {
ItemStack lastItem = (recipeInputs.get(recipeInputs.size() - 1)).items[0];
for (ItemStack stack : mRecipeMap.mRecipeMachineList) {
if (ItemStack.areItemStackTagsEqual(lastItem, stack)) {
recipeInputs.remove(recipeInputs.size() - 1);
break;
}
}
}
return recipeInputs;
}
return recipeInputs;
}
return null;
return recipeInputs;
}
@Nonnull
@Override
public List<PositionedStack> getRecipeOutput(IRecipeHandler recipe, int recipeIndex, String identifier) {
for (String ident : getAllOverlayIdentifier()) {
if (ident.equals(identifier)) {
List<PositionedStack> recipeOutput = new ArrayList<>(recipe.getOtherStacks(recipeIndex));
recipeOutput.removeIf(positionedStack -> FL.getFluid(positionedStack.item, true) != null || positionedStack.item.stackSize == 0);
//try to remove item output if it's chance != 100%
recipeOutput.removeIf(positionedStack -> positionedStack instanceof FixedPositionedStack && ((FixedPositionedStack) positionedStack).mChance > 0 && ((FixedPositionedStack) positionedStack).mChance != ((FixedPositionedStack) positionedStack).mMaxChance);
return recipeOutput;
}
List<PositionedStack> recipeOutput = new ArrayList<>();
if (this.getAllOverlayIdentifier().contains(identifier)) {
recipeOutput.addAll(recipe.getOtherStacks(recipeIndex));
recipeOutput.removeIf(positionedStack -> FL.getFluid(positionedStack.item, true) != null || positionedStack.item.stackSize == 0);
//try to remove item output if it's chance != 100%
recipeOutput.removeIf(positionedStack -> positionedStack instanceof FixedPositionedStack && ((FixedPositionedStack) positionedStack).mChance > 0 && ((FixedPositionedStack) positionedStack).mChance != ((FixedPositionedStack) positionedStack).mMaxChance);
return recipeOutput;
}
return null;
return recipeOutput;
}
}
@@ -3,12 +3,14 @@ package com.github.vfyjxf.nee.processor;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.IRecipeHandler;
import javax.annotation.Nonnull;
import java.util.*;
/**
* @author vfyjxf
*/
public class ICRecipeProcessor implements IRecipeProcessor {
@Nonnull
@Override
public Set<String> getAllOverlayIdentifier() {
return new HashSet<>(Arrays.asList(
@@ -18,32 +20,33 @@ public class ICRecipeProcessor implements IRecipeProcessor {
));
}
@Nonnull
@Override
public String getRecipeProcessorId() {
return "IC2";
}
@Nonnull
@Override
public List<PositionedStack> getRecipeInput(IRecipeHandler recipe, int recipeIndex, String identifier) {
for (String ident : getAllOverlayIdentifier()) {
if (ident.equals(identifier)) {
return new ArrayList<>(recipe.getIngredientStacks(recipeIndex));
}
List<PositionedStack> recipeInputs = new ArrayList<>();
if (this.getAllOverlayIdentifier().contains(identifier)) {
recipeInputs.addAll(recipe.getIngredientStacks(recipeIndex));
return recipeInputs;
}
return null;
return recipeInputs;
}
@Nonnull
@Override
public List<PositionedStack> getRecipeOutput(IRecipeHandler recipe, int recipeIndex, String identifier) {
for (String ident : getAllOverlayIdentifier()) {
if (ident.equals(identifier)) {
List<PositionedStack> recipeOutputs = new ArrayList<>();
recipeOutputs.add(recipe.getResultStack(recipeIndex));
recipeOutputs.addAll(recipe.getOtherStacks(recipeIndex));
return recipeOutputs;
}
List<PositionedStack> recipeOutputs = new ArrayList<>();
if (this.getAllOverlayIdentifier().contains(identifier)) {
recipeOutputs.add(recipe.getResultStack(recipeIndex));
recipeOutputs.addAll(recipe.getOtherStacks(recipeIndex));
return recipeOutputs;
}
return null;
return recipeOutputs;
}
@@ -3,6 +3,7 @@ package com.github.vfyjxf.nee.processor;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.IRecipeHandler;
import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.List;
import java.util.Set;
@@ -12,15 +13,18 @@ import java.util.Set;
*/
public interface IRecipeProcessor {
@Nonnull
default Set<String> getAllOverlayIdentifier(){
return Collections.emptySet();
}
@Nonnull
String getRecipeProcessorId();
@Nonnull
List<PositionedStack> getRecipeInput(IRecipeHandler recipe, int recipeIndex, String identifier);
@Nonnull
List<PositionedStack> getRecipeOutput(IRecipeHandler recipe, int recipeIndex, String identifier);
}
@@ -3,12 +3,14 @@ package com.github.vfyjxf.nee.processor;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.IRecipeHandler;
import javax.annotation.Nonnull;
import java.util.*;
/**
* @author vfyjxf
*/
public class ImmersiveEngineeringRecipeProcessor implements IRecipeProcessor {
@Nonnull
@Override
public Set<String> getAllOverlayIdentifier() {
return new HashSet<>(Arrays.asList(
@@ -19,37 +21,37 @@ public class ImmersiveEngineeringRecipeProcessor implements IRecipeProcessor {
));
}
@Nonnull
@Override
public String getRecipeProcessorId() {
return "ImmersiveEngineering";
}
@Nonnull
@Override
public List<PositionedStack> getRecipeInput(IRecipeHandler recipe, int recipeIndex, String identifier) {
for (String ident : getAllOverlayIdentifier()) {
if (ident.equals(identifier)) {
List<PositionedStack> recipeInputs = new ArrayList<>(recipe.getIngredientStacks(recipeIndex));
if (!("ieArcFurnace".equals(identifier) || "ieCrusher".equals(identifier) || "ieBlastFurnace".equals(identifier))) {
recipeInputs.addAll(recipe.getOtherStacks(recipeIndex));
}
return recipeInputs;
List<PositionedStack> recipeInputs = new ArrayList<>();
if (this.getAllOverlayIdentifier().contains(identifier)) {
recipeInputs.addAll(recipe.getIngredientStacks(recipeIndex));
if (!("ieArcFurnace".equals(identifier) || "ieCrusher".equals(identifier) || "ieBlastFurnace".equals(identifier))) {
recipeInputs.addAll(recipe.getOtherStacks(recipeIndex));
}
return recipeInputs;
}
return null;
return recipeInputs;
}
@Nonnull
@Override
public List<PositionedStack> getRecipeOutput(IRecipeHandler recipe, int recipeIndex, String identifier) {
for (String ident : getAllOverlayIdentifier()) {
if (ident.equals(identifier)) {
List<PositionedStack> recipeOutputs = new ArrayList<>();
recipeOutputs.add(recipe.getResultStack(recipeIndex));
if ("ieArcFurnace".equals(identifier) || "ieCrusher".equals(identifier)) {
recipeOutputs.addAll(recipe.getOtherStacks(recipeIndex));
}
return recipeOutputs;
List<PositionedStack> recipeOutputs = new ArrayList<>();
if (this.getAllOverlayIdentifier().contains(identifier)) {
recipeOutputs.add(recipe.getResultStack(recipeIndex));
if ("ieArcFurnace".equals(identifier) || "ieCrusher".equals(identifier)) {
recipeOutputs.addAll(recipe.getOtherStacks(recipeIndex));
}
return recipeOutputs;
}
return null;
return recipeOutputs;
}
}
@@ -3,12 +3,14 @@ package com.github.vfyjxf.nee.processor;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.IRecipeHandler;
import javax.annotation.Nonnull;
import java.util.*;
/**
* @author vfyjxf
*/
public class MekanismRecipeProcessor implements IRecipeProcessor {
@Nonnull
@Override
public Set<String> getAllOverlayIdentifier() {
return new HashSet<>(Arrays.asList(
@@ -19,34 +21,34 @@ public class MekanismRecipeProcessor implements IRecipeProcessor {
));
}
@Nonnull
@Override
public String getRecipeProcessorId() {
return "Mekanism";
}
@Nonnull
@Override
public List<PositionedStack> getRecipeInput(IRecipeHandler recipe, int recipeIndex, String identifier) {
for (String ident : getAllOverlayIdentifier()) {
if (ident.equals(identifier)) {
List<PositionedStack> recipeInputs = new ArrayList<>(recipe.getIngredientStacks(recipeIndex));
if (!recipe.getOtherStacks(recipeIndex).isEmpty()) {
recipeInputs.addAll(recipe.getOtherStacks(recipeIndex));
}
return recipeInputs;
List<PositionedStack> recipeInputs = new ArrayList<>();
if (this.getAllOverlayIdentifier().contains(identifier)) {
recipeInputs.addAll(recipe.getIngredientStacks(recipeIndex));
if (!recipe.getOtherStacks(recipeIndex).isEmpty()) {
recipeInputs.addAll(recipe.getOtherStacks(recipeIndex));
}
return recipeInputs;
}
return null;
return recipeInputs;
}
@Nonnull
@Override
public List<PositionedStack> getRecipeOutput(IRecipeHandler recipe, int recipeIndex, String identifier) {
for (String ident : getAllOverlayIdentifier()) {
if (ident.equals(identifier)) {
List<PositionedStack> recipeOutputs = new ArrayList<>();
recipeOutputs.add(recipe.getResultStack(recipeIndex));
return recipeOutputs;
}
List<PositionedStack> recipeOutputs = new ArrayList<>();
if (this.getAllOverlayIdentifier().contains(identifier)) {
recipeOutputs.add(recipe.getResultStack(recipeIndex));
return recipeOutputs;
}
return null;
return recipeOutputs;
}
}
@@ -46,23 +46,23 @@ public class RecipeProcessor {
NotEnoughEnergistics.logger.info("Found ThermalExpansion, install ThermalExpansion support");
recipeProcessors.add(new ThermalExpansionRecipeProcessor());
}
if(Loader.isModLoaded("ImmersiveEngineering")){
if (Loader.isModLoaded("ImmersiveEngineering")) {
NotEnoughEnergistics.logger.info("Found ImmersiveEngineering, install ImmersiveEngineering support");
recipeProcessors.add(new ImmersiveEngineeringRecipeProcessor());
}
if(Loader.isModLoaded("Mekanism")){
if (Loader.isModLoaded("Mekanism")) {
NotEnoughEnergistics.logger.info("Found Mekanism, install Mekanism support");
recipeProcessors.add(new MekanismRecipeProcessor());
}
if(Loader.isModLoaded("AWWayofTime")){
if (Loader.isModLoaded("AWWayofTime")) {
NotEnoughEnergistics.logger.info("Found BloodMagic, install BloodMagic support");
recipeProcessors.add(new BloodMagicRecipeProcessor());
}
if(Loader.isModLoaded("BuildCraft|Compat")){
if (Loader.isModLoaded("BuildCraft|Compat")) {
NotEnoughEnergistics.logger.info("Found BuildCraft-Compat, install BuildCraft-Compat support");
recipeProcessors.add(new BuildCraftRecipeProcessor());
}
if(Loader.isModLoaded("miscutils")){
if (Loader.isModLoaded("miscutils")) {
NotEnoughEnergistics.logger.info("Found GT++, install GT++ support");
recipeProcessors.add(new GTPPRecipeProcessor());
}
@@ -4,47 +4,49 @@ import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.IRecipeHandler;
import com.djgiannuzz.thaumcraftneiplugin.items.ItemAspect;
import javax.annotation.Nonnull;
import java.util.*;
/**
* @author vfyjxf
*/
public class TCNEIPluginRecipeProcessor implements IRecipeProcessor{
public class TCNEIPluginRecipeProcessor implements IRecipeProcessor {
@Nonnull
@Override
public Set<String> getAllOverlayIdentifier() {
return new HashSet<>(Arrays.asList(
"arcaneshapedrecipes","arcaneshapelessrecipes","aspectsRecipe",
"cruciblerecipe","infusionCrafting"
"arcaneshapedrecipes", "arcaneshapelessrecipes", "aspectsRecipe",
"cruciblerecipe", "infusionCrafting"
));
}
@Nonnull
@Override
public String getRecipeProcessorId() {
return "TCNEIPlugin";
}
@Nonnull
@Override
public List<PositionedStack> getRecipeInput(IRecipeHandler recipe, int recipeIndex, String identifier) {
for(String ident : getAllOverlayIdentifier()){
if(ident.equals(identifier)){
List<PositionedStack> recipeInputs = new ArrayList<>(recipe.getIngredientStacks(recipeIndex));
recipeInputs.removeIf(positionedStack -> positionedStack.item.getItem() instanceof ItemAspect);
return recipeInputs;
}
List<PositionedStack> recipeInputs = new ArrayList<>();
if (this.getAllOverlayIdentifier().contains(identifier)) {
recipeInputs.addAll(recipe.getIngredientStacks(recipeIndex));
recipeInputs.removeIf(positionedStack -> positionedStack.item.getItem() instanceof ItemAspect);
return recipeInputs;
}
return null;
return recipeInputs;
}
@Nonnull
@Override
public List<PositionedStack> getRecipeOutput(IRecipeHandler recipe, int recipeIndex, String identifier) {
for(String ident : getAllOverlayIdentifier()){
if(ident.equals(identifier)){
List<PositionedStack> recipeOutputs = new ArrayList<>();
recipeOutputs.add(recipe.getResultStack(recipeIndex));
return recipeOutputs;
}
List<PositionedStack> recipeOutputs = new ArrayList<>();
if (this.getAllOverlayIdentifier().contains(identifier)) {
recipeOutputs.add(recipe.getResultStack(recipeIndex));
return recipeOutputs;
}
return null;
return recipeOutputs;
}
}
@@ -5,11 +5,14 @@ import codechicken.nei.recipe.IRecipeHandler;
import cofh.thermalexpansion.plugins.nei.handlers.RecipeHandlerBase;
import cpw.mods.fml.relauncher.ReflectionHelper;
import javax.annotation.Nonnull;
import java.lang.reflect.Field;
import java.util.*;
public class ThermalExpansionRecipeProcessor implements IRecipeProcessor {
@Nonnull
@Override
public Set<String> getAllOverlayIdentifier() {
return new HashSet<>(Arrays.asList(
@@ -18,75 +21,75 @@ public class ThermalExpansionRecipeProcessor implements IRecipeProcessor {
));
}
@Nonnull
@Override
public String getRecipeProcessorId() {
return "ThermalExpansion";
}
@Nonnull
@Override
public List<PositionedStack> getRecipeInput(IRecipeHandler recipe, int recipeIndex, String identifier) {
for (String ident : getAllOverlayIdentifier()) {
if (ident.equals(identifier)) {
List<PositionedStack> recipeInputs = new ArrayList<>(recipe.getIngredientStacks(recipeIndex));
if (recipe instanceof RecipeHandlerBase) {
Class<?> NEIRecipeBase = null;
List<PositionedStack> recipeInputs = new ArrayList<>();
if (this.getAllOverlayIdentifier().contains(identifier)) {
recipeInputs.addAll(recipe.getIngredientStacks(recipeIndex));
if (recipe instanceof RecipeHandlerBase) {
Class<?> NEIRecipeBase = null;
try {
NEIRecipeBase = Class.forName("cofh.thermalexpansion.plugins.nei.handlers.RecipeHandlerBase$NEIRecipeBase");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
if (NEIRecipeBase != null) {
Field secondaryInputField = ReflectionHelper.findField(NEIRecipeBase, "secondaryInput");
PositionedStack secondaryInput = null;
try {
NEIRecipeBase = Class.forName("cofh.thermalexpansion.plugins.nei.handlers.RecipeHandlerBase$NEIRecipeBase");
} catch (ClassNotFoundException e) {
secondaryInput = (PositionedStack) secondaryInputField.get(((RecipeHandlerBase) recipe).arecipes.get(recipeIndex));
} catch (IllegalAccessException e) {
e.printStackTrace();
}
if (NEIRecipeBase != null) {
Field secondaryInputField = ReflectionHelper.findField(NEIRecipeBase, "secondaryInput");
PositionedStack secondaryInput = null;
try {
secondaryInput = (PositionedStack) secondaryInputField.get(((RecipeHandlerBase) recipe).arecipes.get(recipeIndex));
} catch (IllegalAccessException e) {
e.printStackTrace();
}
if (secondaryInput != null) {
recipeInputs.add(secondaryInput);
}
if (secondaryInput != null) {
recipeInputs.add(secondaryInput);
}
}
return recipeInputs;
}
return recipeInputs;
}
return null;
return recipeInputs;
}
@Nonnull
@Override
public List<PositionedStack> getRecipeOutput(IRecipeHandler recipe, int recipeIndex, String identifier) {
for (String ident : getAllOverlayIdentifier()) {
if (ident.equals(identifier)) {
List<PositionedStack> recipeOutputs = new ArrayList<>();
recipeOutputs.add(recipe.getResultStack(recipeIndex));
if (recipe instanceof RecipeHandlerBase) {
Class<?> NEIRecipeBase = null;
List<PositionedStack> recipeOutputs = new ArrayList<>();
if (this.getAllOverlayIdentifier().contains(identifier)) {
recipeOutputs.add(recipe.getResultStack(recipeIndex));
if (recipe instanceof RecipeHandlerBase) {
Class<?> NEIRecipeBase = null;
try {
NEIRecipeBase = Class.forName("cofh.thermalexpansion.plugins.nei.handlers.RecipeHandlerBase$NEIRecipeBase");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
if (NEIRecipeBase != null) {
Field secondaryOutputField = ReflectionHelper.findField(NEIRecipeBase, "secondaryOutput");
Field secondaryOutputChanceField = ReflectionHelper.findField(NEIRecipeBase, "secondaryOutputChance");
PositionedStack secondaryOutput = null;
int secondaryOutputChance = 0;
try {
NEIRecipeBase = Class.forName("cofh.thermalexpansion.plugins.nei.handlers.RecipeHandlerBase$NEIRecipeBase");
} catch (ClassNotFoundException e) {
secondaryOutput = (PositionedStack) secondaryOutputField.get(((RecipeHandlerBase) recipe).arecipes.get(recipeIndex));
secondaryOutputChance = (int) secondaryOutputChanceField.get(((RecipeHandlerBase) recipe).arecipes.get(recipeIndex));
} catch (IllegalAccessException e) {
e.printStackTrace();
}
if (NEIRecipeBase != null) {
Field secondaryOutputField = ReflectionHelper.findField(NEIRecipeBase, "secondaryOutput");
Field secondaryOutputChanceField = ReflectionHelper.findField(NEIRecipeBase, "secondaryOutputChance");
PositionedStack secondaryOutput = null;
int secondaryOutputChance = 0;
try {
secondaryOutput = (PositionedStack) secondaryOutputField.get(((RecipeHandlerBase) recipe).arecipes.get(recipeIndex));
secondaryOutputChance = (int) secondaryOutputChanceField.get(((RecipeHandlerBase) recipe).arecipes.get(recipeIndex));
} catch (IllegalAccessException e) {
e.printStackTrace();
}
if (secondaryOutput != null && secondaryOutputChance >= 100) {
recipeOutputs.add(secondaryOutput);
}
if (secondaryOutput != null && secondaryOutputChance >= 100) {
recipeOutputs.add(secondaryOutput);
}
}
return recipeOutputs;
}
return recipeOutputs;
}
return null;
return recipeOutputs;
}
}
@@ -3,40 +3,45 @@ package com.github.vfyjxf.nee.processor;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.IRecipeHandler;
import javax.annotation.Nonnull;
import java.util.*;
/**
* @author vfyjxf
*/
public class VanillaRecipeProcessor implements IRecipeProcessor {
@Nonnull
@Override
public Set<String> getAllOverlayIdentifier() {
return new HashSet<>(Arrays.asList("brewing", "smelting", "fuel"));
}
@Nonnull
@Override
public String getRecipeProcessorId() {
return "Vanilla";
}
@Nonnull
@Override
public List<PositionedStack> getRecipeInput(IRecipeHandler recipe, int recipeIndex, String identifier) {
List<PositionedStack> recipeInputs = new ArrayList<>();
if ("brewing".equals(identifier) || "smelting".equals(identifier) || "fuel".equals(identifier)) {
if (this.getAllOverlayIdentifier().contains(identifier)) {
recipeInputs.addAll(recipe.getIngredientStacks(recipeIndex));
recipeInputs.addAll(recipe.getOtherStacks(recipeIndex));
}
return recipeInputs;
}
@Nonnull
@Override
public List<PositionedStack> getRecipeOutput(IRecipeHandler recipe, int recipeIndex, String identifier) {
if ("brewing".equals(identifier) || "smelting".equals(identifier) || "fuel".equals(identifier)) {
List<PositionedStack> recipeOutput = new ArrayList<>();
List<PositionedStack> recipeOutput = new ArrayList<>();
if (this.getAllOverlayIdentifier().contains(identifier)) {
recipeOutput.add(recipe.getResultStack(recipeIndex));
return recipeOutput;
}
return null;
return recipeOutput;
}
}
@@ -1,39 +1,19 @@
package com.github.vfyjxf.nee.utils;
import appeng.client.gui.AEBaseGui;
import appeng.container.implementations.ContainerPatternTerm;
import appeng.helpers.IContainerCraftingPacket;
import cpw.mods.fml.relauncher.ReflectionHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
* @author vfyjxf
*/
public class GuiUtils {
public static Slot getSlotUnderMouse(GuiContainer guiContainer, int mouseX, int mouseY) {
if (guiContainer instanceof AEBaseGui) {
Method getSlotMethod = ReflectionHelper.findMethod(AEBaseGui.class, (AEBaseGui) guiContainer, new String[]{"getSlot"}, int.class, int.class);
try {
return (Slot) getSlotMethod.invoke(guiContainer, mouseX, mouseY);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
return null;
}
public static boolean isPatternTermExGui(GuiScreen container) {
try {
Class<?> patternTermExClz = Class.forName("appeng.client.gui.implementations.GuiPatternTermEx");