2014-07-15 03:23:48 +02:00
|
|
|
package com.pahimar.ee3.item;
|
|
|
|
|
|
|
|
import com.pahimar.ee3.creativetab.CreativeTab;
|
|
|
|
import com.pahimar.ee3.reference.Key;
|
|
|
|
import com.pahimar.ee3.reference.Names;
|
|
|
|
import com.pahimar.ee3.reference.Sounds;
|
|
|
|
import com.pahimar.ee3.reference.Textures;
|
|
|
|
import com.pahimar.ee3.util.NBTHelper;
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2014-07-15 18:24:18 +02:00
|
|
|
import net.minecraft.init.Blocks;
|
2014-07-15 03:23:48 +02:00
|
|
|
import net.minecraft.item.ItemPickaxe;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2014-07-15 18:24:18 +02:00
|
|
|
import net.minecraftforge.common.ForgeHooks;
|
2014-07-15 03:23:48 +02:00
|
|
|
|
|
|
|
public class ItemMatterPickAxe extends ItemPickaxe implements IKeyBound, IChargeable
|
|
|
|
{
|
|
|
|
private short maxChargeLevel;
|
|
|
|
|
2014-07-15 18:24:18 +02:00
|
|
|
public ItemMatterPickAxe(ToolMaterial toolMaterial, int maxChargeLevel)
|
2014-07-15 03:23:48 +02:00
|
|
|
{
|
2014-07-15 18:24:18 +02:00
|
|
|
super(toolMaterial);
|
2014-07-15 03:23:48 +02:00
|
|
|
this.maxChargeLevel = (short) maxChargeLevel;
|
|
|
|
this.setCreativeTab(CreativeTab.EE3_TAB);
|
|
|
|
this.setNoRepair();
|
|
|
|
this.setUnlocalizedName(Names.Tools.DARK_MATTER_PICKAXE);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getUnlocalizedName()
|
|
|
|
{
|
|
|
|
return String.format("item.%s%s", Textures.RESOURCE_PREFIX, getUnwrappedUnlocalizedName(super.getUnlocalizedName()));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getUnlocalizedName(ItemStack itemStack)
|
|
|
|
{
|
|
|
|
return String.format("item.%s%s", Textures.RESOURCE_PREFIX, getUnwrappedUnlocalizedName(super.getUnlocalizedName()));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public void registerIcons(IIconRegister iconRegister)
|
|
|
|
{
|
|
|
|
itemIcon = iconRegister.registerIcon(this.getUnlocalizedName().substring(this.getUnlocalizedName().indexOf(".") + 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected String getUnwrappedUnlocalizedName(String unlocalizedName)
|
|
|
|
{
|
|
|
|
return unlocalizedName.substring(unlocalizedName.indexOf(".") + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean getShareTag()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean showDurabilityBar(ItemStack itemStack)
|
|
|
|
{
|
|
|
|
return ((IChargeable) itemStack.getItem()).getChargeLevel(itemStack) > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public double getDurabilityForDisplay(ItemStack itemStack)
|
|
|
|
{
|
|
|
|
if (itemStack.getItem() instanceof IChargeable)
|
|
|
|
{
|
|
|
|
return (double) (this.maxChargeLevel - ((IChargeable) itemStack.getItem()).getChargeLevel(itemStack)) / (double) this.maxChargeLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1d;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public float getDigSpeed(ItemStack itemStack, Block block, int meta)
|
|
|
|
{
|
2014-07-15 18:24:18 +02:00
|
|
|
if ((ForgeHooks.isToolEffective(itemStack, block, meta) || block == Blocks.obsidian || block == Blocks.redstone_ore || block == Blocks.lit_redstone_ore) && (itemStack.getItem() instanceof IChargeable))
|
2014-07-15 03:23:48 +02:00
|
|
|
{
|
|
|
|
return super.getDigSpeed(itemStack, block, meta) + (((IChargeable) itemStack.getItem()).getChargeLevel(itemStack) * 12f);
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.getDigSpeed(itemStack, block, meta);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public short getChargeLevel(ItemStack itemStack)
|
|
|
|
{
|
|
|
|
return NBTHelper.getShort(itemStack, Names.NBT.CHARGE_LEVEL);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setChargeLevel(ItemStack itemStack, short chargeLevel)
|
|
|
|
{
|
|
|
|
if (chargeLevel <= maxChargeLevel)
|
|
|
|
{
|
|
|
|
NBTHelper.setShort(itemStack, Names.NBT.CHARGE_LEVEL, chargeLevel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void increaseChargeLevel(ItemStack itemStack)
|
|
|
|
{
|
|
|
|
if (NBTHelper.getShort(itemStack, Names.NBT.CHARGE_LEVEL) < maxChargeLevel)
|
|
|
|
{
|
|
|
|
NBTHelper.setShort(itemStack, Names.NBT.CHARGE_LEVEL, (short) (NBTHelper.getShort(itemStack, Names.NBT.CHARGE_LEVEL) + 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void decreaseChargeLevel(ItemStack itemStack)
|
|
|
|
{
|
|
|
|
if (NBTHelper.getShort(itemStack, Names.NBT.CHARGE_LEVEL) > 0)
|
|
|
|
{
|
|
|
|
NBTHelper.setShort(itemStack, Names.NBT.CHARGE_LEVEL, (short) (NBTHelper.getShort(itemStack, Names.NBT.CHARGE_LEVEL) - 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void doKeyBindingAction(EntityPlayer entityPlayer, ItemStack itemStack, Key key)
|
|
|
|
{
|
|
|
|
if (key == Key.CHARGE)
|
|
|
|
{
|
|
|
|
if (!entityPlayer.isSneaking())
|
|
|
|
{
|
|
|
|
if (getChargeLevel(itemStack) == maxChargeLevel)
|
|
|
|
{
|
|
|
|
entityPlayer.worldObj.playSoundEffect(entityPlayer.posX, entityPlayer.posY, entityPlayer.posZ, Sounds.FAIL, 1.5f, 1.5f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
increaseChargeLevel(itemStack);
|
|
|
|
entityPlayer.worldObj.playSoundEffect(entityPlayer.posX, entityPlayer.posY, entityPlayer.posZ, Sounds.CHARGE_UP, 0.5F, 0.5F + 0.5F * (getChargeLevel(itemStack) * 1.0F / maxChargeLevel));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (getChargeLevel(itemStack) == 0)
|
|
|
|
{
|
|
|
|
entityPlayer.worldObj.playSoundEffect(entityPlayer.posX, entityPlayer.posY, entityPlayer.posZ, Sounds.FAIL, 1.5f, 1.5f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
decreaseChargeLevel(itemStack);
|
|
|
|
entityPlayer.worldObj.playSoundEffect(entityPlayer.posX, entityPlayer.posY, entityPlayer.posZ, Sounds.CHARGE_DOWN, 0.5F, 1.0F - (0.5F - 0.5F * (getChargeLevel(itemStack) * 1.0F / maxChargeLevel)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|