11package com .rae .creatingspace .content .recipes .air_liquefying ;
22
3- import com .google . gson . JsonObject ;
3+ import com .mojang . serialization . MapCodec ;
44import com .rae .creatingspace .init .RecipeInit ;
5+ import com .simibubi .create .content .kinetics .deployer .ItemApplicationRecipe ;
6+ import com .simibubi .create .content .kinetics .deployer .ItemApplicationRecipeParams ;
57import com .simibubi .create .content .processing .recipe .ProcessingRecipe ;
6- import com .simibubi .create .content .processing .recipe .ProcessingRecipeBuilder .ProcessingRecipeParams ;
8+ import com .simibubi .create .content .processing .recipe .ProcessingRecipeBuilder ;
9+ import com .simibubi .create .content .processing .recipe .ProcessingRecipeParams ;
710import com .simibubi .create .foundation .item .SmartInventory ;
811import com .simibubi .create .foundation .recipe .IRecipeTypeInfo ;
912import net .createmod .catnip .data .Iterate ;
1013import net .minecraft .core .registries .BuiltInRegistries ;
11- import net .minecraft .network .FriendlyByteBuf ;
14+ import net .minecraft .network .RegistryFriendlyByteBuf ;
15+ import net .minecraft .network .codec .StreamCodec ;
1216import net .minecraft .resources .ResourceLocation ;
1317import net .minecraft .world .item .crafting .Recipe ;
18+ import net .minecraft .world .item .crafting .RecipeSerializer ;
1419import net .minecraft .world .level .Level ;
1520import net .minecraft .world .level .block .Block ;
1621import net .minecraft .world .level .block .state .BlockState ;
1722import net .neoforged .neoforge .fluids .FluidStack ;
23+ import net .neoforged .neoforge .items .wrapper .RecipeWrapper ;
1824import org .jetbrains .annotations .NotNull ;
1925
20- import javax .annotation .Nonnull ;
2126import java .util .ArrayList ;
2227import java .util .List ;
2328
24- public class AirLiquefyingRecipe extends ProcessingRecipe <SmartInventory > {
29+ public class AirLiquefyingRecipe extends ProcessingRecipe <RecipeWrapper , AirLiquefyingRecipeParam > {
2530
26- private ResourceLocation blockInFront ;
27- private ResourceLocation dimension ;
31+ private final ResourceLocation blockInFront ;
32+ private final ResourceLocation dimension ;
2833
2934 public static boolean match (AirLiquefierBlockEntity airLiquefierBlockEntity , Recipe <?> recipe ) {
3035 return apply (airLiquefierBlockEntity , recipe , true );
@@ -40,7 +45,7 @@ private static boolean apply(AirLiquefierBlockEntity airLiquefierBlockEntity, Re
4045 BlockState state = airLiquefierBlockEntity .getBlockState ();
4146 BlockState targetedState = airLiquefierBlockEntity .getLevel ().getBlockState (airLiquefierBlockEntity .getBlockPos ().relative (state .getValue (AirLiquefierBlock .FACING )));
4247 Block block = BuiltInRegistries .BLOCK .get (airLiquefyingRecipe .getBlockInFront ());
43- if (block != null && !targetedState .is (block )) {
48+ if (!targetedState .is (block )) {
4449 return false ;
4550 }
4651 ResourceLocation currentDimension = airLiquefierBlockEntity .getLevel ().dimension ().location ();
@@ -69,9 +74,13 @@ private static boolean apply(AirLiquefierBlockEntity airLiquefierBlockEntity, Re
6974
7075 return true ;
7176 }
72-
73- protected AirLiquefyingRecipe (IRecipeTypeInfo type , ProcessingRecipeParams params ) {
77+ public AirLiquefyingRecipe (AirLiquefyingRecipeParam params ) {
78+ this (RecipeInit .AIR_LIQUEFYING , params );
79+ }
80+ protected AirLiquefyingRecipe (IRecipeTypeInfo type , AirLiquefyingRecipeParam params ) {
7481 super (type , params );
82+ blockInFront = params .blockInFront ;
83+ dimension = params .dimension ;
7584 }
7685
7786 public ResourceLocation getBlockInFront () {
@@ -92,9 +101,7 @@ protected int getMaxOutputCount() {
92101 return 0 ;
93102 }
94103
95- public AirLiquefyingRecipe (ProcessingRecipeParams params ) {
96- this (RecipeInit .AIR_LIQUEFYING , params );
97- }
104+
98105
99106 @ Override
100107 protected int getMaxFluidOutputCount () {
@@ -107,37 +114,51 @@ protected boolean canSpecifyDuration() {
107114 }
108115
109116 @ Override
110- public boolean matches (SmartInventory inv , @ Nonnull Level worldIn ) {
117+ public boolean matches (@ NotNull RecipeWrapper smartInventory , @ NotNull Level level ) {
111118 return false ;
112119 }
120+ @ FunctionalInterface
121+ public interface Factory <R extends AirLiquefyingRecipe > extends ProcessingRecipe .Factory <AirLiquefyingRecipeParam , R > {
122+ R create (AirLiquefyingRecipeParam params );
123+ }
113124
125+ public static class Builder <R extends AirLiquefyingRecipe > extends ProcessingRecipeBuilder <AirLiquefyingRecipeParam , R , AirLiquefyingRecipe .Builder <R >> {
126+ public Builder (AirLiquefyingRecipe .Factory <R > factory , ResourceLocation recipeId ) {
127+ super (factory , recipeId );
128+ }
114129
115-
116- @ Override
117- public void readAdditional (@ NotNull FriendlyByteBuf buffer ) {
118- super .readAdditional (buffer );
119- blockInFront = buffer .readResourceLocation ();
120- if (blockInFront .equals (ResourceLocation .parse ("minecraft:_" ))) {
121- blockInFront = null ;
130+ @ Override
131+ protected AirLiquefyingRecipeParam createParams () {
132+ return new AirLiquefyingRecipeParam ();
122133 }
123- dimension = buffer .readResourceLocation ();
124- if (dimension .equals (ResourceLocation .parse ("minecraft:_" ))) {
125- dimension = null ;
134+
135+ @ Override
136+ public AirLiquefyingRecipe .Builder <R > self () {
137+ return this ;
126138 }
139+
127140 }
128141
129- @ Override
130- public void writeAdditional (@ NotNull FriendlyByteBuf buffer ) {
131- super .writeAdditional (buffer );
132- if (blockInFront != null )
133- buffer .writeResourceLocation (blockInFront );
134- else {
135- buffer .writeResourceLocation (ResourceLocation .parse ("minecraft:_" ));
142+ public static class Serializer <R extends AirLiquefyingRecipe > implements RecipeSerializer <R > {
143+ private final MapCodec <R > codec ;
144+ private final StreamCodec <RegistryFriendlyByteBuf , R > streamCodec ;
145+
146+ public Serializer (ProcessingRecipe .Factory <AirLiquefyingRecipeParam , R > factory ) {
147+ this .codec = ProcessingRecipe .codec (factory , AirLiquefyingRecipeParam .CODEC );
148+ this .streamCodec = ProcessingRecipe .streamCodec (factory , AirLiquefyingRecipeParam .STREAM_CODEC );
149+ }
150+
151+ @ Override
152+ public MapCodec <R > codec () {
153+ return codec ;
136154 }
137- if ( dimension != null )
138- buffer . writeResourceLocation ( dimension );
139- else {
140- buffer . writeResourceLocation ( ResourceLocation . parse ( "minecraft:_" )) ;
155+
156+ @ Override
157+ public StreamCodec < RegistryFriendlyByteBuf , R > streamCodec () {
158+ return streamCodec ;
141159 }
160+
142161 }
162+
163+
143164}
0 commit comments