Search in sources :

Example 1 with IEnergy

use of com.witchworks.common.core.capability.energy.IEnergy in project Witchworks by Um-Mitternacht.

the class EnergyHUD method onTick.

@SubscribeEvent
public void onTick(TickEvent.ClientTickEvent event) {
    if (event.phase == TickEvent.Phase.END && Minecraft.getMinecraft().player != null) {
        Optional<IEnergy> optional = EnergyHandler.getEnergy(Minecraft.getMinecraft().player);
        if (optional.isPresent()) {
            IEnergy energy = optional.get();
            if (oldEnergy != energy.get()) {
                oldEnergy = energy.get();
                renderTime = 60;
                visible = 1F;
            }
            if (renderTime > 0 && energy.get() == energy.getMax()) {
                if (ENERGY_HUD.hide && renderTime < 20) {
                    visible -= 0.05F;
                    visible = MathHelper.clamp(visible, 0F, 1F);
                }
                renderTime--;
            }
            if (!reverse) {
                barAlpha += 0.05F;
                if (barAlpha > 1F) {
                    barAlpha = 1F;
                    reverse = true;
                }
            } else {
                barAlpha -= 0.05F;
                if (barAlpha < 0F) {
                    barAlpha = 0;
                    reverse = false;
                }
            }
        }
    }
}
Also used : IEnergy(com.witchworks.common.core.capability.energy.IEnergy) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with IEnergy

use of com.witchworks.common.core.capability.energy.IEnergy in project Witchworks by Um-Mitternacht.

the class EnergyHUD method renderOverlay.

@SubscribeEvent
public void renderOverlay(RenderGameOverlayEvent.Post event) {
    if (event.getType() == RenderGameOverlayEvent.ElementType.HOTBAR && renderTime > 0) {
        Minecraft mc = Minecraft.getMinecraft();
        Optional<IEnergy> optional = EnergyHandler.getEnergy(mc.player);
        if (optional.isPresent()) {
            IEnergy energy = optional.get();
            ScaledResolution res = event.getResolution();
            GlStateManager.pushMatrix();
            GlStateManager.enableBlend();
            float filled = (float) energy.get() / (float) energy.getMax();
            int heightEnd = ENERGY_HUD.heightEnd;
            int heightStart = ENERGY_HUD.heightStart;
            int width = ENERGY_HUD.width;
            int heightUsed = heightEnd - heightStart;
            int heightFilled = (int) ((heightUsed - 28) * filled);
            int posX = ENERGY_HUD.x;
            int posY = res.getScaledHeight() - ENERGY_HUD.y;
            int startPosX = posX - heightEnd;
            if (ENERGY_HUD.hide)
                GlStateManager.color(1F, 1F, 1F, visible);
            mc.getTextureManager().bindTexture(ResourceLocations.ENERGY_BACKGROUND[0]);
            Gui.drawModalRectWithCustomSizedTexture(startPosX - 4, posY + 14, 0F, heightUsed - 28, width, heightFilled, width, heightUsed - 28);
            GlStateManager.pushMatrix();
            GlStateManager.color(1F, 1F, 1F, visible == 1F ? barAlpha : visible);
            mc.getTextureManager().bindTexture(ResourceLocations.ENERGY_BACKGROUND[1]);
            Gui.drawModalRectWithCustomSizedTexture(startPosX - 4, posY + 14, 0F, heightUsed - 28, width, heightFilled, width, heightUsed - 28);
            GlStateManager.popMatrix();
            if (ENERGY_HUD.hide)
                GlStateManager.color(1F, 1F, 1F, visible);
            mc.getTextureManager().bindTexture(ResourceLocations.ENERGY);
            Gui.drawModalRectWithCustomSizedTexture(startPosX - 4, posY, 0F, 0F, width, heightUsed, width, heightUsed);
            int textColor = 0x990066;
            if (ENERGY_HUD.hide) {
                int alpha = (int) (visible * 255);
                textColor = alpha << 24 | 0x990066;
            }
            mc.fontRenderer.drawStringWithShadow("E: " + energy.get(), startPosX, posY - 15, textColor);
            GlStateManager.disableBlend();
            GlStateManager.popMatrix();
        }
    }
}
Also used : IEnergy(com.witchworks.common.core.capability.energy.IEnergy) ScaledResolution(net.minecraft.client.gui.ScaledResolution) Minecraft(net.minecraft.client.Minecraft) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with IEnergy

use of com.witchworks.common.core.capability.energy.IEnergy in project Witchworks 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.getRegen());
        newCap.setUses(oldCap.getUses());
    }
}
Also used : IEnergy(com.witchworks.common.core.capability.energy.IEnergy) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with IEnergy

use of com.witchworks.common.core.capability.energy.IEnergy in project Witchworks 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);
        if (optional.isPresent()) {
            PacketHandler.sendTo(entity, new EnergyMessage(optional.get(), entity.getUniqueID()));
        }
    }
}
Also used : EnergyMessage(com.witchworks.common.core.net.EnergyMessage) IEnergy(com.witchworks.common.core.capability.energy.IEnergy) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 5 with IEnergy

use of com.witchworks.common.core.capability.energy.IEnergy in project Witchworks by Um-Mitternacht.

the class EnergyEvents method playerUpdate.

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

Aggregations

IEnergy (com.witchworks.common.core.capability.energy.IEnergy)5 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)5 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 EnergyMessage (com.witchworks.common.core.net.EnergyMessage)1 Minecraft (net.minecraft.client.Minecraft)1 ScaledResolution (net.minecraft.client.gui.ScaledResolution)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1