Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

KeyBinding.isPressed() fires every tick


Recommended Posts

help, .isPressed() is not working right for me, it fires every tick, like if it was .isKeyDown()

heres my code:

@Mod.EventBusSubscriber(modid = DannysExpansion.MOD_ID, value = Dist.CLIENT)
public class ModKeybinds {

    @SubscribeEvent
    public static void keyEvent(TickEvent.ClientTickEvent event) {
        PlayerEntity player = Minecraft.getInstance().player;
        GameSettings settings = Minecraft.getInstance().gameSettings;

        if (player != null) {
            if(event.phase.equals(TickEvent.Phase.END) && Minecraft.getInstance().isGameFocused()) {
                if (isWearingAntiqueArmor(player)) {
                    if (settings.keyBindForward.isPressed()) {
                        ClientInstance.player().sendChatMessage("asd");
                        NetworkUtil.notifyAntiqueArmor(0);
                    } else if (settings.keyBindBack.isPressed()) {
                        NetworkUtil.notifyAntiqueArmor(1);
                    } else if (settings.keyBindRight.isPressed()) {
                        NetworkUtil.notifyAntiqueArmor(2);
                    } else if (settings.keyBindLeft.isPressed()) {
                        NetworkUtil.notifyAntiqueArmor(3);
                    }
                }
            }
        }
    }

    public static boolean isWearingAntiqueArmor(PlayerEntity player) {
        return  player.getItemStackFromSlot(EquipmentSlotType.HEAD).getItem() == ModItems.ANTIQUE_ARMOR_HELMET.get() &&
                player.getItemStackFromSlot(EquipmentSlotType.CHEST).getItem() == ModItems.ANTIQUE_ARMOR_CHESTPLATE.get() &&
                player.getItemStackFromSlot(EquipmentSlotType.LEGS).getItem() == ModItems.ANTIQUE_ARMOR_LEGGINGS.get() &&
                player.getItemStackFromSlot(EquipmentSlotType.FEET).getItem() == ModItems.ANTIQUE_ARMOR_BOOTS.get();
    }
}

 

Link to post
Share on other sites

hi, i tried this but i keep getting the same outcome

@Mod.EventBusSubscriber(modid = DannysExpansion.MOD_ID, value = Dist.CLIENT)
public class ModKeybinds {
  
    @SubscribeEvent(priority = EventPriority.LOW)
    public static void keyEvent(InputEvent.KeyInputEvent event) {
        PlayerEntity player = Minecraft.getInstance().player;
        GameSettings settings = Minecraft.getInstance().gameSettings;


        if (Minecraft.getInstance().isGameFocused() && isWearingAntiqueArmor(player)) {

            if (settings.keyBindForward.isPressed()) {
                NetworkUtil.notifyAntiqueArmor(0);
            } else if (settings.keyBindBack.isPressed()) {
                NetworkUtil.notifyAntiqueArmor(1);
            } else if (settings.keyBindRight.isPressed()) {
                NetworkUtil.notifyAntiqueArmor(2);
            } else if (settings.keyBindLeft.isPressed()) {
                NetworkUtil.notifyAntiqueArmor(3);
            }
        }
    }

    public static boolean isWearingAntiqueArmor(PlayerEntity player) {
        return  player.getItemStackFromSlot(EquipmentSlotType.HEAD).getItem() == ModItems.ANTIQUE_ARMOR_HELMET.get() &&
                player.getItemStackFromSlot(EquipmentSlotType.CHEST).getItem() == ModItems.ANTIQUE_ARMOR_CHESTPLATE.get() &&
                player.getItemStackFromSlot(EquipmentSlotType.LEGS).getItem() == ModItems.ANTIQUE_ARMOR_LEGGINGS.get() &&
                player.getItemStackFromSlot(EquipmentSlotType.FEET).getItem() == ModItems.ANTIQUE_ARMOR_BOOTS.get();
    }
}

 

Link to post
Share on other sites

I tried this and its the same outcome:

    @SubscribeEvent
    public static void keyEvent(TickEvent.ClientTickEvent event) {
        PlayerEntity player = Minecraft.getInstance().player;
        GameSettings settings = Minecraft.getInstance().gameSettings;

        if (event.phase.equals(TickEvent.Phase.END) && Minecraft.getInstance().isGameFocused() && isWearingAntiqueArmor(player)) {
            while(settings.keyBindForward.isPressed()) {
                NetworkUtil.notifyAntiqueArmor(0);
            }
            while(settings.keyBindBack.isPressed()) {
                NetworkUtil.notifyAntiqueArmor(1);
            }
            while(settings.keyBindRight.isPressed()) {
                NetworkUtil.notifyAntiqueArmor(2);
            }
            while(settings.keyBindLeft.isPressed()) {
                NetworkUtil.notifyAntiqueArmor(3);
            }
        }
    }

 

also, the inventory open action seems to be behaving in the same way, i think i should make my own checker for this

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.