use of WayofTime.bloodmagic.event.SacrificeKnifeUsedEvent in project BloodMagic by WayofTime.
the class PlayerSacrificeHelper method sacrificePlayerHealth.
/**
* Sacrifices a player's health while the player is under the influence of
* incense
*
* @param player - The player sacrificing
* @return Whether or not the health sacrificing succeeded
*/
public static boolean sacrificePlayerHealth(EntityPlayer player) {
if (player.isPotionActive(soulFrayId)) {
return false;
}
double amount = getPlayerIncense(player);
if (amount >= 0) {
float health = player.getHealth();
float maxHealth = player.getMaxHealth();
if (health > maxHealth / 10.0) {
float sacrificedHealth = health - maxHealth / 10.0f;
int lpAdded = (int) (sacrificedHealth * ConfigHandler.values.sacrificialDaggerConversion * getModifier(amount));
SacrificeKnifeUsedEvent evt = new SacrificeKnifeUsedEvent(player, true, true, (int) sacrificedHealth, lpAdded);
if (MinecraftForge.EVENT_BUS.post(evt))
return false;
if (findAndFillAltar(player.getEntityWorld(), player, evt.lpAdded, false)) {
player.setHealth(maxHealth / 10.0f);
setPlayerIncense(player, 0);
player.addPotionEffect(new PotionEffect(RegistrarBloodMagic.SOUL_FRAY, soulFrayDuration));
return true;
}
}
}
return false;
}
use of WayofTime.bloodmagic.event.SacrificeKnifeUsedEvent in project BloodMagic by WayofTime.
the class ItemSacrificialDagger method onItemRightClick.
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
ItemStack stack = player.getHeldItem(hand);
if (PlayerHelper.isFakePlayer(player))
return super.onItemRightClick(world, player, hand);
if (this.canUseForSacrifice(stack)) {
player.setActiveHand(hand);
return new ActionResult<>(EnumActionResult.SUCCESS, stack);
}
int lpAdded = ConfigHandler.values.sacrificialDaggerConversion * 2;
RayTraceResult rayTrace = rayTrace(world, player, false);
if (rayTrace != null && rayTrace.typeOfHit == RayTraceResult.Type.BLOCK) {
TileEntity tile = world.getTileEntity(rayTrace.getBlockPos());
if (tile != null && tile instanceof TileAltar && stack.getItemDamage() == 1)
lpAdded = ((TileAltar) tile).getCapacity();
}
if (!player.capabilities.isCreativeMode) {
SacrificeKnifeUsedEvent evt = new SacrificeKnifeUsedEvent(player, true, true, 2, lpAdded);
if (MinecraftForge.EVENT_BUS.post(evt))
return super.onItemRightClick(world, player, hand);
if (evt.shouldDrainHealth) {
player.hurtResistantTime = 0;
player.attackEntityFrom(DamageSourceBloodMagic.INSTANCE, 0.001F);
player.setHealth(Math.max(player.getHealth() - 2, 0.0001f));
if (player.getHealth() <= 0.001f) {
player.onDeath(DamageSourceBloodMagic.INSTANCE);
player.setHealth(0);
}
// player.attackEntityFrom(BloodMagicAPI.getDamageSource(), 2.0F);
}
if (!evt.shouldFillAltar)
return super.onItemRightClick(world, player, hand);
lpAdded = evt.lpAdded;
}
double posX = player.posX;
double posY = player.posY;
double posZ = player.posZ;
world.playSound(null, posX, posY, posZ, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.8F);
for (int l = 0; l < 8; ++l) world.spawnParticle(EnumParticleTypes.REDSTONE, posX + Math.random() - Math.random(), posY + Math.random() - Math.random(), posZ + Math.random() - Math.random(), 0, 0, 0);
if (!world.isRemote && PlayerHelper.isFakePlayer(player))
return super.onItemRightClick(world, player, hand);
// TODO - Check if SoulFray is active
PlayerSacrificeHelper.findAndFillAltar(world, player, lpAdded, false);
return super.onItemRightClick(world, player, hand);
}
Aggregations