BloodMagic/src/main/java/WayofTime/bloodmagic/item/ItemDaggerOfSacrifice.java

87 lines
3.3 KiB
Java
Raw Normal View History

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.apibutnotreally.util.helper.PlayerSacrificeHelper;
import WayofTime.bloodmagic.apibutnotreally.util.helper.PurificationHelper;
import WayofTime.bloodmagic.api.impl.BloodMagicAPI;
2017-08-15 21:30:48 -07:00
import WayofTime.bloodmagic.client.IVariantProvider;
import com.google.common.collect.Lists;
2015-12-28 19:09:51 -05:00
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.IMob;
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;
import net.minecraftforge.common.util.FakePlayer;
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();
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) {
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;
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;
EntityEntry entityEntry = EntityRegistry.getEntry(target.getClass());
if (entityEntry == null)
return false;
int lifeEssenceRatio = BloodMagicAPI.INSTANCE.getSacrificialValues().getOrDefault(entityEntry.getRegistryName(), 25);
if (lifeEssenceRatio <= 0)
return false;
int lifeEssence = (int) (lifeEssenceRatio * target.getHealth());
2017-08-15 21:30:48 -07:00
if (target instanceof EntityAnimal) {
lifeEssence = (int) (lifeEssence * (1 + PurificationHelper.getCurrentPurity((EntityAnimal) target)));
}
2017-08-15 21:30:48 -07:00
if (target.isChild()) {
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);
target.onDeath(WayofTime.bloodmagic.apibutnotreally.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() {
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
}