Skip to content

Commit

Permalink
changed to config
Browse files Browse the repository at this point in the history
  • Loading branch information
Globox1997 committed Jan 2, 2024
1 parent 6ae8bb6 commit 29e29f4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 27 deletions.
8 changes: 0 additions & 8 deletions src/main/java/net/nutritionz/NutritionMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@

public class NutritionMain implements ModInitializer {

public static int NUTRITION_MAX_VALUES;
public static int NUTRITION_NEGATIVE_VALUE;
public static int NUTRITION_POSITIVE_VALUE;

public static final HashMap<Item, List<Integer>> NUTRITION_ITEM_MAP = new HashMap<Item, List<Integer>>();
public static final HashMap<Integer, List<Object>> NUTRITION_POSITIVE_EFFECTS = new HashMap<Integer, List<Object>>();
public static final HashMap<Integer, List<Object>> NUTRITION_NEGATIVE_EFFECTS = new HashMap<Integer, List<Object>>();
Expand All @@ -26,10 +22,6 @@ public void onInitialize() {
LoaderInit.init();
NutritionServerPacket.init();
EventInit.init();

NUTRITION_MAX_VALUES = ConfigInit.CONFIG.maxNutrition;
NUTRITION_NEGATIVE_VALUE = ConfigInit.CONFIG.negativeNutrition;
NUTRITION_POSITIVE_VALUE = ConfigInit.CONFIG.positiveNutrition;
}

}
29 changes: 13 additions & 16 deletions src/main/java/net/nutritionz/mixin/HungerManagerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@
import net.minecraft.nbt.NbtCompound;
import net.nutritionz.NutritionMain;
import net.nutritionz.access.HungerManagerAccess;
import net.nutritionz.init.ConfigInit;

@Mixin(HungerManager.class)
public class HungerManagerMixin implements HungerManagerAccess {

private int carbohydrateLevel = NutritionMain.NUTRITION_MAX_VALUES;
private int proteinLevel = NutritionMain.NUTRITION_MAX_VALUES;
private int fatLevel = NutritionMain.NUTRITION_MAX_VALUES;
private int vitaminLevel = NutritionMain.NUTRITION_MAX_VALUES;
private int mineralLevel = NutritionMain.NUTRITION_MAX_VALUES;
private int carbohydrateLevel = ConfigInit.CONFIG.maxNutrition;
private int proteinLevel = ConfigInit.CONFIG.maxNutrition;
private int fatLevel = ConfigInit.CONFIG.maxNutrition;
private int vitaminLevel = ConfigInit.CONFIG.maxNutrition;
private int mineralLevel = ConfigInit.CONFIG.maxNutrition;
private Map<Integer, Boolean> effectMap = new HashMap<Integer, Boolean>() {
{
put(0, false);
Expand Down Expand Up @@ -79,7 +80,7 @@ private void updateNutritionEffectsMixin(PlayerEntity player, CallbackInfo info)
if (player.getWorld().getTime() % 16 == 0) {
List<Integer> list = List.of(this.carbohydrateLevel, this.proteinLevel, this.fatLevel, this.vitaminLevel);
for (int i = 0; i < list.size(); i++) {
if (list.get(i) <= NutritionMain.NUTRITION_NEGATIVE_VALUE) {
if (list.get(i) <= ConfigInit.CONFIG.negativeNutrition) {
List<Object> negativeEffectList = NutritionMain.NUTRITION_NEGATIVE_EFFECTS.get(i);
if (negativeEffectList != null && !negativeEffectList.isEmpty()) {
for (int u = 0; u < negativeEffectList.size(); u++) {
Expand All @@ -91,7 +92,7 @@ private void updateNutritionEffectsMixin(PlayerEntity player, CallbackInfo info)
}
this.effectMap.put(i, true);
}
} else if (list.get(i) >= NutritionMain.NUTRITION_POSITIVE_VALUE) {
} else if (list.get(i) >= ConfigInit.CONFIG.positiveNutrition) {
List<Object> positiveEffectList = NutritionMain.NUTRITION_POSITIVE_EFFECTS.get(i);
if (positiveEffectList != null && !positiveEffectList.isEmpty()) {
for (int u = 0; u < positiveEffectList.size(); u++) {
Expand Down Expand Up @@ -135,8 +136,6 @@ private void readNbtMixin(NbtCompound nbt, CallbackInfo info) {
this.fatLevel = nbt.getInt("FatLevel");
this.vitaminLevel = nbt.getInt("VitaminLevel");
this.mineralLevel = nbt.getInt("MineralLevel");
// this.hasNegativeEffects = nbt.getBoolean("HasNegativeEffects");
// this.hasPositiveEffects = nbt.getBoolean("HasPositiveEffects");
}

@Inject(method = "writeNbt", at = @At("TAIL"))
Expand All @@ -146,22 +145,20 @@ private void writeNbtMixin(NbtCompound nbt, CallbackInfo info) {
nbt.putFloat("FatLevel", this.fatLevel);
nbt.putFloat("VitaminLevel", this.vitaminLevel);
nbt.putFloat("MineralLevel", this.mineralLevel);
// nbt.putBoolean("HasNegativeEffects", this.hasNegativeEffects);
// nbt.putBoolean("HasPositiveEffects", this.hasPositiveEffects);
}

@Override
public void addNutritionLevel(int type, int level) {
if (type == 0) {
this.carbohydrateLevel = (this.carbohydrateLevel + level > NutritionMain.NUTRITION_MAX_VALUES) ? NutritionMain.NUTRITION_MAX_VALUES : (this.carbohydrateLevel + level);
this.carbohydrateLevel = (this.carbohydrateLevel + level > ConfigInit.CONFIG.maxNutrition) ? ConfigInit.CONFIG.maxNutrition : (this.carbohydrateLevel + level);
} else if (type == 1) {
this.proteinLevel = (this.proteinLevel + level > NutritionMain.NUTRITION_MAX_VALUES) ? NutritionMain.NUTRITION_MAX_VALUES : (this.proteinLevel + level);
this.proteinLevel = (this.proteinLevel + level > ConfigInit.CONFIG.maxNutrition) ? ConfigInit.CONFIG.maxNutrition : (this.proteinLevel + level);
} else if (type == 2) {
this.fatLevel = (this.fatLevel + level > NutritionMain.NUTRITION_MAX_VALUES) ? NutritionMain.NUTRITION_MAX_VALUES : (this.fatLevel + level);
this.fatLevel = (this.fatLevel + level > ConfigInit.CONFIG.maxNutrition) ? ConfigInit.CONFIG.maxNutrition : (this.fatLevel + level);
} else if (type == 3) {
this.vitaminLevel = (this.vitaminLevel + level > NutritionMain.NUTRITION_MAX_VALUES) ? NutritionMain.NUTRITION_MAX_VALUES : (this.vitaminLevel + level);
this.vitaminLevel = (this.vitaminLevel + level > ConfigInit.CONFIG.maxNutrition) ? ConfigInit.CONFIG.maxNutrition : (this.vitaminLevel + level);
} else if (type == 4) {
this.mineralLevel = (this.mineralLevel + level > NutritionMain.NUTRITION_MAX_VALUES) ? NutritionMain.NUTRITION_MAX_VALUES : (this.mineralLevel + level);
this.mineralLevel = (this.mineralLevel + level > ConfigInit.CONFIG.maxNutrition) ? ConfigInit.CONFIG.maxNutrition : (this.mineralLevel + level);
}
this.shouldUpdateNutritions = true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/nutritionz/screen/NutritionScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {
if (this.hungerManagerAccess != null) {
if (this.hungerManagerAccess.getNutritionLevel(i) > 0) {
context.drawTexture(RenderInit.NUTRITION_ICONS, this.x + 27, this.y + 36 + extraY, 0, 211 + extraBarY,
140 * this.hungerManagerAccess.getNutritionLevel(i) / NutritionMain.NUTRITION_MAX_VALUES, 5);
140 * this.hungerManagerAccess.getNutritionLevel(i) / ConfigInit.CONFIG.maxNutrition, 5);
}
context.drawText(this.textRenderer, Text.translatable("screen.nutritionz.nutritionValue", this.hungerManagerAccess.getNutritionLevel(i), NutritionMain.NUTRITION_MAX_VALUES),
this.x + 127, this.y + 26 + extraY, 0x3F3F3F, false);
context.drawText(this.textRenderer, Text.translatable("screen.nutritionz.nutritionValue", this.hungerManagerAccess.getNutritionLevel(i), ConfigInit.CONFIG.maxNutrition), this.x + 127,
this.y + 26 + extraY, 0x3F3F3F, false);
List<Text> tooltips = new ArrayList<>();
if (isPointWithinBounds(27, 36 + extraY, 31, 5, mouseX, mouseY)) {
if (NutritionMain.NUTRITION_NEGATIVE_EFFECTS.containsKey(i)) {
Expand Down

0 comments on commit 29e29f4

Please sign in to comment.