Skip to content

Commit

Permalink
add nutritionGainRate config
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuqi154 committed Jan 18, 2025
1 parent 513afdc commit 2e8c59d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

public class NutritionCapability implements NBTSerializable {

public static final float SCALE = 40.0f;

public record Nutrition(float fat , float carbohydrate, float protein , float vegetable){
public Nutrition(){
Expand Down Expand Up @@ -122,18 +121,24 @@ public void modifyNutrition(Player player, Nutrition nutrition) {
syncToClientOnRestore(player);
}

/**
* 如一个食物营养值为0.1,0,0,0.2,饱食度是4,那么这个食物给玩家增加的基础营养值就是0.1*4,0,0,0.2*4
* 再乘以营养增加比例,默认是40
* @param player 玩家
* @param food 食物
*/
public void eat(Player player, ItemStack food) {
if(!food.isEdible()) return;
Level level = player.level();
NutritionRecipe wRecipe = NutritionRecipe.getRecipeFromItem(level, food);
if(wRecipe == null) return;
int nutrition = food.getFoodProperties(player).getNutrition();
//因为只看食物自己的属性会比较低,加的点数不够一分钟的消耗,所以需要再乘一个系数
Nutrition n = wRecipe.getNutrition().scale(nutrition).scale(SCALE);
Nutrition recipeNutrition = wRecipe.getNutrition();
Nutrition n = recipeNutrition.scale(nutrition).scale(FHConfig.SERVER.nutritionGainRate.get());
modifyNutrition(player, n);
}

public void consume(Player player) {
// 这个比例可以放到Config里
float radio = - 0.1f * FHConfig.SERVER.nutritionConsumptionRate.get();

Nutrition nutrition = get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ public static class Server {
public final ForgeConfigSpec.ConfigValue<Integer> maxBodyTempChange;

public final ForgeConfigSpec.ConfigValue<Float> nutritionConsumptionRate;
public final ForgeConfigSpec.ConfigValue<Float> nutritionGainRate;


Server(ForgeConfigSpec.Builder builder) {
Expand Down Expand Up @@ -313,6 +314,8 @@ public static class Server {
.define("resetWaterLevelInDeath", true);
nutritionConsumptionRate = builder.comment("The rate of nutrition consumption.")
.define("nutritionConsumptionRate", 1.0f);
nutritionGainRate = builder.comment("The rate of nutrition gain by eating food.")
.define("nutritionGainRate", 40.0f);
builder.pop();

builder.push("Worldgen");
Expand Down

0 comments on commit 2e8c59d

Please sign in to comment.