Worked on tools a bit

This commit is contained in:
DarkGuardsman 2013-11-05 03:39:39 -05:00
parent 2119b5043b
commit f87eec9af1
3 changed files with 73 additions and 30 deletions

View file

@ -12,25 +12,25 @@ import cpw.mods.fml.relauncher.SideOnly;
import dark.core.common.CoreRecipeLoader; import dark.core.common.CoreRecipeLoader;
/** Class for storing materials, there icon names, sub items to be made from them or there sub ores /** Class for storing materials, there icon names, sub items to be made from them or there sub ores
* *
* *
* @author DarkGuardsman */ * @author DarkGuardsman */
public enum EnumMaterial public enum EnumMaterial
{ {
WOOD("Wood", EnumToolMaterial.WOOD, EnumOrePart.INGOTS, EnumOrePart.PLATES, EnumOrePart.RUBBLE, EnumOrePart.ROD, EnumOrePart.GEARS), WOOD("Wood", EnumToolMaterial.WOOD, EnumOrePart.INGOTS, EnumOrePart.PLATES, EnumOrePart.RUBBLE, EnumOrePart.ROD, EnumOrePart.GEARS),
STONE("Stone", EnumToolMaterial.STONE, EnumOrePart.INGOTS, EnumOrePart.SCRAPS), STONE("Stone", EnumToolMaterial.STONE, EnumOrePart.INGOTS, EnumOrePart.SCRAPS),
IRON("Iron", EnumToolMaterial.IRON, EnumOrePart.INGOTS), IRON("Iron", EnumToolMaterial.IRON, EnumOrePart.INGOTS),
OBBY("Obby", true, 7.0f, 500, EnumOrePart.INGOTS, EnumOrePart.RUBBLE, EnumOrePart.SCRAPS, EnumOrePart.PLATES), OBBY("Obby", true, 7.0f, 500, 4, EnumOrePart.INGOTS, EnumOrePart.RUBBLE, EnumOrePart.SCRAPS, EnumOrePart.PLATES),
GOLD("Gold", EnumToolMaterial.GOLD, EnumOrePart.GEARS, EnumOrePart.INGOTS), GOLD("Gold", EnumToolMaterial.GOLD, EnumOrePart.GEARS, EnumOrePart.INGOTS),
COAL("Coal", EnumToolMaterial.WOOD, EnumOrePart.GEARS, EnumOrePart.TUBE, EnumOrePart.PLATES, EnumOrePart.RUBBLE, EnumOrePart.SCRAPS), COAL("Coal", EnumToolMaterial.WOOD, EnumOrePart.GEARS, EnumOrePart.TUBE, EnumOrePart.PLATES, EnumOrePart.RUBBLE, EnumOrePart.SCRAPS),
COPPER("Copper", true, 3.5f, 79), COPPER("Copper", true, 3.5f, 79, 1),
TIN("Tin", true, 2.0f, 50, EnumOrePart.GEARS, EnumOrePart.TUBE), TIN("Tin", true, 2.0f, 50, 1, EnumOrePart.GEARS, EnumOrePart.TUBE),
LEAD("Lead", false, 0, 0, EnumOrePart.GEARS, EnumOrePart.TUBE), LEAD("Lead", false, 0, 0, 1, EnumOrePart.GEARS, EnumOrePart.TUBE),
ALUMINIUM("Aluminum", true, 5.0f, 100, EnumOrePart.GEARS, EnumOrePart.TUBE), ALUMINIUM("Aluminum", true, 5.0f, 100, 2, EnumOrePart.GEARS, EnumOrePart.TUBE),
SILVER("Silver", true, 11.0f, 30, EnumOrePart.GEARS), SILVER("Silver", true, 11.0f, 30, 0, EnumOrePart.GEARS),
STEEL("Steel", true, 7.0f, 1000, EnumOrePart.RUBBLE), STEEL("Steel", true, 7.0f, 4, 1000, EnumOrePart.RUBBLE),
BRONZE("Bronze", true, 6.5f, 560, EnumOrePart.RUBBLE); BRONZE("Bronze", true, 6.5f, 3, 560, EnumOrePart.RUBBLE);
/** Name of the material */ /** Name of the material */
public String simpleName; public String simpleName;
@ -52,18 +52,20 @@ public enum EnumMaterial
public float materialEffectiveness = 2.0f; public float materialEffectiveness = 2.0f;
public int maxUses = 100; public int maxUses = 100;
public float damageBoost = 0;
private EnumMaterial(String name, EnumToolMaterial material, EnumOrePart... enumOreParts) private EnumMaterial(String name, EnumToolMaterial material, EnumOrePart... enumOreParts)
{ {
this(name, false, material.getEfficiencyOnProperMaterial(), material.getMaxUses(), enumOreParts); this(name, false, material.getEfficiencyOnProperMaterial(), material.getMaxUses(), material.getDamageVsEntity(), enumOreParts);
} }
private EnumMaterial(String name, boolean tool, float effectiveness, int toolUses, EnumOrePart... enumOreParts) private EnumMaterial(String name, boolean tool, float effectiveness, int toolUses, float damage, EnumOrePart... enumOreParts)
{ {
this.simpleName = name; this.simpleName = name;
this.hasTools = tool; this.hasTools = tool;
this.materialEffectiveness = effectiveness; this.materialEffectiveness = effectiveness;
this.maxUses = toolUses; this.maxUses = toolUses;
this.damageBoost = damage;
unneedItems = new ArrayList<EnumOrePart>(); unneedItems = new ArrayList<EnumOrePart>();
for (int i = 0; enumOreParts != null && i < enumOreParts.length; i++) for (int i = 0; enumOreParts != null && i < enumOreParts.length; i++)
{ {
@ -73,7 +75,7 @@ public enum EnumMaterial
/** Creates a new item stack using material and part given. Uses a preset length of 50 for parts /** Creates a new item stack using material and part given. Uses a preset length of 50 for parts
* enum so to prevent any unwanted changes in loading of itemStacks metadata. * enum so to prevent any unwanted changes in loading of itemStacks metadata.
* *
* @param mat - material * @param mat - material
* @param part - part * @param part - part
* @return new ItemStack created from the two enums as long as everything goes right */ * @return new ItemStack created from the two enums as long as everything goes right */

View file

@ -6,16 +6,16 @@ import java.util.List;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
/** Enum to store tools that can be created from the material sheet. /** Enum to store tools that can be created from the material sheet.
* *
* @author DarkGuardsman */ * @author DarkGuardsman */
public enum EnumTool public enum EnumTool
{ {
PICKAX("pickaxe", Material.rock, Material.iron, Material.ice, Material.anvil, Material.glass, Material.tnt, Material.piston), PICKAX("pickaxe", Material.rock, Material.iron, Material.ice, Material.anvil, Material.glass, Material.tnt, Material.piston),
AX("axe", Material.wood, Material.pumpkin, Material.plants, Material.vine), AX("axe", Material.wood, Material.pumpkin, Material.plants, Material.vine),
SPADE("shovel", Material.sand, Material.snow, Material.clay, Material.craftedSnow, Material.grass, Material.ground), SPADE("shovel", Material.sand, Material.snow, Material.clay, Material.craftedSnow, Material.grass, Material.ground),
HOE("hoe"), HOE("hoe", Material.plants, Material.pumpkin),
SHEAR("shear", Material.cloth, Material.circuits, Material.web), SHEAR("shear", Material.cloth, Material.circuits, Material.web),
NA5(), SWORD("sword", false, Material.web, Material.vine, Material.coral, Material.pumpkin, Material.leaves, Material.plants),
NA6(), NA6(),
NA7(), NA7(),
NA8(), NA8(),
@ -30,13 +30,18 @@ public enum EnumTool
} }
private EnumTool(String name, Material... mats) private EnumTool(String name, boolean enabled, Material... mats)
{ {
this.name = name; this.name = name;
this.enabled = true; this.enabled = true;
this.setEffectiveList(mats); this.setEffectiveList(mats);
} }
private EnumTool(String name, Material... mats)
{
this(name, true, mats);
}
public void setEffectiveList(Material... blocks) public void setEffectiveList(Material... blocks)
{ {
for (Material block : blocks) for (Material block : blocks)

View file

@ -1,6 +1,7 @@
package dark.core.common.items; package dark.core.common.items;
import java.awt.Color; import java.awt.Color;
import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
@ -17,9 +18,11 @@ import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.stats.StatList; import net.minecraft.stats.StatList;
import net.minecraft.util.Icon; import net.minecraft.util.Icon;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -30,6 +33,7 @@ import net.minecraftforge.event.Event.Result;
import net.minecraftforge.event.entity.player.UseHoeEvent; import net.minecraftforge.event.entity.player.UseHoeEvent;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
@ -40,7 +44,7 @@ import dark.core.prefab.ModPrefab;
/** Flexible tool class that uses NBT to store damage and effect rather than metadata. Metadata /** Flexible tool class that uses NBT to store damage and effect rather than metadata. Metadata
* instead is used to store sub items allowing several different tools to exist within the same item * instead is used to store sub items allowing several different tools to exist within the same item
* *
* @author DarkGuardsman */ * @author DarkGuardsman */
public class ItemCommonTool extends Item implements IExtraItemInfo public class ItemCommonTool extends Item implements IExtraItemInfo
{ {
@ -59,16 +63,24 @@ public class ItemCommonTool extends Item implements IExtraItemInfo
} }
@Override @Override
public void onCreated(ItemStack itemStack, World par2World, EntityPlayer entityPlayer) public void onCreated(ItemStack itemStack, World world, EntityPlayer entityPlayer)
{ {
if (itemStack.stackTagCompound == null) if (itemStack.stackTagCompound == null)
{ {
itemStack.setTagCompound(new NBTTagCompound()); itemStack.setTagCompound(new NBTTagCompound());
} }
itemStack.getTagCompound().setString("Creator", entityPlayer.username); itemStack.getTagCompound().setString("Creator", (entityPlayer != null ? entityPlayer.username : "Magical Dwarfs"));
itemStack.getTagCompound().setInteger("ToolID", itemStack.getItemDamage()); itemStack.getTagCompound().setInteger("ToolID", itemStack.getItemDamage());
} }
@Override
public Multimap getItemAttributeModifiers()
{
Multimap multimap = super.getItemAttributeModifiers();
multimap.put(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName(), new AttributeModifier(field_111210_e, "Tool modifier", 6, 0));
return multimap;
}
@Override @Override
public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean par4) public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean par4)
{ {
@ -165,6 +177,36 @@ public class ItemCommonTool extends Item implements IExtraItemInfo
return false; return false;
} }
@Override
public EnumAction getItemUseAction(ItemStack par1ItemStack)
{
if (EnumMaterial.getToolFromMeta(par1ItemStack.getItemDamage()) == EnumTool.SWORD)
{
return EnumAction.block;
}
return super.getItemUseAction(par1ItemStack);
}
@Override
public int getMaxItemUseDuration(ItemStack par1ItemStack)
{
if (EnumMaterial.getToolFromMeta(par1ItemStack.getItemDamage()) == EnumTool.SWORD)
{
return 72000;
}
return super.getMaxItemUseDuration(par1ItemStack);
}
@Override
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
{
if (EnumMaterial.getToolFromMeta(par1ItemStack.getItemDamage()) == EnumTool.SWORD)
{
par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack));
}
return par1ItemStack;
}
@Override @Override
public boolean itemInteractionForEntity(ItemStack itemstack, EntityPlayer player, EntityLivingBase entity) public boolean itemInteractionForEntity(ItemStack itemstack, EntityPlayer player, EntityLivingBase entity)
{ {
@ -297,7 +339,7 @@ public class ItemCommonTool extends Item implements IExtraItemInfo
@Override @Override
public boolean hitEntity(ItemStack itemStack, EntityLivingBase par2EntityLivingBase, EntityLivingBase par3EntityLivingBase) public boolean hitEntity(ItemStack itemStack, EntityLivingBase par2EntityLivingBase, EntityLivingBase par3EntityLivingBase)
{ {
this.damage(itemStack, 2, par2EntityLivingBase); this.damage(itemStack, EnumMaterial.getToolFromMeta(itemStack.getItemDamage()) == EnumTool.SWORD ? 1 : 2, par2EntityLivingBase);
return true; return true;
} }
@ -310,7 +352,7 @@ public class ItemCommonTool extends Item implements IExtraItemInfo
} }
if (Block.blocksList[par3].getBlockHardness(par2World, par4, par5, par6) != 0.0D) if (Block.blocksList[par3].getBlockHardness(par2World, par4, par5, par6) != 0.0D)
{ {
this.damage(itemStack, 1, par7EntityLivingBase); this.damage(itemStack, EnumMaterial.getToolFromMeta(itemStack.getItemDamage()) == EnumTool.SWORD ? 2 : 1, par7EntityLivingBase);
} }
return true; return true;
@ -336,14 +378,6 @@ public class ItemCommonTool extends Item implements IExtraItemInfo
return false; return false;
} }
@Override
public Multimap getItemAttributeModifiers()
{
Multimap multimap = super.getItemAttributeModifiers();
multimap.put(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName(), new AttributeModifier(field_111210_e, "Tool modifier", 3.0, 0));
return multimap;
}
@Override @Override
public float getStrVsBlock(ItemStack itemStack, Block block) public float getStrVsBlock(ItemStack itemStack, Block block)
{ {
@ -461,7 +495,9 @@ public class ItemCommonTool extends Item implements IExtraItemInfo
ItemStack stack = EnumMaterial.getTool(tool, mat); ItemStack stack = EnumMaterial.getTool(tool, mat);
if (tool.enabled && stack != null) if (tool.enabled && stack != null)
{ {
this.onCreated(stack, null, null);
par3List.add(stack); par3List.add(stack);
} }
} }
} }