Search in sources :

Example 1 with IZoomTool

use of blusunrize.immersiveengineering.api.tool.ZoomHandler.IZoomTool in project ImmersiveEngineering by BluSunrize.

the class ClientEventHandler method onRenderOverlayPre.

@SubscribeEvent
public void onRenderOverlayPre(RenderGameOverlayEvent.Pre event) {
    if (ZoomHandler.isZooming && event.getType() == RenderGameOverlayEvent.ElementType.CROSSHAIRS) {
        event.setCanceled(true);
        if (ZoomHandler.isZooming) {
            ClientUtils.bindTexture("immersiveengineering:textures/gui/scope.png");
            int width = event.getResolution().getScaledWidth();
            int height = event.getResolution().getScaledHeight();
            int resMin = Math.min(width, height);
            float offsetX = (width - resMin) / 2f;
            float offsetY = (height - resMin) / 2f;
            if (resMin == width) {
                ClientUtils.drawColouredRect(0, 0, width, (int) offsetY + 1, 0xff000000);
                ClientUtils.drawColouredRect(0, (int) offsetY + resMin, width, (int) offsetY + 1, 0xff000000);
            } else {
                ClientUtils.drawColouredRect(0, 0, (int) offsetX + 1, height, 0xff000000);
                ClientUtils.drawColouredRect((int) offsetX + resMin, 0, (int) offsetX + 1, height, 0xff000000);
            }
            GlStateManager.enableBlend();
            OpenGlHelper.glBlendFunc(770, 771, 1, 0);
            GlStateManager.translate(offsetX, offsetY, 0);
            ClientUtils.drawTexturedRect(0, 0, resMin, resMin, 0f, 1f, 0f, 1f);
            ClientUtils.bindTexture("immersiveengineering:textures/gui/hud_elements.png");
            ClientUtils.drawTexturedRect(218 / 256f * resMin, 64 / 256f * resMin, 24 / 256f * resMin, 128 / 256f * resMin, 64 / 256f, 88 / 256f, 96 / 256f, 224 / 256f);
            ItemStack equipped = ClientUtils.mc().player.getHeldItem(EnumHand.MAIN_HAND);
            if (!equipped.isEmpty() && equipped.getItem() instanceof IZoomTool) {
                IZoomTool tool = (IZoomTool) equipped.getItem();
                float[] steps = tool.getZoomSteps(equipped, ClientUtils.mc().player);
                if (steps != null && steps.length > 1) {
                    int curStep = -1;
                    float dist = 0;
                    float totalOffset = 0;
                    float stepLength = 118 / (float) steps.length;
                    float stepOffset = (stepLength - 7) / 2f;
                    GlStateManager.translate(223 / 256f * resMin, 64 / 256f * resMin, 0);
                    GlStateManager.translate(0, (5 + stepOffset) / 256 * resMin, 0);
                    for (int i = 0; i < steps.length; i++) {
                        ClientUtils.drawTexturedRect(0, 0, 8 / 256f * resMin, 7 / 256f * resMin, 88 / 256f, 96 / 256f, 96 / 256f, 103 / 256f);
                        GlStateManager.translate(0, stepLength / 256 * resMin, 0);
                        totalOffset += stepLength;
                        if (curStep == -1 || Math.abs(steps[i] - ZoomHandler.fovZoom) < dist) {
                            curStep = i;
                            dist = Math.abs(steps[i] - ZoomHandler.fovZoom);
                        }
                    }
                    GlStateManager.translate(0, -totalOffset / 256 * resMin, 0);
                    if (curStep >= 0 && curStep < steps.length) {
                        GlStateManager.translate(6 / 256f * resMin, curStep * stepLength / 256 * resMin, 0);
                        ClientUtils.drawTexturedRect(0, 0, 8 / 256f * resMin, 7 / 256f * resMin, 88 / 256f, 98 / 256f, 103 / 256f, 110 / 256f);
                        ClientUtils.font().drawString((1 / steps[curStep]) + "x", (int) (16 / 256f * resMin), 0, 0xffffff);
                        GlStateManager.translate(-6 / 256f * resMin, -curStep * stepLength / 256 * resMin, 0);
                    }
                    GlStateManager.translate(0, -((5 + stepOffset) / 256 * resMin), 0);
                    GlStateManager.translate(-223 / 256f * resMin, -64 / 256f * resMin, 0);
                }
            }
            GlStateManager.translate(-offsetX, -offsetY, 0);
        }
    }
}
Also used : IZoomTool(blusunrize.immersiveengineering.api.tool.ZoomHandler.IZoomTool) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with IZoomTool

use of blusunrize.immersiveengineering.api.tool.ZoomHandler.IZoomTool in project ImmersiveEngineering by BluSunrize.

the class ClientEventHandler method onFOVUpdate.

@SubscribeEvent()
public void onFOVUpdate(FOVUpdateEvent event) {
    EntityPlayer player = ClientUtils.mc().player;
    if (!player.getHeldItem(EnumHand.MAIN_HAND).isEmpty() && player.getHeldItem(EnumHand.MAIN_HAND).getItem() instanceof IZoomTool) {
        if (player.isSneaking() && player.onGround) {
            ItemStack equipped = player.getHeldItem(EnumHand.MAIN_HAND);
            IZoomTool tool = (IZoomTool) equipped.getItem();
            if (tool.canZoom(equipped, player)) {
                if (!ZoomHandler.isZooming) {
                    float[] steps = tool.getZoomSteps(equipped, player);
                    if (steps != null && steps.length > 0) {
                        int curStep = -1;
                        float dist = 0;
                        for (int i = 0; i < steps.length; i++) if (curStep == -1 || Math.abs(steps[i] - ZoomHandler.fovZoom) < dist) {
                            curStep = i;
                            dist = Math.abs(steps[i] - ZoomHandler.fovZoom);
                        }
                        if (curStep != -1)
                            ZoomHandler.fovZoom = steps[curStep];
                        else
                            ZoomHandler.fovZoom = event.getFov();
                    }
                    ZoomHandler.isZooming = true;
                }
                event.setNewfov(ZoomHandler.fovZoom);
            } else if (ZoomHandler.isZooming)
                ZoomHandler.isZooming = false;
        } else if (ZoomHandler.isZooming)
            ZoomHandler.isZooming = false;
    } else if (ZoomHandler.isZooming)
        ZoomHandler.isZooming = false;
    if (player.getActivePotionEffect(IEPotions.concreteFeet) != null)
        event.setNewfov(1);
}
Also used : IZoomTool(blusunrize.immersiveengineering.api.tool.ZoomHandler.IZoomTool) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with IZoomTool

use of blusunrize.immersiveengineering.api.tool.ZoomHandler.IZoomTool in project ImmersiveEngineering by BluSunrize.

the class ClientEventHandler method onMouseEvent.

@SubscribeEvent
public void onMouseEvent(MouseEvent event) {
    if (event.getDwheel() != 0) {
        EntityPlayer player = ClientUtils.mc().player;
        if (!player.getHeldItem(EnumHand.MAIN_HAND).isEmpty() && player.isSneaking()) {
            ItemStack equipped = player.getHeldItem(EnumHand.MAIN_HAND);
            if (equipped.getItem() instanceof IZoomTool) {
                IZoomTool tool = (IZoomTool) equipped.getItem();
                if (tool.canZoom(equipped, player)) {
                    float[] steps = tool.getZoomSteps(equipped, player);
                    if (steps != null && steps.length > 0) {
                        int curStep = -1;
                        float dist = 0;
                        for (int i = 0; i < steps.length; i++) if (curStep == -1 || Math.abs(steps[i] - ZoomHandler.fovZoom) < dist) {
                            curStep = i;
                            dist = Math.abs(steps[i] - ZoomHandler.fovZoom);
                        }
                        if (curStep != -1) {
                            int newStep = curStep + (event.getDwheel() > 0 ? -1 : 1);
                            if (newStep >= 0 && newStep < steps.length)
                                ZoomHandler.fovZoom = steps[newStep];
                            event.setCanceled(true);
                        }
                    }
                }
            }
            if (Config.IEConfig.Tools.chemthrower_scroll && equipped.getItem() instanceof ItemChemthrower && ((ItemChemthrower) equipped.getItem()).getUpgrades(equipped).getBoolean("multitank")) {
                ImmersiveEngineering.packetHandler.sendToServer(new MessageChemthrowerSwitch(event.getDwheel() < 0));
                event.setCanceled(true);
            }
            if (equipped.getItem() instanceof ItemRevolver) {
                ImmersiveEngineering.packetHandler.sendToServer(new MessageRevolverRotate(event.getDwheel() < 0));
                event.setCanceled(true);
            }
        }
    }
}
Also used : MessageRevolverRotate(blusunrize.immersiveengineering.common.util.network.MessageRevolverRotate) IZoomTool(blusunrize.immersiveengineering.api.tool.ZoomHandler.IZoomTool) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) MessageChemthrowerSwitch(blusunrize.immersiveengineering.common.util.network.MessageChemthrowerSwitch) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

IZoomTool (blusunrize.immersiveengineering.api.tool.ZoomHandler.IZoomTool)3 ItemStack (net.minecraft.item.ItemStack)3 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 MessageChemthrowerSwitch (blusunrize.immersiveengineering.common.util.network.MessageChemthrowerSwitch)1 MessageRevolverRotate (blusunrize.immersiveengineering.common.util.network.MessageRevolverRotate)1