iron431 / irons-spells-n-spellbooks

Other
77 stars 57 forks source link

Merchants don't restock when they should #508

Open ethan-sargent opened 1 month ago

ethan-sargent commented 1 month ago

https://github.com/iron431/irons-spells-n-spellbooks/blob/395a947c2702622c30731de2c90dfa50ab5c0dc7/src/main/java/io/redspace/ironsspellbooks/entity/mobs/wizards/IMerchantWizard.java#L73-L88

Sometimes when coming back to a merchant after a long time they still have not restocked.

This seems to be because the restock game time and restock day time are updated before the restock actually happens - then allowedToRestock() is called, which checks the new time and denies the restock.

https://github.com/iron431/irons-spells-n-spellbooks/blob/395a947c2702622c30731de2c90dfa50ab5c0dc7/src/main/java/io/redspace/ironsspellbooks/entity/mobs/wizards/IMerchantWizard.java#L46-L48

This means you have to restock at a particular time so that the restock time moves, and then check back quickly before hasDayElapsed becomes true again.

Suggested fix: update the times in restock() at the point of restocking, rather than in shouldRestock(), and only reset the restock counter to 0 in shouldrestock.

That way the time is reset once the restock actually happens, blocking the next restock for half a day from the point of restock as intended.

iron431 commented 1 month ago

fixed on 1.19 and 1.20