Search in sources :

Example 6 with IEnergy

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

the class EnergyEvents method onWorldJoin.

@SubscribeEvent
public void onWorldJoin(EntityJoinWorldEvent event) {
    if (event.getEntity() instanceof EntityPlayerMP) {
        EntityPlayerMP entity = (EntityPlayerMP) event.getEntity();
        Optional<IEnergy> optional = EnergyHandler.getEnergy(entity);
        optional.ifPresent(iEnergy -> iEnergy.syncTo(entity));
    }
}
Also used : IEnergy(com.bewitchment.api.capability.IEnergy) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 7 with IEnergy

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

the class EnergyEvents method onPlayerClone.

@SuppressWarnings("ConstantConditions")
@SubscribeEvent
public void onPlayerClone(net.minecraftforge.event.entity.player.PlayerEvent.Clone event) {
    final EntityPlayer oldPlayer = event.getOriginal();
    final EntityPlayer newPlayer = event.getEntityPlayer();
    if (event.isWasDeath() && oldPlayer.hasCapability(EnergyProvider.ENERGY_CAPABILITY, null) && newPlayer.hasCapability(EnergyProvider.ENERGY_CAPABILITY, null)) {
        final IEnergy oldCap = oldPlayer.getCapability(EnergyProvider.ENERGY_CAPABILITY, null);
        final IEnergy newCap = oldPlayer.getCapability(EnergyProvider.ENERGY_CAPABILITY, null);
        newCap.set(oldCap.get());
        newCap.setMax(oldCap.getMax());
        newCap.setRegen(oldCap.getRegenTime(), oldCap.getRegenBurst());
        newCap.setUses(oldCap.getUses());
    }
}
Also used : IEnergy(com.bewitchment.api.capability.IEnergy) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 8 with IEnergy

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

the class EnergyEvents method playerUpdate.

@SubscribeEvent
public void playerUpdate(LivingEvent.LivingUpdateEvent event) {
    if (!event.getEntity().world.isRemote && event.getEntity() instanceof EntityPlayerMP) {
        final EntityPlayerMP player = (EntityPlayerMP) event.getEntity();
        final Optional<IEnergy> optional = EnergyHandler.getEnergy(player);
        if (optional.isPresent()) {
            final IEnergy energy = optional.get();
            energyRegen(player, energy);
        }
    }
}
Also used : IEnergy(com.bewitchment.api.capability.IEnergy) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

IEnergy (com.bewitchment.api.capability.IEnergy)8 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)5 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)4 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 IIncantation (com.bewitchment.api.incantation.IIncantation)1 Minecraft (net.minecraft.client.Minecraft)1 ScaledResolution (net.minecraft.client.gui.ScaledResolution)1 TextureManager (net.minecraft.client.renderer.texture.TextureManager)1 CommandException (net.minecraft.command.CommandException)1 WrongUsageException (net.minecraft.command.WrongUsageException)1