Add hunger options to autoeat and don't eat bad food (#546)

* no rotten flesh or spider eyes

* remove the unneeded 12 imports and optimize check method

* close #545

Co-authored-by: pol-y-mer <polymer42693@gmail.com>
This commit is contained in:
Bella Who 2020-03-09 14:06:53 +00:00 committed by GitHub
parent e4ada944b4
commit 2b8593f9f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 2 deletions

View File

@ -1,7 +1,11 @@
package me.zeroeightsix.kami.module.modules.player;
import me.zeroeightsix.kami.module.Module;
import me.zeroeightsix.kami.setting.Setting;
import me.zeroeightsix.kami.setting.Settings;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
@ -9,17 +13,26 @@ import net.minecraft.util.FoodStats;
/**
* Created by 086 on 8/04/2018.
* Updated by polymer on 09/04/20
* Updated by S-B99 on 09/04/20
*/
@Module.Info(name = "AutoEat", description = "Automatically eat when hungry", category = Module.Category.PLAYER)
public class AutoEat extends Module {
private Setting<Integer> foodLevel = register(Settings.integerBuilder("Eat level").withValue(15).withMinimum(1).withMaximum(20).build());
private int lastSlot = -1;
private boolean eating = false;
private boolean isValid(ItemStack stack, int food) {
return stack.getItem() instanceof ItemFood && (20 - food) >= ((ItemFood) stack.getItem()).getHealAmount(stack);
return (stack.getItem() instanceof ItemFood && (foodLevel.getValue()- food) >= ((ItemFood) stack.getItem()).getHealAmount(stack)) && passItemCheck(stack.getItem());
}
private boolean passItemCheck(Item item) {
if (item == Items.ROTTEN_FLESH) return false;
if (item == Items.SPIDER_EYE) return false;
return true;
}
@Override
public void onUpdate() {
if (eating && !mc.player.isHandActive()) {