Search in sources :

Example 1 with IBloodReserve

use of com.bewitchment.api.capability.transformations.IBloodReserve 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 IBloodReserve

use of com.bewitchment.api.capability.transformations.IBloodReserve in project Bewitchment by Um-Mitternacht.

the class EntityInternalBloodChanged method handleMessage.

@SideOnly(Side.CLIENT)
@Override
public IMessage handleMessage(MessageContext context) {
    Minecraft.getMinecraft().addScheduledTask(() -> {
        if (Minecraft.getMinecraft().world != null) {
            EntityLivingBase ent = (EntityLivingBase) Minecraft.getMinecraft().world.getEntityByID(entity_id);
            if (ent != null) {
                IBloodReserve br = ent.getCapability(CapabilityBloodReserve.CAPABILITY, null);
                br.setBlood(amount);
                br.setMaxBlood(max);
                br.setDrinker(id_drainer);
            }
        }
    });
    return null;
}
Also used : IBloodReserve(com.bewitchment.api.capability.transformations.IBloodReserve) EntityLivingBase(net.minecraft.entity.EntityLivingBase) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 3 with IBloodReserve

use of com.bewitchment.api.capability.transformations.IBloodReserve in project Bewitchment by Um-Mitternacht.

the class BloodViewerHUD method renderOverlay.

@SubscribeEvent
public void renderOverlay(RenderGameOverlayEvent.Post event) {
    if (event.getType() == RenderGameOverlayEvent.ElementType.HOTBAR && ExtraBarButtonsHUD.INSTANCE.actionScroller[0] == ModAbilities.DRAIN_BLOOD && ExtraBarButtonsHUD.INSTANCE.isInExtraBar && Minecraft.getMinecraft().pointedEntity instanceof EntityLivingBase) {
        IBloodReserve ibr = Minecraft.getMinecraft().pointedEntity.getCapability(CapabilityBloodReserve.CAPABILITY, null);
        float filled = ibr.getPercentFilled();
        if (ibr.getMaxBlood() > 0) {
            GlStateManager.pushMatrix();
            GlStateManager.color(filled, filled, filled);
            GlStateManager.enableAlpha();
            Minecraft mc = Minecraft.getMinecraft();
            ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft());
            mc.getTextureManager().bindTexture(TEXTURE);
            renderTextureAtIndex((sr.getScaledWidth() / 2) - 5d, (sr.getScaledHeight() / 2) - 30d);
            GlStateManager.popMatrix();
        }
    }
}
Also used : IBloodReserve(com.bewitchment.api.capability.transformations.IBloodReserve) ScaledResolution(net.minecraft.client.gui.ScaledResolution) EntityLivingBase(net.minecraft.entity.EntityLivingBase) Minecraft(net.minecraft.client.Minecraft) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with IBloodReserve

use of com.bewitchment.api.capability.transformations.IBloodReserve in project Bewitchment by Um-Mitternacht.

the class PotionBloodDrained method performEffect.

@Override
public void performEffect(EntityLivingBase entity, int amplifier) {
    IBloodReserve br = entity.getCapability(CapabilityBloodReserve.CAPABILITY, null);
    float amount = br.getPercentFilled();
    if (amount > 0 && amount < TRESHOLD) {
        if (br.getDrinkerUUID() != null)
            entity.attackEntityFrom(new DamageSourceDrain(entity.world.getPlayerEntityByUUID(br.getDrinkerUUID())), 0.5f);
        if (br.getDrinkerUUID() != null)
            entity.setRevengeTarget(entity.world.getPlayerEntityByUUID(br.getDrinkerUUID()));
        entity.addPotionEffect(new PotionEffect(this, 200, amplifier));
    } else {
        entity.removePotionEffect(this);
        br.setDrinker(null);
    }
}
Also used : IBloodReserve(com.bewitchment.api.capability.transformations.IBloodReserve) PotionEffect(net.minecraft.potion.PotionEffect)

Example 5 with IBloodReserve

use of com.bewitchment.api.capability.transformations.IBloodReserve 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)

Aggregations

IBloodReserve (com.bewitchment.api.capability.transformations.IBloodReserve)7 EntityInternalBloodChanged (com.bewitchment.common.core.net.messages.EntityInternalBloodChanged)4 EntityLivingBase (net.minecraft.entity.EntityLivingBase)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 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 PotionEffect (net.minecraft.potion.PotionEffect)2 TransformationModifiedEvent (com.bewitchment.api.event.TransformationModifiedEvent)1 NightVisionStatus (com.bewitchment.common.core.net.messages.NightVisionStatus)1 PlayerTransformationChangedMessage (com.bewitchment.common.core.net.messages.PlayerTransformationChangedMessage)1 PlayerVampireBloodChanged (com.bewitchment.common.core.net.messages.PlayerVampireBloodChanged)1 Minecraft (net.minecraft.client.Minecraft)1 ScaledResolution (net.minecraft.client.gui.ScaledResolution)1 Entity (net.minecraft.entity.Entity)1 EntityPolarBear (net.minecraft.entity.monster.EntityPolarBear)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1