2013-07-26 21:18:53 -07:00
|
|
|
package tconstruct.items.tools;
|
|
|
|
|
|
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;
|
|
|
|
|
import net.minecraft.client.entity.EntityPlayerSP;
|
2014-07-28 00:39:37 +03:00
|
|
|
import net.minecraft.enchantment.EnchantmentHelper;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
|
import net.minecraft.item.EnumAction;
|
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import net.minecraft.potion.Potion;
|
|
|
|
|
import net.minecraft.potion.PotionEffect;
|
|
|
|
|
import net.minecraft.util.MathHelper;
|
|
|
|
|
import net.minecraft.world.World;
|
2014-02-05 10:28:54 -05:00
|
|
|
import tconstruct.library.ActiveToolMod;
|
|
|
|
|
import tconstruct.library.TConstructRegistry;
|
|
|
|
|
import tconstruct.library.tools.AbilityHelper;
|
|
|
|
|
import tconstruct.library.tools.HarvestTool;
|
2014-06-04 21:44:48 -08:00
|
|
|
import tconstruct.tools.TinkerTools;
|
2013-07-26 21:18:53 -07:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
|
|
|
|
|
public class Battleaxe extends HarvestTool
|
|
|
|
|
{
|
2014-01-01 08:47:10 -05:00
|
|
|
public Battleaxe()
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-01-01 08:47:10 -05:00
|
|
|
super(4);
|
2013-07-26 21:18:53 -07:00
|
|
|
this.setUnlocalizedName("InfiTool.Battleaxe");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected Material[] getEffectiveMaterials ()
|
|
|
|
|
{
|
|
|
|
|
return materials;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected String getHarvestType ()
|
|
|
|
|
{
|
|
|
|
|
return "axe";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-02-05 08:28:53 -05:00
|
|
|
public boolean onBlockDestroyed (ItemStack itemstack, World world, Block b, int x, int y, int z, EntityLivingBase player)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-02-05 08:28:53 -05:00
|
|
|
if (b != null && b.getMaterial() == Material.leaves)
|
2013-07-26 21:18:53 -07:00
|
|
|
return false;
|
|
|
|
|
|
2014-01-07 13:50:35 -05:00
|
|
|
return AbilityHelper.onBlockChanged(itemstack, world, b, x, y, z, player, random);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
2014-02-05 08:28:53 -05:00
|
|
|
static Material[] materials = { Material.wood, Material.vine, Material.circuits, Material.cactus, Material.gourd };
|
2013-07-26 21:18:53 -07:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Item getHeadItem ()
|
|
|
|
|
{
|
2014-06-04 21:44:48 -08:00
|
|
|
return TinkerTools.broadAxeHead;
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Item getHandleItem ()
|
|
|
|
|
{
|
2014-06-04 21:44:48 -08:00
|
|
|
return TinkerTools.toughRod;
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Item getAccessoryItem ()
|
|
|
|
|
{
|
2014-06-04 21:44:48 -08:00
|
|
|
return TinkerTools.broadAxeHead;
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Item getExtraItem ()
|
|
|
|
|
{
|
2014-06-04 21:44:48 -08:00
|
|
|
return TinkerTools.toughBinding;
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int durabilityTypeAccessory ()
|
|
|
|
|
{
|
|
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int durabilityTypeExtra ()
|
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public float getRepairCost ()
|
|
|
|
|
{
|
|
|
|
|
return 4.0f;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-17 00:31:43 -05:00
|
|
|
@Override
|
2013-07-26 21:18:53 -07:00
|
|
|
public float getDurabilityModifier ()
|
|
|
|
|
{
|
|
|
|
|
return 2.5f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
|
@Override
|
|
|
|
|
public int getRenderPasses (int metadata)
|
|
|
|
|
{
|
|
|
|
|
return 10;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getPartAmount ()
|
|
|
|
|
{
|
|
|
|
|
return 4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getIconSuffix (int partType)
|
|
|
|
|
{
|
|
|
|
|
switch (partType)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
return "_battleaxe_fronthead";
|
|
|
|
|
case 1:
|
|
|
|
|
return "_battleaxe_fronthead_broken";
|
|
|
|
|
case 2:
|
|
|
|
|
return "_battleaxe_handle";
|
|
|
|
|
case 3:
|
|
|
|
|
return "_battleaxe_backhead";
|
|
|
|
|
case 4:
|
|
|
|
|
return "_battleaxe_binding";
|
|
|
|
|
default:
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getEffectSuffix ()
|
|
|
|
|
{
|
|
|
|
|
return "_battleaxe_effect";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getDefaultFolder ()
|
|
|
|
|
{
|
|
|
|
|
return "battleaxe";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-06-30 22:26:00 -08:00
|
|
|
public String[] getTraits ()
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
return new String[] { "weapon", "harvest", "melee", "slicing" };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Battleaxe Specific */
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onItemUse (ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float clickX, float clickY, float clickZ)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public EnumAction getItemUseAction (ItemStack par1ItemStack)
|
|
|
|
|
{
|
|
|
|
|
return EnumAction.bow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ItemStack onItemRightClick (ItemStack stack, World world, EntityPlayer player)
|
|
|
|
|
{
|
2014-02-16 14:23:50 -05:00
|
|
|
// player.rotationYaw += 1;
|
|
|
|
|
// if (player.onGround)
|
|
|
|
|
// {
|
2013-07-26 21:18:53 -07:00
|
|
|
player.setItemInUse(stack, this.getMaxItemUseDuration(stack));
|
2014-02-16 14:23:50 -05:00
|
|
|
// }
|
2013-07-26 21:18:53 -07:00
|
|
|
return stack;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onPlayerStoppedUsing (ItemStack stack, World world, EntityPlayer player, int useCount)
|
|
|
|
|
{
|
2014-02-16 14:23:50 -05:00
|
|
|
// if (player.onGround)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
int time = this.getMaxItemUseDuration(stack) - useCount;
|
|
|
|
|
int boost = time / 100;
|
|
|
|
|
if (boost > 2)
|
|
|
|
|
boost = 2;
|
|
|
|
|
player.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, time * 4, boost));
|
|
|
|
|
player.addPotionEffect(new PotionEffect(Potion.jump.id, time * 4, boost));
|
|
|
|
|
player.addPotionEffect(new PotionEffect(Potion.damageBoost.id, time * 4, 0));
|
|
|
|
|
player.addPotionEffect(new PotionEffect(Potion.hunger.id, time * 2, 0));
|
|
|
|
|
if (time > 5 && player.onGround)
|
|
|
|
|
{
|
|
|
|
|
player.addExhaustion(0.2F);
|
|
|
|
|
player.setSprinting(true);
|
|
|
|
|
|
|
|
|
|
float speed = 0.025F * time;
|
|
|
|
|
if (speed > 0.925f)
|
|
|
|
|
speed = 0.925f;
|
|
|
|
|
|
|
|
|
|
float increase = (float) (0.02 * time + 0.2);
|
|
|
|
|
if (increase > 0.56f)
|
|
|
|
|
increase = 0.56f;
|
|
|
|
|
player.motionY += increase;
|
|
|
|
|
|
|
|
|
|
player.motionX = (double) (-MathHelper.sin(player.rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(player.rotationPitch / 180.0F * (float) Math.PI) * speed);
|
|
|
|
|
player.motionZ = (double) (MathHelper.cos(player.rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(player.rotationPitch / 180.0F * (float) Math.PI) * speed);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-17 00:31:43 -05:00
|
|
|
@Override
|
2013-07-26 21:18:53 -07:00
|
|
|
public int getMaxItemUseDuration (ItemStack par1ItemStack)
|
|
|
|
|
{
|
|
|
|
|
return 72000;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean hitEntity (ItemStack stack, EntityLivingBase mob, EntityLivingBase player)
|
|
|
|
|
{
|
|
|
|
|
AbilityHelper.knockbackEntity(mob, 1.5f);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
|
public void onUpdate (ItemStack stack, World world, Entity entity, int par4, boolean par5)
|
|
|
|
|
{
|
|
|
|
|
super.onUpdate(stack, world, entity, par4, par5);
|
|
|
|
|
if (entity instanceof EntityPlayerSP)
|
|
|
|
|
{
|
|
|
|
|
EntityPlayerSP player = (EntityPlayerSP) entity;
|
|
|
|
|
ItemStack usingItem = player.getItemInUse();
|
|
|
|
|
if (usingItem != null && usingItem.getItem() == this)
|
|
|
|
|
{
|
|
|
|
|
player.movementInput.moveForward *= 5.0F;
|
|
|
|
|
player.movementInput.moveStrafe *= 5.0F;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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
|
|
|
|
2014-07-21 15:07:16 -04:00
|
|
|
World world = player.worldObj;
|
|
|
|
|
final Block wood = world.getBlock(x, y, z);
|
|
|
|
|
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
|
|
|
|
|
final int meta = world.getBlockMetadata(x, y, z);
|
2014-07-28 00:39:37 +03:00
|
|
|
final int fortune = EnchantmentHelper.getFortuneModifier(player);
|
2014-07-21 15:07:16 -04:00
|
|
|
for (int yPos = y + 1; yPos < y + 9; yPos++)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-07-21 15:07:16 -04:00
|
|
|
Block block = world.getBlock(x, yPos, z);
|
|
|
|
|
if (!(tags.getBoolean("Broken")) && block != null && block.getMaterial() == Material.wood)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-07-21 15:07:16 -04:00
|
|
|
Block localblock = world.getBlock(x, yPos, z);
|
|
|
|
|
int localMeta = world.getBlockMetadata(x, yPos, z);
|
|
|
|
|
int hlvl = block.getHarvestLevel(meta);
|
|
|
|
|
|
|
|
|
|
if (hlvl <= tags.getInteger("HarvestLevel"))
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-07-21 15:07:16 -04:00
|
|
|
boolean cancelHarvest = false;
|
|
|
|
|
for (ActiveToolMod mod : TConstructRegistry.activeModifiers)
|
|
|
|
|
{
|
|
|
|
|
if (mod.beforeBlockBreak(this, stack, x, yPos, z, player))
|
|
|
|
|
cancelHarvest = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!cancelHarvest)
|
|
|
|
|
{
|
|
|
|
|
if (block != null && block.getMaterial() == Material.wood)
|
|
|
|
|
{
|
|
|
|
|
localMeta = world.getBlockMetadata(x, yPos, z);
|
|
|
|
|
if (!player.capabilities.isCreativeMode)
|
|
|
|
|
{
|
|
|
|
|
if (block.removedByPlayer(world, player, x, yPos, z))
|
|
|
|
|
{
|
|
|
|
|
block.onBlockDestroyedByPlayer(world, x, yPos, z, localMeta);
|
|
|
|
|
}
|
2014-07-28 00:39:37 +03:00
|
|
|
|
|
|
|
|
// Workaround for dropping experience
|
|
|
|
|
int exp = block.getExpDrop(world, localMeta, fortune);
|
|
|
|
|
block.dropXpOnBlockBreak(world, x, y, z, exp);
|
|
|
|
|
|
2014-07-21 15:07:16 -04:00
|
|
|
block.harvestBlock(world, player, x, yPos, z, localMeta);
|
|
|
|
|
block.onBlockHarvested(world, x, yPos, z, localMeta, player);
|
|
|
|
|
onBlockDestroyed(stack, world, block, x, yPos, z, player);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
WorldHelper.setBlockToAir(world, x, yPos, z);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
2014-07-21 15:07:16 -04:00
|
|
|
else
|
|
|
|
|
break;
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
2014-07-21 15:07:16 -04:00
|
|
|
if (!world.isRemote)
|
|
|
|
|
world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(wood) + (meta << 12));
|
2013-07-26 21:18:53 -07:00
|
|
|
return super.onBlockStartBreak(stack, x, y, z, player);
|
|
|
|
|
}
|
|
|
|
|
}
|