Iron's Spells 'n Spellbooks

Iron's Spells 'n Spellbooks

11M Downloads

Merchants don't restock when they should

ethan-sargent opened this issue ยท 1 comments

commented

if (hasDayElapsed) {
//update times
setLastRestockGameTime(currentGameTime);
setLastRestockCheckDayTime(currentDayTime);
setRestocksToday(0);
}
return this.needsToRestock() && allowedToRestock();
}
default void restock() {
for (MerchantOffer offer : getOffers()) {
offer.updateDemand();
offer.resetUses();
}
this.setRestocksToday(getRestocksToday() + 1);
}

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.

default boolean allowedToRestock() {
return getRestocksToday() == 0 && level().getGameTime() > getLastRestockGameTime() + 2400L;
}

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.

commented

fixed on 1.19 and 1.20