Skip to content

Commit

Permalink
添加:白菜猪肉馅包子 数据组件eat和条件食物
Browse files Browse the repository at this point in the history
  • Loading branch information
MCZME committed Sep 15, 2024
1 parent f4b5261 commit 69977db
Show file tree
Hide file tree
Showing 18 changed files with 190 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/generated/resources/assets/lingshi/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "米饭",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "lingshi:item/buns_filled_with_cabbage_and_pork"
}
}
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
9 changes: 3 additions & 6 deletions src/generated/resources/data/lingshi/recipe/bean.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
}
48 changes: 48 additions & 0 deletions src/main/java/mczme/lingshi/common/datacomponent/Eat.java
Original file line number Diff line number Diff line change
@@ -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<Eat> BASIC_CODEC = RecordCodecBuilder.create(instance ->
instance.group(
Codec.BOOL.fieldOf("getEat").forGetter(Eat::getEat)
).apply(instance, Eat::new)
);
public static final StreamCodec<ByteBuf, Eat> 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;
}
}

}
35 changes: 35 additions & 0 deletions src/main/java/mczme/lingshi/common/item/ConditionalFood.java
Original file line number Diff line number Diff line change
@@ -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<ItemStack> 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));
}
}

}
23 changes: 23 additions & 0 deletions src/main/java/mczme/lingshi/common/registry/ModDataComponents.java
Original file line number Diff line number Diff line change
@@ -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<?>, DataComponentType<Eat>> EAT = REGISTRAR.registerComponentType(
"eat",
builder -> builder
.persistent(Eat.BASIC_CODEC)
.networkSynchronized(Eat.BASIC_STREAM_CODEC)
);

public static void register(IEventBus modEventBus) {
REGISTRAR.register(modEventBus);
}
}
2 changes: 2 additions & 0 deletions src/main/java/mczme/lingshi/common/registry/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public class ModItems {
public static final Supplier<Item> 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<Item> 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<Item> 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)
Expand Down
1 change: 1 addition & 0 deletions src/main/java/mczme/lingshi/data/ItemModels.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),"满足");

Expand Down
13 changes: 10 additions & 3 deletions src/main/java/mczme/lingshi/data/recipe/CraftingRecipeDataGen.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}

}
1 change: 1 addition & 0 deletions src/main/java/mczme/lingshi/lingshi.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public lingshi(IEventBus modEventBus, ModContainer modContainer)
ModMenuTypes.register(modEventBus);
ModFluids.register(modEventBus);
ModEffects.register(modEventBus);
ModDataComponents.register(modEventBus);

IndependentEvent.register();

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/assets/lingshi/textures/item/soybean_milk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 69977db

Please sign in to comment.