Search in sources :

Example 1 with SelectMinionTaskScreen

use of de.teamlapen.vampirism.client.gui.SelectMinionTaskScreen 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)

Aggregations

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 CSimpleInputEvent (de.teamlapen.vampirism.network.CSimpleInputEvent)1 CStartFeedingPacket (de.teamlapen.vampirism.network.CStartFeedingPacket)1 CToggleActionPacket (de.teamlapen.vampirism.network.CToggleActionPacket)1 VampirismPlayerAttributes (de.teamlapen.vampirism.player.VampirismPlayerAttributes)1 VampirePlayer (de.teamlapen.vampirism.player.vampire.VampirePlayer)1 VampireActions (de.teamlapen.vampirism.player.vampire.actions.VampireActions)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 Minecraft (net.minecraft.client.Minecraft)1 KeyBinding (net.minecraft.client.settings.KeyBinding)1 InputMappings (net.minecraft.client.util.InputMappings)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 BlockPos (net.minecraft.util.math.BlockPos)1