11package com .mrh0 .createaddition .recipe .rolling ;
22
3+ import com .mojang .serialization .Codec ;
4+ import com .mojang .serialization .MapCodec ;
5+ import com .mojang .serialization .codecs .RecordCodecBuilder ;
36import com .mrh0 .createaddition .compat .jei .RollingMillAssemblySubCategory ;
47import com .mrh0 .createaddition .index .CABlocks ;
58import com .mrh0 .createaddition .index .CARecipes ;
9+ import com .mrh0 .createaddition .recipe .liquid_burning .LiquidBurningRecipe ;
610import com .simibubi .create .compat .jei .category .sequencedAssembly .SequencedAssemblySubCategory ;
711import com .simibubi .create .content .processing .recipe .ProcessingOutput ;
812import com .simibubi .create .content .processing .recipe .ProcessingRecipe ;
913import com .simibubi .create .content .processing .sequenced .IAssemblyRecipe ;
14+ import com .simibubi .create .foundation .fluid .FluidIngredient ;
1015import net .minecraft .ChatFormatting ;
1116import net .minecraft .core .HolderLookup ;
1217import net .minecraft .core .RegistryAccess ;
18+ import net .minecraft .network .RegistryFriendlyByteBuf ;
1319import net .minecraft .network .chat .Component ;
20+ import net .minecraft .network .codec .StreamCodec ;
1421import net .minecraft .resources .ResourceLocation ;
1522import net .minecraft .world .item .ItemStack ;
1623import net .minecraft .world .item .crafting .Ingredient ;
1926import net .minecraft .world .level .ItemLike ;
2027import net .minecraft .world .level .Level ;
2128import net .neoforged .neoforge .items .wrapper .RecipeWrapper ;
29+ import org .jetbrains .annotations .NotNull ;
2230
2331import java .util .List ;
2432import java .util .Set ;
2533import java .util .function .Supplier ;
2634
2735public class RollingRecipe extends ProcessingRecipe <RecipeWrapper > implements IAssemblyRecipe {
2836 protected final ItemStack output ;
29- protected final ResourceLocation id ;
3037 protected final Ingredient ingredient ;
3138
32- protected RollingRecipe (Ingredient ingredient , ItemStack output , ResourceLocation id ) {
33- super (new RollingRecipeInfo (id , (SequencedAssemblyRollingRecipeSerializer ) CARecipes .ROLLING .get (), CARecipes .ROLLING_TYPE .get ()), new RollingMillRecipeParams (id , ingredient , new ProcessingOutput (output , 1f )));
39+ protected RollingRecipe (String group , Ingredient ingredient , ItemStack output ) {
40+ super (new RollingRecipeInfo ((SequencedAssemblyRollingRecipeSerializer ) CARecipes .ROLLING .get (), CARecipes .ROLLING_TYPE .get ()), new RollingMillRecipeParams (ingredient , new ProcessingOutput (output , 1f )));
3441 this .output = output ;
35- this .id = id ;
3642 this .ingredient = ingredient ;
3743 }
3844
@@ -44,7 +50,7 @@ public Ingredient getIngredient() {
4450 }
4551
4652 @ Override
47- public boolean matches (RecipeWrapper inv , Level worldIn ) {
53+ public boolean matches (RecipeWrapper inv , @ NotNull Level level ) {
4854 if (inv .isEmpty ()) return false ;
4955 return ingredient .test (inv .getItem (0 ));
5056 }
@@ -60,7 +66,7 @@ protected int getMaxOutputCount() {
6066 }
6167
6268 @ Override
63- public ItemStack assemble (RecipeWrapper recipeWrapper , HolderLookup .Provider provider ) {
69+ public @ NotNull ItemStack assemble (@ NotNull RecipeWrapper recipeWrapper , HolderLookup .@ NotNull Provider provider ) {
6470 return this .output ;
6571 }
6672
@@ -70,7 +76,7 @@ public boolean canCraftInDimensions(int width, int height) {
7076 }
7177
7278 @ Override
73- public ItemStack getResultItem (HolderLookup .Provider provider ) {
79+ public @ NotNull ItemStack getResultItem (HolderLookup .@ NotNull Provider provider ) {
7480 return this .output ;
7581 }
7682
@@ -79,26 +85,21 @@ public ItemStack getResultItem() {
7985 }
8086
8187 @ Override
82- public RecipeSerializer <?> getSerializer () {
88+ public @ NotNull RecipeSerializer <?> getSerializer () {
8389 return CARecipes .ROLLING .get ();
8490 }
8591
8692 @ Override
87- public RecipeType <?> getType () {
93+ public @ NotNull RecipeType <?> getType () {
8894 return CARecipes .ROLLING_TYPE .get ();
8995 }
9096
9197 @ Override
92- public ItemStack getToastSymbol () {
98+ public @ NotNull ItemStack getToastSymbol () {
9399 return this .output ;
94100 }
95101
96102 @ Override
97- public boolean isSpecial () {
98- return true ;
99- }
100-
101- @ Override
102103 public Component getDescriptionForAssembly () {
103104 return Component .translatable ("createaddition.recipe.rolling.sequence" ).withStyle (ChatFormatting .DARK_GREEN );
104105 }
@@ -117,4 +118,42 @@ public void addAssemblyIngredients(List<Ingredient> list) {
117118 public Supplier <Supplier <SequencedAssemblySubCategory >> getJEISubCategory () {
118119 return () -> RollingMillAssemblySubCategory ::new ;
119120 }
121+
122+ public static class Serializer implements RecipeSerializer <RollingRecipe > {
123+ private static final MapCodec <RollingRecipe > CODEC = RecordCodecBuilder .mapCodec (
124+ builder -> builder .group (
125+ Codec .STRING .optionalFieldOf ("group" , "" ).forGetter (RollingRecipe ::getGroup ),
126+ //CraftingBookCategory.CODEC.fieldOf("category").orElse(CraftingBookCategory.MISC).forGetter(ChargingRecipe::category),
127+ Ingredient .CODEC .fieldOf ("input" ).forGetter (r -> r .ingredient ),
128+ ItemStack .CODEC .optionalFieldOf ("result" , ItemStack .EMPTY ).forGetter (r -> r .output )
129+ ).apply (builder , RollingRecipe ::new )
130+ );
131+
132+ public static final StreamCodec <RegistryFriendlyByteBuf , RollingRecipe > STREAM_CODEC = StreamCodec .of (
133+ RollingRecipe .Serializer ::toNetwork , RollingRecipe .Serializer ::fromNetwork
134+ );
135+
136+ @ Override
137+ public MapCodec <RollingRecipe > codec () {
138+ return CODEC ;
139+ }
140+
141+ @ Override
142+ public StreamCodec <RegistryFriendlyByteBuf , RollingRecipe > streamCodec () {
143+ return STREAM_CODEC ;
144+ }
145+
146+ private static RollingRecipe fromNetwork (RegistryFriendlyByteBuf buffer ) {
147+ String group = buffer .readUtf ();
148+ ItemStack output = ItemStack .STREAM_CODEC .decode (buffer );
149+ Ingredient input = Ingredient .CONTENTS_STREAM_CODEC .decode (buffer );
150+ return new RollingRecipe (group , input , output );
151+ }
152+
153+ private static void toNetwork (RegistryFriendlyByteBuf buffer , RollingRecipe recipe ) {
154+ buffer .writeUtf (recipe .getGroup ());
155+ ItemStack .STREAM_CODEC .encode (buffer , recipe .output );
156+ Ingredient .CONTENTS_STREAM_CODEC .encode (buffer , recipe .ingredient );
157+ }
158+ }
120159}
0 commit comments