diff --git a/src/main/java/ru/dbotthepony/mc/otm/capability/AndroidCapability.java b/src/main/java/ru/dbotthepony/mc/otm/capability/AndroidCapability.java index d98b91266..703f2ac32 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/capability/AndroidCapability.java +++ b/src/main/java/ru/dbotthepony/mc/otm/capability/AndroidCapability.java @@ -63,8 +63,6 @@ public class AndroidCapability implements ICapabilityProvider, IAndroidCapabilit network_battery = ItemStack.EMPTY; } - public static final BigDecimal ENERGY_FOR_HUNGER_POINT = new BigDecimal(200); - public AndroidCapability(LivingEntity ent) { this.ent = ent; } diff --git a/src/main/java/ru/dbotthepony/mc/otm/capability/AndroidCapabilityPlayer.java b/src/main/java/ru/dbotthepony/mc/otm/capability/AndroidCapabilityPlayer.java index d291b112c..a897b220b 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/capability/AndroidCapabilityPlayer.java +++ b/src/main/java/ru/dbotthepony/mc/otm/capability/AndroidCapabilityPlayer.java @@ -182,6 +182,8 @@ public class AndroidCapabilityPlayer extends AndroidCapability { MatteryNetworking.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) ent), packet); } + public static final BigDecimal ENERGY_FOR_HUNGER_POINT = new BigDecimal(200); + @Override public void tickInner() { super.tickInner(); @@ -193,41 +195,22 @@ public class AndroidCapabilityPlayer extends AndroidCapability { ply.setSwimming(false); } - FoodData stats = ply.getFoodData(); + var stats = ply.getFoodData(); - if (stats.needsFood()) { - int food_points_missing = 20 - stats.getFoodLevel(); - boolean food_changed = false; - float saturation_points_missing = 20F - stats.getSaturationLevel(); - boolean saturation_changed = false; - - while (food_points_missing > 0) { - if (this.extractEnergyInner(ENERGY_FOR_HUNGER_POINT, true).compareTo(ENERGY_FOR_HUNGER_POINT) == 0) { - this.extractEnergyInner(ENERGY_FOR_HUNGER_POINT, false); - food_points_missing--; - food_changed = true; - } else { - break; - } + while (stats.getFoodLevel() < 20) { + if (this.extractEnergyInner(ENERGY_FOR_HUNGER_POINT, true).compareTo(ENERGY_FOR_HUNGER_POINT) == 0) { + this.extractEnergyInner(ENERGY_FOR_HUNGER_POINT, false); + stats.setFoodLevel(stats.getFoodLevel() + 1); + } else { + break; } + } - while (saturation_points_missing >= 1F) { - if (this.extractEnergyInner(ENERGY_FOR_HUNGER_POINT, true).compareTo(ENERGY_FOR_HUNGER_POINT) == 0) { - this.extractEnergyInner(ENERGY_FOR_HUNGER_POINT, false); - saturation_points_missing--; - saturation_changed = true; - } else { - break; - } - } + var food_level = (float) stats.getFoodLevel(); - if (food_changed) { - stats.setFoodLevel(20 - food_points_missing); - } - - if (saturation_changed) { - stats.setSaturation(20F - saturation_points_missing); - } + if (stats.getSaturationLevel() < food_level) { + BigDecimal extracted = this.extractEnergyInner(ENERGY_FOR_HUNGER_POINT.multiply(new BigDecimal(Float.toString(food_level - stats.getSaturationLevel()))), false); + stats.setSaturation(stats.getSaturationLevel() + extracted.divide(ENERGY_FOR_HUNGER_POINT, MatteryCapability.ROUND_RULES).floatValue()); } } } diff --git a/src/main/java/ru/dbotthepony/mc/otm/client/AndroidGui.java b/src/main/java/ru/dbotthepony/mc/otm/client/AndroidGui.java index b7447a87e..53465f347 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/client/AndroidGui.java +++ b/src/main/java/ru/dbotthepony/mc/otm/client/AndroidGui.java @@ -8,6 +8,7 @@ import net.minecraft.client.player.LocalPlayer; import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.effect.MobEffects; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraftforge.client.event.GuiOpenEvent; @@ -78,6 +79,8 @@ public class AndroidGui { return; } + int y_offset = ply.hasEffect(MobEffects.HUNGER) ? 18 : 0; + float level; if (android.getMaxBatteryLevel().compareTo(BigDecimal.ZERO) == 0) { @@ -104,9 +107,9 @@ public class AndroidGui { // Stack, x, y, blitOffset?, (float) image_x, (float) image_y, rect_x, rect_y, total_image_width, total_image_height // Stack, x, y, image_x, image_y, rect_x, rect_y - gui.blit(event.getMatrixStack(), left, top, 0, 0, 80, 9); + gui.blit(event.getMatrixStack(), left, top, 0, y_offset, 80, 9); int shift_left = (int) Math.ceil(level * 79f - 0.5f); - gui.blit(event.getMatrixStack(), left + 79 - shift_left, top, 0, 9, shift_left, 9); + gui.blit(event.getMatrixStack(), left + 79 - shift_left, top, 0, y_offset + 9, shift_left, 9); } } } diff --git a/src/main/resources/assets/overdrive_that_matters/textures/gui/player_gui.png b/src/main/resources/assets/overdrive_that_matters/textures/gui/player_gui.png index f81ce1fd8..a25e2aa82 100644 Binary files a/src/main/resources/assets/overdrive_that_matters/textures/gui/player_gui.png and b/src/main/resources/assets/overdrive_that_matters/textures/gui/player_gui.png differ diff --git a/src/main/resources/assets/overdrive_that_matters/textures/gui/player_gui.xcf b/src/main/resources/assets/overdrive_that_matters/textures/gui/player_gui.xcf index 01c035eb8..6f9010cdd 100644 --- a/src/main/resources/assets/overdrive_that_matters/textures/gui/player_gui.xcf +++ b/src/main/resources/assets/overdrive_that_matters/textures/gui/player_gui.xcf @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b1cb8180776ab920091df6416205faef455472146fe443c37e3adcca88306b06 -size 5273 +oid sha256:c01ad321a7bbdf37e122167c2a9ea7faee8eba5c5fc5fc64f090f32b9bfc7cda +size 5195