From 69977db16fd8262df3e8413b8a798047db2b511a Mon Sep 17 00:00:00 2001 From: MCZME <13183052+mczme@user.noreply.gitee.com> Date: Sun, 15 Sep 2024 12:03:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E7=99=BD=E8=8F=9C?= =?UTF-8?q?=E7=8C=AA=E8=82=89=E9=A6=85=E5=8C=85=E5=AD=90=20=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=BB=84=E4=BB=B6eat=E5=92=8C=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E9=A3=9F=E7=89=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../71e72dbdeb626cc835aaccd2ae47fd3d8794cd24 | 3 +- .../85f12f813aff948f91f5cd129c0ffa86bcb17361 | 4 +- .../9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e | 6 ++- .../resources/assets/lingshi/lang/zh_cn.json | 1 + .../buns_filled_with_cabbage_and_pork.json | 6 +++ .../buns_filled_with_cabbage_and_pork.json | 32 ++++++++++++ .../resources/data/lingshi/recipe/bean.json | 9 ++-- .../buns_filled_with_cabbage_and_pork.json | 19 +++++++ .../lingshi/common/datacomponent/Eat.java | 48 ++++++++++++++++++ .../lingshi/common/item/ConditionalFood.java | 35 +++++++++++++ .../common/registry/ModDataComponents.java | 23 +++++++++ .../lingshi/common/registry/ModItems.java | 2 + .../java/mczme/lingshi/data/ItemModels.java | 1 + .../data/lang/ChineseLanguageProvider.java | 1 + .../data/recipe/CraftingRecipeDataGen.java | 13 +++-- src/main/java/mczme/lingshi/lingshi.java | 1 + .../buns_filled_with_cabbage_and_pork.png | Bin 0 -> 298 bytes .../lingshi/textures/item/soybean_milk.png | Bin 324 -> 287 bytes 18 files changed, 190 insertions(+), 14 deletions(-) create mode 100644 src/generated/resources/assets/lingshi/models/item/buns_filled_with_cabbage_and_pork.json create mode 100644 src/generated/resources/data/lingshi/advancement/recipes/food/buns_filled_with_cabbage_and_pork.json create mode 100644 src/generated/resources/data/lingshi/recipe/buns_filled_with_cabbage_and_pork.json create mode 100644 src/main/java/mczme/lingshi/common/datacomponent/Eat.java create mode 100644 src/main/java/mczme/lingshi/common/item/ConditionalFood.java create mode 100644 src/main/java/mczme/lingshi/common/registry/ModDataComponents.java create mode 100644 src/main/resources/assets/lingshi/textures/item/buns_filled_with_cabbage_and_pork.png diff --git a/src/generated/resources/.cache/71e72dbdeb626cc835aaccd2ae47fd3d8794cd24 b/src/generated/resources/.cache/71e72dbdeb626cc835aaccd2ae47fd3d8794cd24 index 5583a95..fb113a4 100644 --- a/src/generated/resources/.cache/71e72dbdeb626cc835aaccd2ae47fd3d8794cd24 +++ b/src/generated/resources/.cache/71e72dbdeb626cc835aaccd2ae47fd3d8794cd24 @@ -1,5 +1,6 @@ -// 1.21 2024-09-13T20:55:00.8813781 Item Models: lingshi +// 1.21 2024-09-15T11:53:24.2777827 Item Models: lingshi 60ca0011c94253a1b7d4c3ca724eb58d73f18691 assets/lingshi/models/item/bean.json +2492a7d71c259c1b053586cd4c11190c2d9e85a0 assets/lingshi/models/item/buns_filled_with_cabbage_and_pork.json 14f86299910462582d98bcf699b35e34c615ee8e assets/lingshi/models/item/cabbage.json 0e18f939d46f6a164584f621fa97b024122785d9 assets/lingshi/models/item/cabbage_leaf.json 0bcbbc8c3377f7b20a37790cc33d36690c2044c7 assets/lingshi/models/item/cabbage_seed.json diff --git a/src/generated/resources/.cache/85f12f813aff948f91f5cd129c0ffa86bcb17361 b/src/generated/resources/.cache/85f12f813aff948f91f5cd129c0ffa86bcb17361 index 764de87..e2ad11d 100644 --- a/src/generated/resources/.cache/85f12f813aff948f91f5cd129c0ffa86bcb17361 +++ b/src/generated/resources/.cache/85f12f813aff948f91f5cd129c0ffa86bcb17361 @@ -1,2 +1,2 @@ -// 1.21 2024-09-13T20:55:00.8873792 Languages: zh_cn for mod: lingshi -2e1b4e1f1d8cbf6dafcf7443382ad9b22630f6c0 assets/lingshi/lang/zh_cn.json +// 1.21 2024-09-15T11:59:51.5147636 Languages: zh_cn for mod: lingshi +7f40641f62247679c64effe607911965a80fb96f assets/lingshi/lang/zh_cn.json diff --git a/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e b/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e index 8bf8572..966f416 100644 --- a/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e +++ b/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e @@ -1,4 +1,4 @@ -// 1.21 2024-09-13T20:55:00.8843819 Recipes +// 1.21 2024-09-15T11:59:51.5097641 Recipes b8cb7428b718c0ca190af49165cd25554d27fa19 data/lingshi/advancement/recipes/cooking_pot/cooked_rice.json 7d0ef4cd02c38f4648e712a935f0ea32fb50aeff data/lingshi/advancement/recipes/cooking_pot/cooked_rice_1.json d918a2369d899974ffa38d6a363553af9e97fdee data/lingshi/advancement/recipes/cooking_pot/cooked_rice_2.json @@ -13,6 +13,7 @@ b324dfe8c51c5f2f94e08473d966192d14d40c5a data/lingshi/advancement/recipes/cookin 0a4b54bfda8aa98f1a26bbf1d8231c76ed12e770 data/lingshi/advancement/recipes/decorations/skillet.json 129f0de548d7a7b62ee9dcaeb54da65d7095a009 data/lingshi/advancement/recipes/decorations/stove.json bb88842bdcc06e396f9884774adfe5f1291ac547 data/lingshi/advancement/recipes/food/bean.json +7923e34a9e332be9c998177df6224a46cb062ff7 data/lingshi/advancement/recipes/food/buns_filled_with_cabbage_and_pork.json e4ccb4f32d90b93ef63a3f2a17e843c6a8b2322b data/lingshi/advancement/recipes/skillet/baked_potato.json c9b88b929d6f4b7d68c10c6a3915182cb096d363 data/lingshi/advancement/recipes/skillet/cooked_beef.json 0235c27183fa0a2f93fdf2a6726f2f9d1acc95b7 data/lingshi/advancement/recipes/skillet/cooked_chicken.json @@ -29,7 +30,8 @@ e241bb59f1e7d265a9afbd0f38efdc05d5b325eb data/lingshi/advancement/recipes/skille 47116fef6fadd5ebb9231aee1717b2830949e776 data/lingshi/advancement/recipes/skillet/stewed_noodles.json 0e940fa2ba82aed478ee367c4b998f0bc7ead5c3 data/lingshi/advancement/recipes/tools/iron_knife.json e511f76246f906a279fc1ec531922d8f70dfb68c data/lingshi/advancement/recipes/tools/spatula.json -c2ef322f776e7c9d28a7a5c300dae408b2c81b98 data/lingshi/recipe/bean.json +788361cad718382ccd6e890edf01ed71c3a5a04b data/lingshi/recipe/bean.json +651470b8bb6f1d0f878fdc5351176d9e03beac6d data/lingshi/recipe/buns_filled_with_cabbage_and_pork.json bec1047337843fdd073fe87393c3b500ae11a1de data/lingshi/recipe/chopping_board.json 296eac908fe9bf9969c692bece480488e7d33676 data/lingshi/recipe/chopping_board/bean.json 85577ffce21473f6f122b7ef8a92eacaa2e5cfd2 data/lingshi/recipe/chopping_board/cabbage_leaf.json diff --git a/src/generated/resources/assets/lingshi/lang/zh_cn.json b/src/generated/resources/assets/lingshi/lang/zh_cn.json index 05dfd0d..a9ed58c 100644 --- a/src/generated/resources/assets/lingshi/lang/zh_cn.json +++ b/src/generated/resources/assets/lingshi/lang/zh_cn.json @@ -16,6 +16,7 @@ "effect.lingshi.gratification_effect": "满足", "gui.lingshi.cooking_pot_menu": "烹饪锅", "gui.lingshi.skillet_menu": "平底锅", + "item.lingshi.buns_filled_with_cabbage_and_pork": "白菜猪肉馅包子", "item.lingshi.cabbage": "白菜", "item.lingshi.cabbage_leaf": "白菜叶", "item.lingshi.cooked_rice": "米饭", diff --git a/src/generated/resources/assets/lingshi/models/item/buns_filled_with_cabbage_and_pork.json b/src/generated/resources/assets/lingshi/models/item/buns_filled_with_cabbage_and_pork.json new file mode 100644 index 0000000..c7b22e2 --- /dev/null +++ b/src/generated/resources/assets/lingshi/models/item/buns_filled_with_cabbage_and_pork.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "lingshi:item/buns_filled_with_cabbage_and_pork" + } +} \ No newline at end of file diff --git a/src/generated/resources/data/lingshi/advancement/recipes/food/buns_filled_with_cabbage_and_pork.json b/src/generated/resources/data/lingshi/advancement/recipes/food/buns_filled_with_cabbage_and_pork.json new file mode 100644 index 0000000..19fb739 --- /dev/null +++ b/src/generated/resources/data/lingshi/advancement/recipes/food/buns_filled_with_cabbage_and_pork.json @@ -0,0 +1,32 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_dough": { + "conditions": { + "items": [ + { + "items": "lingshi:dough" + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "lingshi:buns_filled_with_cabbage_and_pork" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_the_recipe", + "has_dough" + ] + ], + "rewards": { + "recipes": [ + "lingshi:buns_filled_with_cabbage_and_pork" + ] + } +} \ No newline at end of file diff --git a/src/generated/resources/data/lingshi/recipe/bean.json b/src/generated/resources/data/lingshi/recipe/bean.json index 44a792a..03164f7 100644 --- a/src/generated/resources/data/lingshi/recipe/bean.json +++ b/src/generated/resources/data/lingshi/recipe/bean.json @@ -1,13 +1,10 @@ { - "type": "minecraft:crafting_shaped", + "type": "minecraft:crafting_shapeless", "category": "misc", - "key": { - "A": { + "ingredients": [ + { "item": "lingshi:pod" } - }, - "pattern": [ - "A" ], "result": { "count": 1, diff --git a/src/generated/resources/data/lingshi/recipe/buns_filled_with_cabbage_and_pork.json b/src/generated/resources/data/lingshi/recipe/buns_filled_with_cabbage_and_pork.json new file mode 100644 index 0000000..c937c4c --- /dev/null +++ b/src/generated/resources/data/lingshi/recipe/buns_filled_with_cabbage_and_pork.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:crafting_shapeless", + "category": "misc", + "ingredients": [ + { + "item": "lingshi:dough" + }, + { + "item": "lingshi:sliced_pork" + }, + { + "tag": "neoforge:crops/cabbage" + } + ], + "result": { + "count": 4, + "id": "lingshi:buns_filled_with_cabbage_and_pork" + } +} \ No newline at end of file diff --git a/src/main/java/mczme/lingshi/common/datacomponent/Eat.java b/src/main/java/mczme/lingshi/common/datacomponent/Eat.java new file mode 100644 index 0000000..7df5ba8 --- /dev/null +++ b/src/main/java/mczme/lingshi/common/datacomponent/Eat.java @@ -0,0 +1,48 @@ +package mczme.lingshi.common.datacomponent; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import io.netty.buffer.ByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; + +import java.util.Objects; + +public class Eat { + + public boolean eat = false; + + public static final Codec BASIC_CODEC = RecordCodecBuilder.create(instance -> + instance.group( + Codec.BOOL.fieldOf("getEat").forGetter(Eat::getEat) + ).apply(instance, Eat::new) + ); + public static final StreamCodec BASIC_STREAM_CODEC = StreamCodec.composite( + ByteBufCodecs.BOOL, Eat::getEat, + Eat::new + ); + + public Eat(boolean eat) { + this.eat = eat; + } + + public Boolean getEat() { + return eat; + } + + @Override + public int hashCode() { + return Objects.hash(this.eat); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } else { + return obj instanceof Eat ex + && this.eat == ex.eat; + } + } + +} diff --git a/src/main/java/mczme/lingshi/common/item/ConditionalFood.java b/src/main/java/mczme/lingshi/common/item/ConditionalFood.java new file mode 100644 index 0000000..a7cedaf --- /dev/null +++ b/src/main/java/mczme/lingshi/common/item/ConditionalFood.java @@ -0,0 +1,35 @@ +package mczme.lingshi.common.item; + +import mczme.lingshi.common.datacomponent.Eat; +import mczme.lingshi.common.registry.ModDataComponents; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.food.FoodProperties; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; + +public class ConditionalFood extends Item { + public ConditionalFood(Properties pProperties) { + super(pProperties.component(ModDataComponents.EAT,new Eat(false))); + } + + @Override + public InteractionResultHolder use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) { + ItemStack itemstack = pPlayer.getItemInHand(pUsedHand); + FoodProperties foodproperties = itemstack.getFoodProperties(pPlayer); + Eat eat = itemstack.get(ModDataComponents.EAT); + if (foodproperties != null && eat != null && eat.getEat()) { + if (pPlayer.canEat(foodproperties.canAlwaysEat())) { + pPlayer.startUsingItem(pUsedHand); + return InteractionResultHolder.consume(itemstack); + } else { + return InteractionResultHolder.fail(itemstack); + } + } else { + return InteractionResultHolder.pass(pPlayer.getItemInHand(pUsedHand)); + } + } + +} diff --git a/src/main/java/mczme/lingshi/common/registry/ModDataComponents.java b/src/main/java/mczme/lingshi/common/registry/ModDataComponents.java new file mode 100644 index 0000000..a25bc24 --- /dev/null +++ b/src/main/java/mczme/lingshi/common/registry/ModDataComponents.java @@ -0,0 +1,23 @@ +package mczme.lingshi.common.registry; + +import mczme.lingshi.common.datacomponent.Eat; +import mczme.lingshi.lingshi; +import net.minecraft.core.component.DataComponentType; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.neoforge.registries.DeferredHolder; +import net.neoforged.neoforge.registries.DeferredRegister; + +public class ModDataComponents { + public static final DeferredRegister.DataComponents REGISTRAR = DeferredRegister.createDataComponents(lingshi.MODID); + + public static final DeferredHolder, DataComponentType> EAT = REGISTRAR.registerComponentType( + "eat", + builder -> builder + .persistent(Eat.BASIC_CODEC) + .networkSynchronized(Eat.BASIC_STREAM_CODEC) + ); + + public static void register(IEventBus modEventBus) { + REGISTRAR.register(modEventBus); + } +} diff --git a/src/main/java/mczme/lingshi/common/registry/ModItems.java b/src/main/java/mczme/lingshi/common/registry/ModItems.java index 77fde40..f5b29ea 100644 --- a/src/main/java/mczme/lingshi/common/registry/ModItems.java +++ b/src/main/java/mczme/lingshi/common/registry/ModItems.java @@ -68,6 +68,8 @@ public class ModItems { public static final Supplier SOYBEAN_MILK = registerWithCreateTab("soybean_milk", () -> new Item(new Item.Properties().food(new FoodProperties.Builder() .nutrition(4).saturationModifier(6f) .effect(()-> new MobEffectInstance(MobEffects.MOVEMENT_SPEED,5*20),1.0F).build()))); + public static final Supplier BUNS_FILLED_WITH_CABBAGE_AND_PORK = registerWithCreateTab("buns_filled_with_cabbage_and_pork", () -> new ConditionalFood(new Item.Properties().food(new FoodProperties.Builder() + .nutrition(8).saturationModifier(7.2f).build()))); //可放置食物 public static final Supplier PORK_FEET_RICE = registerWithCreateTab("pork_feet_rice", () -> new FoodBlockItem(ModBlocks.PORK_FEET_RICE.get(), new Item.Properties() .food(new FoodProperties.Builder().usingConvertsTo(Items.BOWL).nutrition(12).saturationModifier(9.4f) diff --git a/src/main/java/mczme/lingshi/data/ItemModels.java b/src/main/java/mczme/lingshi/data/ItemModels.java index a219ce2..83bfc5b 100644 --- a/src/main/java/mczme/lingshi/data/ItemModels.java +++ b/src/main/java/mczme/lingshi/data/ItemModels.java @@ -37,6 +37,7 @@ protected void registerModels() { basicItem(ModItems.SLICED_PORK.get()); basicItem(ModItems.SLICED_BEEF.get()); basicItem(ModItems.SOYBEAN_MILK.get()); + basicItem(ModItems.BUNS_FILLED_WITH_CABBAGE_AND_PORK.get()); basicItem(ModItems.OIL_BUCKET.get()); diff --git a/src/main/java/mczme/lingshi/data/lang/ChineseLanguageProvider.java b/src/main/java/mczme/lingshi/data/lang/ChineseLanguageProvider.java index f7f62b2..a812e0a 100644 --- a/src/main/java/mczme/lingshi/data/lang/ChineseLanguageProvider.java +++ b/src/main/java/mczme/lingshi/data/lang/ChineseLanguageProvider.java @@ -57,6 +57,7 @@ protected void addTranslations() { this.add(ModItems.SLICED_PORK.get(), "切好的猪肉"); this.add(ModItems.SLICED_BEEF.get(), "切好的牛肉"); this.add(ModItems.SOYBEAN_MILK.get(), "豆浆"); + this.add(ModItems.BUNS_FILLED_WITH_CABBAGE_AND_PORK.get(), "白菜猪肉馅包子"); this.add(ModEffects.GRATIFICATION_EFFECT.get(),"满足"); diff --git a/src/main/java/mczme/lingshi/data/recipe/CraftingRecipeDataGen.java b/src/main/java/mczme/lingshi/data/recipe/CraftingRecipeDataGen.java index 6c1e0e8..4e4eff1 100644 --- a/src/main/java/mczme/lingshi/data/recipe/CraftingRecipeDataGen.java +++ b/src/main/java/mczme/lingshi/data/recipe/CraftingRecipeDataGen.java @@ -1,9 +1,11 @@ package mczme.lingshi.data.recipe; import mczme.lingshi.common.registry.ModItems; +import mczme.lingshi.common.tag.NeoforgeTags; import net.minecraft.data.recipes.RecipeCategory; import net.minecraft.data.recipes.RecipeOutput; import net.minecraft.data.recipes.ShapedRecipeBuilder; +import net.minecraft.data.recipes.ShapelessRecipeBuilder; import net.minecraft.tags.ItemTags; import net.minecraft.world.item.Items; import net.neoforged.neoforge.common.Tags; @@ -76,11 +78,16 @@ protected void buildRecipes(RecipeOutput output) { .define('A', ItemTags.WOODEN_SLABS) .unlockedBy("has_glass_panes", has(Tags.Items.GLASS_PANES)) .save(output); - ShapedRecipeBuilder.shaped(RecipeCategory.FOOD, ModItems.BEAN.get()) - .pattern("A") - .define('A', ModItems.POD.get()) + ShapelessRecipeBuilder.shapeless(RecipeCategory.FOOD, ModItems.BEAN.get()) + .requires(ModItems.POD.get()) .unlockedBy("has_pod", has(ModItems.POD.get())) .save(output); + ShapelessRecipeBuilder.shapeless(RecipeCategory.FOOD, ModItems.BUNS_FILLED_WITH_CABBAGE_AND_PORK.get(),4) + .requires(ModItems.DOUGH.get()) + .requires(ModItems.SLICED_PORK.get()) + .requires(NeoforgeTags.CROPS_CABBAGE) + .unlockedBy("has_dough", has(ModItems.DOUGH.get())) + .save(output); } } diff --git a/src/main/java/mczme/lingshi/lingshi.java b/src/main/java/mczme/lingshi/lingshi.java index 4fa525a..eabe490 100644 --- a/src/main/java/mczme/lingshi/lingshi.java +++ b/src/main/java/mczme/lingshi/lingshi.java @@ -31,6 +31,7 @@ public lingshi(IEventBus modEventBus, ModContainer modContainer) ModMenuTypes.register(modEventBus); ModFluids.register(modEventBus); ModEffects.register(modEventBus); + ModDataComponents.register(modEventBus); IndependentEvent.register(); diff --git a/src/main/resources/assets/lingshi/textures/item/buns_filled_with_cabbage_and_pork.png b/src/main/resources/assets/lingshi/textures/item/buns_filled_with_cabbage_and_pork.png new file mode 100644 index 0000000000000000000000000000000000000000..dd93926349bd9b5b40adb3836bf9287ab096feff GIT binary patch literal 298 zcmV+_0oDGAP)H9m%$FX7G`IFjgOl$bD(baw#KP>PY;Dj0Gc2&J_b zW(WWAod5fBa^OFEW1~Q96v)1gw+jS#y}4p=ea>{)7l1~qt$ue)0~-Z0|6HOJ_{T@< zlIJnEDThi*l1c#%dom6u)QraX8vC`(VB>4z_mAuvrvRYYIs+h%XBb}tAhO-1X^K-| z!=9+>2>_$vn0oy*6V;5~5(gEYA3IVKxUR^H*0L$ziv(*E_Y?D1M0-pkqBYyzqNkl&87w{e)A;%JO z2#cH`okEJJSm>gSVb$F)&fu3q2*jEF0~UGZy!U?dW*|qZ+RgJzNmaWSgD!#;m9Mgl z(IVBG%E=a^$ied5zH{! delta 298 zcmV+_0oDGW0>lE4BYy!4Nkl^!4MN-~<31hc7&Q98$?g7_9)fYwvT_cou+qwKQ)Mq|L?Lu4A5|UM*#m zTI9S9($L8_MrXa6(*U57j~2|g?E?lw4L}^ns{^|I5k@PgKEUP8qolc&6K2;hPClu1 wg!}9BzrV5h^dm-->E6L`2T;^H&f$NAUxYe*30@)dEdT%j07*qoM6N<$f_Y<$3IG5A