Moved NEI handlers to plugins package, added drying rack handler

This commit is contained in:
Tonius committed 2014-09-19 13:58:22 +02:00
1 parent 9e7eec8215
commit 66a45e0145
15 files changed
+249 -124

No files matched your search

@@ -1,21 +0,0 @@
package tconstruct.plugins.nei;
import codechicken.nei.api.API;
import codechicken.nei.recipe.DefaultOverlayHandler;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import tconstruct.tools.gui.CraftingStationGui;
public class NEICompat
{
public static void registerNEICompat ()
{
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
{
API.registerGuiOverlay(CraftingStationGui.class, "crafting");
API.registerGuiOverlayHandler(CraftingStationGui.class, new DefaultOverlayHandler(), "crafting");
}
}
}
@@ -0,0 +1,42 @@
package tconstruct.plugins.nei;
import tconstruct.tools.gui.CraftingStationGui;
import codechicken.nei.api.API;
import codechicken.nei.api.IConfigureNEI;
import codechicken.nei.recipe.DefaultOverlayHandler;
public class NEITConstructConfig implements IConfigureNEI
{
@Override
public void loadConfig ()
{
API.registerGuiOverlay(CraftingStationGui.class, "crafting");
API.registerGuiOverlayHandler(CraftingStationGui.class, new DefaultOverlayHandler(), "crafting");
API.registerRecipeHandler(new RecipeHandlerDryingRack());
API.registerUsageHandler(new RecipeHandlerDryingRack());
API.registerRecipeHandler(new RecipeHandlerMelting());
API.registerUsageHandler(new RecipeHandlerMelting());
API.registerRecipeHandler(new RecipeHandlerAlloying());
API.registerUsageHandler(new RecipeHandlerAlloying());
API.registerRecipeHandler(new RecipeHandlerCastingTable());
API.registerUsageHandler(new RecipeHandlerCastingTable());
API.registerRecipeHandler(new RecipeHandlerCastingBasin());
API.registerUsageHandler(new RecipeHandlerCastingBasin());
}
@Override
public String getName ()
{
return "TConstruct";
}
@Override
public String getVersion ()
{
return "${version}";
}
}
@@ -0,0 +1,166 @@
package tconstruct.plugins.nei;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.minecraftforge.fluids.FluidStack;
import org.lwjgl.opengl.GL11;
import tconstruct.library.crafting.AlloyMix;
import tconstruct.library.crafting.Smeltery;
import codechicken.lib.gui.GuiDraw;
import codechicken.nei.PositionedStack;
public class RecipeHandlerAlloying extends RecipeHandlerBase
{
public static final Rectangle OUTPUT_TANK = new Rectangle(118, 9, 18, 32);
public class CachedAlloyingRecipe extends CachedBaseRecipe
{
private List<FluidTankElement> fluidTanks;
private int minAmount;
public CachedAlloyingRecipe(AlloyMix recipe)
{
this.fluidTanks = new ArrayList<FluidTankElement>();
int maxAmount = recipe.mixers.get(0).amount;
int mult = 1;
this.minAmount = maxAmount;
for (FluidStack stack : recipe.mixers)
{
if (stack.amount > maxAmount)
{
maxAmount = stack.amount;
}
if (stack.amount < this.minAmount)
{
this.minAmount = stack.amount;
}
}
FluidTankElement tank = new FluidTankElement(OUTPUT_TANK, maxAmount * mult, recipe.result);
tank.fluid.amount *= mult;
this.fluidTanks.add(tank);
int width = 36 / recipe.mixers.size();
int counter = 0;
for (FluidStack stack : recipe.mixers)
{
if (counter == recipe.mixers.size() - 1)
{
tank = new FluidTankElement(new Rectangle(21 + width * counter, 9, 36 - width * counter, 32), maxAmount * mult, stack);
}
else
{
tank = new FluidTankElement(new Rectangle(21 + width * counter, 9, width, 32), maxAmount * mult, stack);
}
tank.fluid.amount *= mult;
this.fluidTanks.add(tank);
counter++;
}
}
@Override
public PositionedStack getIngredient ()
{
return null;
}
@Override
public PositionedStack getResult ()
{
return null;
}
@Override
public List<FluidTankElement> getFluidTanks ()
{
return this.fluidTanks;
}
}
@Override
public String getRecipeName ()
{
return "Smeltery Alloying";
}
@Override
public String getRecipeID ()
{
return "tconstruct.smeltery.alloying";
}
@Override
public String getGuiTexture ()
{
return "tinker:textures/gui/nei/smeltery.png";
}
@Override
public void loadTransferRects ()
{
this.transferRects.add(new RecipeTransferRect(new Rectangle(76, 21, 22, 15), this.getRecipeID(), new Object[0]));
}
@Override
public void drawBackground (int recipe)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GuiDraw.changeTexture(this.getGuiTexture());
GuiDraw.drawTexturedModalRect(0, 0, 0, 62, 160, 65);
}
@Override
public void loadCraftingRecipes (String outputId, Object... results)
{
if (outputId.equals(this.getRecipeID()))
{
for (AlloyMix recipe : Smeltery.getAlloyList())
{
if (!recipe.mixers.isEmpty())
{
this.arecipes.add(new CachedAlloyingRecipe(recipe));
}
}
}
else
{
super.loadCraftingRecipes(outputId, results);
}
}
@Override
public void loadCraftingRecipes (FluidStack result)
{
for (AlloyMix recipe : Smeltery.getAlloyList())
{
if (areFluidsEqual(recipe.result, result) && !recipe.mixers.isEmpty())
{
this.arecipes.add(new CachedAlloyingRecipe(recipe));
}
}
}
@Override
public void loadUsageRecipes (FluidStack ingredient)
{
for (Iterator<AlloyMix> i = Smeltery.getAlloyList().iterator(); i.hasNext();)
{
AlloyMix recipe = i.next();
for (FluidStack liquid : recipe.mixers)
{
if (areFluidsEqual(liquid, ingredient) && !recipe.mixers.isEmpty())
{
this.arecipes.add(new CachedAlloyingRecipe(recipe));
break;
}
}
}
}
}
@@ -0,0 +1,361 @@
package tconstruct.plugins.nei;
import java.awt.Point;
import java.awt.Rectangle;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IIcon;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidBlock;
import net.minecraftforge.fluids.IFluidContainerItem;
import org.lwjgl.opengl.GL11;
import codechicken.lib.gui.GuiDraw;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.recipe.GuiCraftingRecipe;
import codechicken.nei.recipe.GuiRecipe;
import codechicken.nei.recipe.GuiUsageRecipe;
import codechicken.nei.recipe.TemplateRecipeHandler;
public abstract class RecipeHandlerBase extends TemplateRecipeHandler
{
public abstract class CachedBaseRecipe extends CachedRecipe
{
public List<FluidTankElement> getFluidTanks ()
{
return null;
}
}
public abstract String getRecipeID ();
public void loadCraftingRecipes (FluidStack result)
{
}
public void loadUsageRecipes (FluidStack ingredient)
{
}
@Override
public void drawForeground (int recipe)
{
super.drawForeground(recipe);
this.drawFluidTanks(recipe);
}
@Override
public void loadCraftingRecipes (String outputId, Object... results)
{
try
{
if (outputId.equals("liquid") && results.length == 1 && results[0] instanceof FluidStack)
{
this.loadCraftingRecipes((FluidStack) results[0]);
}
else
{
super.loadCraftingRecipes(outputId, results);
}
}
catch (Throwable ex)
{
ex.printStackTrace();
}
}
@Override
public void loadCraftingRecipes (ItemStack result)
{
FluidStack fluid = getFluidStack(result);
if (fluid != null)
{
this.loadCraftingRecipes(fluid);
}
}
@Override
public void loadUsageRecipes (String inputId, Object... ingredients)
{
try
{
if (inputId.equals("liquid") && ingredients.length == 1 && ingredients[0] instanceof FluidStack)
{
this.loadUsageRecipes((FluidStack) ingredients[0]);
}
else
{
super.loadUsageRecipes(inputId, ingredients);
}
}
catch (Throwable ex)
{
ex.printStackTrace();
}
}
@Override
public void loadUsageRecipes (ItemStack result)
{
FluidStack fluid = getFluidStack(result);
if (fluid != null)
{
this.loadUsageRecipes(fluid);
}
}
@Override
public List<String> handleTooltip (GuiRecipe guiRecipe, List<String> currenttip, int recipe)
{
super.handleTooltip(guiRecipe, currenttip, recipe);
CachedBaseRecipe crecipe = (CachedBaseRecipe) this.arecipes.get(recipe);
if (GuiContainerManager.shouldShowTooltip(guiRecipe))
{
Point mouse = GuiDraw.getMousePosition();
Point offset = guiRecipe.getRecipePosition(recipe);
Point relMouse = new Point(mouse.x - ((guiRecipe.width - 176) / 2) - offset.x, mouse.y - ((guiRecipe.height - 166) / 2) - offset.y);
if (crecipe.getFluidTanks() != null)
{
for (FluidTankElement tank : crecipe.getFluidTanks())
{
if (tank.position.contains(relMouse))
{
tank.handleTooltip(currenttip);
}
}
}
}
return currenttip;
}
@Override
public boolean keyTyped (GuiRecipe gui, char keyChar, int keyCode, int recipe)
{
if (keyCode == NEIClientConfig.getKeyBinding("gui.recipe"))
{
if (this.transferFluidTank(gui, recipe, false))
{
return true;
}
}
else if (keyCode == NEIClientConfig.getKeyBinding("gui.usage"))
{
if (this.transferFluidTank(gui, recipe, true))
{
return true;
}
}
return super.keyTyped(gui, keyChar, keyCode, recipe);
}
@Override
public boolean mouseClicked (GuiRecipe gui, int button, int recipe)
{
if (button == 0)
{
if (this.transferFluidTank(gui, recipe, false))
{
return true;
}
}
else if (button == 1)
{
if (this.transferFluidTank(gui, recipe, true))
{
return true;
}
}
return super.mouseClicked(gui, button, recipe);
}
protected boolean transferFluidTank (GuiRecipe guiRecipe, int recipe, boolean usage)
{
CachedBaseRecipe crecipe = (CachedBaseRecipe) this.arecipes.get(recipe);
Point mousepos = GuiDraw.getMousePosition();
Point offset = guiRecipe.getRecipePosition(recipe);
Point relMouse = new Point(mousepos.x - ((guiRecipe.width - 176) / 2) - offset.x, mousepos.y - ((guiRecipe.height - 166) / 2) - offset.y);
if (crecipe.getFluidTanks() != null)
{
for (FluidTankElement tank : crecipe.getFluidTanks())
{
if (tank.position.contains(relMouse))
{
if ((tank.fluid != null) && tank.fluid.amount > 0)
{
if (usage)
{
if (!GuiUsageRecipe.openRecipeGui("liquid", new Object[] { tank.fluid }))
{
return false;
}
}
else
{
if (!GuiCraftingRecipe.openRecipeGui("liquid", new Object[] { tank.fluid }))
{
return false;
}
}
return true;
}
}
}
}
return false;
}
public void drawFluidTanks (int recipe)
{
CachedBaseRecipe crecipe = (CachedBaseRecipe) this.arecipes.get(recipe);
if (crecipe.getFluidTanks() != null)
{
for (FluidTankElement fluidTank : crecipe.getFluidTanks())
{
fluidTank.draw();
}
}
}
public static FluidStack getFluidStack (ItemStack stack)
{
if (stack == null)
{
return null;
}
Item item = stack.getItem();
FluidStack fluidStack = null;
if ((item instanceof IFluidContainerItem))
{
fluidStack = ((IFluidContainerItem) item).getFluid(stack);
}
if (fluidStack == null)
{
fluidStack = FluidContainerRegistry.getFluidForFilledItem(stack);
}
if ((fluidStack == null) && (Block.getBlockFromItem(stack.getItem()) instanceof IFluidBlock))
{
Fluid fluid = ((IFluidBlock) Block.getBlockFromItem(stack.getItem())).getFluid();
if (fluid != null)
{
return new FluidStack(fluid, 1000);
}
}
return fluidStack;
}
public static boolean areFluidsEqual (FluidStack fluidStack1, FluidStack fluidStack2)
{
if (fluidStack1 == null || fluidStack2 == null)
{
return false;
}
return fluidStack1.isFluidEqual(fluidStack2);
}
public static String getMoltenTooltip (FluidStack fluid)
{
if (fluid == null)
{
return null;
}
return null;
}
public static class FluidTankElement
{
public Rectangle position;
public FluidStack fluid;
public int capacity;
public boolean flowingTexture = false;
public FluidTankElement(Rectangle position, int capacity, FluidStack fluid)
{
this.position = position;
this.capacity = capacity;
this.fluid = fluid;
}
public List<String> handleTooltip (List<String> currenttip)
{
if (this.fluid == null || this.fluid.getFluid() == null || this.fluid.amount <= 0)
{
return currenttip;
}
currenttip.add(this.fluid.getLocalizedName());
currenttip.add(EnumChatFormatting.GRAY.toString() + this.fluid.amount + " mB");
return currenttip;
}
public void draw ()
{
if (this.fluid == null || this.fluid.getFluid() == null || this.fluid.amount <= 0)
{
return;
}
IIcon fluidIcon = null;
if (this.flowingTexture && this.fluid.getFluid().getFlowingIcon() != null)
{
fluidIcon = this.fluid.getFluid().getFlowingIcon();
}
else if (this.fluid.getFluid().getStillIcon() != null)
{
fluidIcon = this.fluid.getFluid().getStillIcon();
}
else
{
return;
}
GuiDraw.changeTexture(TextureMap.locationBlocksTexture);
int color = this.fluid.getFluid().getColor(this.fluid);
GL11.glColor3ub((byte) (color >> 16 & 0xFF), (byte) (color >> 8 & 0xFF), (byte) (color & 0xFF));
GL11.glDisable(GL11.GL_BLEND);
int amount = Math.max(Math.min(this.position.height, this.fluid.amount * this.position.height / this.capacity), 1);
int posY = this.position.y + this.position.height - amount;
for (int i = 0; i < this.position.width; i += 16)
{
for (int j = 0; j < amount; j += 16)
{
int drawWidth = Math.min(this.position.width - i, 16);
int drawHeight = Math.min(amount - j, 16);
int drawX = this.position.x + i;
int drawY = posY + j;
double minU = fluidIcon.getMinU();
double maxU = fluidIcon.getMaxU();
double minV = fluidIcon.getMinV();
double maxV = fluidIcon.getMaxV();
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.addVertexWithUV(drawX, drawY + drawHeight, 0, minU, minV + (maxV - minV) * drawHeight / 16F);
tessellator.addVertexWithUV(drawX + drawWidth, drawY + drawHeight, 0, minU + (maxU - minU) * drawWidth / 16F, minV + (maxV - minV) * drawHeight / 16F);
tessellator.addVertexWithUV(drawX + drawWidth, drawY, 0, minU + (maxU - minU) * drawWidth / 16F, minV);
tessellator.addVertexWithUV(drawX, drawY, 0, minU, minV);
tessellator.draw();
}
}
GL11.glEnable(GL11.GL_BLEND);
}
}
}
@@ -0,0 +1,135 @@
package tconstruct.plugins.nei;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import tconstruct.library.crafting.CastingRecipe;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
public abstract class RecipeHandlerCastingBase extends RecipeHandlerBase
{
public static final Rectangle MOLTEN_FLOW = new Rectangle(60, 8, 6, 11);
public static final Rectangle MOLTEN_FLOW_NO_ITEM = new Rectangle(60, 8, 6, 27);
public class CachedCastingRecipe extends CachedBaseRecipe
{
private List<PositionedStack> resources;
private FluidTankElement metal;
private PositionedStack output = null;
public CachedCastingRecipe(CastingRecipe recipe)
{
this.metal = new FluidTankElement(MOLTEN_FLOW, recipe.castingMetal.amount, recipe.castingMetal);
this.metal.flowingTexture = true;
this.resources = new ArrayList<PositionedStack>();
if (recipe.cast != null)
{
this.resources.add(new PositionedStack(recipe.cast, 55, 19));
}
else
{
this.metal.position = MOLTEN_FLOW_NO_ITEM;
}
this.output = new PositionedStack(recipe.output, 110, 18);
}
@Override
public List<PositionedStack> getIngredients ()
{
return getCycledIngredients(cycleticks / 20, this.resources);
}
@Override
public PositionedStack getResult ()
{
return this.output;
}
@Override
public List<FluidTankElement> getFluidTanks ()
{
List<FluidTankElement> res = new ArrayList<FluidTankElement>();
res.add(this.metal);
return res;
}
}
@Override
public String getRecipeID ()
{
return "tconstruct.smeltery.casting";
}
@Override
public String getGuiTexture ()
{
return "tinker:textures/gui/nei/casting.png";
}
@Override
public void loadTransferRects ()
{
this.transferRects.add(new RecipeTransferRect(new Rectangle(76, 18, 22, 15), this.getRecipeID(), new Object[0]));
}
public abstract List<CastingRecipe> getCastingRecipes ();
@Override
public void loadCraftingRecipes (String outputId, Object... results)
{
if (outputId.equals(this.getRecipeID()))
{
for (CastingRecipe recipe : this.getCastingRecipes())
{
this.arecipes.add(new CachedCastingRecipe(recipe));
}
}
else
{
super.loadCraftingRecipes(outputId, results);
}
}
@Override
public void loadCraftingRecipes (ItemStack result)
{
for (CastingRecipe recipe : getCastingRecipes())
{
if (NEIServerUtils.areStacksSameTypeCrafting(result, recipe.getResult()))
{
this.arecipes.add(new CachedCastingRecipe(recipe));
}
}
}
@Override
public void loadUsageRecipes (ItemStack ingred)
{
for (CastingRecipe recipe : getCastingRecipes())
{
if (NEIServerUtils.areStacksSameTypeCrafting(recipe.cast, ingred))
{
CachedCastingRecipe irecipe = new CachedCastingRecipe(recipe);
irecipe.setIngredientPermutation(irecipe.resources, ingred);
this.arecipes.add(irecipe);
}
}
}
@Override
public void loadUsageRecipes (FluidStack ingredient)
{
for (CastingRecipe recipe : getCastingRecipes())
{
if (areFluidsEqual(recipe.castingMetal, ingredient))
{
this.arecipes.add(new CachedCastingRecipe(recipe));
}
}
}
}
@@ -0,0 +1,41 @@
package tconstruct.plugins.nei;
import java.util.ArrayList;
import java.util.List;
import org.lwjgl.opengl.GL11;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.crafting.CastingRecipe;
import tconstruct.library.crafting.LiquidCasting;
import codechicken.lib.gui.GuiDraw;
public class RecipeHandlerCastingBasin extends RecipeHandlerCastingBase
{
@Override
public String getRecipeName ()
{
return "Casting Basin";
}
@Override
public void drawBackground (int recipe)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GuiDraw.changeTexture(this.getGuiTexture());
GuiDraw.drawTexturedModalRect(30, 0, 0, 62, 112, 55);
}
@Override
public List<CastingRecipe> getCastingRecipes ()
{
LiquidCasting casting = TConstructRegistry.getBasinCasting();
if (casting == null)
{
return new ArrayList<CastingRecipe>();
}
return casting.getCastingRecipes();
}
}
@@ -0,0 +1,41 @@
package tconstruct.plugins.nei;
import java.util.ArrayList;
import java.util.List;
import org.lwjgl.opengl.GL11;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.crafting.CastingRecipe;
import tconstruct.library.crafting.LiquidCasting;
import codechicken.lib.gui.GuiDraw;
public class RecipeHandlerCastingTable extends RecipeHandlerCastingBase
{
@Override
public String getRecipeName ()
{
return "Casting Table";
}
@Override
public void drawBackground (int recipe)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GuiDraw.changeTexture(this.getGuiTexture());
GuiDraw.drawTexturedModalRect(30, 0, 0, 0, 112, 55);
}
@Override
public List<CastingRecipe> getCastingRecipes ()
{
LiquidCasting casting = TConstructRegistry.getTableCasting();
if (casting == null)
{
return new ArrayList<CastingRecipe>();
}
return casting.getCastingRecipes();
}
}
@@ -0,0 +1,126 @@
package tconstruct.plugins.nei;
import java.awt.Rectangle;
import net.minecraft.item.ItemStack;
import org.lwjgl.opengl.GL11;
import tconstruct.library.crafting.DryingRackRecipes;
import tconstruct.library.crafting.DryingRackRecipes.DryingRecipe;
import codechicken.lib.gui.GuiDraw;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
public class RecipeHandlerDryingRack extends RecipeHandlerBase
{
public class CachedDryingRackRecipe extends CachedBaseRecipe
{
public PositionedStack input;
public PositionedStack output;
public int time;
public CachedDryingRackRecipe(DryingRecipe drying)
{
this.input = new PositionedStack(drying.input, 44, 18);
this.output = new PositionedStack(drying.result, 98, 18);
this.time = drying.time;
}
@Override
public PositionedStack getIngredient ()
{
return this.input;
}
@Override
public PositionedStack getResult ()
{
return this.output;
}
}
@Override
public String getRecipeName ()
{
return "Drying Rack";
}
@Override
public String getRecipeID ()
{
return "tconstruct.dryingrack";
}
@Override
public void loadTransferRects ()
{
this.transferRects.add(new RecipeTransferRect(new Rectangle(68, 20, 22, 15), this.getRecipeID(), new Object[0]));
}
@Override
public String getGuiTexture ()
{
return "tinker:textures/gui/nei/dryingrack.png";
}
@Override
public void drawBackground (int recipe)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GuiDraw.changeTexture(this.getGuiTexture());
GuiDraw.drawTexturedModalRect(0, 0, 0, 0, 160, 65);
}
@Override
public void drawExtras (int recipe)
{
int time = ((CachedDryingRackRecipe) this.arecipes.get(recipe)).time;
int seconds = time / 20;
GuiDraw.drawStringC(time + " ticks (" + seconds + " secs)", 81, 40, 0x808080, false);
}
@Override
public void loadCraftingRecipes (String outputId, Object... results)
{
if (outputId.equals(this.getRecipeID()))
{
for (DryingRecipe drying : DryingRackRecipes.recipes)
{
this.arecipes.add(new CachedDryingRackRecipe(drying));
}
}
else
{
super.loadCraftingRecipes(outputId, results);
}
}
@Override
public void loadCraftingRecipes (ItemStack result)
{
for (DryingRecipe drying : DryingRackRecipes.recipes)
{
if (NEIServerUtils.areStacksSameTypeCrafting(drying.result, result))
{
this.arecipes.add(new CachedDryingRackRecipe(drying));
}
}
}
@Override
public void loadUsageRecipes (ItemStack ingred)
{
for (DryingRecipe drying : DryingRackRecipes.recipes)
{
if (NEIServerUtils.areStacksSameTypeCrafting(drying.input, ingred))
{
this.arecipes.add(new CachedDryingRackRecipe(drying));
}
}
}
}
@@ -0,0 +1,138 @@
package tconstruct.plugins.nei;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import mantle.utils.ItemMetaWrapper;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import org.lwjgl.opengl.GL11;
import tconstruct.library.crafting.Smeltery;
import codechicken.lib.gui.GuiDraw;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
public class RecipeHandlerMelting extends RecipeHandlerBase
{
public static final Rectangle MOLTEN_TANK = new Rectangle(115, 20, 18, 18);
public class CachedMeltingRecipe extends CachedBaseRecipe
{
private PositionedStack input;
private int temperature;
private FluidTankElement output;
public CachedMeltingRecipe(ItemStack input)
{
this.input = new PositionedStack(input, 28, 21);
this.temperature = Smeltery.getLiquifyTemperature(input);
this.output = new FluidTankElement(MOLTEN_TANK, 1, Smeltery.getSmelteryResult(input));
this.output.capacity = this.output.fluid != null ? this.output.fluid.amount : 1000;
}
@Override
public PositionedStack getIngredient ()
{
return this.input;
}
@Override
public PositionedStack getResult ()
{
return null;
}
@Override
public List<FluidTankElement> getFluidTanks ()
{
List<FluidTankElement> tanks = new ArrayList<FluidTankElement>();
tanks.add(this.output);
return tanks;
}
}
@Override
public String getRecipeName ()
{
return "Smeltery Melting";
}
@Override
public String getRecipeID ()
{
return "tconstruct.smeltery.melting";
}
@Override
public String getGuiTexture ()
{
return "tinker:textures/gui/nei/smeltery.png";
}
@Override
public void loadTransferRects ()
{
this.transferRects.add(new RecipeTransferRect(new Rectangle(72, 20, 16, 34), this.getRecipeID(), new Object[0]));
}
@Override
public void drawBackground (int recipe)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GuiDraw.changeTexture(this.getGuiTexture());
GuiDraw.drawTexturedModalRect(0, 0, 0, 0, 160, 55);
}
@Override
public void drawExtras (int recipe)
{
int temperature = ((CachedMeltingRecipe) this.arecipes.get(recipe)).temperature;
GuiDraw.drawStringC(temperature + " C", 81, 9, 0x808080, false);
}
@Override
public void loadCraftingRecipes (String outputId, Object... results)
{
if (outputId.equals(getRecipeID()))
{
for (ItemMetaWrapper key : Smeltery.getSmeltingList().keySet())
{
this.arecipes.add(new CachedMeltingRecipe(new ItemStack(key.item, 1, key.meta)));
}
}
else
{
super.loadCraftingRecipes(outputId, results);
}
}
@Override
public void loadCraftingRecipes (FluidStack result)
{
for (Entry<ItemMetaWrapper, FluidStack> pair : Smeltery.getSmeltingList().entrySet())
{
if (areFluidsEqual(pair.getValue(), result))
{
this.arecipes.add(new CachedMeltingRecipe(new ItemStack(pair.getKey().item, 1, pair.getKey().meta)));
}
}
}
@Override
public void loadUsageRecipes (ItemStack ingred)
{
for (ItemMetaWrapper key : Smeltery.getSmeltingList().keySet())
{
if (NEIServerUtils.areStacksSameTypeCrafting(new ItemStack(key.item, 1, key.meta), ingred))
{
this.arecipes.add(new CachedMeltingRecipe(new ItemStack(key.item, 1, key.meta)));
}
}
}
}
@@ -1,20 +0,0 @@
package tconstruct.plugins.nei;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.registry.GameRegistry.ObjectHolder;
import mantle.pulsar.pulse.*;
import tconstruct.TConstruct;
@ObjectHolder(TConstruct.modID)
@Pulse(id = "Tinkers NEI Compatibility", description = "Tinkers Construct compatibility for NEI", modsRequired = "NotEnoughItems")
public class TinkerNEI
{
@Handler
public void init (FMLInitializationEvent event)
{
TConstruct.logger.info("NotEnoughItems detected. Registering TConstruct NEI plugin.");
NEICompat.registerNEICompat();
}
}