2014-09-22 14:29:21 +02:00
|
|
|
package tconstruct.library.tools;
|
|
|
|
|
|
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
import mantle.items.abstracts.CraftingItem;
|
|
|
|
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
|
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraft.util.IIcon;
|
|
|
|
|
import net.minecraft.util.MathHelper;
|
|
|
|
|
import net.minecraft.util.StatCollector;
|
|
|
|
|
import tconstruct.TConstruct;
|
|
|
|
|
import tconstruct.library.TConstructRegistry;
|
|
|
|
|
import tconstruct.library.util.IToolPart;
|
|
|
|
|
import tconstruct.library.util.TextureHelper;
|
|
|
|
|
import tconstruct.tools.TinkerTools;
|
2014-09-26 17:18:36 +02:00
|
|
|
import tconstruct.util.config.PHConstruct;
|
2014-09-22 14:29:21 +02:00
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
public class DynamicToolPart extends CraftingItem implements IToolPart
|
|
|
|
|
{
|
|
|
|
|
public String partName;
|
|
|
|
|
public String texture;
|
|
|
|
|
public IIcon defaultIcon;
|
|
|
|
|
|
2014-09-22 14:36:50 +02:00
|
|
|
private boolean hidden = false;
|
|
|
|
|
|
2014-09-22 14:29:21 +02:00
|
|
|
public DynamicToolPart(String texture, String name)
|
|
|
|
|
{
|
|
|
|
|
this(texture, name, "tinker");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DynamicToolPart(String texture, String name, String domain)
|
|
|
|
|
{
|
|
|
|
|
super(null, null, "parts/", domain, TConstructRegistry.partTab);
|
|
|
|
|
this.setUnlocalizedName("tconstruct." + name);
|
|
|
|
|
this.partName = name;
|
|
|
|
|
this.texture = texture;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-22 14:36:50 +02:00
|
|
|
/**
|
|
|
|
|
* Doesn't add the item to creative tabs
|
|
|
|
|
*/
|
|
|
|
|
public DynamicToolPart hide()
|
|
|
|
|
{
|
|
|
|
|
hidden = true;
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-22 14:29:21 +02:00
|
|
|
// item meta = material id
|
|
|
|
|
@Override
|
|
|
|
|
public int getMaterialID (ItemStack stack)
|
|
|
|
|
{
|
|
|
|
|
if (TConstructRegistry.toolMaterials.keySet().contains(stack.getItemDamage()))
|
|
|
|
|
return stack.getItemDamage();
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getItemStackDisplayName (ItemStack stack)
|
|
|
|
|
{
|
|
|
|
|
tconstruct.library.tools.ToolMaterial toolmat = TConstructRegistry.getMaterial(getMaterialID(stack));
|
|
|
|
|
if(toolmat == null)
|
|
|
|
|
return super.getItemStackDisplayName(stack);
|
|
|
|
|
|
|
|
|
|
String material = toolmat.localizationString.substring(9); // :(
|
|
|
|
|
|
|
|
|
|
// custom name
|
|
|
|
|
if (StatCollector.canTranslate("toolpart." + partName + "." + material))
|
|
|
|
|
{
|
|
|
|
|
return StatCollector.translateToLocal("toolpart." + partName + "." + material);
|
|
|
|
|
}
|
|
|
|
|
// general name
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-10-16 11:10:40 +02:00
|
|
|
// 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);
|
2014-09-22 14:29:21 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getUnlocalizedName(ItemStack stack) {
|
|
|
|
|
int id = getMaterialID(stack);
|
|
|
|
|
if(id == -1)
|
|
|
|
|
return getUnlocalizedName();
|
|
|
|
|
|
|
|
|
|
return "toolpart." + partName + "." + TConstructRegistry.getMaterial(id).materialName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void getSubItems (Item item, CreativeTabs tab, List list)
|
|
|
|
|
{
|
2014-09-22 14:36:50 +02:00
|
|
|
if(hidden)
|
|
|
|
|
return;
|
|
|
|
|
|
2014-09-22 14:29:21 +02:00
|
|
|
// material id == metadata
|
2014-10-15 23:17:41 +02:00
|
|
|
for(Integer matID : TConstructRegistry.defaultToolPartMaterials) {
|
|
|
|
|
ItemStack stack = new ItemStack(item, 1, matID);
|
|
|
|
|
if (this.getMaterialID(stack) != -1)
|
|
|
|
|
list.add(stack);
|
|
|
|
|
}
|
2014-09-22 14:29:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
|
public void registerIcons (IIconRegister iconRegister)
|
|
|
|
|
{
|
|
|
|
|
// get the biggest material index
|
|
|
|
|
int max = -1;
|
|
|
|
|
for(Integer id : TConstructRegistry.toolMaterials.keySet())
|
|
|
|
|
if(id > max)
|
|
|
|
|
max = id;
|
|
|
|
|
|
|
|
|
|
this.icons = new IIcon[max+1];
|
|
|
|
|
|
|
|
|
|
// register icon for each material that has one
|
2014-09-26 17:18:36 +02:00
|
|
|
if(!PHConstruct.minimalTextures)
|
|
|
|
|
for(Map.Entry<Integer, tconstruct.library.tools.ToolMaterial> entry : TConstructRegistry.toolMaterials.entrySet())
|
|
|
|
|
{
|
|
|
|
|
String tex = modTexPrefix + ":" + folder + entry.getValue().materialName.toLowerCase() + texture;
|
|
|
|
|
if(TextureHelper.itemTextureExists(tex))
|
|
|
|
|
this.icons[entry.getKey()] = iconRegister.registerIcon(tex);
|
|
|
|
|
}
|
2014-09-22 14:29:21 +02:00
|
|
|
|
|
|
|
|
// default texture
|
|
|
|
|
this.defaultIcon = iconRegister.registerIcon(modTexPrefix + ":" + folder + texture);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
|
public IIcon getIconFromDamage (int meta)
|
|
|
|
|
{
|
|
|
|
|
if(meta > icons.length)
|
|
|
|
|
return defaultIcon;
|
|
|
|
|
|
|
|
|
|
if(icons[meta] == null)
|
|
|
|
|
return defaultIcon;
|
|
|
|
|
|
|
|
|
|
return icons[meta];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getColorFromItemStack(ItemStack stack, int renderpass) {
|
|
|
|
|
int matId = getMaterialID(stack);
|
|
|
|
|
if(matId > icons.length)
|
|
|
|
|
return super.getColorFromItemStack(stack, renderpass);
|
|
|
|
|
|
2014-10-26 16:36:14 +01:00
|
|
|
if(matId >= 0 && icons[matId] == null)
|
2014-09-22 14:29:21 +02:00
|
|
|
return TConstructRegistry.getMaterial(matId).primaryColor();
|
|
|
|
|
|
|
|
|
|
return super.getColorFromItemStack(stack, renderpass);
|
|
|
|
|
}
|
|
|
|
|
}
|