BloodMagic/src/main/java/WayofTime/bloodmagic/item/ItemDaggerOfSacrifice.java
Nicholas Ignoffo 2fecb427fd Merge apibutnotreally with the main packages
Do not consider anything outside of the true API safe to use. And even then,
I'm changing things. Just wait. Please I beg you.
2018-02-15 18:49:07 -08:00

88 lines
3.3 KiB
Java

package WayofTime.bloodmagic.item;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.impl.BloodMagicAPI;
import WayofTime.bloodmagic.util.PleaseStopUsingMe;
import WayofTime.bloodmagic.util.helper.PlayerSacrificeHelper;
import WayofTime.bloodmagic.util.helper.PurificationHelper;
import WayofTime.bloodmagic.client.IVariantProvider;
import com.google.common.collect.Lists;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.IMob;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
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;
import org.apache.commons.lang3.tuple.Pair;
import java.util.List;
public class ItemDaggerOfSacrifice extends Item implements IVariantProvider {
public ItemDaggerOfSacrifice() {
super();
setUnlocalizedName(BloodMagic.MODID + ".daggerOfSacrifice");
setCreativeTab(BloodMagic.TAB_BM);
setMaxStackSize(1);
setFull3D();
}
@Override
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) {
if (attacker instanceof FakePlayer)
return false;
if (target == null || attacker == null || attacker.getEntityWorld().isRemote || (attacker instanceof EntityPlayer && !(attacker instanceof EntityPlayerMP)))
return false;
if (!target.isNonBoss())
return false;
if (target instanceof EntityPlayer)
return false;
if (target.isChild() && !(target instanceof IMob))
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.getValueManager().getSacrificial().getOrDefault(entityEntry.getRegistryName(), 25);
if (lifeEssenceRatio <= 0)
return false;
int lifeEssence = (int) (lifeEssenceRatio * target.getHealth());
if (target instanceof EntityAnimal) {
lifeEssence = (int) (lifeEssence * (1 + PurificationHelper.getCurrentPurity((EntityAnimal) target)));
}
if (target.isChild()) {
lifeEssence *= 0.5F;
}
if (PlayerSacrificeHelper.findAndFillAltar(attacker.getEntityWorld(), target, lifeEssence, true)) {
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);
target.setHealth(-1);
target.onDeath(PleaseStopUsingMe.damageSource);
}
return false;
}
@Override
public List<Pair<Integer, String>> getVariants() {
List<Pair<Integer, String>> ret = Lists.newArrayList();
ret.add(Pair.of(0, "type=normal"));
return ret;
}
}