I am developing a mod that adds flint and cactus tools, and my axes have weird attack speed and damage. Doing
super(material, material.getDamageVsEntity(), material.getEfficiencyOnProperMaterial());
In the constructor leaves me with values that would make the axe attack really fast and do less damage than I want it to,
super(material);
Gives me a java.lang.ExceptionInInitializerError.
So I have rigged up a system to fix this for the time being, but having to expand this system every time I add a new ToolMaterial will get annoying fast. Help?
Code:
ModAxe.java:
package com.Winseven4lyf.MoreTools.items;
import com.Winseven4lyf.MoreTools.handlers.MaterialHandler;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemAxe;
public class ModAxe extends ItemAxe
{
public ModAxe(String name, ToolMaterial material, CreativeTabs tab)
{
super(material, MaterialHandler.getAxeDamage(material) - 1, MaterialHandler.getAxeAttackSpeed(material) - 4);
setUnlocalizedName(name);
setRegistryName(name);
setCreativeTab(tab);
}
}
MaterialHandler.java:
package com.Winseven4lyf.MoreTools.handlers;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.EnumHelper;
public class MaterialHandler
{
private static float lerp(float a, float b, float t)
{
return (1 - t) * a + t * b;
}
private static ToolMaterial createLerpedMaterial(String name, ToolMaterial a, ToolMaterial b, float t, ItemStack repairItem)
{
return EnumHelper.addToolMaterial(
name,
a.getHarvestLevel(),
(int) Math.floor(lerp(a.getMaxUses(), b.getMaxUses(), 0.5F)),
lerp(a.getEfficiencyOnProperMaterial(), b.getEfficiencyOnProperMaterial(), 0.5F),
lerp(a.getDamageVsEntity(), b.getDamageVsEntity(), 0.5F),
(int) Math.floor(lerp(a.getEnchantability(), b.getEnchantability(), 0.5F))
).setRepairItem(repairItem);
}
private static ToolMaterial createDuplicateMaterial(String name, ToolMaterial original, ItemStack repairItem)
{
return EnumHelper.addToolMaterial(
name,
original.getHarvestLevel(),
original.getMaxUses(),
original.getEfficiencyOnProperMaterial(),
original.getDamageVsEntity(),
original.getEnchantability()
).setRepairItem(repairItem);
}
public static float getAxeAttackSpeed(ToolMaterial material)
{
float output = 0F;
if (material == FLINT)
{
output = 0.85F;
}
else if (material == CACTUS)
{
output = 0.8F;
}
return output;
}
public static float getAxeDamage(ToolMaterial material)
{
float output = 0F;
if (material == FLINT)
{
output = 9F;
}
else if (material == CACTUS)
{
output = 7F;
}
return output;
}
public static final ToolMaterial FLINT =
createLerpedMaterial("flint", ToolMaterial.STONE, ToolMaterial.IRON, 0.5F, new ItemStack(Items.FLINT));
public static final ToolMaterial CACTUS =
createDuplicateMaterial("cactus", ToolMaterial.WOOD, new ItemStack(Blocks.CACTUS));
}