2015-12-28 19:09:51 -05:00
|
|
|
package WayofTime.bloodmagic.item;
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
import WayofTime.bloodmagic.BloodMagic;
|
|
|
|
import WayofTime.bloodmagic.api.util.helper.PlayerSacrificeHelper;
|
|
|
|
import WayofTime.bloodmagic.api.util.helper.PurificationHelper;
|
2017-08-15 18:14:28 -07:00
|
|
|
import WayofTime.bloodmagic.api_impl.BloodMagicAPI;
|
2017-08-15 21:30:48 -07:00
|
|
|
import WayofTime.bloodmagic.client.IVariantProvider;
|
2017-08-15 18:14:28 -07:00
|
|
|
import com.google.common.collect.Lists;
|
2015-12-28 19:09:51 -05:00
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
2017-02-25 18:00:17 -08:00
|
|
|
import net.minecraft.entity.monster.IMob;
|
2016-11-05 11:14:56 -04:00
|
|
|
import net.minecraft.entity.passive.EntityAnimal;
|
2015-12-28 19:09:51 -05:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
2016-03-18 16:50:33 -04:00
|
|
|
import net.minecraft.init.SoundEvents;
|
2015-12-28 19:09:51 -05:00
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2016-03-18 16:50:33 -04:00
|
|
|
import net.minecraft.util.SoundCategory;
|
2017-02-25 17:16:25 -08:00
|
|
|
import net.minecraftforge.common.util.FakePlayer;
|
2017-08-15 18:14:28 -07:00
|
|
|
import net.minecraftforge.fml.common.registry.EntityEntry;
|
|
|
|
import net.minecraftforge.fml.common.registry.EntityRegistry;
|
2016-03-16 01:10:33 -07:00
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
2015-12-28 19:09:51 -05:00
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
import java.util.List;
|
2016-03-16 01:10:33 -07:00
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public class ItemDaggerOfSacrifice extends Item implements IVariantProvider {
|
|
|
|
public ItemDaggerOfSacrifice() {
|
2015-12-28 19:09:51 -05:00
|
|
|
super();
|
2017-08-14 20:53:42 -07:00
|
|
|
setUnlocalizedName(BloodMagic.MODID + ".daggerOfSacrifice");
|
|
|
|
setCreativeTab(BloodMagic.TAB_BM);
|
2015-12-28 19:09:51 -05:00
|
|
|
setMaxStackSize(1);
|
|
|
|
setFull3D();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) {
|
2017-02-25 17:16:25 -08:00
|
|
|
if (attacker instanceof FakePlayer)
|
|
|
|
return false;
|
|
|
|
|
2017-01-01 22:26:42 -08:00
|
|
|
if (target == null || attacker == null || attacker.getEntityWorld().isRemote || (attacker instanceof EntityPlayer && !(attacker instanceof EntityPlayerMP)))
|
2015-12-28 19:09:51 -05:00
|
|
|
return false;
|
|
|
|
|
2016-09-29 18:44:38 -07:00
|
|
|
if (!target.isNonBoss())
|
|
|
|
return false;
|
|
|
|
|
2017-02-25 18:00:17 -08:00
|
|
|
if (target instanceof EntityPlayer)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (target.isChild() && !(target instanceof IMob))
|
2015-12-28 19:09:51 -05:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (target.isDead || target.getHealth() < 0.5F)
|
|
|
|
return false;
|
|
|
|
|
2017-08-15 18:14:28 -07:00
|
|
|
EntityEntry entityEntry = EntityRegistry.getEntry(target.getClass());
|
|
|
|
int lifeEssenceRatio = BloodMagicAPI.INSTANCE.getSacrificialValues().getOrDefault(entityEntry.getRegistryName(), 25);
|
2015-12-30 15:34:40 -05:00
|
|
|
|
2016-11-05 11:14:56 -04:00
|
|
|
if (lifeEssenceRatio <= 0)
|
2016-07-04 20:17:23 -07:00
|
|
|
return false;
|
|
|
|
|
2016-11-05 11:14:56 -04:00
|
|
|
int lifeEssence = (int) (lifeEssenceRatio * target.getHealth());
|
2017-08-15 21:30:48 -07:00
|
|
|
if (target instanceof EntityAnimal) {
|
2016-11-05 11:14:56 -04:00
|
|
|
lifeEssence = (int) (lifeEssence * (1 + PurificationHelper.getCurrentPurity((EntityAnimal) target)));
|
|
|
|
}
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
if (target.isChild()) {
|
2017-02-25 18:00:17 -08:00
|
|
|
lifeEssence *= 0.5F;
|
|
|
|
}
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
if (PlayerSacrificeHelper.findAndFillAltar(attacker.getEntityWorld(), target, lifeEssence, true)) {
|
2017-01-01 22:26:42 -08:00
|
|
|
target.getEntityWorld().playSound(null, target.posX, target.posY, target.posZ, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (target.getEntityWorld().rand.nextFloat() - target.getEntityWorld().rand.nextFloat()) * 0.8F);
|
2015-12-28 19:09:51 -05:00
|
|
|
target.setHealth(-1);
|
2017-08-15 18:14:28 -07:00
|
|
|
target.onDeath(WayofTime.bloodmagic.api.BloodMagicAPI.damageSource);
|
2015-12-28 19:09:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-16 01:10:33 -07:00
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public List<Pair<Integer, String>> getVariants() {
|
2017-08-15 18:14:28 -07:00
|
|
|
List<Pair<Integer, String>> ret = Lists.newArrayList();
|
|
|
|
ret.add(Pair.of(0, "type=normal"));
|
2016-03-16 01:10:33 -07:00
|
|
|
return ret;
|
|
|
|
}
|
2015-12-28 19:09:51 -05:00
|
|
|
}
|