From d4498692f5c6541460a1e59393bc4a0395477645 Mon Sep 17 00:00:00 2001 From: MCZME <13183052+mczme@user.noreply.gitee.com> Date: Fri, 16 Aug 2024 17:54:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E5=B9=B3=E5=BA=95?= =?UTF-8?q?=E9=94=85=E9=85=8D=E6=96=B9=E6=94=AF=E6=8C=81null?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e | 14 +++++++------- .../data/builder/SkilletRecipeBuilder.java | 18 ++++++++++++------ .../data/recipe/SkilletRecipeDatagen.java | 17 +++++++++-------- .../lingshi/common/recipe/SkilletRecipe.java | 12 +++++++++--- .../recipe/input/SkilletRecipeInput.java | 19 +++++++++++++------ .../serializer/SkilletRecipeSerializer.java | 14 +++++--------- .../lingshi/common/registry/ModItems.java | 6 ++++++ 7 files changed, 61 insertions(+), 39 deletions(-) diff --git a/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e b/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e index 9633c33..7db5031 100644 --- a/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e +++ b/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e @@ -1,8 +1,8 @@ -// 1.21 2024-08-16T05:17:35.2742695 Recipes -5bebf6a89fdd6614d0e0b2b0908f76f48afe8ad3 data/lingshi/advancement/recipes/skillet/test00.json -82ba2633d02b797c4ed89708055c8aab59a9cc39 data/lingshi/advancement/recipes/skillet/test01.json -b055e56217dec23b58a0c5f454e5dd060e0ed81a data/lingshi/advancement/recipes/skillet/test02.json +// 1.21 2024-08-16T17:52:52.2996317 Recipes +30317ddefa8c34feeae2fb9b47b40dae9a2c1335 data/lingshi/advancement/recipes/skillet/rice_apple.json +60b5c5b8536660e2fc3758499991b48002d68196 data/lingshi/advancement/recipes/skillet/test01.json +24367c601743c0d2f9df76c4a1e59f6650f0de4a data/lingshi/advancement/recipes/skillet/test02.json 3e41620c4ec5b19f87046dad7fe5c7ed6ede21c2 data/lingshi/recipe/chopping_board/rice.json -9622697bc2a3e83291b218d768aa2c1026c1d38f data/lingshi/recipe/skillet/test00.json -43b74387359bb0f936238fc99d5dce19aa60859a data/lingshi/recipe/skillet/test01.json -49673e41d352c946039d76d4a55b406153e7cc00 data/lingshi/recipe/skillet/test02.json +1268fc69304435f6b1c56650c7e2f8fcc9fe7e6e data/lingshi/recipe/skillet/rice_apple.json +c80602ecff2ea09399aff222a6d36c7b28d0164f data/lingshi/recipe/skillet/test01.json +89bc0e33a11e930f7b69c4d726d92b4f9446b3d3 data/lingshi/recipe/skillet/test02.json diff --git a/src/main/java/mczme/lingshi/common/data/builder/SkilletRecipeBuilder.java b/src/main/java/mczme/lingshi/common/data/builder/SkilletRecipeBuilder.java index 984fe36..c38a4a2 100644 --- a/src/main/java/mczme/lingshi/common/data/builder/SkilletRecipeBuilder.java +++ b/src/main/java/mczme/lingshi/common/data/builder/SkilletRecipeBuilder.java @@ -27,7 +27,8 @@ public class SkilletRecipeBuilder implements RecipeBuilder { private final List items; - private final List fluids; + private final FluidStack fluid; + private ItemStack container; private final ItemStack result; protected final Map> criteria = new LinkedHashMap<>(); @@ -35,9 +36,9 @@ public class SkilletRecipeBuilder implements RecipeBuilder { protected String group; protected CookingFoodRecipeLabel label; - public SkilletRecipeBuilder(List items, List fluids, ItemStack result) { + public SkilletRecipeBuilder(List items, FluidStack fluids, ItemStack result) { this.items = items; - this.fluids = fluids; + this.fluid = fluids; this.result = result; } @@ -54,7 +55,12 @@ public SkilletRecipeBuilder group(@Nullable String pGroupName) { } public SkilletRecipeBuilder setLabel(@Nullable CookingFoodRecipeLabel pLabelName) { - this.label=pLabelName; + this.label = pLabelName; + return this; + } + + public SkilletRecipeBuilder setContainer(ItemStack container) { + this.container = container; return this; } @@ -65,13 +71,13 @@ public Item getResult() { @Override public void save(RecipeOutput pRecipeOutput, ResourceLocation pId) { - ResourceLocation id = ResourceLocation.fromNamespaceAndPath(lingshi.MODID,"skillet/"+pId.getPath()); + ResourceLocation id = ResourceLocation.fromNamespaceAndPath(lingshi.MODID, "skillet/" + pId.getPath()); Advancement.Builder advancement = pRecipeOutput.advancement() .addCriterion("has_the_recipe", RecipeUnlockedTrigger.unlocked(id)) .rewards(AdvancementRewards.Builder.recipe(id)) .requirements(AdvancementRequirements.Strategy.OR); this.criteria.forEach(advancement::addCriterion); - SkilletRecipe recipe = new SkilletRecipe(this.items, this.fluids, this.result, Objects.requireNonNullElse(this.group, ""),Objects.requireNonNullElse(this.label,MISC)); + SkilletRecipe recipe = new SkilletRecipe(this.items, this.fluid, this.container, this.result, Objects.requireNonNullElse(this.group, ""), Objects.requireNonNullElse(this.label, MISC)); pRecipeOutput.accept(id, recipe, advancement.build(id.withPrefix("recipes/"))); } } diff --git a/src/main/java/mczme/lingshi/common/data/recipe/SkilletRecipeDatagen.java b/src/main/java/mczme/lingshi/common/data/recipe/SkilletRecipeDatagen.java index 520db55..c833fc5 100644 --- a/src/main/java/mczme/lingshi/common/data/recipe/SkilletRecipeDatagen.java +++ b/src/main/java/mczme/lingshi/common/data/recipe/SkilletRecipeDatagen.java @@ -17,15 +17,16 @@ public SkilletRecipeDatagen(RecipeOutput output) { } protected void buildRecipes(RecipeOutput output) { - build(List.of(Ingredient.of(Items.DIAMOND),Ingredient.of(Items.IRON_BLOCK)), List.of(), - new ItemStack(Items.APPLE.asItem()), output,"test00", CookingFoodRecipeLabel.PAN_FRY); - build(List.of(Ingredient.of(Items.GOLD_BLOCK),Ingredient.of(Items.IRON_BLOCK)), List.of(), - new ItemStack(Items.DIAMOND.asItem()), output,"test01",CookingFoodRecipeLabel.BOIL); - build(List.of(Ingredient.of(Items.DIAMOND_BLOCK),Ingredient.of(Items.MILK_BUCKET)), List.of(), - new ItemStack(Items.WHEAT.asItem()), output,"test02", CookingFoodRecipeLabel.HEAT); + build(List.of(Ingredient.of(ModItems.RICE.get())), null, new ItemStack(Items.APPLE.asItem())) + .setLabel(CookingFoodRecipeLabel.PAN_FRY) + .setContainer(new ItemStack(Items.BOWL)).save(output,"rice_apple"); + build(List.of(Ingredient.of(Items.GOLD_BLOCK),Ingredient.of(Items.IRON_BLOCK)), null, new ItemStack(Items.DIAMOND.asItem())) + .setLabel(CookingFoodRecipeLabel.BOIL).save(output,"test01"); + build(List.of(Ingredient.of(Items.DIAMOND_BLOCK),Ingredient.of(Items.MILK_BUCKET)), null, new ItemStack(Items.WHEAT.asItem())) + .setLabel(CookingFoodRecipeLabel.HEAT).save(output,"test02"); } - private void build(List items, List fluids, ItemStack result, RecipeOutput output, String pid, CookingFoodRecipeLabel label){ - new SkilletRecipeBuilder(items, fluids, result).setLabel(label).group("Skillet").setLabel(label).unlockedBy(result.toString(),Recipes.has(ModItems.SKILLET.get())).save(output,pid); + private SkilletRecipeBuilder build(List items, FluidStack fluid, ItemStack result){ + return new SkilletRecipeBuilder(items, fluid, result).group("Skillet"); } } diff --git a/src/main/java/mczme/lingshi/common/recipe/SkilletRecipe.java b/src/main/java/mczme/lingshi/common/recipe/SkilletRecipe.java index 92adc79..4dfce38 100644 --- a/src/main/java/mczme/lingshi/common/recipe/SkilletRecipe.java +++ b/src/main/java/mczme/lingshi/common/recipe/SkilletRecipe.java @@ -25,15 +25,17 @@ public class SkilletRecipe extends CookingFoodRecipe implements Recipe items; - private final List fluids; + private final FluidStack fluids; + private final ItemStack container; private final ItemStack result; final String group; - public SkilletRecipe(List items, List fluids, ItemStack result, String group, CookingFoodRecipeLabel label) { + public SkilletRecipe(List items, FluidStack fluids,ItemStack container, ItemStack result, String group, CookingFoodRecipeLabel label) { super(label); this.items = items; this.fluids = fluids; + this.container = container; this.result = result; this.group = group; } @@ -88,7 +90,7 @@ public ItemStack getResult() { return result; } - public List getFluids() { + public FluidStack getFluid() { return fluids; } @@ -96,6 +98,10 @@ public List getItems() { return items; } + public ItemStack getContainer() { + return container; + } + @Override public @NotNull String getGroup() { return this.group; diff --git a/src/main/java/mczme/lingshi/common/recipe/input/SkilletRecipeInput.java b/src/main/java/mczme/lingshi/common/recipe/input/SkilletRecipeInput.java index 86e3c97..e2927ea 100644 --- a/src/main/java/mczme/lingshi/common/recipe/input/SkilletRecipeInput.java +++ b/src/main/java/mczme/lingshi/common/recipe/input/SkilletRecipeInput.java @@ -9,11 +9,13 @@ public class SkilletRecipeInput implements RecipeInput { private final List items; - private final List fluids; + private final FluidStack fluids; + private final ItemStack container; - public SkilletRecipeInput(List items, List fluids) { + public SkilletRecipeInput(List items, FluidStack fluid, ItemStack container) { this.items = items; - this.fluids = fluids; + this.fluids = fluid; + this.container = container; } @Override @@ -21,13 +23,18 @@ public ItemStack getItem(int pIndex) { return this.items.get(pIndex); } - public FluidStack getFluid(int pIndex) { - return this.fluids.get(pIndex); + public FluidStack getFluid() { + return this.fluids; + } + + public ItemStack getContainer() { + return container; } @Override public int size() { - return items.size()+fluids.size(); + int i = fluids.isEmpty()?0:1; + return items.size()+i; } @Override diff --git a/src/main/java/mczme/lingshi/common/recipe/serializer/SkilletRecipeSerializer.java b/src/main/java/mczme/lingshi/common/recipe/serializer/SkilletRecipeSerializer.java index 05e1ae1..0afe249 100644 --- a/src/main/java/mczme/lingshi/common/recipe/serializer/SkilletRecipeSerializer.java +++ b/src/main/java/mczme/lingshi/common/recipe/serializer/SkilletRecipeSerializer.java @@ -20,27 +20,23 @@ public class SkilletRecipeSerializer implements RecipeSerializer public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(inst -> inst.group( Ingredient.CODEC.listOf().fieldOf("ingredients").forGetter(SkilletRecipe::getItems), - FluidStack.CODEC.listOf().fieldOf("fluids").forGetter(SkilletRecipe::getFluids), + FluidStack.OPTIONAL_CODEC.optionalFieldOf("fluid",null).forGetter(SkilletRecipe::getFluid), + ItemStack.OPTIONAL_CODEC.optionalFieldOf("container", null).forGetter(SkilletRecipe::getContainer), ItemStack.CODEC.fieldOf("result").forGetter(SkilletRecipe::getResult), Codec.STRING.fieldOf("group").forGetter(SkilletRecipe::getGroup), CookingFoodRecipeLabel.CODEC.fieldOf("label").forGetter(SkilletRecipe::getLabel) ).apply(inst, SkilletRecipe::new)); - public static final StreamCodec> FLUIDSTACK_STREAM_CODEC = - FluidStack.STREAM_CODEC.apply( - ByteBufCodecs.list(SkilletRecipe.MAX_SLOT) - ); public static final StreamCodec> INGREDIENT_STREAM_CODEC = - Ingredient.CONTENTS_STREAM_CODEC.apply( - ByteBufCodecs.list(SkilletRecipe.MAX_SLOT) - ); + Ingredient.CONTENTS_STREAM_CODEC.apply(ByteBufCodecs.list(SkilletRecipe.MAX_SLOT)); public static final StreamCodec CookingFoodLabel_STREAM_CODEC = StreamCodec.of(SkilletRecipeSerializer::encode,SkilletRecipeSerializer::decode); public static final StreamCodec STREAM_CODEC = StreamCodec.composite( INGREDIENT_STREAM_CODEC,SkilletRecipe::getItems, - FLUIDSTACK_STREAM_CODEC,SkilletRecipe::getFluids, + FluidStack.OPTIONAL_STREAM_CODEC,SkilletRecipe::getFluid, + ItemStack.OPTIONAL_STREAM_CODEC,SkilletRecipe::getContainer, ItemStack.STREAM_CODEC,SkilletRecipe::getResult, ByteBufCodecs.STRING_UTF8,SkilletRecipe::getGroup, CookingFoodLabel_STREAM_CODEC,SkilletRecipe::getLabel, diff --git a/src/main/java/mczme/lingshi/common/registry/ModItems.java b/src/main/java/mczme/lingshi/common/registry/ModItems.java index 59254fa..9db857d 100644 --- a/src/main/java/mczme/lingshi/common/registry/ModItems.java +++ b/src/main/java/mczme/lingshi/common/registry/ModItems.java @@ -29,12 +29,18 @@ public class ModItems { public static final Supplier IRON_KNIFE = registerWithCreateTab("iron_knife", () -> new KnifeItem(Tiers.IRON,new Item.Properties().attributes(SwordItem.createAttributes(Tiers.IRON, 3, -2.4F)))); + public static final Supplier EMPTY_BOWL = register("empty_bowl",()-> new Item(new Item.Properties())); + private static Supplier registerWithCreateTab(String item_name, Supplier itemSupplier) { Supplier item = ITEMS.register(item_name, itemSupplier); ITEMS_LIST.add(item); return item; } + private static Supplier register(String item_name, Supplier itemSupplier) { + return ITEMS.register(item_name, itemSupplier); + } + public static void register(IEventBus modEventBus) { ITEMS.register(modEventBus); }