Better Questing - Quest Book

Better Questing - Quest Book

18M Downloads

Dual Wielding QuestBooks opens two Quest views

Drethic opened this issue ยท 10 comments

commented

If you have a QuestBook in each hand the Quest view logic is triggering twice.

  • Investigate a way to catch the second trigger
  • If needed, ask @Funwayguy to add a GUI API getter on GuiScreenThemed.parent to see if it's null or not to assist with the triggering
commented

You forgot to check the handedness here:
https://github.com/Drethic/QuestBook/blob/1.10.2/src/main/java/drethic/questbook/item/ItemQuestBook.java#L47

I suggest only opening the GUI if the book is in the player's main hand.

commented

@Funwayguy: It might make sense to limit players to one instance on BetterQuesting's end as well.

commented

The reason I didn't want to limit the book to opening to just one hand is I use books in both. Example is while running around in Botania I have the book in my left hand for reference and work with the flowers, wand, spreaders, etc with my right.

commented

@Drethic You could just make a check that the book in the offhand doesn't open if there's an existing book in the player's main hand. Minecraft also has a quick hand swap key so it's still not really a problem to just limit it to main hand and then swap back and forth with a single key press.

@WesCook Minecraft is in charge of opening UIs not me. If it's told to open something else (or the same thing) I can't do a lot to stop it. It's like asking asking a store for 2 of something and complaining because they let you buy more than 1.

commented

@Funwayguy I took an initial swing at limiting it if there is a book in the main hand as well. Not sure it's optimal code but it should work for now. I'll have to research to see if there is a better way to use the EnumHand than a switch case.

This seems like a lot of code for a simple if block:
https://github.com/Drethic/QuestBook/blob/dev-1.10/src/main/java/drethic/questbook/item/ItemQuestBook.java#L52-L61

commented

A switch statement for 2 values would generate a lot of code. You could grab the stack of both hands and xor them, so it should only open once regardless of hand state.

commented

The problem with xor based on the stack is the event is triggered twice and I can only tell which hand is actively trying to open the book based on the EnumHand value. So even if the player has a book in both hands I don't know if it's the first or second time I've seen the event without adding counting code which could add up to equal or exceed the switch code.

commented

Ah, gotchya. And you can't compare the events directly either.

Is it deterministic which hand fires first? eg. Assuming it's main hand, you could have it always open the GUI when used in the main hand. If opened from the offhand, check if the book is also in the main (and exit if so).

commented

I think I found it, the Enum Class has a .name() method which allows me to convert it from a constant to a string for comparison. That means I can then turn that whole block into a 3 line if statement. Hopefully that should catch all the edge cases for the duplicate GUI window.

commented

Fix released for 1.12, just need to back port it to 1.10 and 1.7.10