Search in sources :

Example 1 with MessageRevolverRotate

use of blusunrize.immersiveengineering.common.util.network.MessageRevolverRotate 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)1 MessageChemthrowerSwitch (blusunrize.immersiveengineering.common.util.network.MessageChemthrowerSwitch)1 MessageRevolverRotate (blusunrize.immersiveengineering.common.util.network.MessageRevolverRotate)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1