diff --git a/README.md b/README.md index ed01307a..18b79576 100644 --- a/README.md +++ b/README.md @@ -240,6 +240,7 @@ All changes are toggleable via config files. * **Skip Credits:** Skips the credits screen after the player goes through the end podium portal * **Skip Missing Registry Entries Screen:** Automatically confirms the 'Missing Registry Entries' screen on world load * **Sleeping Time:** Determines at which time of day sleeping is allowed in ticks (0 - 24000) +* **Smart Eat:** Requires the hunger bar to be missing food points equal to or more than the amount restored by the food * **Smooth Scrolling:** Adds smooth scrolling to every in-game list * **Soulbound Vexes:** Summoned vexes will also die when their summoner is killed * **Spawn Caps:** Sets maximum spawning limits for different entity types diff --git a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java index 963dc3a4..4381cd45 100644 --- a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java +++ b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java @@ -1133,6 +1133,11 @@ public static class ItemsCategory }) public String[] utCustomUseDurations = new String[] {}; + @Config.RequiresMcRestart + @Config.Name("Smart Eat") + @Config.Comment("Requires the hunger bar to be missing food points equal to or more than the amount restored by the food") + public boolean utSmartEatToggle = false; + @Config.Name("Super Hot Torch") @Config.Comment("Enables one-time ignition of entities by hitting them with a torch") public boolean utSuperHotTorchToggle = false; diff --git a/src/main/java/mod/acgaming/universaltweaks/core/UTLoadingPlugin.java b/src/main/java/mod/acgaming/universaltweaks/core/UTLoadingPlugin.java index 21c9e3b6..a07dc5b3 100644 --- a/src/main/java/mod/acgaming/universaltweaks/core/UTLoadingPlugin.java +++ b/src/main/java/mod/acgaming/universaltweaks/core/UTLoadingPlugin.java @@ -126,7 +126,7 @@ public class UTLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader put("mixins.tweaks.items.attackcooldown.server.json", () -> UTConfigTweaks.ITEMS.ATTACK_COOLDOWN.utAttackCooldownToggle); put("mixins.tweaks.items.bottle.json", () -> UTConfigTweaks.ITEMS.utGlassBottlesConsumeWaterSource); put("mixins.tweaks.items.bucket.json", () -> UTConfigTweaks.ITEMS.utPreventBucketPlacingInPortal); - put("mixins.tweaks.items.eating.json", () -> UTConfigTweaks.ITEMS.utAlwaysEatToggle); + put("mixins.tweaks.items.eating.json", () -> UTConfigTweaks.ITEMS.utAlwaysEatToggle || UTConfigTweaks.ITEMS.utSmartEatToggle); put("mixins.tweaks.items.hardcorebuckets.json", () -> UTConfigTweaks.ITEMS.utHardcoreBucketsToggle); put("mixins.tweaks.items.infinityallarrows.json", () -> UTConfigTweaks.ITEMS.INFINITY.utAllArrowsAreInfinite); put("mixins.tweaks.items.infinitymending.json", () -> UTConfigTweaks.ITEMS.INFINITY.utInfinityEnchantmentConflicts); diff --git a/src/main/java/mod/acgaming/universaltweaks/tweaks/items/eating/mixin/UTSmartEatMixin.java b/src/main/java/mod/acgaming/universaltweaks/tweaks/items/eating/mixin/UTSmartEatMixin.java new file mode 100644 index 00000000..a17a7f90 --- /dev/null +++ b/src/main/java/mod/acgaming/universaltweaks/tweaks/items/eating/mixin/UTSmartEatMixin.java @@ -0,0 +1,29 @@ +package mod.acgaming.universaltweaks.tweaks.items.eating.mixin; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemFood; +import net.minecraft.item.ItemStack; + +import com.llamalad7.mixinextras.sugar.Local; +import mod.acgaming.universaltweaks.config.UTConfigTweaks; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(ItemFood.class) +public abstract class UTSmartEatMixin +{ + @Shadow + public boolean alwaysEdible; + + @Shadow + public abstract int getHealAmount(ItemStack stack); + + @Redirect(method = "onItemRightClick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/EntityPlayer;canEat(Z)Z")) + public boolean utSmartEat(EntityPlayer player, boolean ignoreHunger, @Local ItemStack itemstack) + { + if (!UTConfigTweaks.ITEMS.utSmartEatToggle || this.alwaysEdible) return player.canEat(true); + return player.canEat(false) && this.getHealAmount(itemstack) <= (20 - player.getFoodStats().getFoodLevel()); + } +} \ No newline at end of file diff --git a/src/main/resources/mixins.tweaks.items.eating.json b/src/main/resources/mixins.tweaks.items.eating.json index d84ed16b..c6f9340c 100644 --- a/src/main/resources/mixins.tweaks.items.eating.json +++ b/src/main/resources/mixins.tweaks.items.eating.json @@ -3,5 +3,5 @@ "refmap": "universaltweaks.refmap.json", "minVersion": "0.8", "compatibilityLevel": "JAVA_8", - "mixins": ["UTAlwaysEatMixin"] + "mixins": ["UTAlwaysEatMixin", "UTSmartEatMixin"] } \ No newline at end of file