commit
5ec35fcd08
12 changed files with 531 additions and 10 deletions
|
@ -19,6 +19,7 @@ public class NBTHolder {
|
|||
public static final String NBT_RUNNING = "isRunning";
|
||||
public static final String NBT_RUNTIME = "runtime";
|
||||
public static final String NBT_REAGENTTANK = "reagentTanks";
|
||||
public static final String NBT_CURRENT_INCENSE = "BM:CurrentIncense";
|
||||
public static final String NBT_ALTAR_TIER = "upgradeLevel";
|
||||
public static final String NBT_ALTAR_ACTIVE = "isActive";
|
||||
public static final String NBT_ALTAR_LIQUID_REQ = "liquidRequired";
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package WayofTime.bloodmagic.api.event;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraftforge.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
|
||||
@Cancelable
|
||||
public class SacrificeKnifeUsedEvent extends Event {
|
||||
public final EntityPlayer player;
|
||||
public boolean shouldDrainHealth;
|
||||
public boolean shouldFillAltar;
|
||||
public final int healthDrained;
|
||||
|
||||
public SacrificeKnifeUsedEvent(EntityPlayer player, boolean shouldDrainHealth, boolean shouldFillAltar, int hp) {
|
||||
this.player = player;
|
||||
this.shouldDrainHealth = shouldDrainHealth;
|
||||
this.shouldFillAltar = shouldFillAltar;
|
||||
this.healthDrained = hp;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package WayofTime.bloodmagic.api.util.helper;
|
||||
|
||||
import WayofTime.bloodmagic.api.NBTHolder;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class IncenseHelper {
|
||||
public static float getCurrentIncense(EntityPlayer player) {
|
||||
NBTTagCompound data = player.getEntityData();
|
||||
if (data.hasKey(NBTHolder.NBT_CURRENT_INCENSE)) {
|
||||
return data.getFloat(NBTHolder.NBT_CURRENT_INCENSE);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void setCurrentIncense(EntityPlayer player, float amount) {
|
||||
NBTTagCompound data = player.getEntityData();
|
||||
data.setFloat(NBTHolder.NBT_CURRENT_INCENSE, amount);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
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 {
|
||||
public static float scalingOfSacrifice = 0.001f;
|
||||
public static int soulFrayDuration = 400;
|
||||
public static Potion soulFrayId;
|
||||
|
||||
public static float getPlayerIncense(EntityPlayer player) {
|
||||
return IncenseHelper.getCurrentIncense(player);
|
||||
}
|
||||
|
||||
public static void setPlayerIncense(EntityPlayer player, float amount) {
|
||||
IncenseHelper.setCurrentIncense(player, amount);
|
||||
}
|
||||
|
||||
public static boolean incrementIncense(EntityPlayer player, float min, float max, float increment) {
|
||||
float amount = getPlayerIncense(player);
|
||||
if (amount < min || amount >= max) {
|
||||
return false;
|
||||
}
|
||||
|
||||
amount = amount + Math.min(increment, max - amount);
|
||||
setPlayerIncense(player, amount);
|
||||
|
||||
// System.out.println("Amount of incense: " + amount + ", Increment: " + increment);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean sacrificePlayerHealth(EntityPlayer player) {
|
||||
if (player.isPotionActive(soulFrayId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
float 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;
|
||||
|
||||
if (findAndFillAltar(player.getEntityWorld(), player, (int) (sacrificedHealth * 100f * getModifier(amount)))) {
|
||||
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) {
|
||||
return 1 + amount * scalingOfSacrifice;
|
||||
}
|
||||
|
||||
public static boolean findAndFillAltar(World world, EntityPlayer player, int amount) {
|
||||
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) {
|
||||
return false;
|
||||
}
|
||||
|
||||
altarEntity.sacrificialDaggerCall(amount, false);
|
||||
altarEntity.startCycle();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static IBloodAltar getAltar(World world, BlockPos blockPos) {
|
||||
TileEntity tileEntity;
|
||||
|
||||
for (int i = -2; i <= 2; i++) {
|
||||
for (int j = -2; j <= 2; j++) {
|
||||
for (int k = -2; k <= 1; k++) {
|
||||
tileEntity = world.getTileEntity(new BlockPos(i + blockPos.getX(), k + blockPos.getY(), j + blockPos.getZ()));
|
||||
|
||||
if (tileEntity instanceof IBloodAltar) {
|
||||
return (IBloodAltar) tileEntity;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue