Search in sources :

Example 1 with EntityInternalBloodChanged

use of com.bewitchment.common.core.net.messages.EntityInternalBloodChanged in project Bewitchment by Um-Mitternacht.

the class BloodEvents method onJoin.

@SubscribeEvent
public static void onJoin(EntityJoinWorldEvent evt) {
    Entity e = evt.getEntity();
    if (!e.world.isRemote && e instanceof EntityLivingBase) {
        IBloodReserve br = e.getCapability(CapabilityBloodReserve.CAPABILITY, null);
        if (br.getMaxBlood() == 0) {
            int maxBlood = 100;
            if (e instanceof EntityPlayer) {
                maxBlood = 480;
            } else if (e instanceof EntityVillager) {
                maxBlood = 240;
            } else if (e instanceof EntityCow || e instanceof EntityHorse || e instanceof EntityPolarBear) {
                maxBlood = 150;
            } else if (e instanceof EntityDonkey || e instanceof EntityLlama) {
                maxBlood = 130;
            } else if (e instanceof EntitySheep) {
                maxBlood = 110;
            } else if (e instanceof EntityWolf || e instanceof EntityOcelot) {
                maxBlood = 80;
            } else if (e instanceof EntityChicken || e instanceof EntityParrot) {
                maxBlood = 50;
            } else {
                maxBlood = -1;
            }
            br.setMaxBlood(maxBlood);
            br.setBlood(maxBlood);
            EntityLivingBase ent = (EntityLivingBase) e;
            NetworkHandler.HANDLER.sendToAllAround(new EntityInternalBloodChanged(ent), new TargetPoint(e.dimension, ent.posX, ent.posY, ent.posZ, 32));
        } else {
            EntityLivingBase ent = (EntityLivingBase) e;
            NetworkHandler.HANDLER.sendToAllAround(new EntityInternalBloodChanged(ent), new TargetPoint(e.dimension, ent.posX, ent.posY, ent.posZ, 32));
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) EntityInternalBloodChanged(com.bewitchment.common.core.net.messages.EntityInternalBloodChanged) TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint) TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint) IBloodReserve(com.bewitchment.api.capability.transformations.IBloodReserve) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPolarBear(net.minecraft.entity.monster.EntityPolarBear) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with EntityInternalBloodChanged

use of com.bewitchment.common.core.net.messages.EntityInternalBloodChanged in project Bewitchment by Um-Mitternacht.

the class TransformationEvents method onPlayerJoin.

@SubscribeEvent
public void onPlayerJoin(PlayerLoggedInEvent evt) {
    if (evt.player instanceof EntityPlayerMP) {
        EntityPlayerMP player = (EntityPlayerMP) evt.player;
        NetworkHandler.HANDLER.sendTo(new PlayerTransformationChangedMessage(player), player);
        NetworkHandler.HANDLER.sendTo(new PlayerVampireBloodChanged(player), player);
        NetworkHandler.HANDLER.sendTo(new EntityInternalBloodChanged(player), player);
        NetworkHandler.HANDLER.sendTo(new NightVisionStatus(player.getCapability(CapabilityTransformationData.CAPABILITY, null).isNightVisionActive()), player);
    }
}
Also used : NightVisionStatus(com.bewitchment.common.core.net.messages.NightVisionStatus) EntityInternalBloodChanged(com.bewitchment.common.core.net.messages.EntityInternalBloodChanged) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) PlayerVampireBloodChanged(com.bewitchment.common.core.net.messages.PlayerVampireBloodChanged) PlayerTransformationChangedMessage(com.bewitchment.common.core.net.messages.PlayerTransformationChangedMessage) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with EntityInternalBloodChanged

use of com.bewitchment.common.core.net.messages.EntityInternalBloodChanged 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 4 with EntityInternalBloodChanged

use of com.bewitchment.common.core.net.messages.EntityInternalBloodChanged 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)

Example 5 with EntityInternalBloodChanged

use of com.bewitchment.common.core.net.messages.EntityInternalBloodChanged in project Bewitchment by Um-Mitternacht.

the class TransformationHelper method drainBloodFromEntity.

public static void drainBloodFromEntity(EntityPlayer player, EntityLivingBase entity) {
    IBloodReserve br = entity.getCapability(CapabilityBloodReserve.CAPABILITY, null);
    ITransformationData data = player.getCapability(CapabilityTransformationData.CAPABILITY, null);
    if (br.getBlood() > 0 && br.getMaxBlood() > 0) {
        int transferred = (int) Math.min(br.getBlood(), br.getBlood() * 0.05 * data.getLevel());
        if (transferred > 0 && (BewitchmentAPI.getAPI().addVampireBlood(player, transferred) || player.isSneaking())) {
            br.setBlood(br.getBlood() - transferred);
            NetworkHandler.HANDLER.sendToAllAround(new EntityInternalBloodChanged(entity), new TargetPoint(entity.dimension, entity.posX, entity.posY, entity.posZ, 32));
        }
    }
}
Also used : IBloodReserve(com.bewitchment.api.capability.transformations.IBloodReserve) ITransformationData(com.bewitchment.common.core.capability.transformation.ITransformationData) EntityInternalBloodChanged(com.bewitchment.common.core.net.messages.EntityInternalBloodChanged) TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint) TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint)

Aggregations

EntityInternalBloodChanged (com.bewitchment.common.core.net.messages.EntityInternalBloodChanged)5 IBloodReserve (com.bewitchment.api.capability.transformations.IBloodReserve)4 ITransformationData (com.bewitchment.common.core.capability.transformation.ITransformationData)3 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)3 TargetPoint (net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint)3 NightVisionStatus (com.bewitchment.common.core.net.messages.NightVisionStatus)2 PlayerTransformationChangedMessage (com.bewitchment.common.core.net.messages.PlayerTransformationChangedMessage)2 PlayerVampireBloodChanged (com.bewitchment.common.core.net.messages.PlayerVampireBloodChanged)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 TransformationModifiedEvent (com.bewitchment.api.event.TransformationModifiedEvent)1 Entity (net.minecraft.entity.Entity)1 EntityPolarBear (net.minecraft.entity.monster.EntityPolarBear)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 PotionEffect (net.minecraft.potion.PotionEffect)1