9
9
import com .google .gson .JsonObject ;
10
10
import dan200 .computercraft .shared .computer .core .ComputerFamily ;
11
11
import dan200 .computercraft .shared .computer .items .IComputerItem ;
12
+ import dan200 .computercraft .shared .computer .recipe .ComputerConvertRecipe ;
12
13
import dan200 .computercraft .shared .turtle .items .TurtleItemFactory ;
13
14
import dan200 .computercraft .shared .util .RecipeUtil ;
14
- import net .minecraft .inventory .InventoryCrafting ;
15
15
import net .minecraft .item .ItemStack ;
16
16
import net .minecraft .item .crafting .IRecipe ;
17
- import net .minecraft .item .crafting .Ingredient ;
18
- import net .minecraft .item .crafting .ShapedRecipes ;
19
17
import net .minecraft .util .JsonUtils ;
20
- import net .minecraft .util .NonNullList ;
21
- import net .minecraft .world .World ;
22
18
import net .minecraftforge .common .crafting .CraftingHelper ;
23
19
import net .minecraftforge .common .crafting .IRecipeFactory ;
24
20
import net .minecraftforge .common .crafting .JsonContext ;
25
21
26
22
import javax .annotation .Nonnull ;
27
23
28
- public class TurtleRecipe extends ShapedRecipes
24
+ public class TurtleRecipe extends ComputerConvertRecipe
29
25
{
30
- private final NonNullList <Ingredient > m_recipe ;
31
- private final ComputerFamily m_family ;
26
+ private final ComputerFamily family ;
32
27
33
- public TurtleRecipe ( String group , int width , int height , NonNullList < Ingredient > recipe , ComputerFamily family )
28
+ public TurtleRecipe ( String group , @ Nonnull CraftingHelper . ShapedPrimer primer , ComputerFamily family )
34
29
{
35
- super ( group , width , height , recipe , TurtleItemFactory .create ( -1 , null , -1 , family , null , null , 0 , null ) );
36
- m_recipe = recipe ;
37
- m_family = family ;
38
- }
39
-
40
- @ Override
41
- public boolean matches ( @ Nonnull InventoryCrafting _inventory , @ Nonnull World world )
42
- {
43
- return !getCraftingResult ( _inventory ).isEmpty ();
30
+ super ( group , primer , TurtleItemFactory .create ( -1 , null , -1 , family , null , null , 0 , null ) );
31
+ this .family = family ;
44
32
}
45
33
46
34
@ Nonnull
47
35
@ Override
48
- public ItemStack getCraftingResult ( @ Nonnull InventoryCrafting inventory )
36
+ protected ItemStack convert ( @ Nonnull ItemStack stack )
49
37
{
50
- // See if we match the recipe, and extract the input computercraft ID
51
- int computerID = -1 ;
52
- String label = null ;
53
- for ( int y = 0 ; y < 3 ; ++y )
54
- {
55
- for ( int x = 0 ; x < 3 ; ++x )
56
- {
57
- ItemStack item = inventory .getStackInRowAndColumn ( x , y );
58
- Ingredient target = m_recipe .get ( x + y * 3 );
59
-
60
- if ( item .getItem () instanceof IComputerItem )
61
- {
62
- IComputerItem itemComputer = (IComputerItem ) item .getItem ();
63
- if ( itemComputer .getFamily ( item ) != m_family ) return ItemStack .EMPTY ;
38
+ IComputerItem item = (IComputerItem ) stack .getItem ();
39
+ int computerID = item .getComputerID ( stack );
40
+ String label = item .getLabel ( stack );
64
41
65
- computerID = itemComputer .getComputerID ( item );
66
- label = itemComputer .getLabel ( item );
67
- }
68
- else if ( !target .apply ( item ) )
69
- {
70
- return ItemStack .EMPTY ;
71
- }
72
- }
73
- }
42
+ if ( family == ComputerFamily .Beginners ) computerID = -1 ;
74
43
75
- // Build a turtle with the same ID the computer had
76
- // Construct the new stack
77
- if ( m_family != ComputerFamily .Beginners )
78
- {
79
- return TurtleItemFactory .create ( computerID , label , -1 , m_family , null , null , 0 , null );
80
- }
81
- else
82
- {
83
- return TurtleItemFactory .create ( -1 , label , -1 , m_family , null , null , 0 , null );
84
- }
44
+ return TurtleItemFactory .create ( computerID , label , -1 , family , null , null , 0 , null );
85
45
}
86
46
87
47
public static class Factory implements IRecipeFactory
@@ -92,7 +52,8 @@ public IRecipe parse( JsonContext context, JsonObject json )
92
52
String group = JsonUtils .getString ( json , "group" , "" );
93
53
ComputerFamily family = RecipeUtil .getFamily ( json , "family" );
94
54
CraftingHelper .ShapedPrimer primer = RecipeUtil .getPrimer ( context , json );
95
- return new TurtleRecipe ( group , primer .width , primer .height , primer .input , family );
55
+
56
+ return new TurtleRecipe ( group , primer , family );
96
57
}
97
58
}
98
59
}
0 commit comments