2015-11-07 16:51:41 +00:00
|
|
|
package WayofTime.bloodmagic.api.util.helper;
|
|
|
|
|
2016-03-17 20:00:44 +00:00
|
|
|
import WayofTime.bloodmagic.api.altar.IBloodAltar;
|
|
|
|
import WayofTime.bloodmagic.registry.ModPotions;
|
2015-11-07 16:51:41 +00:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.potion.Potion;
|
|
|
|
import net.minecraft.potion.PotionEffect;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2016-03-17 20:00:44 +00:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2015-11-07 16:51:41 +00:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
public class PlayerSacrificeHelper
|
|
|
|
{
|
2016-01-27 00:39:39 +00:00
|
|
|
public static float scalingOfSacrifice = 1f;
|
2015-11-07 16:51:41 +00:00
|
|
|
public static int soulFrayDuration = 400;
|
|
|
|
public static Potion soulFrayId;
|
|
|
|
|
2016-01-27 00:39:39 +00:00
|
|
|
public static double getPlayerIncense(EntityPlayer player)
|
2015-12-30 20:34:40 +00:00
|
|
|
{
|
2015-11-07 16:51:41 +00:00
|
|
|
return IncenseHelper.getCurrentIncense(player);
|
|
|
|
}
|
|
|
|
|
2016-01-27 00:39:39 +00:00
|
|
|
public static void setPlayerIncense(EntityPlayer player, double amount)
|
2015-12-30 20:34:40 +00:00
|
|
|
{
|
2015-11-07 16:51:41 +00:00
|
|
|
IncenseHelper.setCurrentIncense(player, amount);
|
|
|
|
}
|
|
|
|
|
2016-01-27 00:39:39 +00:00
|
|
|
public static boolean incrementIncense(EntityPlayer player, double min, double incenseAddition, double increment)
|
2015-12-30 20:34:40 +00:00
|
|
|
{
|
2016-01-27 00:39:39 +00:00
|
|
|
double amount = getPlayerIncense(player);
|
|
|
|
if (amount < min || amount >= incenseAddition)
|
2015-12-30 20:34:40 +00:00
|
|
|
{
|
2015-11-07 16:51:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-27 00:39:39 +00:00
|
|
|
amount = amount + Math.min(increment, incenseAddition - amount);
|
2015-11-07 16:51:41 +00:00
|
|
|
setPlayerIncense(player, amount);
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
// System.out.println("Amount of incense: " + amount + ", Increment: " +
|
|
|
|
// increment);
|
2015-11-07 16:51:41 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
public static boolean sacrificePlayerHealth(EntityPlayer player)
|
|
|
|
{
|
|
|
|
if (player.isPotionActive(soulFrayId))
|
|
|
|
{
|
2015-11-07 16:51:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-27 00:39:39 +00:00
|
|
|
double amount = getPlayerIncense(player);
|
2015-11-07 16:51:41 +00:00
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
if (amount >= 0)
|
|
|
|
{
|
2015-11-07 16:51:41 +00:00
|
|
|
float health = player.getHealth();
|
|
|
|
float maxHealth = player.getMaxHealth();
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
if (health > maxHealth / 10.0)
|
|
|
|
{
|
2015-11-07 16:51:41 +00:00
|
|
|
float sacrificedHealth = health - maxHealth / 10.0f;
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
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);
|
2016-03-17 20:00:44 +00:00
|
|
|
player.addPotionEffect(new PotionEffect(ModPotions.soulFray, soulFrayDuration));
|
2015-11-07 16:51:41 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-27 00:39:39 +00:00
|
|
|
public static double getModifier(double amount)
|
2015-12-30 20:34:40 +00:00
|
|
|
{
|
2015-11-07 16:51:41 +00:00
|
|
|
return 1 + amount * scalingOfSacrifice;
|
|
|
|
}
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
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));
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
if (altarEntity == null)
|
|
|
|
{
|
2015-11-07 16:51:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
altarEntity.sacrificialDaggerCall(amount, false);
|
|
|
|
altarEntity.startCycle();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
public static IBloodAltar getAltar(World world, BlockPos blockPos)
|
|
|
|
{
|
2015-11-07 16:51:41 +00:00
|
|
|
TileEntity tileEntity;
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
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()));
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
if (tileEntity instanceof IBloodAltar)
|
|
|
|
{
|
2015-11-07 16:51:41 +00:00
|
|
|
return (IBloodAltar) tileEntity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|