13
13
import net .minecraft .recipe .*;
14
14
import net .minecraft .screen .ScreenHandler ;
15
15
import net .minecraft .text .Text ;
16
+ import net .minecraft .util .Identifier ;
16
17
import net .minecraft .util .ItemScatterer ;
17
18
import net .minecraft .util .collection .DefaultedList ;
18
19
import net .minecraft .util .math .BlockPos ;
19
20
import net .minecraft .util .math .Direction ;
21
+ import org .jetbrains .annotations .Nullable ;
20
22
21
23
import java .util .ArrayList ;
22
24
import java .util .List ;
25
+ import java .util .Map ;
23
26
import java .util .Optional ;
24
27
25
28
import static com .github .tatercertified .fabricautocrafter .AutoCrafterMod .TYPE ;
@@ -35,7 +38,7 @@ public class CraftingTableBlockEntity extends LockableContainerBlockEntity imple
35
38
private final CraftingInventory craftingInventory = new CraftingInventory (null , 3 , 3 );
36
39
public DefaultedList <ItemStack > inventory ;
37
40
public ItemStack output = ItemStack .EMPTY ;
38
- private Recipe <?> lastRecipe ;
41
+ private RecipeEntry <?> lastRecipe ;
39
42
40
43
public CraftingTableBlockEntity (BlockPos pos , BlockState state ) {
41
44
super (TYPE , pos , state );
@@ -162,36 +165,45 @@ public void provideRecipeInputs(RecipeMatcher finder) {
162
165
}
163
166
164
167
@ Override
165
- public void setLastRecipe (Recipe <?> recipe ) {
168
+ public void setLastRecipe (@ Nullable RecipeEntry <?> recipe ) {
166
169
lastRecipe = recipe ;
167
170
}
168
171
169
172
@ Override
170
- public Recipe <?> getLastRecipe () {
173
+ public RecipeEntry <?> getLastRecipe () {
171
174
return lastRecipe ;
172
175
}
173
176
177
+
178
+
174
179
@ Override
175
180
public void clear () {
176
181
this .inventory .clear ();
177
182
}
178
183
179
184
private Optional <CraftingRecipe > getCurrentRecipe () {
180
- //Optimization Code from Crec0
185
+ // Optimization Code from Crec0
181
186
if (this .world == null || this .isEmpty ()) return Optional .empty ();
182
187
183
- CraftingRecipe lastRecipe = (CraftingRecipe ) getLastRecipe ();
184
188
RecipeManager manager = this .world .getRecipeManager ();
185
189
186
- if (lastRecipe != null ) {
187
- CraftingRecipe mapRecipe = manager .getAllOfType (RecipeType .CRAFTING ).get (lastRecipe );
188
- if (mapRecipe != null && mapRecipe .matches (craftingInventory , world )) {
189
- return Optional .of (lastRecipe );
190
+ var getLastRecipe = getLastRecipe ();
191
+
192
+ if (getLastRecipe != null ) {
193
+ CraftingRecipe recipe = (CraftingRecipe ) getLastRecipe .value ();
194
+ Map <Identifier , RecipeEntry <CraftingRecipe >> craftingRecipes = manager .getAllOfType (RecipeType .CRAFTING );
195
+ if (craftingRecipes .containsKey (recipe ) && craftingRecipes .get (recipe ) != null ) {
196
+ CraftingRecipe mapRecipe = craftingRecipes .get (recipe ).value ();
197
+ if (mapRecipe != null && mapRecipe .matches (craftingInventory , world )) {
198
+ return Optional .of (recipe );
199
+ }
190
200
}
191
201
}
192
- Optional <CraftingRecipe > recipe = manager .getFirstMatch (RecipeType .CRAFTING , craftingInventory , world );
202
+
203
+ Optional <RecipeEntry <CraftingRecipe >> recipe = manager .getFirstMatch (RecipeType .CRAFTING , craftingInventory , world );
193
204
recipe .ifPresent (this ::setLastRecipe );
194
- return recipe ;
205
+
206
+ return recipe .map (RecipeEntry ::value );
195
207
}
196
208
197
209
private ItemStack craft () {
0 commit comments