Jump to content

Recommended Posts

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

 

Posted

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.

Posted

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

 

Posted

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

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...

×   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.

Announcements



×
×
  • Create New...

Important Information

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