Search in sources :

Example 1 with InputEvent

use of net.minecraftforge.client.event.InputEvent in project Vampirism by TeamLapen.

the class ModKeys method handleInputEvent.

@SubscribeEvent
public void handleInputEvent(InputEvent event) {
    // Only call isPressed once, so
    KEY keyPressed = getPressedKeyBinding();
    // get value here!
    if (!suckKeyDown && keyPressed == KEY.SUCK) {
        RayTraceResult mouseOver = Minecraft.getInstance().hitResult;
        suckKeyDown = true;
        PlayerEntity player = Minecraft.getInstance().player;
        if (mouseOver != null && !player.isSpectator() && VampirePlayer.getOpt(player).map(vp -> vp.getLevel() > 0 && !vp.getActionHandler().isActionActive(VampireActions.bat)).orElse(false)) {
            if (mouseOver instanceof EntityRayTraceResult) {
                VampirismMod.dispatcher.sendToServer(new CStartFeedingPacket(((EntityRayTraceResult) mouseOver).getEntity().getId()));
            } else if (mouseOver instanceof BlockRayTraceResult) {
                BlockPos pos = ((BlockRayTraceResult) mouseOver).getBlockPos();
                VampirismMod.dispatcher.sendToServer(new CStartFeedingPacket(pos));
            } else {
                LOGGER.warn("Unknown mouse over type while trying to feed");
            }
        }
    } else if (keyPressed == KEY.ACTION) {
        if (Minecraft.getInstance().player.isAlive()) {
            IPlayableFaction<?> faction = VampirismPlayerAttributes.get(Minecraft.getInstance().player).faction;
            if (faction != null) {
                Minecraft.getInstance().setScreen(new SelectActionScreen(faction.getColor(), false));
            }
        }
    } else if (keyPressed == KEY.SKILL) {
        VampirismMod.dispatcher.sendToServer(new CSimpleInputEvent(CSimpleInputEvent.Type.VAMPIRISM_MENU));
    } else if (keyPressed == KEY.VISION) {
        VampirismMod.dispatcher.sendToServer(new CSimpleInputEvent(CSimpleInputEvent.Type.TOGGLE_VAMPIRE_VISION));
    } else if (keyPressed == KEY.ACTION1) {
        long t = System.currentTimeMillis();
        if (t - lastAction1Trigger > ACTION_BUTTON_COOLDOWN) {
            lastAction1Trigger = System.currentTimeMillis();
            PlayerEntity player = Minecraft.getInstance().player;
            if (player.isAlive()) {
                FactionPlayerHandler.getOpt(player).ifPresent(factionHandler -> factionHandler.getCurrentFactionPlayer().ifPresent(factionPlayer -> toggleBoundAction(factionPlayer, factionHandler.getBoundAction(1))));
            }
        }
    } else if (keyPressed == KEY.ACTION2) {
        long t = System.currentTimeMillis();
        if (t - lastAction2Trigger > ACTION_BUTTON_COOLDOWN) {
            lastAction2Trigger = System.currentTimeMillis();
            PlayerEntity player = Minecraft.getInstance().player;
            if (player.isAlive()) {
                FactionPlayerHandler.getOpt(player).ifPresent(factionHandler -> factionHandler.getCurrentFactionPlayer().ifPresent(factionPlayer -> toggleBoundAction(factionPlayer, factionHandler.getBoundAction(2))));
            }
        }
    } else if (keyPressed == KEY.ACTION3) {
        long t = System.currentTimeMillis();
        if (t - lastAction3Trigger > ACTION_BUTTON_COOLDOWN) {
            lastAction3Trigger = System.currentTimeMillis();
            PlayerEntity player = Minecraft.getInstance().player;
            if (player.isAlive()) {
                FactionPlayerHandler.getOpt(player).ifPresent(factionHandler -> factionHandler.getCurrentFactionPlayer().ifPresent(factionPlayer -> toggleBoundAction(factionPlayer, factionHandler.getBoundAction(3))));
            }
        }
    } else if (keyPressed == KEY.MINION) {
        if (FactionPlayerHandler.getOpt(Minecraft.getInstance().player).map(FactionPlayerHandler::getLordLevel).orElse(0) > 0) {
            Minecraft.getInstance().setScreen(new SelectMinionTaskScreen());
        }
    }
    if (suckKeyDown && !SUCK.isDown()) {
        suckKeyDown = false;
        VampirismMod.dispatcher.sendToServer(new CSimpleInputEvent(CSimpleInputEvent.Type.FINISH_SUCK_BLOOD));
    }
}
Also used : IPlayableFaction(de.teamlapen.vampirism.api.entity.factions.IPlayableFaction) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) CSimpleInputEvent(de.teamlapen.vampirism.network.CSimpleInputEvent) InputMappings(net.minecraft.client.util.InputMappings) CToggleActionPacket(de.teamlapen.vampirism.network.CToggleActionPacket) ClientRegistry(net.minecraftforge.fml.client.registry.ClientRegistry) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) Dist(net.minecraftforge.api.distmarker.Dist) SelectMinionTaskScreen(de.teamlapen.vampirism.client.gui.SelectMinionTaskScreen) RayTraceResult(net.minecraft.util.math.RayTraceResult) Minecraft(net.minecraft.client.Minecraft) FactionPlayerHandler(de.teamlapen.vampirism.entity.factions.FactionPlayerHandler) EntityRayTraceResult(net.minecraft.util.math.EntityRayTraceResult) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) CStartFeedingPacket(de.teamlapen.vampirism.network.CStartFeedingPacket) VampireActions(de.teamlapen.vampirism.player.vampire.actions.VampireActions) PlayerEntity(net.minecraft.entity.player.PlayerEntity) VampirePlayer(de.teamlapen.vampirism.player.vampire.VampirePlayer) KeyBinding(net.minecraft.client.settings.KeyBinding) BlockPos(net.minecraft.util.math.BlockPos) VampirismMod(de.teamlapen.vampirism.VampirismMod) KeyModifier(net.minecraftforge.client.settings.KeyModifier) GLFW(org.lwjgl.glfw.GLFW) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) MinecraftForge(net.minecraftforge.common.MinecraftForge) Logger(org.apache.logging.log4j.Logger) IFactionPlayer(de.teamlapen.vampirism.api.entity.player.IFactionPlayer) IAction(de.teamlapen.vampirism.api.entity.player.actions.IAction) SelectActionScreen(de.teamlapen.vampirism.client.gui.SelectActionScreen) KeyConflictContext(net.minecraftforge.client.settings.KeyConflictContext) InputEvent(net.minecraftforge.client.event.InputEvent) LogManager(org.apache.logging.log4j.LogManager) VampirismPlayerAttributes(de.teamlapen.vampirism.player.VampirismPlayerAttributes) EntityRayTraceResult(net.minecraft.util.math.EntityRayTraceResult) CStartFeedingPacket(de.teamlapen.vampirism.network.CStartFeedingPacket) RayTraceResult(net.minecraft.util.math.RayTraceResult) EntityRayTraceResult(net.minecraft.util.math.EntityRayTraceResult) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) PlayerEntity(net.minecraft.entity.player.PlayerEntity) IPlayableFaction(de.teamlapen.vampirism.api.entity.factions.IPlayableFaction) SelectActionScreen(de.teamlapen.vampirism.client.gui.SelectActionScreen) CSimpleInputEvent(de.teamlapen.vampirism.network.CSimpleInputEvent) BlockPos(net.minecraft.util.math.BlockPos) SelectMinionTaskScreen(de.teamlapen.vampirism.client.gui.SelectMinionTaskScreen) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 2 with InputEvent

use of net.minecraftforge.client.event.InputEvent in project Werewolves by TeamLapen.

the class ModKeys method handleInputEvent.

@SubscribeEvent
public void handleInputEvent(InputEvent event) {
    Optional<KeyBinding> keyOpt = getPressedKeyBinding();
    keyOpt.ifPresent(key -> {
        PlayerEntity player = Minecraft.getInstance().player;
        LazyOptional<WerewolfPlayer> werewolfOpt = WerewolfPlayer.getOptEx(Minecraft.getInstance().player);
        if (key == LEAP) {
            werewolfOpt.filter(w -> !w.getActionHandler().isActionOnCooldown(ModActions.leap) && w.getForm().isTransformed()).ifPresent(w -> {
                WerewolvesMod.dispatcher.sendToServer(new InputEventPacket(InputEventPacket.LEAP, ""));
                WerewolfPlayer.get(player).getActionHandler().toggleAction(ModActions.leap);
            });
        } else if (key == BITE) {
            werewolfOpt.ifPresent(werewolf -> {
                RayTraceResult mouseOver = Minecraft.getInstance().hitResult;
                Entity entity = mouseOver instanceof EntityRayTraceResult ? ((EntityRayTraceResult) mouseOver).getEntity() : null;
                if (entity instanceof LivingEntity && werewolf.canBite() && werewolf.canBiteEntity(((LivingEntity) entity))) {
                    WerewolvesMod.dispatcher.sendToServer(new InputEventPacket(InputEventPacket.BITE, "" + ((EntityRayTraceResult) mouseOver).getEntity().getId()));
                    clientEventHandler.onZoomPressed();
                }
            });
        }
    });
}
Also used : Entity(net.minecraft.entity.Entity) ModActions(de.teamlapen.werewolves.core.ModActions) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) InputEventPacket(de.teamlapen.werewolves.network.InputEventPacket) InputMappings(net.minecraft.client.util.InputMappings) KeyBinding(net.minecraft.client.settings.KeyBinding) KeyModifier(net.minecraftforge.client.settings.KeyModifier) ClientRegistry(net.minecraftforge.fml.client.registry.ClientRegistry) GLFW(org.lwjgl.glfw.GLFW) LazyOptional(net.minecraftforge.common.util.LazyOptional) RayTraceResult(net.minecraft.util.math.RayTraceResult) MinecraftForge(net.minecraftforge.common.MinecraftForge) Minecraft(net.minecraft.client.Minecraft) WerewolfPlayer(de.teamlapen.werewolves.entities.player.werewolf.WerewolfPlayer) EntityRayTraceResult(net.minecraft.util.math.EntityRayTraceResult) Optional(java.util.Optional) WerewolvesMod(de.teamlapen.werewolves.WerewolvesMod) KeyConflictContext(net.minecraftforge.client.settings.KeyConflictContext) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) InputEvent(net.minecraftforge.client.event.InputEvent) LivingEntity(net.minecraft.entity.LivingEntity) KeyBinding(net.minecraft.client.settings.KeyBinding) WerewolfPlayer(de.teamlapen.werewolves.entities.player.werewolf.WerewolfPlayer) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) EntityRayTraceResult(net.minecraft.util.math.EntityRayTraceResult) RayTraceResult(net.minecraft.util.math.RayTraceResult) EntityRayTraceResult(net.minecraft.util.math.EntityRayTraceResult) InputEventPacket(de.teamlapen.werewolves.network.InputEventPacket) PlayerEntity(net.minecraft.entity.player.PlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

Minecraft (net.minecraft.client.Minecraft)2 KeyBinding (net.minecraft.client.settings.KeyBinding)2 InputMappings (net.minecraft.client.util.InputMappings)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 EntityRayTraceResult (net.minecraft.util.math.EntityRayTraceResult)2 RayTraceResult (net.minecraft.util.math.RayTraceResult)2 InputEvent (net.minecraftforge.client.event.InputEvent)2 KeyConflictContext (net.minecraftforge.client.settings.KeyConflictContext)2 KeyModifier (net.minecraftforge.client.settings.KeyModifier)2 MinecraftForge (net.minecraftforge.common.MinecraftForge)2 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)2 ClientRegistry (net.minecraftforge.fml.client.registry.ClientRegistry)2 GLFW (org.lwjgl.glfw.GLFW)2 VampirismMod (de.teamlapen.vampirism.VampirismMod)1 IPlayableFaction (de.teamlapen.vampirism.api.entity.factions.IPlayableFaction)1 IFactionPlayer (de.teamlapen.vampirism.api.entity.player.IFactionPlayer)1 IAction (de.teamlapen.vampirism.api.entity.player.actions.IAction)1 SelectActionScreen (de.teamlapen.vampirism.client.gui.SelectActionScreen)1 SelectMinionTaskScreen (de.teamlapen.vampirism.client.gui.SelectMinionTaskScreen)1 FactionPlayerHandler (de.teamlapen.vampirism.entity.factions.FactionPlayerHandler)1