Worked on tools
This commit is contained in:
parent
329c24fc0e
commit
2f5cd2a767
4 changed files with 248 additions and 18 deletions
|
@ -16,6 +16,7 @@ import dark.core.common.items.EnumOrePart;
|
|||
import dark.core.common.items.ItemOreDirv;
|
||||
import dark.core.common.items.ItemParts;
|
||||
import dark.core.common.items.ItemParts.Parts;
|
||||
import dark.core.common.items.ItemTool;
|
||||
import dark.core.common.items.ItemWrench;
|
||||
|
||||
public class CoreRecipeLoader extends RecipeLoader
|
||||
|
@ -38,6 +39,7 @@ public class CoreRecipeLoader extends RecipeLoader
|
|||
public static ItemStack valvePart;
|
||||
public static ItemStack unfinishedTank;
|
||||
public static Item itemGlowingSand;
|
||||
public static Item itemDiggingTool;
|
||||
|
||||
@Override
|
||||
public void loadRecipes()
|
||||
|
|
|
@ -9,33 +9,36 @@ import net.minecraft.util.Icon;
|
|||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import dark.core.common.CoreRecipeLoader;
|
||||
import dark.core.common.DarkMain;
|
||||
|
||||
/** Class for storing materials, there icon names, sub items to be made from them or there sub ores
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public enum EnumMaterial
|
||||
{
|
||||
WOOD("Wood", EnumOrePart.INGOTS, EnumOrePart.PLATES, EnumOrePart.RUBBLE, EnumOrePart.ROD, EnumOrePart.GEARS),
|
||||
STONE("Stone", EnumOrePart.INGOTS, EnumOrePart.SCRAPS),
|
||||
IRON("Iron", EnumOrePart.INGOTS),
|
||||
OBBY("Obby", EnumOrePart.INGOTS, EnumOrePart.RUBBLE, EnumOrePart.SCRAPS, EnumOrePart.PLATES),
|
||||
GOLD("Gold", EnumOrePart.GEARS, EnumOrePart.INGOTS),
|
||||
COAL("Coal", EnumOrePart.GEARS, EnumOrePart.TUBE, EnumOrePart.PLATES, EnumOrePart.RUBBLE, EnumOrePart.SCRAPS),
|
||||
WOOD("Wood", false, EnumOrePart.INGOTS, EnumOrePart.PLATES, EnumOrePart.RUBBLE, EnumOrePart.ROD, EnumOrePart.GEARS),
|
||||
STONE("Stone", false, EnumOrePart.INGOTS, EnumOrePart.SCRAPS),
|
||||
IRON("Iron", false, EnumOrePart.INGOTS),
|
||||
OBBY("Obby", true, EnumOrePart.INGOTS, EnumOrePart.RUBBLE, EnumOrePart.SCRAPS, EnumOrePart.PLATES),
|
||||
GOLD("Gold", false, EnumOrePart.GEARS, EnumOrePart.INGOTS),
|
||||
COAL("Coal", false, EnumOrePart.GEARS, EnumOrePart.TUBE, EnumOrePart.PLATES, EnumOrePart.RUBBLE, EnumOrePart.SCRAPS),
|
||||
|
||||
COPPER("Copper"),
|
||||
TIN("Tin", EnumOrePart.GEARS, EnumOrePart.TUBE),
|
||||
LEAD("Lead", EnumOrePart.GEARS, EnumOrePart.TUBE),
|
||||
ALUMINIUM("Aluminum", EnumOrePart.GEARS, EnumOrePart.TUBE),
|
||||
SILVER("Silver", EnumOrePart.GEARS),
|
||||
STEEL("Steel", EnumOrePart.RUBBLE),
|
||||
BRONZE("Bronze", EnumOrePart.RUBBLE);
|
||||
COPPER("Copper", true),
|
||||
TIN("Tin", true, EnumOrePart.GEARS, EnumOrePart.TUBE),
|
||||
LEAD("Lead", true, EnumOrePart.GEARS, EnumOrePart.TUBE),
|
||||
ALUMINIUM("Aluminum", true, EnumOrePart.GEARS, EnumOrePart.TUBE),
|
||||
SILVER("Silver", true, EnumOrePart.GEARS),
|
||||
STEEL("Steel", true, EnumOrePart.RUBBLE),
|
||||
BRONZE("Bronze", true, EnumOrePart.RUBBLE);
|
||||
|
||||
/** Name of the material */
|
||||
public String simpleName;
|
||||
/** List of ore parts that to not be created for the material */
|
||||
public List<EnumOrePart> unneedItems;
|
||||
|
||||
public boolean hasTools = false;
|
||||
|
||||
/** Limit by which each material is restricted by for creating orePart sub items */
|
||||
public static final int itemCountPerMaterial = 50;
|
||||
|
||||
|
@ -43,10 +46,10 @@ public enum EnumMaterial
|
|||
@SideOnly(Side.CLIENT)
|
||||
Icon[] itemIcons;
|
||||
|
||||
private EnumMaterial(String name, EnumOrePart... enumOreParts)
|
||||
private EnumMaterial(String name, boolean tool, EnumOrePart... enumOreParts)
|
||||
{
|
||||
this.simpleName = name;
|
||||
|
||||
this.hasTools = tool;
|
||||
unneedItems = new ArrayList<EnumOrePart>();
|
||||
for (int i = 0; enumOreParts != null && i < enumOreParts.length; i++)
|
||||
{
|
||||
|
@ -56,7 +59,7 @@ public enum EnumMaterial
|
|||
|
||||
/** 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.
|
||||
*
|
||||
*
|
||||
* @param mat - material
|
||||
* @param part - part
|
||||
* @return new ItemStack created from the two enums as long as everything goes right */
|
||||
|
@ -106,4 +109,24 @@ public enum EnumMaterial
|
|||
}
|
||||
return this.unneedItems == null || !this.unneedItems.contains(part);
|
||||
}
|
||||
|
||||
public boolean shouldCreateTool()
|
||||
{
|
||||
return this.hasTools;
|
||||
}
|
||||
|
||||
public static ItemStack getTool(EnumTools tool, EnumMaterial mat)
|
||||
{
|
||||
return mat.getTool(tool);
|
||||
}
|
||||
|
||||
public ItemStack getTool(EnumTools tool)
|
||||
{
|
||||
ItemStack stack = null;
|
||||
if (DarkMain.recipeLoader.itemDiggingTool instanceof ItemTool)
|
||||
{
|
||||
stack = new ItemStack(DarkMain.recipeLoader.itemDiggingTool.itemID, (this.ordinal() * 10) + tool.ordinal(), 1);
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
|
53
src/dark/core/common/items/EnumTools.java
Normal file
53
src/dark/core/common/items/EnumTools.java
Normal file
|
@ -0,0 +1,53 @@
|
|||
package dark.core.common.items;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
|
||||
/** Enum to store tools that can be created from the material sheet.
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public enum EnumTools
|
||||
{
|
||||
PICKAX("Pick-Ax", Material.rock, Material.iron, Material.ice, Material.anvil, Material.glass, Material.tnt),
|
||||
AX("Wood-Ax", Material.wood, Material.pumpkin, Material.plants, Material.vine),
|
||||
SPADE("Shade", Material.sand, Material.snow, Material.clay, Material.craftedSnow, Material.grass, Material.ground),
|
||||
NA3(),
|
||||
NA4(),
|
||||
NA5(),
|
||||
NA6(),
|
||||
NA7(),
|
||||
NA8(),
|
||||
NA9();
|
||||
|
||||
public final List<Material> effecticVsMaterials = new ArrayList<Material>();
|
||||
public String name = "tool";
|
||||
|
||||
private EnumTools()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private EnumTools(String name, Material... mats)
|
||||
{
|
||||
this.name = name;
|
||||
this.setEffectiveList(mats);
|
||||
}
|
||||
|
||||
public void setEffectiveList(Material... blocks)
|
||||
{
|
||||
for (Material block : blocks)
|
||||
{
|
||||
this.addEffectiveBlock(block);
|
||||
}
|
||||
}
|
||||
|
||||
public void addEffectiveBlock(Material block)
|
||||
{
|
||||
if (block != null)
|
||||
{
|
||||
this.effecticVsMaterials.add(block);
|
||||
}
|
||||
}
|
||||
}
|
152
src/dark/core/common/items/ItemTool.java
Normal file
152
src/dark/core/common/items/ItemTool.java
Normal file
|
@ -0,0 +1,152 @@
|
|||
package dark.core.common.items;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.SharedMonsterAttributes;
|
||||
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import dark.core.common.DarkMain;
|
||||
|
||||
public class ItemTool extends Item
|
||||
{
|
||||
protected List<Material> blocksEffectiveAgainstPick = new ArrayList<Material>();
|
||||
protected List<Material> blocksEffectiveAgainstAx = new ArrayList<Material>();
|
||||
protected List<Material> blocksEffectiveAgainstSpade = new ArrayList<Material>();
|
||||
|
||||
public float efficiencyOnProperMaterial = 4.0F;
|
||||
protected int maxUses, enchant;
|
||||
|
||||
/** Damage versus entities. */
|
||||
public float damageVsEntity;
|
||||
|
||||
public ItemTool(String name, int maxUses, float effective, int enchant)
|
||||
{
|
||||
super(DarkMain.CONFIGURATION.getItem("Items", "Tool:" + name, DarkMain.getNextItemId()).getInt());
|
||||
this.maxStackSize = 1;
|
||||
this.setCreativeTab(CreativeTabs.tabTools);
|
||||
this.maxUses = maxUses;
|
||||
this.enchant = enchant;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void damage(ItemStack itemStack, int damage, EntityLivingBase entity)
|
||||
{
|
||||
// Saves the frequency in the ItemStack
|
||||
if (itemStack.getTagCompound() == null)
|
||||
{
|
||||
itemStack.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
this.setDamage(itemStack, itemStack.getTagCompound().getInteger("toolDamage") + damage);
|
||||
}
|
||||
|
||||
public void setDamage(ItemStack itemStack, int damage)
|
||||
{
|
||||
// Saves the frequency in the ItemStack
|
||||
if (itemStack.getTagCompound() == null)
|
||||
{
|
||||
itemStack.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
int meta = itemStack.getItemDamage();
|
||||
int maxDamage = 1000;
|
||||
switch (meta % 10)
|
||||
{
|
||||
case 0:
|
||||
maxDamage = 450;
|
||||
break;
|
||||
case 1:
|
||||
maxDamage = 900;
|
||||
break;
|
||||
case 2:
|
||||
maxDamage = 100;
|
||||
break;
|
||||
}
|
||||
|
||||
damage = Math.max(Math.min(damage, maxDamage), 0);
|
||||
itemStack.getTagCompound().setInteger("toolDamage", damage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hitEntity(ItemStack itemStack, EntityLivingBase par2EntityLivingBase, EntityLivingBase par3EntityLivingBase)
|
||||
{
|
||||
this.damage(itemStack, 2, par2EntityLivingBase);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockDestroyed(ItemStack itemStack, World par2World, int par3, int par4, int par5, int par6, EntityLivingBase par7EntityLivingBase)
|
||||
{
|
||||
if ((double) Block.blocksList[par3].getBlockHardness(par2World, par4, par5, par6) != 0.0D)
|
||||
{
|
||||
this.damage(itemStack, 1, par7EntityLivingBase);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemEnchantability()
|
||||
{
|
||||
return this.enchant;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public boolean isFull3D()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack)
|
||||
{
|
||||
//We will have to check on how this is done to prevent issues
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Multimap getItemAttributeModifiers()
|
||||
{
|
||||
Multimap multimap = super.getItemAttributeModifiers();
|
||||
multimap.put(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName(), new AttributeModifier(field_111210_e, "Tool modifier", (double) this.damageVsEntity, 0));
|
||||
return multimap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getStrVsBlock(ItemStack par1ItemStack, Block par2Block)
|
||||
{
|
||||
if (par1ItemStack.get)
|
||||
if (this.blocksEffectiveAgainst.contains(par2Block.blockMaterial))
|
||||
{
|
||||
return this.efficiencyOnProperMaterial;
|
||||
}
|
||||
|
||||
return 1.0F;
|
||||
}
|
||||
|
||||
/** FORGE: Overridden to allow custom tool effectiveness */
|
||||
@Override
|
||||
public float getStrVsBlock(ItemStack stack, Block block, int meta)
|
||||
{
|
||||
if (ForgeHooks.isToolEffective(stack, block, meta))
|
||||
{
|
||||
return efficiencyOnProperMaterial;
|
||||
}
|
||||
return getStrVsBlock(stack, block);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue