Skip to content

Commit

Permalink
Fix log spam with multiple calls to combinedItemApiProvider (Fabric…
Browse files Browse the repository at this point in the history
…MC#3387)

(cherry picked from commit d6f4a34)
  • Loading branch information
Technici4n authored and modmuss50 committed Nov 2, 2023
1 parent 52b3ebe commit bb1ee60
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,14 @@ public Storage<FluidVariant> find(ItemStack itemStack, ContainerItemContext cont
}

public static Event<FluidStorage.CombinedItemApiProvider> getOrCreateItemEvent(Item item) {
// register here is thread-safe, so the query below will return a valid provider (possibly one registered before or from another thread).
FluidStorage.ITEM.registerForItems(new Provider(), item);
ItemApiLookup.ItemApiProvider<Storage<FluidVariant>, ContainerItemContext> existingProvider = FluidStorage.ITEM.getProvider(item);

if (existingProvider == null) {
FluidStorage.ITEM.registerForItems(new Provider(), item);
// The provider might not be new Provider() if a concurrent registration happened, re-query.
existingProvider = FluidStorage.ITEM.getProvider(item);
}

if (existingProvider instanceof Provider registeredProvider) {
return registeredProvider.event;
} else {
Expand Down

0 comments on commit bb1ee60

Please sign in to comment.