2626import dev .compactmods .crafting .util .BlockSpaceUtil ;
2727import dev .compactmods .crafting .util .CodecExtensions ;
2828import net .minecraft .advancements .critereon .ItemPredicate ;
29- import net .minecraft .core .registries .BuiltInRegistries ;
3029import net .minecraft .network .RegistryFriendlyByteBuf ;
3130import net .minecraft .network .codec .ByteBufCodecs ;
3231import net .minecraft .network .codec .StreamCodec ;
3332import net .minecraft .resources .ResourceLocation ;
34- import net .minecraft .world .item .Item ;
3533import net .minecraft .world .item .ItemStack ;
3634import net .minecraft .world .item .crafting .Recipe ;
3735import net .minecraft .world .item .crafting .RecipeHolder ;
5654public record MiniaturizationRecipe (
5755 TreeMap <Integer , IRecipeLayer > layers ,
5856 ItemPredicate catalystMatcher ,
59- List < ItemStack > catalystItems ,
57+ ItemStack catalyst ,
6058 ItemStack [] outputs ,
6159 AABB dimensions ,
6260 int requiredTime ,
@@ -73,21 +71,6 @@ public record MiniaturizationRecipe(
7371 public static final Codec <IRecipeComponent > COMPONENT_CODEC =
7472 RecipeComponentTypeCodec .INSTANCE .dispatchStable (IRecipeComponent ::getType , RecipeComponentType ::getCodec );
7573
76- private record CatalystData (ItemPredicate predicate , List <ItemStack > items ) {}
77-
78- private static final Codec <CatalystData > CATALYST_CODEC = RecordCodecBuilder .create (instance -> instance .group (
79- ResourceLocation .CODEC .listOf ().fieldOf ("items" ).forGetter (data -> data .items .stream ().map (stack -> net .minecraft .core .registries .BuiltInRegistries .ITEM .getKey (stack .getItem ())).toList ())
80- ).apply (instance , itemIds -> {
81- List <ItemStack > itemStacks = itemIds .stream ()
82- .map (id -> new ItemStack (BuiltInRegistries .ITEM .get (id )))
83- .toList ();
84-
85- ItemPredicate predicate = ItemPredicate .Builder .item ()
86- .of (itemStacks .stream ().map (ItemStack ::getItem ).toArray (Item []::new ))
87- .build ();
88-
89- return new CatalystData (predicate , itemStacks );
90- }));
9174
9275 public static final MapCodec <MiniaturizationRecipe > CODEC = RecordCodecBuilder .mapCodec (i -> i .group (
9376 Codec .INT .optionalFieldOf ("craftingTime" , 200 )
@@ -105,8 +88,8 @@ private record CatalystData(ItemPredicate predicate, List<ItemStack> items) {}
10588 ItemStack .STRICT_CODEC .listOf ().fieldOf ("outputs" )
10689 .forGetter (MiniaturizationRecipe ::codecOutputs ),
10790
108- CATALYST_CODEC .fieldOf ("catalyst" )
109- .forGetter (recipe -> new CatalystData ( recipe . catalystTest (), recipe . catalystItems ()) )
91+ ItemStack . STRICT_CODEC .fieldOf ("catalyst" )
92+ .forGetter (MiniaturizationRecipe :: catalyst )
11093
11194 ).apply (i , MiniaturizationRecipe ::fromCodec ));
11295
@@ -116,7 +99,7 @@ private record CatalystData(ItemPredicate predicate, List<ItemStack> items) {}
11699 ByteBufCodecs .fromCodec (LAYER_CODEC ).apply (ByteBufCodecs .list ()), MiniaturizationRecipe ::codecLayerList ,
117100 MiniaturizationRecipeComponents .STREAM_CODEC , MiniaturizationRecipe ::components ,
118101 ItemStack .LIST_STREAM_CODEC , MiniaturizationRecipe ::codecOutputs ,
119- ByteBufCodecs . fromCodecWithRegistries ( CATALYST_CODEC ), recipe -> new CatalystData ( recipe . catalystMatcher , recipe . catalystItems ) ,
102+ ItemStack . STREAM_CODEC , MiniaturizationRecipe :: catalyst ,
120103 MiniaturizationRecipe ::fromCodec
121104 );
122105
@@ -130,7 +113,7 @@ private record CatalystData(ItemPredicate predicate, List<ItemStack> items) {}
130113
131114 public static MiniaturizationRecipe fromCodec (int craftTime , int recipeSize , List <IRecipeLayer > layers ,
132115 MiniaturizationRecipeComponents components , List <ItemStack > outputs ,
133- CatalystData catalystData ) {
116+ ItemStack catalyst ) {
134117 var layers1 = new TreeMap <Integer , IRecipeLayer >();
135118
136119 // region Layers
@@ -196,7 +179,11 @@ public static MiniaturizationRecipe fromCodec(int craftTime, int recipeSize, Lis
196179 componentTotals .put (comp , count );
197180 });
198181
199- var recipe = new MiniaturizationRecipe (layers1 , catalystData .predicate (), catalystData .items (), outputs .toArray (new ItemStack [0 ]),
182+ ItemPredicate catalystPredicate = ItemPredicate .Builder .item ()
183+ .of (catalyst .getItem ())
184+ .build ();
185+
186+ var recipe = new MiniaturizationRecipe (layers1 , catalystPredicate , catalyst , outputs .toArray (new ItemStack [0 ]),
200187 recipeDims , craftTime , hasFixedFootprint ,
201188 componentTotals , components );
202189
0 commit comments