Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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();
    }
}

 

Read the javadocs for the isKeyDown() and isPressed() methods of KeyBinding.  They make it pretty clear which of the two methods you should be using in a tick event handler.

  • Author

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();
    }
}

 

  • Author

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

  • Author

i want something that returns true only on the press action, seems that KeyBinding.isPressed() returns true on press, sets a timer of like 10 ticks and when that timer reach 0 it starts behaving like KeyBinding.isKeyDown()

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.