2016-01-07 16:01:38 +00:00
|
|
|
package WayofTime.bloodmagic.item.soul;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
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.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.EnumAction;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.item.ItemSword;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
|
|
import WayofTime.bloodmagic.BloodMagic;
|
|
|
|
import WayofTime.bloodmagic.api.Constants;
|
2016-01-07 17:59:46 +00:00
|
|
|
import WayofTime.bloodmagic.api.soul.ISoul;
|
|
|
|
import WayofTime.bloodmagic.api.soul.ISoulWeapon;
|
2016-01-07 21:36:52 +00:00
|
|
|
import WayofTime.bloodmagic.api.soul.PlayerSoulHandler;
|
2016-01-07 16:01:38 +00:00
|
|
|
import WayofTime.bloodmagic.api.util.helper.NBTHelper;
|
|
|
|
import WayofTime.bloodmagic.registry.ModItems;
|
|
|
|
import WayofTime.bloodmagic.util.helper.TextHelper;
|
|
|
|
|
|
|
|
import com.google.common.collect.HashMultimap;
|
|
|
|
import com.google.common.collect.Multimap;
|
|
|
|
|
|
|
|
public class ItemSoulSword extends ItemSword implements ISoulWeapon
|
|
|
|
{
|
2016-01-07 21:36:52 +00:00
|
|
|
public int[] soulBracket = new int[] { 16 };
|
|
|
|
public double[] damageAdded = new double[] { 1 };
|
|
|
|
public double[] soulDrainPerSwing = new double[] { 0.1 };
|
|
|
|
|
2016-01-07 16:01:38 +00:00
|
|
|
public ItemSoulSword()
|
|
|
|
{
|
|
|
|
super(ModItems.soulToolMaterial);
|
|
|
|
|
|
|
|
setUnlocalizedName(Constants.Mod.MODID + ".soul.sword");
|
|
|
|
setHasSubtypes(true);
|
|
|
|
setNoRepair();
|
|
|
|
setCreativeTab(BloodMagic.tabBloodMagic);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
|
|
|
{
|
|
|
|
if (player.isSneaking()) //TODO: change its state depending on soul consumption
|
|
|
|
setActivated(stack, !getActivated(stack));
|
|
|
|
|
|
|
|
if (getActivated(stack))
|
|
|
|
{
|
2016-01-07 21:36:52 +00:00
|
|
|
double soulsRemaining = PlayerSoulHandler.getTotalSouls(player);
|
|
|
|
int level = getLevel(stack, soulsRemaining);
|
|
|
|
|
|
|
|
double drain = level >= 0 ? soulDrainPerSwing[level] : 0;
|
|
|
|
double extraDamage = level >= 0 ? damageAdded[level] : 0;
|
|
|
|
|
|
|
|
setDrainOfActivatedSword(stack, drain);
|
|
|
|
setDamageOfActivatedSword(stack, 7 + extraDamage);
|
2016-01-07 16:01:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
2016-01-07 21:36:52 +00:00
|
|
|
private int getLevel(ItemStack stack, double soulsRemaining)
|
|
|
|
{
|
|
|
|
int lvl = -1;
|
|
|
|
for (int i = 0; i < soulBracket.length; i++)
|
|
|
|
{
|
|
|
|
if (soulsRemaining >= soulBracket[i])
|
|
|
|
{
|
|
|
|
lvl = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return lvl;
|
|
|
|
}
|
|
|
|
|
2016-01-07 16:01:38 +00:00
|
|
|
@Override
|
|
|
|
public EnumAction getItemUseAction(ItemStack stack)
|
|
|
|
{
|
|
|
|
return EnumAction.BLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced)
|
|
|
|
{
|
|
|
|
NBTHelper.checkNBT(stack);
|
|
|
|
|
|
|
|
tooltip.add(TextHelper.localizeEffect("tooltip.BloodMagic.soul.sword.desc"));
|
|
|
|
|
|
|
|
if (getActivated(stack))
|
|
|
|
tooltip.add(TextHelper.localize("tooltip.BloodMagic.activated"));
|
|
|
|
else
|
|
|
|
tooltip.add(TextHelper.localize("tooltip.BloodMagic.deactivated"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity)
|
|
|
|
{
|
|
|
|
if (getActivated(stack))
|
|
|
|
{
|
2016-01-07 21:36:52 +00:00
|
|
|
double drain = this.getDrainOfActivatedSword(stack);
|
|
|
|
if (drain > 0)
|
|
|
|
{
|
|
|
|
double soulsRemaining = PlayerSoulHandler.getTotalSouls(player);
|
|
|
|
|
|
|
|
if (drain > soulsRemaining)
|
|
|
|
{
|
|
|
|
setActivated(stack, false);
|
|
|
|
return false;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
PlayerSoulHandler.consumeSouls(player, drain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-07 16:01:38 +00:00
|
|
|
return super.onLeftClickEntity(stack, player, entity);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean getActivated(ItemStack stack)
|
|
|
|
{
|
|
|
|
return stack.getItemDamage() > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private ItemStack setActivated(ItemStack stack, boolean activated)
|
|
|
|
{
|
|
|
|
stack.setItemDamage(activated ? 1 : 0);
|
|
|
|
|
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<ItemStack> getRandomSoulDrop(EntityLivingBase killedEntity, EntityLivingBase attackingEntity, ItemStack stack, int looting)
|
|
|
|
{
|
|
|
|
List<ItemStack> soulList = new ArrayList<ItemStack>();
|
|
|
|
|
|
|
|
if (getActivated(stack))
|
|
|
|
{
|
|
|
|
ISoul soul = ((ISoul) ModItems.monsterSoul);
|
|
|
|
ItemStack soulStack = soul.createSoul(0, looting * 0.5 + 1);
|
|
|
|
soulList.add(soulStack);
|
|
|
|
}
|
|
|
|
|
|
|
|
return soulList;
|
|
|
|
}
|
|
|
|
|
|
|
|
public double getDamageOfActivatedSword(ItemStack stack)
|
|
|
|
{
|
|
|
|
NBTHelper.checkNBT(stack);
|
|
|
|
|
|
|
|
NBTTagCompound tag = stack.getTagCompound();
|
|
|
|
return tag.getDouble(Constants.NBT.SOUL_SWORD_DAMAGE);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDamageOfActivatedSword(ItemStack stack, double damage)
|
|
|
|
{
|
|
|
|
NBTHelper.checkNBT(stack);
|
|
|
|
|
|
|
|
NBTTagCompound tag = stack.getTagCompound();
|
|
|
|
|
|
|
|
tag.setDouble(Constants.NBT.SOUL_SWORD_DAMAGE, damage);
|
|
|
|
}
|
|
|
|
|
2016-01-07 21:36:52 +00:00
|
|
|
public double getDrainOfActivatedSword(ItemStack stack)
|
|
|
|
{
|
|
|
|
NBTHelper.checkNBT(stack);
|
|
|
|
|
|
|
|
NBTTagCompound tag = stack.getTagCompound();
|
|
|
|
return tag.getDouble(Constants.NBT.SOUL_SWORD_ACTIVE_DRAIN);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDrainOfActivatedSword(ItemStack stack, double drain)
|
|
|
|
{
|
|
|
|
NBTHelper.checkNBT(stack);
|
|
|
|
|
|
|
|
NBTTagCompound tag = stack.getTagCompound();
|
|
|
|
|
|
|
|
tag.setDouble(Constants.NBT.SOUL_SWORD_ACTIVE_DRAIN, drain);
|
|
|
|
}
|
|
|
|
|
2016-01-07 16:01:38 +00:00
|
|
|
@Override
|
|
|
|
public Multimap<String, AttributeModifier> getAttributeModifiers(ItemStack stack)
|
|
|
|
{
|
|
|
|
Multimap<String, AttributeModifier> multimap = HashMultimap.<String, AttributeModifier>create();
|
|
|
|
multimap.put(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName(), new AttributeModifier(itemModifierUUID, "Weapon modifier", getActivated(stack) ? getDamageOfActivatedSword(stack) : 2, 0));
|
|
|
|
return multimap;
|
|
|
|
}
|
|
|
|
}
|