Jump to content

[1.7.10] NEI + My Mod


HalestormXV

Recommended Posts

So one huge request I keep getting is to add NEI into my mod so that the Crafting Recipe's that are created in my custom crafting manager show up in NEI.

 

It is a pretty basic crafting manager that uses 5x5 and I have a custom smelting manager. I want to be able to answer my community and give them what they are asking (we can't always do this but I figure NEI is beneficial anyway).

 

Problem is I cannot find anything with how to integrate NEI into your mod. Anyone have any starting points I can jump off of? I haven't started any of the code yet, so i am at the VERY beginning stages of it but it is something being sought highly by my community, and like any mod author I want to try and give them what i can. And I know I can do this, but I just need to learn how.

Link to comment
Share on other sites

Basically you need to provide a class which extends

TemplateRecipeHandler

that will take in either an output item (and reconstruct the recipe) or take in an input, and list all recipes that contain it.

 

I've only got 1-to-1 recipes myself, but this should give you an idea of what the class looks like:

 

 

package com.draco18s.ores.recipes.nei;

import java.util.ArrayList;
import java.util.List;

import org.lwjgl.opengl.GL11;

import com.draco18s.hardlib.api.HardLibAPI;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.oredict.OreDictionary;
import codechicken.nei.PositionedStack;
import codechicken.nei.api.IOverlayHandler;
import codechicken.nei.api.IRecipeOverlayRenderer;
import codechicken.nei.recipe.GuiRecipe;
import codechicken.nei.recipe.ICraftingHandler;
import codechicken.nei.recipe.TemplateRecipeHandler;

public class SifterNEI extends TemplateRecipeHandler {

@Override
public String getRecipeName() {
	return "Sifter";
}

@Override
public String getOverlayIdentifier() {
	return "sifter";
}

@Override
public String getGuiTexture() {
	return "ores:textures/gui/sifter.png";
}

//loads recipes from output
@Override
public void loadCraftingRecipes(String outputId, Object...results) {
	if ((outputId.equals("item") || outputId.equals("sifter")) && (results.length > 0)) {
		loadCraftingRecipes((ItemStack)results[0]);
	}
}

//loads recipes from output
@Override
public void loadCraftingRecipes(ItemStack result) {
	ItemStack ingredient = HardLibAPI.recipeManager.getSiftRecipeInput(result);
	//the not-equals here is exclusion code specific to my device
	if(ingredient!=null && !ItemStack.areItemStacksEqual(ingredient, result)) {
		CachedRecipe recipe = new CachedSifterRecipe(ingredient);
		arecipes.add(recipe);
	}
}

//load recipes from partial recipe input
@Override
public void loadUsageRecipes(String inputId, Object... ingredients) {
	if(ingredients.length >= 1 && ingredients[0] instanceof ItemStack)
		loadUsageRecipes((ItemStack) ingredients[0]);
}

//load recipes from partial recipe input
@Override
public void loadUsageRecipes(ItemStack ingredient) {
	ItemStack output = HardLibAPI.recipeManager.getSiftResult(ingredient, false);
	if(output!=null && !ItemStack.areItemStacksEqual(ingredient, output)) {
		CachedRecipe recipe = new CachedSifterRecipe(HardLibAPI.recipeManager.getSiftRecipeInput(output));
		arecipes.add(recipe);
	}
}

//this is for drawing extra widgets like progress bars, smelting indicators, etc.
//I do not recall what the various numbers indicate.  First two are, IIRC, the position on the screen
@Override
public void drawExtras(int recipe) {
	drawProgressBar(74, 20, 176, 0, 17, 24, 40, 1);
}

//You will need to extend TemplateRecipeHandler.CachedRecipe, but you will need to modify the particulars.
//numbers in the positioned stacks below are location on screen.
public class CachedSifterRecipe extends TemplateRecipeHandler.CachedRecipe {
	private PositionedStack ingredient;
	private PositionedStack stack;

	public CachedSifterRecipe(Object _ingredient) {
		super();
		if(_ingredient instanceof ItemStack) {
			ItemStack ingred = ((ItemStack)_ingredient).copy();
			ingred.stackSize = 64; //specific for my machine
			ingred.stackSize = HardLibAPI.recipeManager.getSiftAmount(ingred);
			ingredient = new PositionedStack(ingred, 66, 2);
			stack = new PositionedStack(HardLibAPI.recipeManager.getSiftResult((ItemStack)_ingredient, false), 75, 47);
		}
		else if(_ingredient instanceof String) {
			ArrayList<ItemStack> list = OreDictionary.getOres((String)_ingredient);

			if (list.size() > 0) {
				ingredient = new PositionedStack(list, 66, 2);
				stack = new PositionedStack(HardLibAPI.recipeManager.getSiftResult((ItemStack)_ingredient, false), 75, 47);
			}
		} else {
			ingredient = null;
		}
	}

	@Override
	public PositionedStack getIngredient() {
		return ingredient;
	}

	@Override
	public PositionedStack getResult() {
		return stack;
	}

	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof CachedSifterRecipe)) {
			return false;
		}
		CachedSifterRecipe other = (CachedSifterRecipe)obj;
		if (ingredient == null) {
			if (other.ingredient != null)
				return false;
		}
		else if (ingredient.item == null) {
			if (other.ingredient.item != null)
				return false;
		}
		else if (!ItemStack.areItemStacksEqual(ingredient.item, other.ingredient.item)) {
			return false;
		}
		if (stack == null) {
			if (other.stack != null)
				return false;
		}
		else if (stack.item == null) {
			if (other.stack.item != null)
				return false;
		}
		else if (!ItemStack.areItemStacksEqual(stack.item, other.stack.item)) {
			return false;
		}
		return true;
	}
}
}

 

 

Then you need to register it with NEI:

 

		TemplateRecipeHandler handler = new SifterNEI();
	API.registerUsageHandler(handler);
	API.registerRecipeHandler(handler);
	API.registerGuiOverlay(GuiContainerSifter.class, "sifter");
	API.registerGuiOverlayHandler(GuiContainerSifter.class, new DefaultOverlayHandler(), "sifter");

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Alright that is helpful. Now is implementing the NEI API (or any API) different in 1.7.10 or is this tutorial (judging by the date of the post I imagine that actually was for 1.7.x? Or at least universal):

http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/1571434-tutorial-modding-with-apis

 

still an accurate way to do it. I haven't used an API for anything yet so forgive what would seem like a rudimentary question.

Link to comment
Share on other sites

My code above was for 1.7.10 and was for a very simple machine.  CoolAlias's tutorials are extra generic and cover how to go about working with an API of any sort, looks like 1.7.10 though.

 

The only thing to be aware of when programming for an API is what to do if the API is not present, ie. if someone does not have NEI installed.

 

For something like NEI, this is easy: wrap your NEI API calls in a separate class and only call methods in that class if NEI is loaded.  For other things, like when a block or item needs to implement some API interface, but you still want that item to work when the API isn't available, you need to use the @Optional annotations, found in the cpw.mods.fml.common package (

import cpw.mods.fml.common;

).

 

@Optional is essentially (a flag for) some wicked clever ASM that strips out interfaces and/or methods if the target mod isn't installed (as not stripping them out would cause ClassNotFound errors).  Lets you have TileEntities which extend IEnergyProvider from [tech mod here] and IGenerator from [some other tech mod] and work with either but require none, instead using your own blocks.

 

Here's an example:

 

public class IndustryEventHandler {
@SubscribeEvent
public void onCrafting(PlayerEvent.ItemCraftedEvent event) {
	//standard event method
}

@SubscribeEvent
@Optional.Method(modid = "HardLib")
public void itemFrameCompare(ItemFrameComparatorPowerEvent event) {
	if(event.stack == null || !(event.entity instanceof EntityItemFrame) || event.power > 0) return;
		event.power = ((EntityItemFrame)event.entity).getRotation()*2+1;
}
}

 

The

itemFrameCompare

method has an event object of type

ItemFrameComparatorPowerEvent

which I had added to my own core library, but the mod this is in has no other dependencies, so it was not set up to actually depend on that library.  So rather than go "surprise, you need my library" I marked it as optional.  The feature won't work without the library, but there was no reason to enforce the dependency for such a trivial feature.

(This event/method adds the ItemFrame Comparator function present in 1.8 to 1.7.10 in order to meet the demands of a requested feature in one of my other mods, the general-purpose orientation code was easy to write and fit in with this particular mod).

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • So i know for a fact this has been asked before but Render stuff troubles me a little and i didnt find any answer for recent version. I have a custom nausea effect. Currently i add both my nausea effect and the vanilla one for the effect. But the problem is that when I open the inventory, both are listed, while I'd only want mine to show up (both in the inv and on the GUI)   I've arrived to the GameRender (on joined/net/minecraft/client) and also found shaders on client-extra/assets/minecraft/shaders/post and client-extra/assets/minecraft/shaders/program but I'm lost. I understand that its like a regular screen, where I'd render stuff "over" the game depending on data on the server, but If someone could point to the right client and server classes that i can read to see how i can manage this or any tip would be apreciated
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.