|
1 | 1 | package org.cyclops.structuredcrafting.craft; |
2 | 2 |
|
3 | | -import com.google.common.cache.CacheBuilder; |
4 | | -import com.google.common.cache.CacheLoader; |
5 | | -import com.google.common.cache.LoadingCache; |
6 | 3 | import com.google.common.collect.Lists; |
7 | 4 | import com.google.common.collect.Maps; |
8 | | -import com.google.common.util.concurrent.UncheckedExecutionException; |
9 | 5 | import lombok.ToString; |
10 | | -import net.minecraft.inventory.IInventory; |
11 | 6 | import net.minecraft.item.ItemStack; |
12 | 7 | import net.minecraft.item.crafting.IRecipe; |
13 | | -import net.minecraft.item.crafting.IRecipeSerializer; |
14 | 8 | import net.minecraft.item.crafting.IRecipeType; |
15 | 9 | import net.minecraft.util.Direction; |
16 | 10 | import net.minecraft.util.NonNullList; |
17 | | -import net.minecraft.util.ResourceLocation; |
18 | 11 | import net.minecraft.util.math.BlockPos; |
19 | 12 | import net.minecraft.world.World; |
20 | | -import net.minecraft.world.dimension.DimensionType; |
21 | | -import net.minecraft.world.server.ServerWorld; |
22 | | -import net.minecraftforge.common.DimensionManager; |
23 | | -import net.minecraftforge.fml.server.ServerLifecycleHooks; |
24 | | -import org.apache.commons.lang3.tuple.Pair; |
25 | 13 | import org.apache.logging.log4j.Level; |
| 14 | +import org.cyclops.cyclopscore.helper.CraftingHelpers; |
26 | 15 | import org.cyclops.structuredcrafting.StructuredCrafting; |
27 | 16 | import org.cyclops.structuredcrafting.block.BlockStructuredCrafter; |
28 | 17 | import org.cyclops.structuredcrafting.craft.provider.IItemStackProvider; |
29 | 18 | import org.cyclops.structuredcrafting.craft.provider.IItemStackProviderRegistry; |
30 | 19 |
|
31 | 20 | import java.util.List; |
32 | 21 | import java.util.Map; |
33 | | -import java.util.concurrent.ExecutionException; |
34 | | -import java.util.concurrent.TimeUnit; |
35 | 22 |
|
36 | 23 | /** |
37 | 24 | * A crafting matrix represented with blockstates. |
38 | 25 | * @author rubensworks |
39 | 26 | */ |
40 | 27 | public class WorldCraftingMatrix { |
41 | 28 |
|
42 | | - private static final LoadingCache<Pair<WorldInventoryCrafting, DimensionType>, IRecipe> CACHE_RECIPES = CacheBuilder.newBuilder() |
43 | | - .expireAfterWrite(1, TimeUnit.MINUTES).build(new CacheLoader<Pair<WorldInventoryCrafting, DimensionType>, IRecipe>() { |
44 | | - @Override |
45 | | - public IRecipe load(Pair<WorldInventoryCrafting, DimensionType> key) throws Exception { |
46 | | - ServerWorld world = DimensionManager.getWorld(ServerLifecycleHooks.getCurrentServer(), key.getRight(), false, false); |
47 | | - IRecipe recipe = world.getRecipeManager().getRecipe(IRecipeType.CRAFTING, key.getLeft(), world).orElse(null); |
48 | | - |
49 | | - if (recipe == null) { |
50 | | - recipe = NULL_RECIPE; |
51 | | - } |
52 | | - return recipe; |
53 | | - } |
54 | | - }); |
55 | | - // A dummy recipe that represents null, because guava's cache doesn't allow null entries. |
56 | | - private static final IRecipe NULL_RECIPE = new IRecipe() { |
57 | | - |
58 | | - @Override |
59 | | - public boolean matches(IInventory inv, World worldIn) { |
60 | | - return false; |
61 | | - } |
62 | | - |
63 | | - @Override |
64 | | - public ItemStack getCraftingResult(IInventory inv) { |
65 | | - return null; |
66 | | - } |
67 | | - |
68 | | - @Override |
69 | | - public boolean canFit(int width, int height) { |
70 | | - return false; |
71 | | - } |
72 | | - |
73 | | - @Override |
74 | | - public ItemStack getRecipeOutput() { |
75 | | - return null; |
76 | | - } |
77 | | - |
78 | | - @Override |
79 | | - public ResourceLocation getId() { |
80 | | - return null; |
81 | | - } |
82 | | - |
83 | | - @Override |
84 | | - public IRecipeSerializer<?> getSerializer() { |
85 | | - return null; |
86 | | - } |
87 | | - |
88 | | - @Override |
89 | | - public IRecipeType<?> getType() { |
90 | | - return null; |
91 | | - } |
92 | | - }; |
93 | | - |
94 | 29 | private final World world; |
95 | 30 | private final BlockPos centerPos; |
96 | 31 | private final Direction.Axis axis; |
@@ -254,15 +189,7 @@ public void setPosition(int i, int j, int rotation, BlockPos pos, IItemStackProv |
254 | 189 | } |
255 | 190 |
|
256 | 191 | protected IRecipe getRecipe(World world) { |
257 | | - try { |
258 | | - IRecipe recipe = CACHE_RECIPES.get(Pair.of(inventoryCrafting, world.getDimension().getType())); |
259 | | - if (recipe == NULL_RECIPE) { |
260 | | - recipe = null; |
261 | | - } |
262 | | - return recipe; |
263 | | - } catch (ExecutionException | UncheckedExecutionException e) { |
264 | | - return null; |
265 | | - } |
| 192 | + return CraftingHelpers.findRecipeCached(IRecipeType.CRAFTING, inventoryCrafting, world, true).orElse(null); |
266 | 193 | } |
267 | 194 |
|
268 | 195 | public ItemStack getOutput(World world) { |
|
0 commit comments