Search in sources :

Example 6 with ITransformationData

use of com.bewitchment.common.core.capability.transformation.ITransformationData in project Bewitchment by Um-Mitternacht.

the class ApiInstance method addVampireBlood.

/**
 * @param player The player whose blood reserve is being modified
 * @param amount The amount of blood to add (negative values will decrease the total)
 * @return <i>When adding</i> blood this will return true if the value changed and false otherwise: this is <b>true</b> if there was
 * even a little bit of space in the pool, but the blood added was greater than the amount that could be inserted,
 * and <b>false</b> if the pool was maxed.<br>
 * <i>When removing</i> blood this will return true if ALL the blood requested was drained.
 * If the amount drained is greater than the amount available this will return false, and no blood will be drained from the pool
 * @throws UnsupportedOperationException if the player is not a vampire
 */
@Override
public boolean addVampireBlood(EntityPlayer player, int amount) {
    ITransformationData data = player.getCapability(CapabilityTransformationData.CAPABILITY, null);
    boolean flag = data.addVampireBlood(amount);
    if (player instanceof EntityPlayerMP) {
        NetworkHandler.HANDLER.sendTo(new PlayerVampireBloodChanged(player), (EntityPlayerMP) player);
    }
    return flag;
}
Also used : ITransformationData(com.bewitchment.common.core.capability.transformation.ITransformationData) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) PlayerVampireBloodChanged(com.bewitchment.common.core.net.messages.PlayerVampireBloodChanged)

Example 7 with ITransformationData

use of com.bewitchment.common.core.capability.transformation.ITransformationData in project Bewitchment by Um-Mitternacht.

the class ApiInstance method setTypeAndLevel.

@Override
public void setTypeAndLevel(EntityPlayer player, ITransformation type, int level, boolean isClient) {
    ITransformationData data = player.getCapability(CapabilityTransformationData.CAPABILITY, null);
    IBloodReserve ibr = player.getCapability(CapabilityBloodReserve.CAPABILITY, null);
    data.setType(type);
    data.setLevel(level);
    data.setNightVision(data.isNightVisionActive() && (type == ModTransformations.WEREWOLF || type == ModTransformations.VAMPIRE));
    if ((type == ModTransformations.SPECTRE || type == ModTransformations.VAMPIRE)) {
        ibr.setMaxBlood(-1);
        player.removePotionEffect(ModPotions.bloodDrained);
    } else if (ibr.getMaxBlood() < 0) {
        ibr.setMaxBlood(480);
        ibr.setBlood(480);
    }
    if (isClient) {
        HotbarAction.refreshActions(player, player.world);
    } else {
        NetworkHandler.HANDLER.sendTo(new PlayerTransformationChangedMessage(player), (EntityPlayerMP) player);
        NetworkHandler.HANDLER.sendTo(new PlayerVampireBloodChanged(player), (EntityPlayerMP) player);
        NetworkHandler.HANDLER.sendTo(new EntityInternalBloodChanged(player), (EntityPlayerMP) player);
        NetworkHandler.HANDLER.sendTo(new NightVisionStatus(player.getCapability(CapabilityTransformationData.CAPABILITY, null).isNightVisionActive()), (EntityPlayerMP) player);
    }
    MinecraftForge.EVENT_BUS.post(new TransformationModifiedEvent(player, type, level));
}
Also used : ITransformationData(com.bewitchment.common.core.capability.transformation.ITransformationData) IBloodReserve(com.bewitchment.api.capability.transformations.IBloodReserve) NightVisionStatus(com.bewitchment.common.core.net.messages.NightVisionStatus) TransformationModifiedEvent(com.bewitchment.api.event.TransformationModifiedEvent) EntityInternalBloodChanged(com.bewitchment.common.core.net.messages.EntityInternalBloodChanged) PlayerVampireBloodChanged(com.bewitchment.common.core.net.messages.PlayerVampireBloodChanged) PlayerTransformationChangedMessage(com.bewitchment.common.core.net.messages.PlayerTransformationChangedMessage)

Example 8 with ITransformationData

use of com.bewitchment.common.core.capability.transformation.ITransformationData in project Bewitchment by Um-Mitternacht.

the class VampireAbilityHandler method onHotbarAbilityToggled.

@SubscribeEvent
public void onHotbarAbilityToggled(HotbarActionTriggeredEvent evt) {
    ITransformationData data = evt.player.getCapability(CapabilityTransformationData.CAPABILITY, null);
    if (evt.action == ModAbilities.NIGHT_VISION) {
        boolean newStatus = !data.isNightVisionActive();
        data.setNightVision(newStatus);
        if (evt.player instanceof EntityPlayerMP) {
            NetworkHandler.HANDLER.sendTo(new NightVisionStatus(newStatus), (EntityPlayerMP) evt.player);
        }
    } else if (evt.action == ModAbilities.DRAIN_BLOOD) {
        RayTraceResult rt = RayTraceHelper.rayTraceResult(evt.player, RayTraceHelper.fromLookVec(evt.player, evt.player.getEntityAttribute(EntityPlayer.REACH_DISTANCE).getAttributeValue()), true, true);
        if (rt != null && rt.typeOfHit == Type.ENTITY) {
            if (rt.entityHit instanceof EntityLivingBase) {
                EntityLivingBase entity = (EntityLivingBase) rt.entityHit;
                if (canDrainBloodFrom(evt.player, entity)) {
                    TransformationHelper.drainBloodFromEntity(evt.player, entity);
                } else {
                    entity.attackEntityAsMob(evt.player);
                }
            }
        }
    } else if (evt.action == ModAbilities.BAT_SWARM) {
        if (!(evt.player.getRidingEntity() instanceof EntityBatSwarm) && BewitchmentAPI.getAPI().addVampireBlood(evt.player, -150)) {
            EntityBatSwarm bs = new EntityBatSwarm(evt.player.world);
            float pitch = (Math.abs(evt.player.rotationPitch) < 7) ? 0 : evt.player.rotationPitch;
            bs.setPositionAndRotation(evt.player.posX, evt.player.posY + evt.player.getEyeHeight(), evt.player.posZ, evt.player.rotationYaw, pitch);
            evt.player.world.spawnEntity(bs);
            evt.player.startRiding(bs);
        }
    }
}
Also used : ITransformationData(com.bewitchment.common.core.capability.transformation.ITransformationData) NightVisionStatus(com.bewitchment.common.core.net.messages.NightVisionStatus) EntityBatSwarm(com.bewitchment.common.entity.EntityBatSwarm) RayTraceResult(net.minecraft.util.math.RayTraceResult) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 9 with ITransformationData

use of com.bewitchment.common.core.capability.transformation.ITransformationData in project Bewitchment by Um-Mitternacht.

the class VampireAbilityHandler method tickChecks.

@SubscribeEvent
public void tickChecks(PlayerTickEvent evt) {
    ITransformationData data = evt.player.getCapability(CapabilityTransformationData.CAPABILITY, null);
    if (data.getType() == ModTransformations.VAMPIRE && evt.side.isServer()) {
        // Check sun damage
        if (evt.player.world.getTotalWorldTime() % 40 == 0 && evt.player.world.canBlockSeeSky(evt.player.getPosition()) && evt.player.world.isDaytime() && !evt.player.world.isRainingAt(evt.player.getPosition())) {
            if (data.getLevel() < 5 || !BewitchmentAPI.getAPI().addVampireBlood(evt.player, -(13 + data.getLevel()))) {
                evt.player.attackEntityFrom(SUN_DAMAGE, 11 - data.getLevel());
            }
        }
        // Replace hunger mechanics with blood mechanics
        if (evt.player.ticksExisted % 30 == 0) {
            // No healing from food
            evt.player.getFoodStats().setFoodLevel(10);
            if (data.getBlood() == 0) {
                evt.player.addPotionEffect(new PotionEffect(MobEffects.MINING_FATIGUE, 200, 2, false, false));
                evt.player.addPotionEffect(new PotionEffect(MobEffects.WEAKNESS, 200, 2, false, false));
            } else {
                if (evt.player.getHealth() < evt.player.getMaxHealth() && BewitchmentAPI.getAPI().addVampireBlood(evt.player, -20)) {
                    evt.player.heal(1);
                }
            }
            // Hunger drains blood
            PotionEffect effect = evt.player.getActivePotionEffect(MobEffects.HUNGER);
            if (effect != null) {
                BewitchmentAPI.getAPI().addVampireBlood(evt.player, -effect.getAmplifier() * 5);
            }
            // Fire resistance becomes hunger
            PotionEffect pe = evt.player.getActivePotionEffect(MobEffects.FIRE_RESISTANCE);
            if (pe != null) {
                evt.player.addPotionEffect(new PotionEffect(MobEffects.HUNGER, pe.getDuration(), pe.getAmplifier()));
                evt.player.removePotionEffect(MobEffects.FIRE_RESISTANCE);
            }
            // No need for air
            evt.player.setAir(150);
        }
    }
}
Also used : ITransformationData(com.bewitchment.common.core.capability.transformation.ITransformationData) PotionEffect(net.minecraft.potion.PotionEffect) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 10 with ITransformationData

use of com.bewitchment.common.core.capability.transformation.ITransformationData in project Bewitchment by Um-Mitternacht.

the class BloodEvents method fillBloodOverTime.

@SubscribeEvent
public static void fillBloodOverTime(LivingUpdateEvent evt) {
    EntityLivingBase ent = evt.getEntityLiving();
    if (!ent.world.isRemote) {
        boolean ignore = false;
        IBloodReserve br = ent.getCapability(CapabilityBloodReserve.CAPABILITY, null);
        if (br.getMaxBlood() > br.getBlood() && ent.ticksExisted % 80 == 0) {
            int baseIncrease = getBloodRegen(br);
            if (ent instanceof EntityPlayer) {
                ITransformationData data = ent.getCapability(CapabilityTransformationData.CAPABILITY, null);
                if (data.getType() != ModTransformations.VAMPIRE) {
                    ent.addPotionEffect(new PotionEffect(MobEffects.HUNGER, 60, 1));
                }
                if (data.getType() == ModTransformations.VAMPIRE || data.getType() == ModTransformations.SPECTRE)
                    ignore = true;
                br.setBlood(br.getBlood() + baseIncrease);
            } else if (ent instanceof EntityVillager) {
                // TODO check for villagers nearby. Regen rate should be nerfed when many are in the same place
                br.setBlood(br.getBlood() + baseIncrease);
            } else {
                br.setBlood(br.getBlood() + baseIncrease);
            }
            float stored = br.getPercentFilled();
            if (!ignore && stored < PotionBloodDrained.TRESHOLD) {
                ent.addPotionEffect(new PotionEffect(ModPotions.bloodDrained, 200, 0));
            }
            NetworkHandler.HANDLER.sendToAllAround(new EntityInternalBloodChanged(ent), new TargetPoint(ent.dimension, ent.posX, ent.posY, ent.posZ, 32));
        }
    }
}
Also used : IBloodReserve(com.bewitchment.api.capability.transformations.IBloodReserve) ITransformationData(com.bewitchment.common.core.capability.transformation.ITransformationData) PotionEffect(net.minecraft.potion.PotionEffect) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityInternalBloodChanged(com.bewitchment.common.core.net.messages.EntityInternalBloodChanged) TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint) TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

ITransformationData (com.bewitchment.common.core.capability.transformation.ITransformationData)13 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)8 IBloodReserve (com.bewitchment.api.capability.transformations.IBloodReserve)3 EntityInternalBloodChanged (com.bewitchment.common.core.net.messages.EntityInternalBloodChanged)3 PlayerVampireBloodChanged (com.bewitchment.common.core.net.messages.PlayerVampireBloodChanged)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)3 NightVisionStatus (com.bewitchment.common.core.net.messages.NightVisionStatus)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 PotionEffect (net.minecraft.potion.PotionEffect)2 TargetPoint (net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint)2 TransformationModifiedEvent (com.bewitchment.api.event.TransformationModifiedEvent)1 PlayerTransformationChangedMessage (com.bewitchment.common.core.net.messages.PlayerTransformationChangedMessage)1 EntityBatSwarm (com.bewitchment.common.entity.EntityBatSwarm)1 Minecraft (net.minecraft.client.Minecraft)1 ScaledResolution (net.minecraft.client.gui.ScaledResolution)1 AttributeModifier (net.minecraft.entity.ai.attributes.AttributeModifier)1 IAttributeInstance (net.minecraft.entity.ai.attributes.IAttributeInstance)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1