99import com .google .gson .JsonObject ;
1010import dan200 .computercraft .shared .computer .core .ComputerFamily ;
1111import dan200 .computercraft .shared .computer .items .IComputerItem ;
12+ import dan200 .computercraft .shared .computer .recipe .ComputerConvertRecipe ;
1213import dan200 .computercraft .shared .turtle .items .TurtleItemFactory ;
1314import dan200 .computercraft .shared .util .RecipeUtil ;
14- import net .minecraft .inventory .InventoryCrafting ;
1515import net .minecraft .item .ItemStack ;
1616import net .minecraft .item .crafting .IRecipe ;
17- import net .minecraft .item .crafting .Ingredient ;
18- import net .minecraft .item .crafting .ShapedRecipes ;
1917import net .minecraft .util .JsonUtils ;
20- import net .minecraft .util .NonNullList ;
21- import net .minecraft .world .World ;
2218import net .minecraftforge .common .crafting .CraftingHelper ;
2319import net .minecraftforge .common .crafting .IRecipeFactory ;
2420import net .minecraftforge .common .crafting .JsonContext ;
2521
2622import javax .annotation .Nonnull ;
2723
28- public class TurtleRecipe extends ShapedRecipes
24+ public class TurtleRecipe extends ComputerConvertRecipe
2925{
30- private final NonNullList <Ingredient > m_recipe ;
31- private final ComputerFamily m_family ;
26+ private final ComputerFamily family ;
3227
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 )
3429 {
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 ;
4432 }
4533
4634 @ Nonnull
4735 @ Override
48- public ItemStack getCraftingResult ( @ Nonnull InventoryCrafting inventory )
36+ protected ItemStack convert ( @ Nonnull ItemStack stack )
4937 {
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 );
6441
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 ;
7443
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 );
8545 }
8646
8747 public static class Factory implements IRecipeFactory
@@ -92,7 +52,8 @@ public IRecipe parse( JsonContext context, JsonObject json )
9252 String group = JsonUtils .getString ( json , "group" , "" );
9353 ComputerFamily family = RecipeUtil .getFamily ( json , "family" );
9454 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 );
9657 }
9758 }
9859}
0 commit comments