Search in sources :

Example 1 with NightVisionStatus

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

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

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

Aggregations

NightVisionStatus (com.bewitchment.common.core.net.messages.NightVisionStatus)3 ITransformationData (com.bewitchment.common.core.capability.transformation.ITransformationData)2 EntityInternalBloodChanged (com.bewitchment.common.core.net.messages.EntityInternalBloodChanged)2 PlayerTransformationChangedMessage (com.bewitchment.common.core.net.messages.PlayerTransformationChangedMessage)2 PlayerVampireBloodChanged (com.bewitchment.common.core.net.messages.PlayerVampireBloodChanged)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 IBloodReserve (com.bewitchment.api.capability.transformations.IBloodReserve)1 TransformationModifiedEvent (com.bewitchment.api.event.TransformationModifiedEvent)1 EntityBatSwarm (com.bewitchment.common.entity.EntityBatSwarm)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1