
I redone where the items/blocsks are stored and how the configs are handled to clean up it and give space. You can change the config line to AWWayofTime if you want to keep the compatibility with old configs. Now you reference the blocks from the ModBlocks and Items from the ModItems.
379 lines
12 KiB
Java
379 lines
12 KiB
Java
package WayofTime.alchemicalWizardry.common.items;
|
|
|
|
import WayofTime.alchemicalWizardry.common.AlchemicalWizardry;
|
|
import WayofTime.alchemicalWizardry.common.IBindable;
|
|
import com.google.common.collect.Multimap;
|
|
import cpw.mods.fml.relauncher.Side;
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.client.renderer.texture.IconRegister;
|
|
import net.minecraft.enchantment.Enchantment;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
import net.minecraft.entity.SharedMonsterAttributes;
|
|
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
|
import net.minecraft.entity.item.EntityItem;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.item.ItemSpade;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
import net.minecraft.nbt.NBTTagList;
|
|
import net.minecraft.util.Icon;
|
|
import net.minecraft.world.World;
|
|
import net.minecraftforge.common.ForgeHooks;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class BoundShovel extends ItemSpade implements IBindable {
|
|
/**
|
|
* Array of blocks the tool has extra effect against.
|
|
*/
|
|
public static final Block[] blocksEffectiveAgainst = new Block[]{Block.grass, Block.dirt, Block.sand, Block.gravel, Block.snow, Block.blockSnow, Block.blockClay, Block.tilledField, Block.slowSand, Block.mycelium};
|
|
|
|
public float efficiencyOnProperMaterial = 12.0F;
|
|
|
|
/**
|
|
* Damage versus entities.
|
|
*/
|
|
public float damageVsEntity;
|
|
|
|
private static Icon activeIcon;
|
|
private static Icon passiveIcon;
|
|
|
|
private int energyUsed;
|
|
|
|
public BoundShovel(int id)
|
|
{
|
|
super(id, AlchemicalWizardry.bloodBoundToolMaterial);
|
|
this.maxStackSize = 1;
|
|
//this.setMaxDamage(par3EnumToolMaterial.getMaxUses());
|
|
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("No, not that type of spade.");
|
|
|
|
if (!(par1ItemStack.stackTagCompound == null))
|
|
{
|
|
if (par1ItemStack.stackTagCompound.getBoolean("isActive"))
|
|
{
|
|
par3List.add("Activated");
|
|
} else
|
|
{
|
|
par3List.add("Deactivated");
|
|
}
|
|
|
|
if (!par1ItemStack.stackTagCompound.getString("ownerName").equals(""))
|
|
{
|
|
par3List.add("Current owner: " + par1ItemStack.stackTagCompound.getString("ownerName"));
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
@SideOnly(Side.CLIENT)
|
|
public void registerIcons(IconRegister iconRegister)
|
|
{
|
|
this.itemIcon = iconRegister.registerIcon("AlchemicalWizardry:BoundShovel_activated");
|
|
this.activeIcon = iconRegister.registerIcon("AlchemicalWizardry:BoundShovel_activated");
|
|
this.passiveIcon = iconRegister.registerIcon("AlchemicalWizardry:SheathedItem");
|
|
}
|
|
|
|
@Override
|
|
public Icon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining)
|
|
{
|
|
if (stack.stackTagCompound == null)
|
|
{
|
|
stack.setTagCompound(new NBTTagCompound());
|
|
}
|
|
|
|
NBTTagCompound tag = stack.stackTagCompound;
|
|
|
|
if (tag.getBoolean("isActive"))
|
|
{
|
|
return this.activeIcon;
|
|
} else
|
|
{
|
|
return this.passiveIcon;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
|
|
{
|
|
EnergyItems.checkAndSetItemOwner(par1ItemStack, par3EntityPlayer);
|
|
|
|
if (par3EntityPlayer.isSneaking())
|
|
{
|
|
this.setActivated(par1ItemStack, !getActivated(par1ItemStack));
|
|
par1ItemStack.stackTagCompound.setInteger("worldTimeDelay", (int) (par2World.getWorldTime() - 1) % 200);
|
|
return par1ItemStack;
|
|
}
|
|
|
|
if (!getActivated(par1ItemStack))
|
|
{
|
|
return par1ItemStack;
|
|
}
|
|
|
|
if (par3EntityPlayer.isPotionActive(AlchemicalWizardry.customPotionInhibit))
|
|
{
|
|
return par1ItemStack;
|
|
}
|
|
|
|
int posX = (int) par3EntityPlayer.posX;
|
|
int posY = (int) par3EntityPlayer.posY;
|
|
int posZ = (int) par3EntityPlayer.posZ;
|
|
boolean silkTouch = false;
|
|
int so = Enchantment.silkTouch.effectId;
|
|
int fortune = Enchantment.fortune.effectId;
|
|
int fortuneLvl = 0;
|
|
NBTTagList enchants = par1ItemStack.getEnchantmentTagList();
|
|
|
|
if (enchants != null)
|
|
{
|
|
for (int i = 0; i < enchants.tagCount(); i++)
|
|
{
|
|
if (enchants.tagAt(i) instanceof NBTTagCompound)
|
|
{
|
|
NBTTagCompound nbt = (NBTTagCompound) enchants.tagAt(i);
|
|
int id = nbt.getShort("id");
|
|
|
|
if (id == so)
|
|
{
|
|
silkTouch = true;
|
|
}
|
|
|
|
if (id == fortune)
|
|
{
|
|
fortuneLvl = nbt.getShort("lvl");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
for (int i = -5; i <= 5; i++)
|
|
{
|
|
for (int j = 0; j <= 10; j++)
|
|
{
|
|
for (int k = -5; k <= 5; k++)
|
|
{
|
|
Block block = Block.blocksList[par2World.getBlockId(posX + i, posY + j, posZ + k)];
|
|
int meta = par2World.getBlockMetadata(posX + i, posY + j, posZ + k);
|
|
|
|
if (block != null)
|
|
{
|
|
float str = getStrVsBlock(par1ItemStack, block);
|
|
|
|
if (str > 1.1f && par2World.canMineBlock(par3EntityPlayer, posX + i, posY + j, posZ + k))
|
|
{
|
|
//par1ItemStack.getEnchantmentTagList();
|
|
if (silkTouch)
|
|
{
|
|
ItemStack droppedItem = new ItemStack(block, 1, meta);
|
|
|
|
if (!par2World.isRemote)
|
|
{
|
|
par2World.spawnEntityInWorld(new EntityItem(par2World, posX, posY + par3EntityPlayer.getEyeHeight(), posZ, droppedItem));
|
|
}
|
|
} else
|
|
{
|
|
ArrayList<ItemStack> itemDropList = block.getBlockDropped(par2World, posX + i, posY + j, posZ + k, meta, fortuneLvl);
|
|
|
|
if (itemDropList != null)
|
|
{
|
|
for (ItemStack item : itemDropList)
|
|
{
|
|
if (!par2World.isRemote)
|
|
{
|
|
par2World.spawnEntityInWorld(new EntityItem(par2World, posX, posY + par3EntityPlayer.getEyeHeight(), posZ, item));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
par2World.setBlockToAir(posX + i, posY + j, posZ + k);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
EnergyItems.syphonBatteries(par1ItemStack, par3EntityPlayer, 10000);
|
|
return par1ItemStack;
|
|
}
|
|
|
|
@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.stackTagCompound == null)
|
|
{
|
|
par1ItemStack.setTagCompound(new NBTTagCompound());
|
|
}
|
|
|
|
// if(par1ItemStack.stackTagCompound.getBoolean("isActive"))
|
|
// {
|
|
// EnergyItems.syphonBatteries(par1ItemStack, par3EntityPlayer, 1);
|
|
// }
|
|
|
|
if (par2World.getWorldTime() % 200 == par1ItemStack.stackTagCompound.getInteger("worldTimeDelay") && par1ItemStack.stackTagCompound.getBoolean("isActive"))
|
|
{
|
|
if (!par3EntityPlayer.capabilities.isCreativeMode)
|
|
{
|
|
EnergyItems.syphonBatteries(par1ItemStack, par3EntityPlayer, 20);
|
|
}
|
|
}
|
|
|
|
par1ItemStack.setItemDamage(0);
|
|
return;
|
|
}
|
|
|
|
public void setActivated(ItemStack par1ItemStack, boolean newActivated)
|
|
{
|
|
NBTTagCompound itemTag = par1ItemStack.stackTagCompound;
|
|
|
|
if (itemTag == null)
|
|
{
|
|
par1ItemStack.setTagCompound(new NBTTagCompound());
|
|
}
|
|
|
|
itemTag.setBoolean("isActive", newActivated);
|
|
}
|
|
|
|
public boolean getActivated(ItemStack par1ItemStack)
|
|
{
|
|
NBTTagCompound itemTag = par1ItemStack.stackTagCompound;
|
|
|
|
if (itemTag == null)
|
|
{
|
|
par1ItemStack.setTagCompound(new NBTTagCompound());
|
|
}
|
|
|
|
return itemTag.getBoolean("isActive");
|
|
}
|
|
|
|
/**
|
|
* Returns the strength of the stack against a given block. 1.0F base, (Quality+1)*2 if correct blocktype, 1.5F if
|
|
* sword
|
|
*/
|
|
public float getStrVsBlock(ItemStack par1ItemStack, Block par2Block)
|
|
{
|
|
if (!getActivated(par1ItemStack))
|
|
{
|
|
return 0.0F;
|
|
}
|
|
|
|
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)
|
|
{
|
|
if (!getActivated(par1ItemStack))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
//par1ItemStack.damageItem(2, par3EntityLivingBase);
|
|
return true;
|
|
}
|
|
|
|
public boolean onBlockDestroyed(ItemStack par1ItemStack, World par2World, int par3, int par4, int par5, int par6, EntityLivingBase par7EntityLivingBase)
|
|
{
|
|
if ((double) Block.blocksList[par3].getBlockHardness(par2World, par4, par5, par6) != 0.0D)
|
|
{
|
|
//par1ItemStack.damageItem(1, 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;
|
|
}
|
|
|
|
/**
|
|
* Return whether this item is repairable in an anvil.
|
|
*/
|
|
// public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack)
|
|
// {
|
|
// return false;
|
|
// }
|
|
@Override
|
|
public Multimap getItemAttributeModifiers()
|
|
{
|
|
Multimap multimap = super.getItemAttributeModifiers();
|
|
multimap.put(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName(), new AttributeModifier(field_111210_e, "Tool modifier", (double) this.damageVsEntity, 0));
|
|
return multimap;
|
|
}
|
|
|
|
/**
|
|
* FORGE: Overridden to allow custom tool effectiveness
|
|
*/
|
|
@Override
|
|
public float getStrVsBlock(ItemStack stack, Block block, int meta)
|
|
{
|
|
if (!getActivated(stack))
|
|
{
|
|
return 0.0F;
|
|
}
|
|
|
|
if (ForgeHooks.isToolEffective(stack, block, meta))
|
|
{
|
|
return efficiencyOnProperMaterial;
|
|
}
|
|
|
|
return getStrVsBlock(stack, block);
|
|
}
|
|
|
|
public boolean canHarvestBlock(Block par1Block)
|
|
{
|
|
return par1Block == Block.snow ? true : par1Block == Block.blockSnow;
|
|
}
|
|
|
|
@Override
|
|
public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity)
|
|
{
|
|
return !getActivated(stack);
|
|
}
|
|
}
|