2013-07-26 21:18:53 -07:00
|
|
|
package tconstruct.items.tools;
|
|
|
|
|
|
2013-11-25 14:08:18 -05:00
|
|
|
import java.util.List;
|
2013-07-26 21:18:53 -07:00
|
|
|
|
2014-01-16 01:36:18 -05:00
|
|
|
import mantle.world.WorldHelper;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
|
import net.minecraft.block.material.Material;
|
2013-11-25 14:08:18 -05:00
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2014-06-04 14:32:15 -04:00
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
2013-12-31 14:11:05 -05:00
|
|
|
import net.minecraft.init.Blocks;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.item.Item;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2013-12-31 14:11:05 -05:00
|
|
|
import net.minecraft.util.IIcon;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.util.MovingObjectPosition;
|
|
|
|
|
import net.minecraft.world.World;
|
2014-02-05 10:28:54 -05:00
|
|
|
import tconstruct.common.TRepo;
|
|
|
|
|
import tconstruct.library.ActiveToolMod;
|
|
|
|
|
import tconstruct.library.TConstructRegistry;
|
|
|
|
|
import tconstruct.library.crafting.ToolBuilder;
|
|
|
|
|
import tconstruct.library.tools.AbilityHelper;
|
|
|
|
|
import tconstruct.library.tools.HarvestTool;
|
2013-07-26 21:18:53 -07:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
|
|
|
|
|
public class Hammer extends HarvestTool
|
|
|
|
|
{
|
2013-12-31 14:11:05 -05:00
|
|
|
public Hammer()
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2013-12-31 14:11:05 -05:00
|
|
|
super(2);
|
2013-07-26 21:18:53 -07:00
|
|
|
this.setUnlocalizedName("InfiTool.Hammer");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
|
@Override
|
|
|
|
|
public int getRenderPasses (int metadata)
|
|
|
|
|
{
|
|
|
|
|
return 10;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getPartAmount ()
|
|
|
|
|
{
|
|
|
|
|
return 4;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-17 00:31:43 -05:00
|
|
|
@Override
|
2013-07-26 21:18:53 -07:00
|
|
|
public int durabilityTypeAccessory ()
|
|
|
|
|
{
|
|
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-17 00:31:43 -05:00
|
|
|
@Override
|
2013-07-26 21:18:53 -07:00
|
|
|
public int durabilityTypeExtra ()
|
|
|
|
|
{
|
|
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected String getHarvestType ()
|
|
|
|
|
{
|
|
|
|
|
return "pickaxe";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected Material[] getEffectiveMaterials ()
|
|
|
|
|
{
|
|
|
|
|
return materials;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-05 09:11:06 -05:00
|
|
|
static Material[] materials = new Material[] { Material.rock, Material.iron, Material.ice, Material.glass, Material.piston, Material.anvil };
|
2013-07-26 21:18:53 -07:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Item getHeadItem ()
|
|
|
|
|
{
|
2013-11-29 23:16:32 -05:00
|
|
|
return TRepo.hammerHead;
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Item getHandleItem ()
|
|
|
|
|
{
|
2013-11-29 23:16:32 -05:00
|
|
|
return TRepo.toughRod;
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Item getAccessoryItem ()
|
|
|
|
|
{
|
2013-11-29 23:16:32 -05:00
|
|
|
return TRepo.largePlate;
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Item getExtraItem ()
|
|
|
|
|
{
|
2013-11-29 23:16:32 -05:00
|
|
|
return TRepo.largePlate;
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
2014-02-17 00:31:43 -05:00
|
|
|
@Override
|
2013-07-26 21:18:53 -07:00
|
|
|
public float getDurabilityModifier ()
|
|
|
|
|
{
|
|
|
|
|
return 4.5f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getIconSuffix (int partType)
|
|
|
|
|
{
|
|
|
|
|
switch (partType)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
return "_hammer_head";
|
|
|
|
|
case 1:
|
|
|
|
|
return "_hammer_handle_broken";
|
|
|
|
|
case 2:
|
|
|
|
|
return "_hammer_handle";
|
|
|
|
|
case 3:
|
|
|
|
|
return "_hammer_front";
|
|
|
|
|
case 4:
|
|
|
|
|
return "_hammer_back";
|
|
|
|
|
default:
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getEffectSuffix ()
|
|
|
|
|
{
|
|
|
|
|
return "_hammer_effect";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getDefaultFolder ()
|
|
|
|
|
{
|
|
|
|
|
return "hammer";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2013-12-31 14:11:05 -05:00
|
|
|
public IIcon getIcon (ItemStack stack, int renderPass)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
NBTTagCompound tags = stack.getTagCompound();
|
|
|
|
|
|
|
|
|
|
if (tags != null)
|
|
|
|
|
{
|
|
|
|
|
tags = stack.getTagCompound().getCompoundTag("InfiTool");
|
|
|
|
|
if (renderPass < getPartAmount())
|
|
|
|
|
{
|
|
|
|
|
if (renderPass == 0) // Handle
|
|
|
|
|
{
|
|
|
|
|
if (tags.getBoolean("Broken"))
|
|
|
|
|
return (brokenIcons.get(tags.getInteger("RenderHandle")));
|
|
|
|
|
return handleIcons.get(tags.getInteger("RenderHandle"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (renderPass == 1) // Head
|
|
|
|
|
{
|
|
|
|
|
return (headIcons.get(tags.getInteger("RenderHead")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (renderPass == 2) // Accessory
|
|
|
|
|
{
|
|
|
|
|
return (accessoryIcons.get(tags.getInteger("RenderAccessory")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (renderPass == 3) // Extra
|
|
|
|
|
{
|
|
|
|
|
return (extraIcons.get(tags.getInteger("RenderExtra")));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (renderPass == getPartAmount())
|
|
|
|
|
{
|
|
|
|
|
if (tags.hasKey("Effect1"))
|
|
|
|
|
return (effectIcons.get(tags.getInteger("Effect1")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (renderPass == getPartAmount() + 1)
|
|
|
|
|
{
|
|
|
|
|
if (tags.hasKey("Effect2"))
|
|
|
|
|
return (effectIcons.get(tags.getInteger("Effect2")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (renderPass == getPartAmount() + 2)
|
|
|
|
|
{
|
|
|
|
|
if (tags.hasKey("Effect3"))
|
|
|
|
|
return (effectIcons.get(tags.getInteger("Effect3")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (renderPass == getPartAmount() + 3)
|
|
|
|
|
{
|
|
|
|
|
if (tags.hasKey("Effect4"))
|
|
|
|
|
return (effectIcons.get(tags.getInteger("Effect4")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (renderPass == getPartAmount() + 4)
|
|
|
|
|
{
|
|
|
|
|
if (tags.hasKey("Effect5"))
|
|
|
|
|
return (effectIcons.get(tags.getInteger("Effect5")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (renderPass == getPartAmount() + 5)
|
|
|
|
|
{
|
|
|
|
|
if (tags.hasKey("Effect6"))
|
|
|
|
|
return (effectIcons.get(tags.getInteger("Effect6")));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return blankSprite;
|
|
|
|
|
}
|
|
|
|
|
return emptyIcon;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-25 14:08:18 -05:00
|
|
|
@Override
|
2014-02-07 17:11:03 -05:00
|
|
|
public void getSubItems (Item id, CreativeTabs tab, List list)
|
2013-11-25 14:08:18 -05:00
|
|
|
{
|
|
|
|
|
super.getSubItems(id, tab, list);
|
|
|
|
|
|
|
|
|
|
ItemStack tool = ToolBuilder.instance.buildTool(new ItemStack(getHeadItem(), 1, 10), new ItemStack(getHandleItem(), 1, 8), new ItemStack(getAccessoryItem(), 1, 11), new ItemStack(
|
|
|
|
|
getExtraItem(), 1, 11), "InfiMiner");
|
|
|
|
|
|
|
|
|
|
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
|
|
|
|
|
tags.setInteger("Modifiers", 0);
|
|
|
|
|
tags.setInteger("Attack", Integer.MAX_VALUE / 100);
|
|
|
|
|
tags.setInteger("TotalDurability", Integer.MAX_VALUE / 100);
|
|
|
|
|
tags.setInteger("BaseDurability", Integer.MAX_VALUE / 100);
|
|
|
|
|
tags.setInteger("MiningSpeed", Integer.MAX_VALUE / 100);
|
|
|
|
|
tags.setInteger("Unbreaking", 10);
|
|
|
|
|
|
|
|
|
|
tags.setBoolean("Built", true);
|
|
|
|
|
list.add(tool);
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-26 21:18:53 -07:00
|
|
|
@Override
|
|
|
|
|
public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPlayer player)
|
|
|
|
|
{
|
2013-08-05 13:36:19 -07:00
|
|
|
if (!stack.hasTagCompound())
|
|
|
|
|
return false;
|
2013-08-31 05:13:31 -07:00
|
|
|
|
2013-07-26 21:18:53 -07:00
|
|
|
World world = player.worldObj;
|
2014-06-04 14:32:15 -04:00
|
|
|
MovingObjectPosition mop = AbilityHelper.raytraceFromEntity(world, player, true, 4.5D);
|
|
|
|
|
if (mop != null && player instanceof EntityPlayerMP)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-06-04 14:32:15 -04:00
|
|
|
EntityPlayerMP mplayer = (EntityPlayerMP) player;
|
|
|
|
|
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
|
|
|
|
|
if (!tags.hasKey("AOEBreaking") || !tags.getBoolean("AOEBreaking"))
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-06-04 14:32:15 -04:00
|
|
|
tags.setBoolean("AOEBreaking", true);
|
2013-07-26 21:18:53 -07:00
|
|
|
|
2014-06-04 14:32:15 -04:00
|
|
|
int xRange = 1;
|
|
|
|
|
int yRange = 1;
|
|
|
|
|
int zRange = 1;
|
|
|
|
|
switch (mop.sideHit)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
case 1:
|
|
|
|
|
yRange = 0;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
case 3:
|
|
|
|
|
zRange = 0;
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
case 5:
|
|
|
|
|
xRange = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-08-31 05:13:31 -07:00
|
|
|
|
2014-06-04 14:32:15 -04:00
|
|
|
for (int xPos = x - xRange; xPos <= x + xRange; xPos++)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-06-04 14:32:15 -04:00
|
|
|
for (int yPos = y - yRange; yPos <= y + yRange; yPos++)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-06-04 14:32:15 -04:00
|
|
|
for (int zPos = z - zRange; zPos <= z + zRange; zPos++)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-06-04 14:32:15 -04:00
|
|
|
Block block = world.getBlock(xPos, yPos, zPos);
|
|
|
|
|
for (Material mat : this.materials)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-06-04 14:32:15 -04:00
|
|
|
if (block != null && mat == block.getMaterial()
|
|
|
|
|
&& block.getPlayerRelativeBlockHardness(mplayer, world, x, yPos, z) > 0)
|
|
|
|
|
mplayer.theItemInWorldManager.tryHarvestBlock(xPos, yPos, zPos);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-04 14:32:15 -04:00
|
|
|
tags.setBoolean("AOEBreaking", false);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
2014-06-04 14:32:15 -04:00
|
|
|
return super.onBlockStartBreak(stack, x, y, z, player);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-02-03 10:02:49 -05:00
|
|
|
public float getDigSpeed (ItemStack stack, Block block, int meta)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
if (!stack.hasTagCompound())
|
|
|
|
|
return 1.0f;
|
|
|
|
|
|
|
|
|
|
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
|
|
|
|
|
if (tags.getBoolean("Broken"))
|
|
|
|
|
return 0.1f;
|
|
|
|
|
|
|
|
|
|
Material[] materials = getEffectiveMaterials();
|
|
|
|
|
for (int i = 0; i < materials.length; i++)
|
|
|
|
|
{
|
2014-02-05 08:28:53 -05:00
|
|
|
if (materials[i] == block.getMaterial())
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2013-07-22 21:53:01 -07:00
|
|
|
return getblockSpeed(tags, block, meta);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-08-31 05:13:31 -07:00
|
|
|
|
2014-02-16 14:23:50 -05:00
|
|
|
/*
|
|
|
|
|
* if (block == Block.silverfish) return getblockSpeed(tags, block,
|
|
|
|
|
* meta);
|
|
|
|
|
*/
|
2013-08-31 05:13:31 -07:00
|
|
|
|
2014-02-03 10:02:49 -05:00
|
|
|
return super.getDigSpeed(stack, block, meta);
|
2013-07-22 21:53:01 -07:00
|
|
|
}
|
2013-07-26 21:18:53 -07:00
|
|
|
|
2013-07-22 21:53:01 -07:00
|
|
|
float getblockSpeed (NBTTagCompound tags, Block block, int meta)
|
|
|
|
|
{
|
|
|
|
|
float mineSpeed = tags.getInteger("MiningSpeed");
|
|
|
|
|
int heads = 1;
|
|
|
|
|
if (tags.hasKey("MiningSpeed2"))
|
|
|
|
|
{
|
|
|
|
|
mineSpeed += tags.getInteger("MiningSpeed2");
|
|
|
|
|
heads++;
|
|
|
|
|
}
|
|
|
|
|
if (tags.hasKey("MiningSpeedHandle"))
|
|
|
|
|
{
|
|
|
|
|
mineSpeed += tags.getInteger("MiningSpeedHandle");
|
|
|
|
|
heads++;
|
|
|
|
|
}
|
2013-07-26 21:18:53 -07:00
|
|
|
|
2013-07-22 21:53:01 -07:00
|
|
|
if (tags.hasKey("MiningSpeedExtra"))
|
|
|
|
|
{
|
|
|
|
|
mineSpeed += tags.getInteger("MiningSpeedExtra");
|
|
|
|
|
heads++;
|
|
|
|
|
}
|
|
|
|
|
float trueSpeed = mineSpeed / (heads * 300f);
|
2014-02-01 15:17:30 -05:00
|
|
|
int hlvl = block.getHarvestLevel(meta);
|
2013-07-22 21:53:01 -07:00
|
|
|
int durability = tags.getInteger("Damage");
|
2013-07-26 21:18:53 -07:00
|
|
|
|
2013-07-22 21:53:01 -07:00
|
|
|
float stonebound = tags.getFloat("Shoddy");
|
2013-08-26 20:17:21 -07:00
|
|
|
float bonusLog = (float) Math.log(durability / 216f + 1) * 2 * stonebound;
|
2013-07-22 21:53:01 -07:00
|
|
|
trueSpeed += bonusLog;
|
2013-07-26 21:18:53 -07:00
|
|
|
|
2013-07-22 21:53:01 -07:00
|
|
|
if (hlvl <= tags.getInteger("HarvestLevel"))
|
|
|
|
|
return trueSpeed;
|
|
|
|
|
return 0.1f;
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
2014-02-16 14:23:50 -05:00
|
|
|
/*
|
|
|
|
|
* @Override public void onUpdate (ItemStack stack, World world, Entity
|
|
|
|
|
* entity, int par4, boolean par5) { super.onUpdate(stack, world, entity,
|
|
|
|
|
* par4, par5); if (entity instanceof EntityPlayer) { EntityPlayer player =
|
|
|
|
|
* (EntityPlayer) entity; ItemStack equipped =
|
|
|
|
|
* player.getCurrentEquippedItem(); if (equipped == stack) {
|
|
|
|
|
* player.addPotionEffect(new PotionEffect(Potion.digSlowdown.id, 1, 1)); }
|
|
|
|
|
* } }
|
|
|
|
|
*/
|
2013-07-26 21:18:53 -07:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String[] toolCategories ()
|
|
|
|
|
{
|
|
|
|
|
return new String[] { "weapon", "harvest", "melee", "bludgeoning" };
|
|
|
|
|
}
|
2013-11-10 13:57:35 -08:00
|
|
|
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|