Fix @WayofTime using the shaped/shapeless in the joshie folder, when he should be using the ones in the api folder.

Repackage the NEI stuff to the main folder, I was being egotistical.
Also Includes @Tonius changes for adding a recipe button to the alchemical chemistry set for the nei handler.
And adds some checks, to the recipes, as sometimes they crash when adding/removing any.
This commit is contained in:
joshiejack 2014-10-16 05:27:37 +01:00
parent 772bcf1ee6
commit d0e974ddef
9 changed files with 208 additions and 545 deletions

View file

@ -6,6 +6,8 @@ import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentRegistry;
import WayofTime.alchemicalWizardry.api.altarRecipeRegistry.AltarRecipeRegistry;
import WayofTime.alchemicalWizardry.api.bindingRegistry.BindingRegistry;
import WayofTime.alchemicalWizardry.api.harvest.HarvestRegistry;
import WayofTime.alchemicalWizardry.api.items.ShapedBloodOrbRecipe;
import WayofTime.alchemicalWizardry.api.items.ShapelessBloodOrbRecipe;
import WayofTime.alchemicalWizardry.api.rituals.Rituals;
import WayofTime.alchemicalWizardry.api.summoningRegistry.SummoningRegistry;
import WayofTime.alchemicalWizardry.common.*;
@ -41,8 +43,6 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import joshie.alchemicalWizardy.ShapedBloodOrbRecipe;
import joshie.alchemicalWizardy.ShapelessBloodOrbRecipe;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;

View file

@ -0,0 +1,179 @@
package WayofTime.alchemicalWizardry.client.nei;
import static WayofTime.alchemicalWizardry.client.nei.NEIConfig.bloodOrbs;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import WayofTime.alchemicalWizardry.api.alchemy.AlchemyRecipe;
import WayofTime.alchemicalWizardry.api.alchemy.AlchemyRecipeRegistry;
import WayofTime.alchemicalWizardry.api.items.interfaces.IBloodOrb;
import WayofTime.alchemicalWizardry.common.tileEntity.gui.GuiWritingTable;
import codechicken.nei.ItemList;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.TemplateRecipeHandler;
/**
* NEI Alchemy Recipe Handler by joshie *
*/
public class NEIAlchemyRecipeHandler extends TemplateRecipeHandler {
public class CachedAlchemyRecipe extends CachedRecipe {
public class BloodOrbs {
public PositionedStack stack;
public BloodOrbs(ItemStack orb) {
this.stack = new PositionedStack(orb, 136, 47, false);
}
}
ArrayList<BloodOrbs> orbs;
PositionedStack output;
List<PositionedStack> inputs;
int lp;
public CachedAlchemyRecipe(AlchemyRecipe recipe, ItemStack orb) {
this(recipe);
this.orbs = new ArrayList<BloodOrbs>();
orbs.add(new BloodOrbs(orb));
}
public CachedAlchemyRecipe(AlchemyRecipe recipe) {
List<PositionedStack> inputs = new ArrayList<PositionedStack>();
ItemStack[] stacks = recipe.getRecipe();
if (stacks.length > 0) inputs.add(new PositionedStack(stacks[0], 76, 3));
if (stacks.length > 1) inputs.add(new PositionedStack(stacks[1], 51, 19));
if (stacks.length > 2) inputs.add(new PositionedStack(stacks[2], 101, 19));
if (stacks.length > 3) inputs.add(new PositionedStack(stacks[3], 64, 47));
if (stacks.length > 4) inputs.add(new PositionedStack(stacks[4], 88, 47));
this.inputs = inputs;
this.output = new PositionedStack(recipe.getResult(), 76, 25);
this.lp = recipe.getAmountNeeded() * 100;
this.orbs = new ArrayList<BloodOrbs>();
for (Item orb : bloodOrbs) {
if (((IBloodOrb) orb).getOrbLevel() >= recipe.getOrbLevel()) {
orbs.add(new BloodOrbs(new ItemStack(orb)));
}
}
}
@Override
public List<PositionedStack> getIngredients() {
return inputs;
}
@Override
public PositionedStack getResult() {
return output;
}
@Override
public PositionedStack getOtherStack() {
if (orbs == null || orbs.size() <= 0) return null;
return orbs.get((cycleticks / 48) % orbs.size()).stack;
}
}
@Override
public TemplateRecipeHandler newInstance() {
for (ItemStack item : ItemList.items) {
if (item != null && item.getItem() instanceof IBloodOrb) {
bloodOrbs.add(item.getItem());
}
}
return super.newInstance();
}
@Override
public String getOverlayIdentifier() {
return "alchemicalwizardry.alchemy";
}
@Override
public void loadTransferRects() {
transferRects.add(new RecipeTransferRect(new Rectangle(134, 22, 16, 24), "alchemicalwizardry.alchemy"));
}
@Override
public Class<? extends GuiContainer> getGuiClass() {
return GuiWritingTable.class;
}
@Override
public void loadCraftingRecipes(String outputId, Object... results) {
if (outputId.equals("alchemicalwizardry.alchemy") && getClass() == NEIAlchemyRecipeHandler.class) {
for (AlchemyRecipe recipe : AlchemyRecipeRegistry.recipes) {
if (recipe.getResult() != null) arecipes.add(new CachedAlchemyRecipe(recipe));
}
} else {
super.loadCraftingRecipes(outputId, results);
}
}
@Override
public void loadCraftingRecipes(ItemStack result) {
for (AlchemyRecipe recipe : AlchemyRecipeRegistry.recipes) {
if (recipe == null) continue;
ItemStack output = recipe.getResult();
if (NEIServerUtils.areStacksSameTypeCrafting(result, recipe.getResult())) {
arecipes.add(new CachedAlchemyRecipe(recipe));
}
}
}
@Override
public void loadUsageRecipes(ItemStack ingredient) {
if (ingredient.getItem() instanceof IBloodOrb) {
for (AlchemyRecipe recipe : AlchemyRecipeRegistry.recipes) {
if (recipe == null) continue;
if (((IBloodOrb) ingredient.getItem()).getOrbLevel() >= recipe.getOrbLevel()) {
arecipes.add(new CachedAlchemyRecipe(recipe, ingredient));
}
}
} else {
for (AlchemyRecipe recipe : AlchemyRecipeRegistry.recipes) {
if (recipe == null) continue;
ItemStack[] stacks = recipe.getRecipe();
for (ItemStack stack : stacks) {
if (NEIServerUtils.areStacksSameTypeCrafting(stack, ingredient)) {
arecipes.add(new CachedAlchemyRecipe(recipe));
break;
}
}
}
}
}
@Override
public void drawExtras(int id) {
CachedAlchemyRecipe cache = (CachedAlchemyRecipe) arecipes.get(id);
Minecraft.getMinecraft().fontRenderer.drawString("\u00a77" + cache.lp + "LP", getLPX(cache.lp), 34, 0);
}
public int getLPX(int lp) {
if (lp < 10) return 122;
else if (lp < 100) return 122;
else if (lp < 1000) return 130;
else if (lp < 10000) return 127;
else if (lp < 100000) return 124;
return 122;
}
@Override
public String getRecipeName() {
return StatCollector.translateToLocal("tile.blockWritingTable.name");
}
@Override
public String getGuiTexture() {
return new ResourceLocation("alchemicalwizardry", "gui/nei/alchemy.png").toString();
}
}

View file

@ -0,0 +1,185 @@
package WayofTime.alchemicalWizardry.client.nei;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.lang.reflect.Field;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import org.lwjgl.input.Mouse;
import WayofTime.alchemicalWizardry.api.altarRecipeRegistry.AltarRecipe;
import WayofTime.alchemicalWizardry.api.altarRecipeRegistry.AltarRecipeRegistry;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.GuiRecipe;
import codechicken.nei.recipe.TemplateRecipeHandler;
/**
* NEI Altar Recipe Handler by joshie *
*/
public class NEIAltarRecipeHandler extends TemplateRecipeHandler {
public class CachedAltarRecipe extends CachedRecipe {
PositionedStack input;
PositionedStack output;
int tier, lp_amount, consumption, drain;
public CachedAltarRecipe(AltarRecipe recipe) {
input = new PositionedStack(recipe.requiredItem, 38, 2, false);
output = new PositionedStack(recipe.result, 132, 32, false);
tier = recipe.minTier;
lp_amount = recipe.liquidRequired;
consumption = recipe.consumptionRate;
drain = recipe.drainRate;
}
@Override
public PositionedStack getIngredient() {
return input;
}
@Override
public PositionedStack getResult() {
return output;
}
}
@Override
public void loadCraftingRecipes(String outputId, Object... results) {
if (outputId.equals("alchemicalwizardry.altar") && getClass() == NEIAltarRecipeHandler.class) {
for(AltarRecipe recipe: AltarRecipeRegistry.altarRecipes) {
if(recipe != null && recipe.result != null) arecipes.add(new CachedAltarRecipe(recipe));
}
} else {
super.loadCraftingRecipes(outputId, results);
}
}
@Override
public void loadCraftingRecipes(ItemStack result) {
for(AltarRecipe recipe: AltarRecipeRegistry.altarRecipes) {
if(NEIServerUtils.areStacksSameTypeCrafting(recipe.result, result)) {
if(recipe != null && recipe.result != null) arecipes.add(new CachedAltarRecipe(recipe));
}
}
}
@Override
public void loadUsageRecipes(ItemStack ingredient) {
for(AltarRecipe recipe: AltarRecipeRegistry.altarRecipes) {
if(NEIServerUtils.areStacksSameTypeCrafting(recipe.requiredItem, ingredient)) {
if(recipe != null && recipe.result != null) arecipes.add(new CachedAltarRecipe(recipe));
}
}
}
//Mouse Position helper
public Point getMouse(int width, int height) {
Point mousepos = this.getMousePosition();
int guiLeft = (width - 176) / 2;
int guiTop = (height - 166) / 2;
Point relMouse = new Point(mousepos.x - guiLeft, mousepos.y - guiTop);
return relMouse;
}
//width helper, getting width normal way hates me on compile
public int getGuiWidth(GuiRecipe gui) {
try {
Field f = gui.getClass().getField("width");
return (Integer) f.get(gui);
} catch (NoSuchFieldException e) {
try {
Field f = gui.getClass().getField("field_146294_l");
return (Integer) f.get(gui);
} catch (Exception e2) {
return 0;
}
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
//height helper, getting height normal way hates me on compile
public int getGuiHeight(GuiRecipe gui) {
try {
Field f = gui.getClass().getField("height");
return (Integer) f.get(gui);
} catch (NoSuchFieldException e) {
try {
Field f = gui.getClass().getField("field_146295_m");
return (Integer) f.get(gui);
} catch (Exception e2) {
return 0;
}
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
@Override
public void drawExtras(int id) {
CachedAltarRecipe recipe = (CachedAltarRecipe) arecipes.get(id);
Minecraft.getMinecraft().fontRenderer.drawString("\u00a77" + StatCollector.translateToLocal("bm.string.tier") + ": " + recipe.tier, 78, 5, 0);
Minecraft.getMinecraft().fontRenderer.drawString("\u00a77" + "LP: " + recipe.lp_amount, 78, 15, 0);
}
@Override
public List<String> handleTooltip(GuiRecipe gui, List<String> currenttip, int id) {
currenttip = super.handleTooltip(gui, currenttip, id);
Point mouse = getMouse(getGuiWidth(gui), getGuiHeight(gui));
CachedAltarRecipe recipe = (CachedAltarRecipe) arecipes.get(id);
int yLow = id % 2 == 0 ? 38 : 102;
int yHigh = id % 2 == 0 ? 72 : 136;
if(mouse.x >= 19 && mouse.x <= 80 && mouse.y >= yLow && mouse.y <= yHigh) {
currenttip.add(StatCollector.translateToLocal("bm.string.consume") + ": " + recipe.consumption + "LP/t");
currenttip.add(StatCollector.translateToLocal("bm.string.drain") + ": " + recipe.drain + "LP/t");
}
return currenttip;
}
@Override
public String getOverlayIdentifier() {
return "altarrecipes";
}
@Override
public void loadTransferRects() {
transferRects.add(new RecipeTransferRect(new Rectangle(90, 32, 22, 16), "alchemicalwizardry.altar"));
}
@Override
public String getRecipeName() {
return " " + StatCollector.translateToLocal("tile.bloodAltar.name");
}
@Override
public String getGuiTexture() {
return new ResourceLocation("alchemicalwizardry", "gui/nei/altar.png").toString();
}
public static Point getMousePosition() {
Dimension size = displaySize();
Dimension res = displayRes();
return new Point(Mouse.getX() * size.width / res.width, size.height - Mouse.getY() * size.height / res.height - 1);
}
public static Dimension displaySize() {
Minecraft mc = Minecraft.getMinecraft();
ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
return new Dimension(res.getScaledWidth(), res.getScaledHeight());
}
public static Dimension displayRes() {
Minecraft mc = Minecraft.getMinecraft();
return new Dimension(mc.displayWidth, mc.displayHeight);
}
}

View file

@ -0,0 +1,141 @@
package WayofTime.alchemicalWizardry.client.nei;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.StatCollector;
import WayofTime.alchemicalWizardry.api.items.ShapedBloodOrbRecipe;
import WayofTime.alchemicalWizardry.api.items.interfaces.IBloodOrb;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.ShapedRecipeHandler;
/**
* NEI Blood Orb Shaped Recipe Handler by joshie *
*/
public class NEIBloodOrbShapedHandler extends ShapedRecipeHandler {
public class CachedBloodOrbRecipe extends CachedShapedRecipe {
public CachedBloodOrbRecipe(int width, int height, Object[] items, ItemStack out) {
super(width, height, items, out);
}
@Override
public void setIngredients(int width, int height, Object[] items) {
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
if (items[y * width + x] == null)
continue;
Object o = items[y * width + x];
if (o instanceof ItemStack) {
PositionedStack stack = new PositionedStack(items[y * width + x], 25 + x * 18, 6 + y * 18, false);
stack.setMaxSize(1);
ingredients.add(stack);
} else if (o instanceof Integer) {
ArrayList<ItemStack> orbs = new ArrayList();
for (Item item : NEIConfig.bloodOrbs) {
if (((IBloodOrb) item).getOrbLevel() >= (Integer) o) {
orbs.add(new ItemStack(item));
}
}
PositionedStack stack = new PositionedStack(orbs, 25 + x * 18, 6 + y * 18, false);
stack.setMaxSize(1);
ingredients.add(stack);
}
}
}
}
}
@Override
public void loadCraftingRecipes(String outputId, Object... results) {
if (outputId.equals("crafting") && getClass() == NEIBloodOrbShapedHandler.class) {
for (IRecipe irecipe : (List<IRecipe>) CraftingManager.getInstance().getRecipeList()) {
if (irecipe instanceof ShapedBloodOrbRecipe) {
CachedBloodOrbRecipe recipe = forgeShapedRecipe((ShapedBloodOrbRecipe) irecipe);
if (recipe == null)
continue;
recipe.computeVisuals();
arecipes.add(recipe);
}
}
} else {
super.loadCraftingRecipes(outputId, results);
}
}
@Override
public void loadCraftingRecipes(ItemStack result) {
for (IRecipe irecipe : (List<IRecipe>) CraftingManager.getInstance().getRecipeList()) {
if (irecipe instanceof ShapedBloodOrbRecipe) {
CachedBloodOrbRecipe recipe = forgeShapedRecipe((ShapedBloodOrbRecipe) irecipe);
if (recipe == null || !NEIServerUtils.areStacksSameTypeCrafting(recipe.result.item, result))
continue;
recipe.computeVisuals();
arecipes.add(recipe);
}
}
}
@Override
public void loadUsageRecipes(ItemStack ingredient) {
for (IRecipe irecipe : (List<IRecipe>) CraftingManager.getInstance().getRecipeList()) {
CachedShapedRecipe recipe = null;
if (irecipe instanceof ShapedBloodOrbRecipe)
recipe = forgeShapedRecipe((ShapedBloodOrbRecipe) irecipe);
if (recipe == null || !recipe.contains(recipe.ingredients, ingredient.getItem()))
continue;
recipe.computeVisuals();
if (recipe.contains(recipe.ingredients, ingredient)) {
recipe.setIngredientPermutation(recipe.ingredients, ingredient);
arecipes.add(recipe);
}
}
}
private CachedBloodOrbRecipe forgeShapedRecipe(ShapedBloodOrbRecipe recipe) {
int width;
int height;
try {
width = recipe.width;
height = recipe.height;
} catch (Exception e) {
e.printStackTrace();
return null;
}
Object[] items = recipe.getInput();
for (Object item : items)
if (item instanceof List && ((List<?>) item).isEmpty())// ore
// handler,
// no ores
return null;
return new CachedBloodOrbRecipe(width, height, items, recipe.getRecipeOutput());
}
@Override
public void loadTransferRects() {
transferRects.add(new RecipeTransferRect(new Rectangle(84, 23, 24, 18), "crafting"));
}
@Override
public String getOverlayIdentifier() {
return "crafting";
}
@Override
public String getRecipeName() {
return StatCollector.translateToLocal("bm.string.crafting.orb.shaped");
}
}

View file

@ -0,0 +1,130 @@
package WayofTime.alchemicalWizardry.client.nei;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.StatCollector;
import WayofTime.alchemicalWizardry.api.items.ShapelessBloodOrbRecipe;
import WayofTime.alchemicalWizardry.api.items.interfaces.IBloodOrb;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.ShapelessRecipeHandler;
/**
* NEI Blood Orb Shapeless Recipe Handler by joshie *
*/
public class NEIBloodOrbShapelessHandler extends ShapelessRecipeHandler {
public class CachedBloodOrbRecipe extends CachedShapelessRecipe {
public CachedBloodOrbRecipe(ArrayList<Object> items, ItemStack recipeOutput) {
super(items, recipeOutput);
}
@Override
public void setIngredients(List<?> items) {
ingredients.clear();
for (int ingred = 0; ingred < items.size(); ingred++) {
Object o = items.get(ingred);
if (o instanceof ItemStack) {
PositionedStack stack = new PositionedStack(items.get(ingred), 25 + stackorder[ingred][0] * 18, 6 + stackorder[ingred][1] * 18);
stack.setMaxSize(1);
ingredients.add(stack);
} else if (o instanceof Integer) {
ArrayList<ItemStack> orbs = new ArrayList();
for (Item item : NEIConfig.bloodOrbs) {
if (((IBloodOrb) item).getOrbLevel() >= (Integer) o) {
orbs.add(new ItemStack(item));
}
}
PositionedStack stack = new PositionedStack(orbs, 25 + stackorder[ingred][0] * 18, 6 + stackorder[ingred][1] * 18);
stack.setMaxSize(1);
ingredients.add(stack);
}
}
}
}
@Override
public void loadCraftingRecipes(String outputId, Object... results) {
if (outputId.equals("crafting") && getClass() == NEIBloodOrbShapelessHandler.class) {
List<IRecipe> allrecipes = CraftingManager.getInstance().getRecipeList();
for (IRecipe irecipe : allrecipes) {
CachedBloodOrbRecipe recipe = null;
if (irecipe instanceof ShapelessBloodOrbRecipe)
recipe = forgeShapelessRecipe((ShapelessBloodOrbRecipe) irecipe);
if (recipe == null)
continue;
arecipes.add(recipe);
}
} else {
super.loadCraftingRecipes(outputId, results);
}
}
@Override
public void loadCraftingRecipes(ItemStack result) {
List<IRecipe> allrecipes = CraftingManager.getInstance().getRecipeList();
for (IRecipe irecipe : allrecipes) {
if (NEIServerUtils.areStacksSameTypeCrafting(irecipe.getRecipeOutput(), result)) {
CachedBloodOrbRecipe recipe = null;
if (irecipe instanceof ShapelessBloodOrbRecipe)
recipe = forgeShapelessRecipe((ShapelessBloodOrbRecipe) irecipe);
if (recipe == null)
continue;
arecipes.add(recipe);
}
}
}
@Override
public void loadUsageRecipes(ItemStack ingredient) {
List<IRecipe> allrecipes = CraftingManager.getInstance().getRecipeList();
for (IRecipe irecipe : allrecipes) {
CachedBloodOrbRecipe recipe = null;
if (irecipe instanceof ShapelessBloodOrbRecipe)
recipe = forgeShapelessRecipe((ShapelessBloodOrbRecipe) irecipe);
if (recipe == null)
continue;
if (recipe.contains(recipe.ingredients, ingredient)) {
recipe.setIngredientPermutation(recipe.ingredients, ingredient);
arecipes.add(recipe);
}
}
}
public CachedBloodOrbRecipe forgeShapelessRecipe(ShapelessBloodOrbRecipe recipe) {
ArrayList<Object> items = recipe.getInput();
for (Object item : items)
if (item instanceof List && ((List<?>) item).isEmpty())//ore handler, no ores
return null;
return new CachedBloodOrbRecipe(items, recipe.getRecipeOutput());
}
@Override
public void loadTransferRects() {
transferRects.add(new RecipeTransferRect(new Rectangle(84, 23, 24, 18), "crafting"));
}
@Override
public String getOverlayIdentifier() {
return "crafting";
}
@Override
public String getRecipeName() {
return StatCollector.translateToLocal("bm.string.crafting.orb.shapeless");
}
}

View file

@ -0,0 +1,33 @@
package WayofTime.alchemicalWizardry.client.nei;
import java.util.ArrayList;
import net.minecraft.item.Item;
import codechicken.nei.api.API;
import codechicken.nei.api.IConfigureNEI;
public class NEIConfig implements IConfigureNEI {
public static ArrayList<Item> bloodOrbs = new ArrayList<Item>();
@Override
public void loadConfig() {
API.registerRecipeHandler(new NEIAlchemyRecipeHandler());
API.registerUsageHandler(new NEIAlchemyRecipeHandler());
API.registerRecipeHandler(new NEIAltarRecipeHandler());
API.registerUsageHandler(new NEIAltarRecipeHandler());
API.registerRecipeHandler(new NEIBloodOrbShapedHandler());
API.registerUsageHandler(new NEIBloodOrbShapedHandler());
API.registerRecipeHandler(new NEIBloodOrbShapelessHandler());
API.registerUsageHandler(new NEIBloodOrbShapelessHandler());
}
@Override
public String getName() {
return "Blood Magic NEI";
}
@Override
public String getVersion() {
return "1.3";
}
}