mirror of
https://github.com/GTNewHorizons/BloodMagic.git
synced 2026-11-24 13:54:48 +00:00
275 lines
9.8 KiB
Java
275 lines
9.8 KiB
Java
package WayofTime.alchemicalWizardry.common.items;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
|
import net.minecraft.enchantment.EnchantmentHelper;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
import net.minecraft.entity.item.EntityItem;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.item.ItemPickaxe;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
import net.minecraft.util.IIcon;
|
|
import net.minecraft.util.StatCollector;
|
|
import net.minecraft.util.Vec3;
|
|
import net.minecraft.world.World;
|
|
import net.minecraftforge.common.ForgeHooks;
|
|
|
|
import com.google.common.collect.HashMultiset;
|
|
import com.google.common.collect.Multiset;
|
|
|
|
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 cpw.mods.fml.relauncher.Side;
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
import gregtech.common.blocks.GTBlockOre;
|
|
|
|
public class BoundPickaxe extends ItemPickaxe implements IBindable {
|
|
|
|
public float efficiencyOnProperMaterial = 12.0F;
|
|
public float damageVsEntity;
|
|
public int rightClickCost = 10000;
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
private IIcon activeIcon;
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
private IIcon passiveIcon;
|
|
|
|
private int energyUsed;
|
|
|
|
public BoundPickaxe() {
|
|
super(AlchemicalWizardry.bloodBoundToolMaterial);
|
|
this.maxStackSize = 1;
|
|
this.efficiencyOnProperMaterial = 12.0F;
|
|
this.damageVsEntity = 5;
|
|
setCreativeTab(AlchemicalWizardry.tabBloodMagic);
|
|
this.setEnergyUsed(5);
|
|
setHarvestLevel("pickaxe", 7);
|
|
}
|
|
|
|
public void setEnergyUsed(int i) {
|
|
energyUsed = i;
|
|
}
|
|
|
|
public int getEnergyUsed() {
|
|
return this.energyUsed;
|
|
}
|
|
|
|
@Override
|
|
public int drainCost() {
|
|
return this.energyUsed;
|
|
}
|
|
|
|
@Override
|
|
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) {
|
|
par3List.add(StatCollector.translateToLocal("tooltip.boundpickaxe.desc1"));
|
|
par3List.add(StatCollector.translateToLocal("tooltip.boundpickaxe.desc2"));
|
|
addBindingInformation(par1ItemStack, par3List);
|
|
}
|
|
|
|
@Override
|
|
@SideOnly(Side.CLIENT)
|
|
public void registerIcons(IIconRegister iconRegister) {
|
|
this.itemIcon = iconRegister.registerIcon("AlchemicalWizardry:BoundPickaxe_activated");
|
|
this.activeIcon = iconRegister.registerIcon("AlchemicalWizardry:BoundPickaxe_activated");
|
|
this.passiveIcon = iconRegister.registerIcon("AlchemicalWizardry:SheathedItem");
|
|
}
|
|
|
|
@Override
|
|
public IIcon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining) {
|
|
if (IBindable.isActive(stack)) {
|
|
return this.activeIcon;
|
|
} else {
|
|
return this.passiveIcon;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
|
|
if (checkRightClick(par1ItemStack, par2World, par3EntityPlayer)) {
|
|
return par1ItemStack;
|
|
}
|
|
Vec3 blockVec = SpellHelper.getEntityBlockVector(par3EntityPlayer);
|
|
int posX = (int) (blockVec.xCoord);
|
|
int posY = (int) (blockVec.yCoord);
|
|
int posZ = (int) (blockVec.zCoord);
|
|
boolean silkTouch = EnchantmentHelper.getSilkTouchModifier(par3EntityPlayer);
|
|
int fortuneLvl = EnchantmentHelper.getFortuneModifier(par3EntityPlayer);
|
|
|
|
HashMultiset<ItemType> dropMultiset = HashMultiset.create();
|
|
|
|
for (int i = -5; i <= 5; i++) {
|
|
for (int j = -5; j <= 5; j++) {
|
|
for (int k = -5; k <= 5; k++) {
|
|
Block block = par2World.getBlock(posX + i, posY + j, posZ + k);
|
|
int meta = par2World.getBlockMetadata(posX + i, posY + j, posZ + k);
|
|
|
|
if (block != null && block.getBlockHardness(par2World, posX + i, posY + j, posZ + k) != -1) {
|
|
float str = func_150893_a(par1ItemStack, block);
|
|
|
|
if (str > 1.1f && par2World.canMineBlock(par3EntityPlayer, posX + i, posY + j, posZ + k)) {
|
|
if (silkTouch && block
|
|
.canSilkHarvest(par2World, par3EntityPlayer, posX + i, posY + j, posZ + k, meta)) {
|
|
dropMultiset.add(new ItemType(block, meta));
|
|
} else {
|
|
ArrayList<ItemStack> itemDropList;
|
|
if (AlchemicalWizardry.isGregTechLoaded && block instanceof GTBlockOre) {
|
|
itemDropList = ((GTBlockOre) block).getDropsForPlayer(
|
|
par2World,
|
|
posX + i,
|
|
posY + j,
|
|
posZ + k,
|
|
meta,
|
|
fortuneLvl,
|
|
par3EntityPlayer);
|
|
} else {
|
|
itemDropList = block
|
|
.getDrops(par2World, posX + i, posY + j, posZ + k, meta, fortuneLvl);
|
|
}
|
|
|
|
if (itemDropList != null) {
|
|
for (ItemStack stack : itemDropList)
|
|
dropMultiset.add(ItemType.fromStack(stack), stack.stackSize);
|
|
}
|
|
}
|
|
|
|
par2World.setBlockToAir(posX + i, posY + j, posZ + k);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
dropMultisetStacks(dropMultiset, par2World, posX, posY + par3EntityPlayer.getEyeHeight(), posZ);
|
|
|
|
return par1ItemStack;
|
|
}
|
|
|
|
public static void dropMultisetStacks(Multiset<ItemType> dropMultiset, World world, double x, double y, double z) {
|
|
for (Multiset.Entry<ItemType> entry : dropMultiset.entrySet()) {
|
|
int count = entry.getCount();
|
|
ItemType type = entry.getElement();
|
|
int maxStackSize = type.item.getItemStackLimit(type.createStack(1));
|
|
|
|
// Drop in groups of maximum size
|
|
while (count >= maxStackSize) {
|
|
world.spawnEntityInWorld(new EntityItem(world, x, y, z, type.createStack(maxStackSize)));
|
|
count -= maxStackSize;
|
|
}
|
|
// Drop remainder
|
|
if (count > 0) world.spawnEntityInWorld(new EntityItem(world, x, y, z, type.createStack(count)));
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5) {
|
|
if (!(par3Entity instanceof EntityPlayer)) {
|
|
return;
|
|
}
|
|
|
|
EntityPlayer par3EntityPlayer = (EntityPlayer) par3Entity;
|
|
|
|
if (par1ItemStack.getTagCompound() == null) {
|
|
par1ItemStack.setTagCompound(new NBTTagCompound());
|
|
}
|
|
|
|
checkPassiveDrain(par1ItemStack, par2World, par3EntityPlayer);
|
|
|
|
par1ItemStack.setItemDamage(0);
|
|
}
|
|
|
|
/**
|
|
* Returns the strength of the stack against a given block. 1.0F base, (Quality+1)*2 if correct blocktype, 1.5F if
|
|
* sword
|
|
*/
|
|
@Override
|
|
public float func_150893_a(ItemStack par1ItemStack, Block par2Block) // getStrVsBlock
|
|
{
|
|
if (!IBindable.isActive(par1ItemStack)) {
|
|
return 0.0F;
|
|
}
|
|
|
|
return super.func_150893_a(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.
|
|
*/
|
|
@Override
|
|
public boolean hitEntity(ItemStack par1ItemStack, EntityLivingBase par2EntityLivingBase,
|
|
EntityLivingBase par3EntityLivingBase) {
|
|
return IBindable.isActive(par1ItemStack);
|
|
}
|
|
|
|
@Override
|
|
public boolean onBlockDestroyed(ItemStack par1ItemStack, World par2World, Block par3, int par4, int par5, int par6,
|
|
EntityLivingBase par7EntityLivingBase) {
|
|
|
|
if (par7EntityLivingBase instanceof EntityPlayer) {
|
|
EnergyItems.syphonBatteries(par1ItemStack, (EntityPlayer) par7EntityLivingBase, drainCost());
|
|
}
|
|
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.
|
|
*/
|
|
@Override
|
|
public int getItemEnchantability() {
|
|
return 30;
|
|
}
|
|
|
|
/**
|
|
* FORGE: Overridden to allow custom tool effectiveness
|
|
*/
|
|
@Override
|
|
public float getDigSpeed(ItemStack stack, Block block, int meta) {
|
|
if (!IBindable.isActive(stack)) {
|
|
return 0.0F;
|
|
}
|
|
|
|
if (ForgeHooks.isToolEffective(stack, block, meta)) {
|
|
return efficiencyOnProperMaterial;
|
|
}
|
|
|
|
return func_150893_a(stack, block);
|
|
}
|
|
|
|
@Override
|
|
public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) {
|
|
return !IBindable.isActive(stack);
|
|
}
|
|
|
|
@Override
|
|
public int getHarvestLevel(ItemStack stack, String toolClass) {
|
|
return IBindable.isActive(stack) ? super.getHarvestLevel(stack, toolClass) : -1;
|
|
}
|
|
|
|
@Override
|
|
public boolean isBoundTool() {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public int rightClickCost() {
|
|
return rightClickCost;
|
|
}
|
|
}
|