Skip to content

Commit

Permalink
Implement smart eat tweak
Browse files Browse the repository at this point in the history
Closes #583
  • Loading branch information
ACGaming committed Oct 27, 2024
1 parent dbf089f commit 0d1d736
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}
2 changes: 1 addition & 1 deletion src/main/resources/mixins.tweaks.items.eating.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"refmap": "universaltweaks.refmap.json",
"minVersion": "0.8",
"compatibilityLevel": "JAVA_8",
"mixins": ["UTAlwaysEatMixin"]
"mixins": ["UTAlwaysEatMixin", "UTSmartEatMixin"]
}

0 comments on commit 0d1d736

Please sign in to comment.