Search in sources :

Example 6 with DemonWillHolder

use of WayofTime.bloodmagic.soul.DemonWillHolder in project BloodMagic by WayofTime.

the class GenericHandler method sendPlayerDemonWillAura.

// @SideOnly(Side.SERVER)
public static void sendPlayerDemonWillAura(EntityPlayer player) {
    if (player instanceof EntityPlayerMP) {
        BlockPos pos = player.getPosition();
        DemonWillHolder holder = WorldDemonWillHandler.getWillHolder(player.getEntityWorld().provider.getDimension(), pos.getX() >> 4, pos.getZ() >> 4);
        if (holder != null) {
            BloodMagicPacketHandler.sendTo(new DemonAuraPacketProcessor(holder), (EntityPlayerMP) player);
        } else {
            BloodMagicPacketHandler.sendTo(new DemonAuraPacketProcessor(new DemonWillHolder()), (EntityPlayerMP) player);
        }
    }
}
Also used : DemonAuraPacketProcessor(WayofTime.bloodmagic.network.DemonAuraPacketProcessor) DemonWillHolder(WayofTime.bloodmagic.soul.DemonWillHolder) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPos(net.minecraft.util.math.BlockPos)

Example 7 with DemonWillHolder

use of WayofTime.bloodmagic.soul.DemonWillHolder in project BloodMagic by WayofTime.

the class WorldDemonWillHandler method fillWill.

public static double fillWill(World world, BlockPos pos, EnumDemonWillType type, double amount, boolean doFill) {
    WillChunk willChunk = getWillChunk(world, pos);
    DemonWillHolder currentWill = willChunk.getCurrentWill();
    if (!doFill) {
        return amount;
    }
    currentWill.addWill(type, amount);
    markChunkAsDirty(willChunk, world.provider.getDimension());
    return amount;
}
Also used : DemonWillHolder(WayofTime.bloodmagic.soul.DemonWillHolder)

Example 8 with DemonWillHolder

use of WayofTime.bloodmagic.soul.DemonWillHolder in project BloodMagic by WayofTime.

the class WorldDemonWillHandler method getHighestDemonWillType.

public static EnumDemonWillType getHighestDemonWillType(World world, BlockPos pos) {
    double currentMax = 0;
    EnumDemonWillType currentHighest = EnumDemonWillType.DEFAULT;
    WillChunk willChunk = getWillChunk(world, pos);
    DemonWillHolder currentWill = willChunk.getCurrentWill();
    for (EnumDemonWillType type : EnumDemonWillType.values()) {
        if (currentWill.getWill(type) > currentMax) {
            currentMax = currentWill.getWill(type);
            currentHighest = type;
        }
    }
    return currentHighest;
}
Also used : DemonWillHolder(WayofTime.bloodmagic.soul.DemonWillHolder) EnumDemonWillType(WayofTime.bloodmagic.soul.EnumDemonWillType)

Example 9 with DemonWillHolder

use of WayofTime.bloodmagic.soul.DemonWillHolder in project BloodMagic by WayofTime.

the class WorldDemonWillHandler method getCurrentWill.

public static double getCurrentWill(World world, BlockPos pos, EnumDemonWillType type) {
    WillChunk willChunk = getWillChunk(world, pos);
    if (willChunk == null) {
        return 0;
    }
    DemonWillHolder currentWill = willChunk.getCurrentWill();
    return currentWill.getWill(type);
}
Also used : DemonWillHolder(WayofTime.bloodmagic.soul.DemonWillHolder)

Example 10 with DemonWillHolder

use of WayofTime.bloodmagic.soul.DemonWillHolder in project BloodMagic by WayofTime.

the class RitualLava method performRitual.

@Override
public void performRitual(IMasterRitualStone masterRitualStone) {
    timer++;
    World world = masterRitualStone.getWorldObj();
    int currentEssence = masterRitualStone.getOwnerNetwork().getCurrentEssence();
    int lpDrain = 0;
    if (currentEssence < getRefreshCost()) {
        masterRitualStone.getOwnerNetwork().causeNausea();
        return;
    }
    BlockPos pos = masterRitualStone.getBlockPos();
    List<EnumDemonWillType> willConfig = masterRitualStone.getActiveWillConfig();
    double rawWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.DEFAULT, willConfig);
    double rawDrained = 0;
    DemonWillHolder holder = WorldDemonWillHandler.getWillHolder(world, pos);
    AreaDescriptor lavaRange = getBlockRange(LAVA_RANGE);
    int maxLavaVolume = getMaxVolumeForRange(LAVA_RANGE, willConfig, holder);
    if (!lavaRange.isWithinRange(getMaxVerticalRadiusForRange(LAVA_RANGE, willConfig, holder), getMaxHorizontalRadiusForRange(LAVA_RANGE, willConfig, holder)) || (maxLavaVolume != 0 && lavaRange.getVolume() > maxLavaVolume)) {
        return;
    }
    for (BlockPos newPos : lavaRange.getContainedPositions(pos)) {
        IBlockState state = world.getBlockState(newPos);
        if (world.isAirBlock(newPos) || Utils.isFlowingLiquid(world, newPos, state)) {
            int lpCost = getLPCostForRawWill(rawWill);
            if (currentEssence < lpCost) {
                break;
            }
            world.setBlockState(newPos, Blocks.FLOWING_LAVA.getDefaultState());
            currentEssence -= lpCost;
            lpDrain += lpCost;
            if (rawWill > 0) {
                double drain = getWillCostForRawWill(rawWill);
                rawWill -= drain;
                rawDrained += drain;
            }
        }
    }
    if (rawWill > 0) {
        AreaDescriptor chestRange = getBlockRange(LAVA_TANK_RANGE);
        TileEntity tile = world.getTileEntity(chestRange.getContainedPositions(pos).get(0));
        double drain = getWillCostForRawWill(rawWill);
        int lpCost = getLPCostForRawWill(rawWill);
        if (rawWill >= drain && currentEssence >= lpCost) {
            if (tile != null) {
                if (tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null)) {
                    IFluidHandler handler = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null);
                    double filled = handler.fill(new FluidStack(FluidRegistry.LAVA, 1000), true);
                    double ratio = filled / 1000;
                    rawWill -= drain * ratio;
                    rawDrained += drain * ratio;
                    currentEssence -= Math.ceil(lpCost * ratio);
                    lpDrain += Math.ceil(lpCost * ratio);
                }
            }
        }
    }
    double vengefulWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.VENGEFUL, willConfig);
    double steadfastWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.STEADFAST, willConfig);
    double corrosiveWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.CORROSIVE, willConfig);
    if (vengefulWill >= vengefulWillDrain) {
        double vengefulDrained = 0;
        AreaDescriptor fuseRange = getBlockRange(FIRE_FUSE_RANGE);
        AxisAlignedBB fuseArea = fuseRange.getAABB(pos);
        List<EntityLivingBase> entities = world.getEntitiesWithinAABB(EntityLivingBase.class, fuseArea);
        for (EntityLivingBase entity : entities) {
            if (vengefulWill < vengefulWillDrain) {
                break;
            }
            if (entity instanceof EntityPlayer) {
                continue;
            }
            if (!entity.isPotionActive(RegistrarBloodMagic.FIRE_FUSE)) {
                entity.addPotionEffect(new PotionEffect(RegistrarBloodMagic.FIRE_FUSE, 100, 0));
                vengefulDrained += vengefulWillDrain;
                vengefulWill -= vengefulWillDrain;
            }
        }
        if (vengefulDrained > 0) {
            WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.VENGEFUL, vengefulDrained, true);
        }
    }
    if (steadfastWill >= steadfastWillDrain) {
        double steadfastDrained = 0;
        AreaDescriptor resistRange = getBlockRange(FIRE_RESIST_RANGE);
        int duration = getFireResistForWill(steadfastWill);
        AxisAlignedBB resistArea = resistRange.getAABB(pos);
        List<EntityPlayer> entities = world.getEntitiesWithinAABB(EntityPlayer.class, resistArea);
        for (EntityPlayer entity : entities) {
            if (steadfastWill < steadfastWillDrain) {
                break;
            }
            if (!entity.isPotionActive(MobEffects.FIRE_RESISTANCE) || (entity.getActivePotionEffect(MobEffects.FIRE_RESISTANCE).getDuration() < 2)) {
                entity.addPotionEffect(new PotionEffect(MobEffects.FIRE_RESISTANCE, 100, 0));
                steadfastDrained += steadfastWillDrain;
                steadfastWill -= steadfastWillDrain;
            }
        }
        if (steadfastDrained > 0) {
            WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.STEADFAST, steadfastDrained, true);
        }
    }
    if (timer % corrosiveRefreshTime == 0 && corrosiveWill >= corrosiveWillDrain) {
        double corrosiveDrained = 0;
        AreaDescriptor resistRange = getBlockRange(FIRE_DAMAGE_RANGE);
        float damage = getCorrosiveDamageForWill(corrosiveWill);
        AxisAlignedBB damageArea = resistRange.getAABB(pos);
        List<EntityLivingBase> entities = world.getEntitiesWithinAABB(EntityLivingBase.class, damageArea);
        for (EntityLivingBase entity : entities) {
            if (corrosiveWill < corrosiveWillDrain) {
                break;
            }
            if (!entity.isDead && entity.hurtTime <= 0 && Utils.isImmuneToFireDamage(entity)) {
                if (entity.attackEntityFrom(DamageSourceBloodMagic.INSTANCE, damage)) {
                    corrosiveDrained += corrosiveWillDrain;
                    corrosiveWill -= corrosiveWillDrain;
                }
            }
        }
        if (corrosiveDrained > 0) {
            WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.CORROSIVE, corrosiveDrained, true);
        }
    }
    if (rawDrained > 0) {
        WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.DEFAULT, rawDrained, true);
    }
    masterRitualStone.getOwnerNetwork().syphon(lpDrain);
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IBlockState(net.minecraft.block.state.IBlockState) PotionEffect(net.minecraft.potion.PotionEffect) FluidStack(net.minecraftforge.fluids.FluidStack) World(net.minecraft.world.World) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) TileEntity(net.minecraft.tileentity.TileEntity) EntityLivingBase(net.minecraft.entity.EntityLivingBase) DemonWillHolder(WayofTime.bloodmagic.soul.DemonWillHolder) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) EnumDemonWillType(WayofTime.bloodmagic.soul.EnumDemonWillType)

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