BloodMagic/src/main/java/WayofTime/alchemicalWizardry/common/items/BoundShovel.java

274 lines
8.5 KiB
Java
Raw Normal View History

package WayofTime.alchemicalWizardry.common.items;
import java.util.List;
import net.minecraft.block.Block;
2015-07-30 08:44:01 -04:00
import net.minecraft.block.state.IBlockState;
2014-10-13 22:33:20 +02:00
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemSpade;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
2015-07-30 08:44:01 -04:00
import net.minecraft.util.BlockPos;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
2015-07-30 08:44:01 -04:00
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import WayofTime.alchemicalWizardry.AlchemicalWizardry;
import WayofTime.alchemicalWizardry.api.items.interfaces.IBindable;
import WayofTime.alchemicalWizardry.common.ItemType;
import WayofTime.alchemicalWizardry.common.spell.complex.effect.SpellHelper;
import com.google.common.collect.HashMultiset;
public class BoundShovel extends ItemSpade implements IBindable
{
public float efficiencyOnProperMaterial = 12.0F;
public float damageVsEntity;
private int energyUsed;
public BoundShovel()
{
super(AlchemicalWizardry.bloodBoundToolMaterial);
this.maxStackSize = 1;
this.efficiencyOnProperMaterial = 12.0F;
this.damageVsEntity = 5;
setCreativeTab(AlchemicalWizardry.tabBloodMagic);
setEnergyUsed(5);
}
public void setEnergyUsed(int i)
{
energyUsed = i;
}
public int getEnergyUsed()
{
return this.energyUsed;
}
@Override
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
{
par3List.add(StatCollector.translateToLocal("tooltip.boundshovel.desc"));
2015-01-16 10:00:50 -05:00
if (!(par1ItemStack.getTagCompound() == null))
{
2015-01-16 10:00:50 -05:00
if (par1ItemStack.getTagCompound().getBoolean("isActive"))
{
par3List.add(StatCollector.translateToLocal("tooltip.sigil.state.activated"));
} else
{
par3List.add(StatCollector.translateToLocal("tooltip.sigil.state.deactivated"));
}
2015-01-16 10:00:50 -05:00
if (!par1ItemStack.getTagCompound().getString("ownerName").equals(""))
{
par3List.add(StatCollector.translateToLocal("tooltip.owner.currentowner") + " " + par1ItemStack.getTagCompound().getString("ownerName"));
}
}
}
@Override
2015-07-30 08:44:01 -04:00
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer par3EntityPlayer)
{
2015-07-30 08:44:01 -04:00
if (!EnergyItems.checkAndSetItemOwner(stack, par3EntityPlayer) || par3EntityPlayer.isSneaking())
{
2015-07-30 08:44:01 -04:00
this.setActivated(stack, !getActivated(stack));
stack.getTagCompound().setInteger("worldTimeDelay", (int) (world.getWorldTime() - 1) % 200);
return stack;
}
2015-04-10 20:32:09 +02:00
2015-07-30 08:44:01 -04:00
if (world.isRemote)
2015-04-10 20:32:09 +02:00
{
2015-07-30 08:44:01 -04:00
return stack;
2015-04-10 20:32:09 +02:00
}
2015-07-30 08:44:01 -04:00
if (!getActivated(stack) || SpellHelper.isFakePlayer(world, par3EntityPlayer))
{
2015-07-30 08:44:01 -04:00
return stack;
}
if (par3EntityPlayer.isPotionActive(AlchemicalWizardry.customPotionInhibit))
{
2015-07-30 08:44:01 -04:00
return stack;
}
2015-07-30 08:44:01 -04:00
if(!EnergyItems.syphonBatteries(stack, par3EntityPlayer, 10000))
{
2015-07-30 08:44:01 -04:00
return stack;
}
2015-07-30 08:44:01 -04:00
BlockPos pos = par3EntityPlayer.getPosition();
2014-10-13 22:33:20 +02:00
boolean silkTouch = EnchantmentHelper.getSilkTouchModifier(par3EntityPlayer);
int fortuneLvl = EnchantmentHelper.getFortuneModifier(par3EntityPlayer);
2015-04-10 20:30:52 +02:00
HashMultiset<ItemType> dropMultiset = HashMultiset.create();
for (int i = -5; i <= 5; i++)
{
for (int j = 0; j <= 10; j++)
{
for (int k = -5; k <= 5; k++)
{
2015-07-30 08:44:01 -04:00
BlockPos newPos = pos.add(i, j, k);
IBlockState state = world.getBlockState(newPos);
Block block = state.getBlock();
if (block != null)
{
2015-07-30 08:44:01 -04:00
float str = getStrVsBlock(stack, block);
2015-07-30 08:44:01 -04:00
if (str > 1.1f && world.canMineBlockBody(par3EntityPlayer, newPos))
{
2015-07-30 08:44:01 -04:00
if (silkTouch && block.canSilkHarvest(world, newPos, state, par3EntityPlayer))
{
2015-07-30 08:44:01 -04:00
dropMultiset.add(new ItemType(block, block.getMetaFromState(state)));
} else
{
2015-07-30 08:44:01 -04:00
List<ItemStack> itemDropList = block.getDrops(world, newPos, state, fortuneLvl);
if (itemDropList != null)
{
2015-07-30 08:44:01 -04:00
for (ItemStack stacky : itemDropList)
dropMultiset.add(ItemType.fromStack(stacky), stacky.stackSize);
}
}
2015-07-30 08:44:01 -04:00
world.setBlockToAir(newPos);
}
}
}
}
}
2015-04-10 20:30:52 +02:00
2015-07-30 08:44:01 -04:00
BoundPickaxe.dropMultisetStacks(dropMultiset, world, pos.getX(), pos.getY() + par3EntityPlayer.getEyeHeight(), pos.getZ());
return stack;
}
@Override
public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5)
{
if (!(par3Entity instanceof EntityPlayer))
{
return;
}
EntityPlayer par3EntityPlayer = (EntityPlayer) par3Entity;
2015-01-16 10:00:50 -05:00
if (par1ItemStack.getTagCompound() == null)
{
par1ItemStack.setTagCompound(new NBTTagCompound());
}
2015-01-16 10:00:50 -05:00
if (par2World.getWorldTime() % 200 == par1ItemStack.getTagCompound().getInteger("worldTimeDelay") && par1ItemStack.getTagCompound().getBoolean("isActive"))
{
if (!par3EntityPlayer.capabilities.isCreativeMode)
{
if(!EnergyItems.syphonBatteries(par1ItemStack, par3EntityPlayer, 20))
{
this.setActivated(par1ItemStack, false);
}
}
}
par1ItemStack.setItemDamage(0);
}
2015-07-30 08:44:01 -04:00
public void setActivated(ItemStack stack, boolean newActivated)
{
2015-07-30 08:44:01 -04:00
stack.setItemDamage(newActivated ? 1 : 0);
}
2015-07-30 08:44:01 -04:00
public boolean getActivated(ItemStack stack)
{
2015-07-30 08:44:01 -04:00
return stack.getItemDamage() == 1;
}
/**
* Returns the strength of the stack against a given block. 1.0F base, (Quality+1)*2 if correct blocktype, 1.5F if
* sword
*/
@Override
2015-07-30 08:44:01 -04:00
public float getStrVsBlock(ItemStack par1ItemStack, Block par2Block)
{
if (!getActivated(par1ItemStack))
{
return 0.0F;
}
2015-07-30 08:44:01 -04:00
return super.getStrVsBlock(par1ItemStack, par2Block);
}
/**
* Current implementations of this method in child classes do not use the entry argument beside ev. They just raise
* the damage on the stack.
*/
public boolean hitEntity(ItemStack par1ItemStack, EntityLivingBase par2EntityLivingBase, EntityLivingBase par3EntityLivingBase)
{
return getActivated(par1ItemStack);
}
public boolean onBlockDestroyed(ItemStack par1ItemStack, World par2World, int par3, int par4, int par5, int par6, EntityLivingBase par7EntityLivingBase)
{
return true;
}
@SideOnly(Side.CLIENT)
/**
* Returns True is the item is renderer in full 3D when hold.
*/
public boolean isFull3D()
{
return true;
}
/**
* Return the enchantability factor of the item, most of the time is based on material.
*/
public int getItemEnchantability()
{
return 30;
}
/**
* FORGE: Overridden to allow custom tool effectiveness
*/
@Override
2015-07-30 08:44:01 -04:00
public float getDigSpeed(ItemStack stack, IBlockState state)
{
if (!getActivated(stack))
{
return 0.0F;
}
2015-07-30 08:44:01 -04:00
for (String type : getToolClasses(stack))
{
2015-07-30 08:44:01 -04:00
if (state.getBlock().isToolEffective(type, state))
return efficiencyOnProperMaterial;
}
2015-07-30 08:44:01 -04:00
return super.getDigSpeed(stack, state);
}
@Override
public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity)
{
return !getActivated(stack);
}
2014-10-13 22:33:20 +02:00
@Override
public int getHarvestLevel(ItemStack stack, String toolClass)
{
if (getActivated(stack) && "shovel".equals(toolClass))
2014-10-13 22:33:20 +02:00
{
return 5;
}
return 0;
}
}