BloodMagic/src/main/java/WayofTime/bloodmagic/api/util/helper/PlayerSacrificeHelper.java

121 lines
3.4 KiB
Java
Raw Normal View History

2015-11-07 16:51:41 +00:00
package WayofTime.bloodmagic.api.util.helper;
import WayofTime.bloodmagic.api.altar.IBloodAltar;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
public class PlayerSacrificeHelper
{
2015-11-07 16:51:41 +00:00
public static float scalingOfSacrifice = 0.001f;
public static int soulFrayDuration = 400;
public static Potion soulFrayId;
public static float getPlayerIncense(EntityPlayer player)
{
2015-11-07 16:51:41 +00:00
return IncenseHelper.getCurrentIncense(player);
}
public static void setPlayerIncense(EntityPlayer player, float amount)
{
2015-11-07 16:51:41 +00:00
IncenseHelper.setCurrentIncense(player, amount);
}
public static boolean incrementIncense(EntityPlayer player, float min, float max, float increment)
{
2015-11-07 16:51:41 +00:00
float amount = getPlayerIncense(player);
if (amount < min || amount >= max)
{
2015-11-07 16:51:41 +00:00
return false;
}
amount = amount + Math.min(increment, max - amount);
setPlayerIncense(player, amount);
// System.out.println("Amount of incense: " + amount + ", Increment: " +
// increment);
2015-11-07 16:51:41 +00:00
return true;
}
public static boolean sacrificePlayerHealth(EntityPlayer player)
{
if (player.isPotionActive(soulFrayId))
{
2015-11-07 16:51:41 +00:00
return false;
}
float amount = getPlayerIncense(player);
if (amount >= 0)
{
2015-11-07 16:51:41 +00:00
float health = player.getHealth();
float maxHealth = player.getMaxHealth();
if (health > maxHealth / 10.0)
{
2015-11-07 16:51:41 +00:00
float sacrificedHealth = health - maxHealth / 10.0f;
if (findAndFillAltar(player.getEntityWorld(), player, (int) (sacrificedHealth * 100f * getModifier(amount))))
{
2015-11-07 16:51:41 +00:00
player.setHealth(maxHealth / 10.0f);
setPlayerIncense(player, 0);
player.addPotionEffect(new PotionEffect(soulFrayId.id, soulFrayDuration));
return true;
}
}
}
return false;
}
public static float getModifier(float amount)
{
2015-11-07 16:51:41 +00:00
return 1 + amount * scalingOfSacrifice;
}
public static boolean findAndFillAltar(World world, EntityPlayer player, int amount)
{
2015-11-07 16:51:41 +00:00
int posX = (int) Math.round(player.posX - 0.5f);
int posY = (int) player.posY;
int posZ = (int) Math.round(player.posZ - 0.5f);
IBloodAltar altarEntity = getAltar(world, new BlockPos(posX, posY, posZ));
if (altarEntity == null)
{
2015-11-07 16:51:41 +00:00
return false;
}
altarEntity.sacrificialDaggerCall(amount, false);
altarEntity.startCycle();
return true;
}
public static IBloodAltar getAltar(World world, BlockPos blockPos)
{
2015-11-07 16:51:41 +00:00
TileEntity tileEntity;
for (int i = -2; i <= 2; i++)
{
for (int j = -2; j <= 2; j++)
{
for (int k = -2; k <= 1; k++)
{
2015-11-07 16:51:41 +00:00
tileEntity = world.getTileEntity(new BlockPos(i + blockPos.getX(), k + blockPos.getY(), j + blockPos.getZ()));
if (tileEntity instanceof IBloodAltar)
{
2015-11-07 16:51:41 +00:00
return (IBloodAltar) tileEntity;
}
}
}
}
return null;
}
}