Skip to content

Commit

Permalink
Added an NEI handler for tool material stats.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tonius committed Sep 24, 2014
1 parent 9d640c2 commit 328baf5
Show file tree
Hide file tree
Showing 6 changed files with 275 additions and 25 deletions.
5 changes: 2 additions & 3 deletions resources/assets/tinker/lang/en_US.lang
Expand Up @@ -782,7 +782,7 @@ material.slime=Slime
material.slime.ability=Slimy
material.paper=Paper
material.paper.ability=Writable
material.blueslime=BlueSlime
material.blueslime=Blue Slime
material.blueslime.display=Slime
material.blueslime.ability=Slimy
material.cobalt=Cobalt
Expand All @@ -793,8 +793,7 @@ material.copper=Copper
material.bronze=Bronze
material.alumite=Alumite
material.steel=Steel
material.pigiron=Pigiron
material.pigiron.display=Pig Iron
material.pigiron=Pig Iron
material.pigiron.ability=Tasty
material.thaumium=Thaumium
material.thaumium.ability=Thaumic
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 12 additions & 11 deletions src/main/java/tconstruct/plugins/nei/NEITConstructConfig.java
Expand Up @@ -14,17 +14,12 @@ 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());
registerHandler(new RecipeHandlerDryingRack());
registerHandler(new RecipeHandlerToolMaterials());
registerHandler(new RecipeHandlerMelting());
registerHandler(new RecipeHandlerAlloying());
registerHandler(new RecipeHandlerCastingTable());
registerHandler(new RecipeHandlerCastingBasin());
}

@Override
Expand All @@ -39,4 +34,10 @@ public String getVersion ()
return "${version}";
}

private static void registerHandler (RecipeHandlerBase handler)
{
API.registerRecipeHandler(handler);
API.registerUsageHandler(handler);
}

}
21 changes: 10 additions & 11 deletions src/main/java/tconstruct/plugins/nei/RecipeHandlerBase.java
Expand Up @@ -2,6 +2,7 @@

import java.awt.Point;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;

import net.minecraft.block.Block;
Expand Down Expand Up @@ -106,9 +107,9 @@ public void loadUsageRecipes (String inputId, Object... ingredients)
}

@Override
public void loadUsageRecipes (ItemStack result)
public void loadUsageRecipes (ItemStack ingred)
{
FluidStack fluid = getFluidStack(result);
FluidStack fluid = getFluidStack(ingred);
if (fluid != null)
{
this.loadUsageRecipes(fluid);
Expand Down Expand Up @@ -230,6 +231,13 @@ public void drawFluidTanks (int recipe)
}
}

public static List getSingleList (Object o)
{
List list = new ArrayList();
list.add(o);
return list;
}

public static FluidStack getFluidStack (ItemStack stack)
{
if (stack == null)
Expand Down Expand Up @@ -266,15 +274,6 @@ public static boolean areFluidsEqual (FluidStack fluidStack1, FluidStack fluidSt
return fluidStack1.isFluidEqual(fluidStack2);
}

public static String getMoltenTooltip (FluidStack fluid)
{
if (fluid == null)
{
return null;
}
return null;
}

public static class FluidTankElement
{
public Rectangle position;
Expand Down
251 changes: 251 additions & 0 deletions src/main/java/tconstruct/plugins/nei/RecipeHandlerToolMaterials.java
@@ -0,0 +1,251 @@
package tconstruct.plugins.nei;

import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;

import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;

import org.lwjgl.opengl.GL11;

import tconstruct.library.TConstructRegistry;
import tconstruct.library.crafting.CastingRecipe;
import tconstruct.library.crafting.PatternBuilder;
import tconstruct.library.crafting.PatternBuilder.ItemKey;
import tconstruct.library.crafting.PatternBuilder.MaterialSet;
import tconstruct.library.tools.DynamicToolPart;
import tconstruct.library.tools.ToolMaterial;
import tconstruct.library.util.HarvestLevels;
import tconstruct.library.util.IToolPart;
import tconstruct.tools.items.ToolPart;
import tconstruct.util.config.PHConstruct;
import codechicken.lib.gui.GuiDraw;
import codechicken.nei.PositionedStack;

public class RecipeHandlerToolMaterials extends RecipeHandlerBase
{

public class CachedToolMaterialsRecipe extends CachedBaseRecipe
{

public List<PositionedStack> toolParts;
public ToolMaterial material;

public CachedToolMaterialsRecipe(List<ItemStack> toolParts, int materialID)
{
this.toolParts = new ArrayList<PositionedStack>();
for (ItemStack stack : toolParts)
{
this.toolParts.add(new PositionedStack(stack, 10, 10));
}
this.material = TConstructRegistry.getMaterial(materialID);
}

@Override
public PositionedStack getIngredient ()
{
return this.toolParts.get(cycleticks / 20 % this.toolParts.size());
}

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

}

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

@Override
public String getRecipeID ()
{
return "tconstruct.tools.materials";
}

@Override
public String getGuiTexture ()
{
return "tinker:textures/gui/nei/toolmaterials.png";
}

@Override
public int recipiesPerPage ()
{
return 1;
}

@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, 130);
}

@Override
public void loadTransferRects ()
{
this.transferRects.add(new RecipeTransferRect(new Rectangle(10, 30, 16, 16), this.getRecipeID(), new Object[0]));
}

@Override
public void drawExtras (int recipe)
{
CachedToolMaterialsRecipe crecipe = (CachedToolMaterialsRecipe) this.arecipes.get(recipe);
if (crecipe.material != null)
{
GuiDraw.drawString(EnumChatFormatting.BOLD + crecipe.material.localizedName(), 35, 10, 0x404040, false);
GuiDraw.drawString("Base Durability: " + crecipe.material.durability, 35, 20, 0x404040, false);
GuiDraw.drawString("Handle Modifier: " + crecipe.material.handleModifier + "x", 35, 30, 0x404040, false);
GuiDraw.drawString("Full Durability: " + Math.round(crecipe.material.durability * crecipe.material.handleModifier), 35, 40, 0x404040, false);
GuiDraw.drawString("Mining Speed: " + crecipe.material.miningspeed / 100F, 35, 50, 0x404040, false);
GuiDraw.drawString("Mining Level: " + HarvestLevels.getHarvestLevelName(crecipe.material.harvestLevel), 35, 60, 0x404040, false);
String heart = crecipe.material.attack == 2 ? " Heart" : " Hearts";
if (crecipe.material.attack() % 2 == 0)
{
GuiDraw.drawString("Attack: " + crecipe.material.attack / 2 + heart, 35, 70, 0x404040, false);
}
else
{
GuiDraw.drawString("Attack: " + crecipe.material.attack / 2F + heart, 35, 70, 0x404040, false);
}
int abilityY = 85;
if (crecipe.material.reinforced > 0)
{
GuiDraw.drawString(getReinforcedString(crecipe.material.reinforced), 35, 85, 0x404040, false);
abilityY += 10;
}
String ability = crecipe.material.ability();
if (ability != null)
{
if (crecipe.material.stonebound != 0)
{
GuiDraw.drawString(ability + " (" + Math.abs(crecipe.material.stonebound) + ")", 35, abilityY, 0x404040, false);
}
else
{
GuiDraw.drawString(ability, 35, abilityY, 0x404040, false);
}
}
}
}

@Override
public void loadCraftingRecipes (String outputId, Object... results)
{
if (outputId.equals(this.getRecipeID()))
{
ToolMaterial mat;
for (int matID : TConstructRegistry.toolMaterials.keySet())
{
List<ItemStack> toolParts = new ArrayList<ItemStack>();
mat = TConstructRegistry.toolMaterials.get(matID);
for (ItemKey key : PatternBuilder.instance.materials)
{
MaterialSet set = PatternBuilder.instance.materialSets.get(key.key);
if (set.materialID == matID)
{
ItemStack stack = new ItemStack(key.item, 1, key.damage);
toolParts.add(stack);
}
}
for (List list : TConstructRegistry.patternPartMapping.keySet())
{
if ((Integer) list.get(2) == matID)
{
toolParts.add(TConstructRegistry.patternPartMapping.get(list));
}
}
if (!PHConstruct.craftMetalTools)
{
for (CastingRecipe recipe : TConstructRegistry.getTableCasting().getCastingRecipes())
{
ItemStack castResult = recipe.getResult();
if (castResult.getItem() instanceof IToolPart)
{
if (((IToolPart) castResult.getItem()).getMaterialID(castResult) == matID)
{
toolParts.add(castResult);
}
}
}
}
this.arecipes.add(new CachedToolMaterialsRecipe(toolParts, matID));
}
}
else
{
super.loadCraftingRecipes(outputId, results);
}
}

@Override
public void loadUsageRecipes (ItemStack ingred)
{
if (ingred.getItem() instanceof ToolPart || ingred.getItem() instanceof DynamicToolPart)
{
int materialID = ((IToolPart) ingred.getItem()).getMaterialID(ingred);
if (materialID >= 0)
{
this.arecipes.add(new CachedToolMaterialsRecipe(getSingleList(ingred), materialID));
}
}
else if (PatternBuilder.instance.getPartID(ingred) < Short.MAX_VALUE)
{
int materialID = PatternBuilder.instance.getPartID(ingred);
this.arecipes.add(new CachedToolMaterialsRecipe(getSingleList(ingred), materialID));
}
else
{
super.loadUsageRecipes(ingred);
}
}

public static String getReinforcedString (int reinforced)
{
if (reinforced > 9)
return "Unbreakable";
String ret = "Reinforced ";
switch (reinforced)
{
case 1:
ret += "I";
break;
case 2:
ret += "II";
break;
case 3:
ret += "III";
break;
case 4:
ret += "IV";
break;
case 5:
ret += "V";
break;
case 6:
ret += "VI";
break;
case 7:
ret += "VII";
break;
case 8:
ret += "VIII";
break;
case 9:
ret += "IX";
break;
default:
ret += "X";
break;
}
return ret;
}

}

0 comments on commit 328baf5

Please sign in to comment.