Skip to content

Commit 28574ba

Browse files
committed
wip processing recipes porting
1 parent cd6c135 commit 28574ba

File tree

10 files changed

+128
-140
lines changed

10 files changed

+128
-140
lines changed

src/main/java/com/mrh0/createaddition/index/CARecipes.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import com.mrh0.createaddition.recipe.charging.ChargingRecipeSerializer;
77
import com.mrh0.createaddition.recipe.conditions.HasFluidTagCondition;
88
import com.mrh0.createaddition.recipe.liquid_burning.LiquidBurningRecipe;
9-
import com.mrh0.createaddition.recipe.liquid_burning.LiquidBurningRecipeSerializer;
109
import com.mrh0.createaddition.recipe.rolling.RollingRecipe;
1110
import com.mrh0.createaddition.recipe.rolling.RollingRecipeProcessingFactory;
1211
import com.mrh0.createaddition.recipe.rolling.SequencedAssemblyRollingRecipeSerializer;

src/main/java/com/mrh0/createaddition/recipe/FluidRecipeWrapper.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import net.minecraft.world.item.Items;
77
import net.minecraft.world.item.crafting.RecipeInput;
88
import net.neoforged.neoforge.fluids.FluidStack;
9+
import org.jetbrains.annotations.NotNull;
910

1011
public class FluidRecipeWrapper implements Container, RecipeInput {
1112

@@ -31,7 +32,7 @@ public boolean isEmpty() {
3132
}
3233

3334
@Override
34-
public ItemStack getItem(int p_70301_1_) {
35+
public @NotNull ItemStack getItem(int i) {
3536
return new ItemStack(Items.AIR);
3637
}
3738

@@ -41,25 +42,25 @@ public int size() {
4142
}
4243

4344
@Override
44-
public ItemStack removeItem(int p_70298_1_, int p_70298_2_) {
45+
public @NotNull ItemStack removeItem(int p_70298_1_, int p_70298_2_) {
4546
return new ItemStack(Items.AIR);
4647
}
4748

4849
@Override
49-
public ItemStack removeItemNoUpdate(int p_70304_1_) {
50+
public @NotNull ItemStack removeItemNoUpdate(int p_70304_1_) {
5051
return new ItemStack(Items.AIR);
5152
}
5253

5354
@Override
54-
public void setItem(int p_70299_1_, ItemStack p_70299_2_) {
55+
public void setItem(int p_70299_1_, @NotNull ItemStack stack) {
5556
}
5657

5758
@Override
5859
public void setChanged() {
5960
}
6061

6162
@Override
62-
public boolean stillValid(Player p_70300_1_) {
63+
public boolean stillValid(@NotNull Player player) {
6364
return true;
6465
}
6566

src/main/java/com/mrh0/createaddition/recipe/charging/ChargingRecipe.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,4 @@ private static void toNetwork(RegistryFriendlyByteBuf buffer, ChargingRecipe rec
122122
Ingredient.CONTENTS_STREAM_CODEC.encode(buffer, recipe.ingredient);
123123
}
124124
}
125-
126125
}
Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
11
package com.mrh0.createaddition.recipe.liquid_burning;
22

3+
import com.mojang.serialization.Codec;
4+
import com.mojang.serialization.MapCodec;
5+
import com.mojang.serialization.codecs.RecordCodecBuilder;
36
import com.mrh0.createaddition.CreateAddition;
47
import com.mrh0.createaddition.index.CARecipes;
58
import com.mrh0.createaddition.recipe.FluidRecipeWrapper;
9+
import com.mrh0.createaddition.recipe.charging.ChargingRecipe;
610
import com.simibubi.create.foundation.fluid.FluidIngredient;
711

812
import net.minecraft.core.HolderLookup;
913
import net.minecraft.core.Registry;
1014
import net.minecraft.core.RegistryAccess;
15+
import net.minecraft.network.RegistryFriendlyByteBuf;
16+
import net.minecraft.network.codec.StreamCodec;
1117
import net.minecraft.resources.ResourceLocation;
1218
import net.minecraft.world.item.ItemStack;
1319
import net.minecraft.world.item.Items;
20+
import net.minecraft.world.item.crafting.Ingredient;
1421
import net.minecraft.world.item.crafting.Recipe;
1522
import net.minecraft.world.item.crafting.RecipeSerializer;
1623
import net.minecraft.world.item.crafting.RecipeType;
1724
import net.minecraft.world.level.Level;
25+
import org.jetbrains.annotations.NotNull;
1826

1927
public class LiquidBurningRecipe implements Recipe<FluidRecipeWrapper> {
20-
21-
protected final ResourceLocation id;
2228
protected FluidIngredient fluidIngredients;
2329
protected int burnTime;
2430
protected boolean superheated;
2531

26-
@SuppressWarnings("deprecation")
27-
public LiquidBurningRecipe(ResourceLocation id, FluidIngredient fluid, int burnTime, boolean superheated) {
28-
this.id = id;
32+
public LiquidBurningRecipe(String group, FluidIngredient fluid, int burnTime, boolean superheated) {
2933
this.fluidIngredients = fluid;
3034
this.burnTime = burnTime;
3135
this.superheated = superheated;
3236
}
3337

3438
@Override
35-
public boolean matches(FluidRecipeWrapper wrapper, Level world) {
36-
if(fluidIngredients == null)
37-
return false;
38-
if(wrapper == null)
39-
return false;
40-
if(wrapper.fluid == null)
41-
return false;
39+
public boolean matches(@NotNull FluidRecipeWrapper wrapper, @NotNull Level world) {
40+
if(fluidIngredients == null) return false;
41+
if(wrapper.fluid == null) return false;
4242
return fluidIngredients.test(wrapper.fluid);
4343
}
4444

4545
@Override
46-
public ItemStack assemble(FluidRecipeWrapper fluidRecipeWrapper, HolderLookup.Provider provider) {
46+
public @NotNull ItemStack assemble(@NotNull FluidRecipeWrapper fluidRecipeWrapper, HolderLookup.@NotNull Provider provider) {
4747
return new ItemStack(Items.AIR);
4848
}
4949

@@ -53,17 +53,17 @@ public boolean canCraftInDimensions(int w, int h) {
5353
}
5454

5555
@Override
56-
public ItemStack getResultItem(HolderLookup.Provider provider) {
56+
public @NotNull ItemStack getResultItem(HolderLookup.@NotNull Provider provider) {
5757
return new ItemStack(Items.AIR);
5858
}
5959

6060
@Override
61-
public RecipeSerializer<?> getSerializer() {
61+
public @NotNull RecipeSerializer<?> getSerializer() {
6262
return CARecipes.LIQUID_BURNING.get();
6363
}
6464

6565
@Override
66-
public RecipeType<?> getType() {
66+
public @NotNull RecipeType<?> getType() {
6767
return CARecipes.LIQUID_BURNING_TYPE.get();
6868
}
6969

@@ -78,4 +78,45 @@ public int getBurnTime() {
7878
public boolean isSuperheated() {
7979
return this.superheated;
8080
}
81+
82+
public static class Serializer implements RecipeSerializer<LiquidBurningRecipe> {
83+
private static final MapCodec<LiquidBurningRecipe> CODEC = RecordCodecBuilder.mapCodec(
84+
builder -> builder.group(
85+
Codec.STRING.optionalFieldOf("group", "").forGetter(LiquidBurningRecipe::getGroup),
86+
//CraftingBookCategory.CODEC.fieldOf("category").orElse(CraftingBookCategory.MISC).forGetter(ChargingRecipe::category),
87+
FluidIngredient.CODEC.fieldOf("input").forGetter(r -> r.fluidIngredients),
88+
Codec.INT.optionalFieldOf("burnTime", 0).forGetter(r -> r.burnTime),
89+
Codec.BOOL.optionalFieldOf("superheated", false).forGetter(r -> r.superheated)
90+
).apply(builder, LiquidBurningRecipe::new)
91+
);
92+
93+
public static final StreamCodec<RegistryFriendlyByteBuf, LiquidBurningRecipe> STREAM_CODEC = StreamCodec.of(
94+
LiquidBurningRecipe.Serializer::toNetwork, LiquidBurningRecipe.Serializer::fromNetwork
95+
);
96+
97+
@Override
98+
public MapCodec<LiquidBurningRecipe> codec() {
99+
return CODEC;
100+
}
101+
102+
@Override
103+
public StreamCodec<RegistryFriendlyByteBuf, LiquidBurningRecipe> streamCodec() {
104+
return STREAM_CODEC;
105+
}
106+
107+
private static LiquidBurningRecipe fromNetwork(RegistryFriendlyByteBuf buffer) {
108+
String group = buffer.readUtf();
109+
boolean superheated = buffer.readBoolean();
110+
int burnTime = buffer.readInt();
111+
FluidIngredient input = FluidIngredient.STREAM_CODEC.decode(buffer);
112+
return new LiquidBurningRecipe(group, input, burnTime, superheated);
113+
}
114+
115+
private static void toNetwork(RegistryFriendlyByteBuf buffer, LiquidBurningRecipe recipe) {
116+
buffer.writeUtf(recipe.getGroup());
117+
buffer.writeBoolean(recipe.superheated);
118+
buffer.writeInt(recipe.burnTime);
119+
FluidIngredient.STREAM_CODEC.encode(buffer, recipe.fluidIngredients);
120+
}
121+
}
81122
}

src/main/java/com/mrh0/createaddition/recipe/liquid_burning/LiquidBurningRecipeSerializer.java

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/main/java/com/mrh0/createaddition/recipe/rolling/RollingMillRecipeParams.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.mrh0.createaddition.recipe.rolling;
22

3+
import com.mrh0.createaddition.CreateAddition;
34
import com.mrh0.createaddition.config.CommonConfig;
45
import com.simibubi.create.content.processing.recipe.HeatCondition;
56
import com.simibubi.create.content.processing.recipe.ProcessingOutput;

src/main/java/com/mrh0/createaddition/recipe/rolling/RollingRecipe.java

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
package 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;
36
import com.mrh0.createaddition.compat.jei.RollingMillAssemblySubCategory;
47
import com.mrh0.createaddition.index.CABlocks;
58
import com.mrh0.createaddition.index.CARecipes;
9+
import com.mrh0.createaddition.recipe.liquid_burning.LiquidBurningRecipe;
610
import com.simibubi.create.compat.jei.category.sequencedAssembly.SequencedAssemblySubCategory;
711
import com.simibubi.create.content.processing.recipe.ProcessingOutput;
812
import com.simibubi.create.content.processing.recipe.ProcessingRecipe;
913
import com.simibubi.create.content.processing.sequenced.IAssemblyRecipe;
14+
import com.simibubi.create.foundation.fluid.FluidIngredient;
1015
import net.minecraft.ChatFormatting;
1116
import net.minecraft.core.HolderLookup;
1217
import net.minecraft.core.RegistryAccess;
18+
import net.minecraft.network.RegistryFriendlyByteBuf;
1319
import net.minecraft.network.chat.Component;
20+
import net.minecraft.network.codec.StreamCodec;
1421
import net.minecraft.resources.ResourceLocation;
1522
import net.minecraft.world.item.ItemStack;
1623
import net.minecraft.world.item.crafting.Ingredient;
@@ -19,20 +26,19 @@
1926
import net.minecraft.world.level.ItemLike;
2027
import net.minecraft.world.level.Level;
2128
import net.neoforged.neoforge.items.wrapper.RecipeWrapper;
29+
import org.jetbrains.annotations.NotNull;
2230

2331
import java.util.List;
2432
import java.util.Set;
2533
import java.util.function.Supplier;
2634

2735
public 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

Comments
 (0)