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
  • Loading branch information
Technici4n authored Nov 2, 2023
1 parent 6ed720c commit d6f4a34
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 d6f4a34

Please sign in to comment.