2015-12-28 19:09:51 -05:00
|
|
|
package WayofTime.bloodmagic.item;
|
|
|
|
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
import net.minecraft.entity.boss.IBossDisplayData;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.BlockPos;
|
|
|
|
import net.minecraft.world.World;
|
2016-02-25 08:54:18 -05:00
|
|
|
import WayofTime.bloodmagic.BloodMagic;
|
|
|
|
import WayofTime.bloodmagic.ConfigHandler;
|
|
|
|
import WayofTime.bloodmagic.api.BloodMagicAPI;
|
|
|
|
import WayofTime.bloodmagic.api.Constants;
|
|
|
|
import WayofTime.bloodmagic.api.DamageSourceBloodMagic;
|
|
|
|
import WayofTime.bloodmagic.api.altar.IBloodAltar;
|
2015-12-28 19:09:51 -05:00
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public class ItemDaggerOfSacrifice extends Item
|
|
|
|
{
|
|
|
|
public ItemDaggerOfSacrifice()
|
|
|
|
{
|
2015-12-28 19:09:51 -05:00
|
|
|
super();
|
|
|
|
setUnlocalizedName(Constants.Mod.MODID + ".daggerOfSacrifice");
|
2016-01-18 22:34:12 -08:00
|
|
|
setRegistryName(Constants.BloodMagicItem.DAGGER_OF_SACRIFICE.getRegName());
|
2015-12-28 19:09:51 -05:00
|
|
|
setCreativeTab(BloodMagic.tabBloodMagic);
|
|
|
|
setMaxStackSize(1);
|
|
|
|
setFull3D();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-12-30 15:34:40 -05:00
|
|
|
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker)
|
|
|
|
{
|
2015-12-28 19:09:51 -05:00
|
|
|
if (target == null || attacker == null || attacker.worldObj.isRemote || (attacker instanceof EntityPlayer && !(attacker instanceof EntityPlayerMP)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (target.isChild() || target instanceof EntityPlayer || target instanceof IBossDisplayData)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (target.isDead || target.getHealth() < 0.5F)
|
|
|
|
return false;
|
|
|
|
|
2016-01-19 19:46:49 -08:00
|
|
|
String entityName = target.getClass().getSimpleName();
|
2015-12-28 19:09:51 -05:00
|
|
|
int lifeEssence = 500;
|
2016-01-19 19:46:49 -08:00
|
|
|
|
|
|
|
if (ConfigHandler.entitySacrificeValues.containsKey(entityName))
|
|
|
|
lifeEssence = ConfigHandler.entitySacrificeValues.get(entityName);
|
|
|
|
|
|
|
|
if (BloodMagicAPI.getEntitySacrificeValues().containsKey(entityName))
|
|
|
|
lifeEssence = BloodMagicAPI.getEntitySacrificeValues().get(entityName);
|
2015-12-30 15:34:40 -05:00
|
|
|
|
|
|
|
if (findAndFillAltar(attacker.worldObj, target, lifeEssence))
|
|
|
|
{
|
2015-12-28 19:09:51 -05:00
|
|
|
double posX = target.posX;
|
|
|
|
double posY = target.posY;
|
|
|
|
double posZ = target.posZ;
|
|
|
|
target.worldObj.playSoundEffect((double) ((float) posX + 0.5F), (double) ((float) posY + 0.5F), (double) ((float) posZ + 0.5F), "random.fizz", 0.5F, 2.6F + (target.worldObj.rand.nextFloat() - target.worldObj.rand.nextFloat()) * 0.8F);
|
|
|
|
target.setHealth(-1);
|
|
|
|
target.onDeath(new DamageSourceBloodMagic());
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public boolean findAndFillAltar(World world, EntityLivingBase sacrifice, int amount)
|
|
|
|
{
|
2015-12-28 19:09:51 -05:00
|
|
|
IBloodAltar bloodAltar = findBloodAltar(world, sacrifice.getPosition());
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
if (bloodAltar != null)
|
|
|
|
{
|
2015-12-28 19:09:51 -05:00
|
|
|
bloodAltar.sacrificialDaggerCall(amount, true);
|
|
|
|
bloodAltar.startCycle();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public IBloodAltar findBloodAltar(World world, BlockPos blockPos)
|
|
|
|
{
|
2015-12-28 19:09:51 -05:00
|
|
|
TileEntity tileEntity;
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
for (int i = -2; i <= 2; i++)
|
|
|
|
{
|
|
|
|
for (int j = -2; j <= 2; j++)
|
|
|
|
{
|
|
|
|
for (int k = -2; k <= 1; k++)
|
|
|
|
{
|
2015-12-28 19:09:51 -05:00
|
|
|
tileEntity = world.getTileEntity(blockPos.add(i, k, j));
|
|
|
|
|
|
|
|
if ((tileEntity instanceof IBloodAltar))
|
|
|
|
return (IBloodAltar) tileEntity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|