Skip to content

Commit

Permalink
Fix arrow shaft name / add CustomMaterial support to DynamicToolPart
Browse files Browse the repository at this point in the history
  • Loading branch information
squeek502 committed Jan 1, 2015
1 parent 90ef930 commit 1c80f92
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 11 deletions.
1 change: 1 addition & 0 deletions resources/assets/tinker/lang/en_US.lang
Expand Up @@ -587,6 +587,7 @@ toolpart.CrossbowLimb=%%material Crossbow Limb
toolpart.CrossbowBody=%%material Crossbow Body
toolpart.BowLimb=%%material Bow Limb
toolpart.Bolt=%%material Bolt
toolpart.Shaft=%%material Arrow Shaft

# Now with translations of specific material and part combinations:
#toolpart.ToolRod.wood=Wooden Tool Rod
Expand Down
74 changes: 64 additions & 10 deletions src/main/java/tconstruct/library/tools/DynamicToolPart.java
Expand Up @@ -14,6 +14,7 @@
import tconstruct.library.TConstructRegistry;
import tconstruct.library.util.IToolPart;
import tconstruct.library.util.TextureHelper;
import tconstruct.library.tools.CustomMaterial;
import tconstruct.tools.TinkerTools;
import tconstruct.util.config.PHConstruct;

Expand All @@ -25,20 +26,32 @@ public class DynamicToolPart extends CraftingItem implements IToolPart
public String partName;
public String texture;
public IIcon defaultIcon;
public Class<? extends CustomMaterial> customMaterialClass;

private boolean hidden = false;

public DynamicToolPart(String texture, String name)
{
this(texture, name, "tinker");
this(texture, name, (Class<? extends CustomMaterial>) null);
}

public DynamicToolPart(String texture, String name, Class<? extends CustomMaterial> customMaterialClass)
{
this(texture, name, "tinker", customMaterialClass);
}

public DynamicToolPart(String texture, String name, String domain)
{
this(texture, name, domain, (Class<? extends CustomMaterial>) null);
}

public DynamicToolPart(String texture, String name, String domain, Class<? extends CustomMaterial> customMaterialClass)
{
super(null, null, "parts/", domain, TConstructRegistry.partTab);
this.setUnlocalizedName("tconstruct." + name);
this.partName = name;
this.texture = texture;
this.customMaterialClass = customMaterialClass;
}

/**
Expand All @@ -64,11 +77,38 @@ public int getMaterialID (ItemStack stack)
@Override
public String getItemStackDisplayName (ItemStack stack)
{
tconstruct.library.tools.ToolMaterial toolmat = TConstructRegistry.getMaterial(getMaterialID(stack));
if(toolmat == null)
return super.getItemStackDisplayName(stack);
String material = "";
String matName = "";
if (customMaterialClass == null)
{
tconstruct.library.tools.ToolMaterial toolmat = TConstructRegistry.getMaterial(getMaterialID(stack));
if(toolmat == null)
return super.getItemStackDisplayName(stack);

String material = toolmat.localizationString.substring(9); // :(
material = toolmat.localizationString.substring(9); // :(
matName = toolmat.prefixName();
}
else
{
CustomMaterial customMaterial = TConstructRegistry.getCustomMaterial(getMaterialID(stack), customMaterialClass);
if (customMaterial == null)
return super.getItemStackDisplayName(stack);

material = "";
if (customMaterial.input != null)
{
material = customMaterial.input.getUnlocalizedName();
int firstPeriodIndex = material.indexOf('.');
if (firstPeriodIndex >= 0)
material = material.substring(firstPeriodIndex+1);
matName = customMaterial.input.getDisplayName();
}
else
{
material = customMaterial.oredict;
matName = customMaterial.oredict;
}
}

// custom name
if (StatCollector.canTranslate("toolpart." + partName + "." + material))
Expand All @@ -79,11 +119,8 @@ public String getItemStackDisplayName (ItemStack stack)
else
{
// specific material name for materials?
String matName;
if(StatCollector.canTranslate("toolpart.material." + material))
matName = StatCollector.translateToLocal("toolpart.material." + material);
else
matName = toolmat.prefixName();

return StatCollector.translateToLocal("toolpart." + partName).replaceAll("%%material", matName);
}
Expand All @@ -95,7 +132,19 @@ public String getUnlocalizedName(ItemStack stack) {
if(id == -1)
return getUnlocalizedName();

return "toolpart." + partName + "." + TConstructRegistry.getMaterial(id).materialName;
String material = "unknown";
if (customMaterialClass == null)
{
tconstruct.library.tools.ToolMaterial toolmat = TConstructRegistry.getMaterial(getMaterialID(stack));
material = toolmat.materialName;
}
else
{
CustomMaterial customMaterial = TConstructRegistry.getCustomMaterial(getMaterialID(stack), customMaterialClass);
material = customMaterial.input != null ? customMaterial.input.getUnlocalizedName() : customMaterial.oredict;
}

return "toolpart." + partName + "." + material;
}

@Override
Expand Down Expand Up @@ -156,7 +205,12 @@ public int getColorFromItemStack(ItemStack stack, int renderpass) {
return super.getColorFromItemStack(stack, renderpass);

if(matId >= 0 && icons[matId] == null)
return TConstructRegistry.getMaterial(matId).primaryColor();
{
if (customMaterialClass == null)
return TConstructRegistry.getMaterial(getMaterialID(stack)).primaryColor();
else
return TConstructRegistry.getCustomMaterial(getMaterialID(stack), customMaterialClass).color;
}

return super.getColorFromItemStack(stack, renderpass);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/tconstruct/weaponry/TinkerWeaponry.java
Expand Up @@ -144,7 +144,7 @@ private void registerItems()
TinkerTools.arrowhead = arrowhead = new DynamicToolPart("_arrowhead", "ArrowHead");
TinkerTools.fletching = fletching = new Fletching().setUnlocalizedName("tconstruct.Fletching");
partShuriken = new DynamicToolPart("_shuriken", "Shuriken");
partArrowShaft = new DynamicToolPart("_arrow_shaft", "Shaft");
partArrowShaft = new DynamicToolPart("_arrow_shaft", "Shaft", ArrowShaftMaterial.class);
partBowLimb = new DynamicToolPart("_bow_limb", "BowLimb");
partCrossbowLimb = new DynamicToolPart("_crossbow_limb", "CrossbowLimb");
partCrossbowBody = new DynamicToolPart("_crossbow_body", "CrossbowBody");
Expand Down

0 comments on commit 1c80f92

Please sign in to comment.