-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cache for FoodValues during JEI plugin running
- Loading branch information
1 parent
5dae290
commit dd6c872
Showing
8 changed files
with
57 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/com/sihenzhang/crockpot/integration/jei/FoodValuesDefinitionCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.sihenzhang.crockpot.integration.jei; | ||
|
||
import com.sihenzhang.crockpot.base.FoodCategory; | ||
import com.sihenzhang.crockpot.recipe.FoodValuesDefinition; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.Level; | ||
|
||
import java.util.EnumMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class FoodValuesDefinitionCache { | ||
private static Map<FoodCategory, Set<ItemStack>> CACHE; | ||
|
||
private FoodValuesDefinitionCache() { | ||
} | ||
|
||
public static void regenerate(Level level) { | ||
var map = new EnumMap<FoodCategory, Set<ItemStack>>(FoodCategory.class); | ||
for (var category : FoodCategory.values()) { | ||
map.put(category, FoodValuesDefinition.getMatchedItems(category, level)); | ||
} | ||
CACHE = Map.copyOf(map); | ||
} | ||
|
||
public static Set<ItemStack> getMatchedItems(FoodCategory category) { | ||
var result = CACHE.get(category); | ||
if (result.isEmpty()) { | ||
return Set.of(); | ||
} | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters