Skip to content
This repository was archived by the owner on Mar 10, 2025. It is now read-only.

Commit a975731

Browse files
committed
Meteor moment
1 parent a357194 commit a975731

1 file changed

Lines changed: 316 additions & 0 deletions

File tree

Lines changed: 316 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,316 @@
1+
/*
2+
* This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client).
3+
* Copyright (c) Meteor Development.
4+
*/
5+
6+
package fartenware.modules.main;
7+
8+
import baritone.api.BaritoneAPI;
9+
import meteordevelopment.meteorclient.events.entity.player.ItemUseCrosshairTargetEvent;
10+
import meteordevelopment.meteorclient.events.world.TickEvent;
11+
import meteordevelopment.meteorclient.settings.BoolSetting;
12+
import meteordevelopment.meteorclient.settings.IntSetting;
13+
import meteordevelopment.meteorclient.settings.Setting;
14+
import meteordevelopment.meteorclient.settings.SettingGroup;
15+
import meteordevelopment.meteorclient.systems.modules.Categories;
16+
import meteordevelopment.meteorclient.systems.modules.Module;
17+
import meteordevelopment.meteorclient.systems.modules.Modules;
18+
import meteordevelopment.meteorclient.systems.modules.combat.AnchorAura;
19+
import meteordevelopment.meteorclient.systems.modules.combat.BedAura;
20+
import meteordevelopment.meteorclient.systems.modules.combat.CrystalAura;
21+
import meteordevelopment.meteorclient.systems.modules.combat.KillAura;
22+
import meteordevelopment.meteorclient.utils.Utils;
23+
import meteordevelopment.meteorclient.utils.player.InvUtils;
24+
import meteordevelopment.orbit.EventHandler;
25+
import net.minecraft.entity.effect.StatusEffect;
26+
import net.minecraft.entity.effect.StatusEffectInstance;
27+
import net.minecraft.entity.effect.StatusEffects;
28+
import net.minecraft.item.Item;
29+
import net.minecraft.item.ItemStack;
30+
import net.minecraft.item.Items;
31+
32+
import java.util.ArrayList;
33+
import java.util.List;
34+
import java.util.Map;
35+
36+
public class AutoGap extends Module {
37+
private static final Class<? extends Module>[] AURAS = new Class[] { KillAura.class, CrystalAura.class, AnchorAura.class, BedAura.class };
38+
39+
private final SettingGroup sgGeneral = settings.getDefaultGroup();
40+
private final SettingGroup sgPotions = settings.createGroup("Potions");
41+
private final SettingGroup sgHealth = settings.createGroup("Health");
42+
43+
// General
44+
45+
private final Setting<Boolean> allowEgap = sgGeneral.add(new BoolSetting.Builder()
46+
.name("allow-egap")
47+
.description("Allow eating E-Gaps over Gaps if found.")
48+
.defaultValue(true)
49+
.build()
50+
);
51+
52+
private final Setting<Boolean> always = sgGeneral.add(new BoolSetting.Builder()
53+
.name("always")
54+
.description("If it should always eat.")
55+
.defaultValue(false)
56+
.build()
57+
);
58+
59+
private final Setting<Boolean> pauseAuras = sgGeneral.add(new BoolSetting.Builder()
60+
.name("pause-auras")
61+
.description("Pauses all auras when eating.")
62+
.defaultValue(true)
63+
.build()
64+
);
65+
66+
private final Setting<Boolean> pauseBaritone = sgGeneral.add(new BoolSetting.Builder()
67+
.name("pause-baritone")
68+
.description("Pause baritone when eating.")
69+
.defaultValue(true)
70+
.build()
71+
);
72+
73+
// Potions
74+
75+
private final Setting<Boolean> potionsRegeneration = sgPotions.add(new BoolSetting.Builder()
76+
.name("potions-regeneration")
77+
.description("If it should eat when Regeneration runs out.")
78+
.defaultValue(false)
79+
.build()
80+
);
81+
82+
private final Setting<Boolean> potionsFireResistance = sgPotions.add(new BoolSetting.Builder()
83+
.name("potions-fire-resistance")
84+
.description("If it should eat when Fire Resistance runs out. Requires E-Gaps.")
85+
.defaultValue(true)
86+
.visible(allowEgap::get)
87+
.build()
88+
);
89+
90+
private final Setting<Boolean> potionsResistance = sgPotions.add(new BoolSetting.Builder()
91+
.name("potions-absorption")
92+
.description("If it should eat when Resistance runs out. Requires E-Gaps.")
93+
.defaultValue(false)
94+
.visible(allowEgap::get)
95+
.build()
96+
);
97+
98+
// Health
99+
100+
private final Setting<Boolean> healthEnabled = sgHealth.add(new BoolSetting.Builder()
101+
.name("health-enabled")
102+
.description("If it should eat when health drops below threshold.")
103+
.defaultValue(true)
104+
.build()
105+
);
106+
107+
private final Setting<Integer> healthThreshold = sgHealth.add(new IntSetting.Builder()
108+
.name("health-threshold")
109+
.description("Health threshold to eat at. Includes absorption.")
110+
.defaultValue(20)
111+
.min(0)
112+
.sliderMax(40)
113+
.build()
114+
);
115+
116+
private boolean requiresEGap;
117+
118+
private boolean eating;
119+
private int slot, prevSlot;
120+
121+
private final List<Class<? extends Module>> wasAura = new ArrayList<>();
122+
private boolean wasBaritone;
123+
124+
public AutoGap() {
125+
super(Categories.Player, "auto-gap", "Automatically eats Gaps or E-Gaps.");
126+
}
127+
128+
@Override
129+
public void onDeactivate() {
130+
if (eating) stopEating();
131+
}
132+
133+
@EventHandler
134+
private void onTick(TickEvent.Pre event) {
135+
if (eating) {
136+
// If we are eating check if we should still be still eating
137+
if (shouldEat()) {
138+
// Check if the item in current slot is not gap or egap
139+
if (isNotGapOrEGap(mc.player.getInventory().getStack(slot))) {
140+
// If not try finding a new slot
141+
int slot = findSlot();
142+
143+
// If no valid slot was found then stop eating
144+
if (slot == -1) {
145+
stopEating();
146+
return;
147+
}
148+
// Otherwise change to the new slot
149+
else {
150+
changeSlot(slot);
151+
}
152+
}
153+
154+
// Continue eating
155+
eat();
156+
}
157+
// If we shouldn't be eating anymore then stop
158+
else {
159+
stopEating();
160+
}
161+
}
162+
else {
163+
// If we are not eating check if we should start eating
164+
if (shouldEat()) {
165+
// Try to find a valid slot
166+
slot = findSlot();
167+
168+
// If slot was found then start eating
169+
if (slot != -1) startEating();
170+
}
171+
}
172+
}
173+
174+
@EventHandler
175+
private void onItemUseCrosshairTarget(ItemUseCrosshairTargetEvent event) {
176+
if (eating) event.target = null;
177+
}
178+
179+
private void startEating() {
180+
prevSlot = mc.player.getInventory().selectedSlot;
181+
eat();
182+
183+
// Pause auras
184+
wasAura.clear();
185+
if (pauseAuras.get()) {
186+
for (Class<? extends Module> klass : AURAS) {
187+
Module module = Modules.get().get(klass);
188+
189+
if (module.isActive()) {
190+
wasAura.add(klass);
191+
module.toggle();
192+
}
193+
}
194+
}
195+
196+
// Pause baritone
197+
wasBaritone = false;
198+
if (pauseBaritone.get()) {
199+
wasBaritone = true;
200+
BaritoneAPI.getProvider().getPrimaryBaritone().getCommandManager().execute("pause");
201+
}
202+
}
203+
204+
private void eat() {
205+
changeSlot(slot);
206+
setPressed(true);
207+
if (!mc.player.isUsingItem()) Utils.rightClick();
208+
209+
eating = true;
210+
}
211+
212+
private void stopEating() {
213+
changeSlot(prevSlot);
214+
setPressed(false);
215+
216+
eating = false;
217+
218+
// Resume auras
219+
if (pauseAuras.get()) {
220+
for (Class<? extends Module> klass : AURAS) {
221+
Module module = Modules.get().get(klass);
222+
223+
if (wasAura.contains(klass) && !module.isActive()) {
224+
module.toggle();
225+
}
226+
}
227+
}
228+
229+
// Resume baritone
230+
if (pauseBaritone.get() && wasBaritone) {
231+
BaritoneAPI.getProvider().getPrimaryBaritone().getCommandManager().execute("resume");
232+
}
233+
}
234+
235+
private void setPressed(boolean pressed) {
236+
mc.options.useKey.setPressed(pressed);
237+
}
238+
239+
private void changeSlot(int slot) {
240+
InvUtils.swap(slot, false);
241+
this.slot = slot;
242+
}
243+
244+
private boolean shouldEat() {
245+
requiresEGap = false;
246+
247+
if (always.get()) return true;
248+
if (shouldEatPotions()) return true;
249+
return shouldEatHealth();
250+
}
251+
252+
private boolean shouldEatPotions() {
253+
Map<StatusEffect, StatusEffectInstance> effects = mc.player.getActiveStatusEffects();
254+
255+
// Regeneration
256+
if (potionsRegeneration.get() && !effects.containsKey(StatusEffects.REGENERATION)) return true;
257+
258+
// Fire resistance
259+
if (potionsFireResistance.get() && !effects.containsKey(StatusEffects.FIRE_RESISTANCE)) {
260+
requiresEGap = true;
261+
return true;
262+
}
263+
264+
// Absorption
265+
if (potionsResistance.get() && !effects.containsKey(StatusEffects.RESISTANCE)) {
266+
requiresEGap = true;
267+
return true;
268+
}
269+
270+
return false;
271+
}
272+
273+
private boolean shouldEatHealth() {
274+
if (!healthEnabled.get()) return false;
275+
276+
int health = Math.round(mc.player.getHealth() + mc.player.getAbsorptionAmount());
277+
return health < healthThreshold.get();
278+
}
279+
280+
private int findSlot() {
281+
boolean preferEGap = this.allowEgap.get() || requiresEGap;
282+
int slot = -1;
283+
284+
for (int i = 0; i < 9; i++) {
285+
// Skip if item stack is empty
286+
ItemStack stack = mc.player.getInventory().getStack(i);
287+
if (stack.isEmpty()) continue;
288+
289+
// Skip if item isn't a gap or egap
290+
if (isNotGapOrEGap(stack)) continue;
291+
Item item = stack.getItem();
292+
293+
// If egap was found and preferEGap is true we can return the current slot
294+
if (item == Items.ENCHANTED_GOLDEN_APPLE && preferEGap) {
295+
slot = i;
296+
break;
297+
}
298+
// If gap was found and egap is not required we can return the current slot
299+
else if (item == Items.GOLDEN_APPLE && !requiresEGap) {
300+
slot = i;
301+
if (!preferEGap) break;
302+
}
303+
}
304+
305+
return slot;
306+
}
307+
308+
private boolean isNotGapOrEGap(ItemStack stack) {
309+
Item item = stack.getItem();
310+
return item != Items.GOLDEN_APPLE && item != Items.ENCHANTED_GOLDEN_APPLE;
311+
}
312+
313+
public boolean isEating() {
314+
return isActive() && eating;
315+
}
316+
}

0 commit comments

Comments
 (0)