Search in sources :

Example 1 with DemonWillHolder

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;
}
Also used : DemonWillHolder(WayofTime.bloodmagic.soul.DemonWillHolder)

Example 2 with DemonWillHolder

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;
}
Also used : DemonWillHolder(WayofTime.bloodmagic.soul.DemonWillHolder)

Example 3 with DemonWillHolder

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);
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) DemonWillHolder(WayofTime.bloodmagic.soul.DemonWillHolder) EnumDemonWillType(WayofTime.bloodmagic.soul.EnumDemonWillType)

Example 4 with DemonWillHolder

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());
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IBlockState(net.minecraft.block.state.IBlockState) PotionEffect(net.minecraft.potion.PotionEffect) World(net.minecraft.world.World) Random(java.util.Random) IGrowable(net.minecraft.block.IGrowable) EntityLivingBase(net.minecraft.entity.EntityLivingBase) DemonWillHolder(WayofTime.bloodmagic.soul.DemonWillHolder) Block(net.minecraft.block.Block) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) EnumDemonWillType(WayofTime.bloodmagic.soul.EnumDemonWillType)

Example 5 with DemonWillHolder

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;
}
Also used : DemonWillHolder(WayofTime.bloodmagic.soul.DemonWillHolder) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World)

Aggregations

DemonWillHolder (WayofTime.bloodmagic.soul.DemonWillHolder)10 EnumDemonWillType (WayofTime.bloodmagic.soul.EnumDemonWillType)4 BlockPos (net.minecraft.util.math.BlockPos)4 World (net.minecraft.world.World)3 IBlockState (net.minecraft.block.state.IBlockState)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 PotionEffect (net.minecraft.potion.PotionEffect)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 DemonAuraPacketProcessor (WayofTime.bloodmagic.network.DemonAuraPacketProcessor)1 Random (java.util.Random)1 Block (net.minecraft.block.Block)1 IGrowable (net.minecraft.block.IGrowable)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 TileEntity (net.minecraft.tileentity.TileEntity)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1 FluidStack (net.minecraftforge.fluids.FluidStack)1 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)1