diff --git a/Client/src/main/java/com/baseband/client/Setup.java b/Client/src/main/java/com/baseband/client/Setup.java index 77fd06d..400d1fd 100644 --- a/Client/src/main/java/com/baseband/client/Setup.java +++ b/Client/src/main/java/com/baseband/client/Setup.java @@ -17,6 +17,7 @@ import com.baseband.client.module.movement.ElytraFly; import com.baseband.client.module.movement.NoSlowDown; import com.baseband.client.module.movement.Velocity; import com.baseband.client.module.render.*; +import com.baseband.client.module.world.AutoEat; import com.baseband.client.module.world.AutoSignText; import com.baseband.client.module.world.Selection; @@ -59,6 +60,7 @@ public class Setup { new ElytraBot(), new ChatFilter(), new Baritone(), + new AutoEat() }; diff --git a/Client/src/main/java/com/baseband/client/mixins/IMinecraft.java b/Client/src/main/java/com/baseband/client/mixins/IMinecraft.java index 4d7a6d2..5e6336e 100644 --- a/Client/src/main/java/com/baseband/client/mixins/IMinecraft.java +++ b/Client/src/main/java/com/baseband/client/mixins/IMinecraft.java @@ -4,9 +4,13 @@ import net.minecraft.client.Minecraft; import net.minecraft.util.Timer; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; +import org.spongepowered.asm.mixin.gen.Invoker; @Mixin(Minecraft.class) public interface IMinecraft { @Accessor("timer") Timer getTimer(); + + @Invoker("rightClickMouse") + void rightClick(); } diff --git a/Client/src/main/java/com/baseband/client/module/Category.java b/Client/src/main/java/com/baseband/client/module/Category.java index ffe09dd..09866e8 100644 --- a/Client/src/main/java/com/baseband/client/module/Category.java +++ b/Client/src/main/java/com/baseband/client/module/Category.java @@ -18,7 +18,6 @@ public enum Category { COMBAT("Combat", Combat.class), MOVEMENT("Movement", Movement.class), WORLD("World", World.class) - ; Category(String name, Class annotationClass) { diff --git a/Client/src/main/java/com/baseband/client/module/world/AutoEat.java b/Client/src/main/java/com/baseband/client/module/world/AutoEat.java new file mode 100644 index 0000000..1619484 --- /dev/null +++ b/Client/src/main/java/com/baseband/client/module/world/AutoEat.java @@ -0,0 +1,70 @@ +package com.baseband.client.module.world; + +import com.baseband.client.event.events.BaritoneEvent; +import com.baseband.client.mixins.IMinecraft; +import com.baseband.client.module.Feature; +import com.baseband.client.module.category.World; +import net.minecraft.client.settings.KeyBinding; +import net.minecraft.item.ItemAppleGold; +import net.minecraft.item.ItemChorusFruit; +import net.minecraft.item.ItemFood; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumHand; +import net.minecraft.util.FoodStats; + +@World +public class AutoEat extends Feature { + + private int lastSlot = -1; + private boolean eating = false; + + @Override + public String toString() { + return "AutoEat"; + } + + @Override + public void onTick() { + if (eating && !mc.player.isHandActive()) { + if (lastSlot != -1) { + mc.player.inventory.currentItem = lastSlot; + lastSlot = -1; + } + eating = false; + KeyBinding.setKeyBindState(mc.gameSettings.keyBindUseItem.getKeyCode(), false); + return; + } + if (eating) return; + + FoodStats stats = mc.player.getFoodStats(); + if (isValid(mc.player.getHeldItemOffhand(), stats.getFoodLevel())) { + mc.player.setActiveHand(EnumHand.OFF_HAND); + eating = true; + KeyBinding.setKeyBindState(mc.gameSettings.keyBindUseItem.getKeyCode(), true); + ((IMinecraft) mc).rightClick(); + } else { + for (int i = 0; i < 9; i++) { + if (isValid(mc.player.inventory.getStackInSlot(i), stats.getFoodLevel())) { + lastSlot = mc.player.inventory.currentItem; + mc.player.inventory.currentItem = i; + eating = true; + KeyBinding.setKeyBindState(mc.gameSettings.keyBindUseItem.getKeyCode(), true); + ((IMinecraft) mc).rightClick(); + return; + } + } + } + } + + public void baritone(BaritoneEvent e) { + if(!e.isCancelled()) { + e.setCancelled(eating); + } + } + + + + private boolean isValid(ItemStack stack, int food) { + return stack.getItem() instanceof ItemFood && !(stack.getItem() instanceof ItemChorusFruit) && ((20 - food)>=((ItemFood) stack.getItem()).getHealAmount(stack) || (stack.getItem() instanceof ItemAppleGold && mc.player.getHealth() < 20f)); + } +}