use of WayofTime.bloodmagic.soul.DemonWillHolder in project BloodMagic by WayofTime.
the class WorldDemonWillHandler method drainWill.
public static double drainWill(World world, BlockPos pos, EnumDemonWillType type, double amount, boolean doDrain) {
WillChunk willChunk = getWillChunk(world, pos);
DemonWillHolder currentWill = willChunk.getCurrentWill();
double drain = Math.min(currentWill.getWill(type), amount);
if (!doDrain) {
return drain;
}
drain = currentWill.drainWill(type, drain);
markChunkAsDirty(willChunk, world.provider.getDimension());
return drain;
}
use of WayofTime.bloodmagic.soul.DemonWillHolder in project BloodMagic by WayofTime.
the class WorldDemonWillHandler method fillWillToMaximum.
public static double fillWillToMaximum(World world, BlockPos pos, EnumDemonWillType type, double amount, double max, boolean doFill) {
WillChunk willChunk = getWillChunk(world, pos);
DemonWillHolder currentWill = willChunk.getCurrentWill();
double fill = Math.min(amount, max - currentWill.getWill(type));
if (!doFill || fill <= 0) {
return fill > 0 ? fill : 0;
}
fill = currentWill.addWill(type, amount, max);
markChunkAsDirty(willChunk, world.provider.getDimension());
return fill;
}
use of WayofTime.bloodmagic.soul.DemonWillHolder in project BloodMagic by WayofTime.
the class Ritual method getErrorForBlockRangeOnFail.
public ITextComponent getErrorForBlockRangeOnFail(EntityPlayer player, String range, IMasterRitualStone master, BlockPos offset1, BlockPos offset2) {
AreaDescriptor descriptor = this.getBlockRange(range);
if (descriptor == null) {
return new TextComponentTranslation("ritual.bloodmagic.blockRange.tooBig", "?");
}
List<EnumDemonWillType> willConfig = master.getActiveWillConfig();
DemonWillHolder holder = WorldDemonWillHandler.getWillHolder(master.getWorldObj(), master.getBlockPos());
int maxVolume = this.getMaxVolumeForRange(range, willConfig, holder);
int maxVertical = this.getMaxVerticalRadiusForRange(range, willConfig, holder);
int maxHorizontal = this.getMaxHorizontalRadiusForRange(range, willConfig, holder);
if (maxVolume > 0 && descriptor.getVolumeForOffsets(offset1, offset2) > maxVolume) {
return new TextComponentTranslation("ritual.bloodmagic.blockRange.tooBig", maxVolume);
} else {
return new TextComponentTranslation("ritual.bloodmagic.blockRange.tooFar", maxVertical, maxHorizontal);
}
}
use of WayofTime.bloodmagic.soul.DemonWillHolder in project BloodMagic by WayofTime.
the class RitualGreenGrove method performRitual.
@Override
public void performRitual(IMasterRitualStone masterRitualStone) {
World world = masterRitualStone.getWorldObj();
BlockPos pos = masterRitualStone.getBlockPos();
int currentEssence = masterRitualStone.getOwnerNetwork().getCurrentEssence();
if (currentEssence < getRefreshCost()) {
masterRitualStone.getOwnerNetwork().causeNausea();
return;
}
int maxGrowths = currentEssence / getRefreshCost();
int totalGrowths = 0;
List<EnumDemonWillType> willConfig = masterRitualStone.getActiveWillConfig();
DemonWillHolder holder = WorldDemonWillHandler.getWillHolder(world, pos);
double corrosiveWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.CORROSIVE, willConfig);
double rawWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.DEFAULT, willConfig);
double steadfastWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.STEADFAST, willConfig);
double vengefulWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.VENGEFUL, willConfig);
refreshTime = getRefreshTimeForRawWill(rawWill);
double growthChance = getPlantGrowthChanceForWill(vengefulWill);
boolean consumeRawWill = rawWill >= rawWillDrain && refreshTime != defaultRefreshTime;
boolean consumeVengefulWill = vengefulWill >= vengefulWillDrain && growthChance != defaultGrowthChance;
double rawDrain = 0;
double vengefulDrain = 0;
AreaDescriptor growingRange = getBlockRange(GROW_RANGE);
int maxGrowthVolume = getMaxVolumeForRange(GROW_RANGE, willConfig, holder);
if (!growingRange.isWithinRange(getMaxVerticalRadiusForRange(GROW_RANGE, willConfig, holder), getMaxHorizontalRadiusForRange(GROW_RANGE, willConfig, holder)) || (maxGrowthVolume != 0 && growingRange.getVolume() > maxGrowthVolume)) {
return;
}
for (BlockPos newPos : growingRange.getContainedPositions(pos)) {
IBlockState state = world.getBlockState(newPos);
if (!BloodMagicAPI.INSTANCE.getBlacklist().getGreenGrove().contains(state)) {
if (state.getBlock() instanceof IGrowable) {
if (world.rand.nextDouble() < growthChance) {
state.getBlock().updateTick(world, newPos, state, new Random());
IBlockState newState = world.getBlockState(newPos);
if (!newState.equals(state)) {
totalGrowths++;
if (consumeRawWill) {
rawWill -= rawWillDrain;
rawDrain += rawWillDrain;
}
if (consumeVengefulWill) {
vengefulWill -= vengefulWillDrain;
vengefulDrain += vengefulWillDrain;
}
}
}
}
}
if (totalGrowths >= maxGrowths || (consumeRawWill && rawWill < rawWillDrain) || (consumeVengefulWill && vengefulWill < vengefulWillDrain)) {
break;
}
}
if (rawDrain > 0) {
WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.DEFAULT, rawDrain, true);
}
if (vengefulDrain > 0) {
WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.VENGEFUL, vengefulDrain, true);
}
AreaDescriptor hydrateRange = getBlockRange(HYDRATE_RANGE);
double steadfastDrain = 0;
if (steadfastWill > steadfastWillDrain) {
AxisAlignedBB aabb = hydrateRange.getAABB(pos);
steadfastDrain += steadfastWillDrain * Utils.plantSeedsInArea(world, aabb, 2, 1);
steadfastWill -= steadfastDrain;
for (BlockPos newPos : hydrateRange.getContainedPositions(pos)) {
if (steadfastWill < steadfastWillDrain) {
break;
}
IBlockState state = world.getBlockState(newPos);
Block block = state.getBlock();
boolean hydratedBlock = false;
if (block == Blocks.DIRT || block == Blocks.GRASS) {
world.setBlockState(newPos, farmlandState);
hydratedBlock = true;
} else if (block == Blocks.FARMLAND) {
int meta = block.getMetaFromState(state);
if (meta < 7) {
world.setBlockState(newPos, farmlandState);
hydratedBlock = true;
}
}
if (hydratedBlock) {
steadfastWill -= steadfastWillDrain;
steadfastDrain += steadfastWillDrain;
}
}
}
if (steadfastDrain > 0) {
WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.STEADFAST, steadfastDrain, true);
}
double corrosiveDrain = 0;
if (corrosiveWill > corrosiveWillDrain) {
AreaDescriptor leechRange = getBlockRange(LEECH_RANGE);
AxisAlignedBB mobArea = leechRange.getAABB(pos);
List<EntityLivingBase> entityList = world.getEntitiesWithinAABB(EntityLivingBase.class, mobArea);
for (EntityLivingBase entityLiving : entityList) {
if (corrosiveWill < corrosiveWillDrain) {
break;
}
if (entityLiving instanceof EntityPlayer) {
continue;
}
if (entityLiving.isPotionActive(RegistrarBloodMagic.PLANT_LEECH) || !entityLiving.isPotionApplicable(new PotionEffect(RegistrarBloodMagic.PLANT_LEECH))) {
continue;
}
entityLiving.addPotionEffect(new PotionEffect(RegistrarBloodMagic.PLANT_LEECH, 200, 0));
corrosiveWill -= corrosiveWillDrain;
corrosiveDrain += corrosiveWillDrain;
}
if (corrosiveDrain > 0) {
WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.CORROSIVE, corrosiveDrain, true);
}
}
masterRitualStone.getOwnerNetwork().syphon(totalGrowths * getRefreshCost());
}
use of WayofTime.bloodmagic.soul.DemonWillHolder in project BloodMagic by WayofTime.
the class Ritual method setBlockRangeByBounds.
public boolean setBlockRangeByBounds(String range, IMasterRitualStone master, BlockPos offset1, BlockPos offset2) {
AreaDescriptor descriptor = this.getBlockRange(range);
World world = master.getWorldObj();
BlockPos masterPos = master.getBlockPos();
DemonWillHolder holder = WorldDemonWillHandler.getWillHolder(world, masterPos);
if (canBlockRangeBeModified(range, descriptor, master, offset1, offset2, holder)) {
descriptor.modifyAreaByBlockPositions(offset1, offset2);
return true;
}
return false;
}
Aggregations