Skip to content

Commit

Permalink
Merge branch 'master' into 1.21.2-update
Browse files Browse the repository at this point in the history
  • Loading branch information
Wide-Cat authored Nov 3, 2024
2 parents 006aec8 + 0d7879a commit c84577a
Showing 1 changed file with 48 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@

package meteordevelopment.meteorclient.systems.modules.misc;

import java.util.Set;

import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.events.world.TickEvent;
import meteordevelopment.meteorclient.settings.BoolSetting;
import meteordevelopment.meteorclient.settings.EntityTypeListSetting;
import meteordevelopment.meteorclient.settings.IntSetting;
import meteordevelopment.meteorclient.settings.Setting;
import meteordevelopment.meteorclient.settings.SettingGroup;
import meteordevelopment.meteorclient.settings.*;
import meteordevelopment.meteorclient.systems.friends.Friends;
import meteordevelopment.meteorclient.systems.modules.Categories;
import meteordevelopment.meteorclient.systems.modules.Module;
Expand All @@ -29,16 +25,17 @@
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Colors;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import net.minecraft.util.Formatting;

import java.util.Set;

public class AutoLog extends Module {
private final SettingGroup sgGeneral = settings.getDefaultGroup();
private final SettingGroup sgEntities = settings.createGroup("Entities");

private final Setting<Integer> health = sgGeneral.add(new IntSetting.Builder()
.name("health")
.description("Automatically disconnects when health is lower or equal to this value.")
.description("Automatically disconnects when health is lower or equal to this value. Set to 0 to disable.")
.defaultValue(6)
.range(0, 19)
.sliderMax(19)
Expand All @@ -47,7 +44,7 @@ public class AutoLog extends Module {

private final Setting<Boolean> smart = sgGeneral.add(new BoolSetting.Builder()
.name("smart")
.description("Disconnects when you're about to take enough damage to kill you.")
.description("Disconnects when it detects you're about to take enough damage to set you under the 'health' setting.")
.defaultValue(true)
.build()
);
Expand All @@ -66,6 +63,22 @@ public class AutoLog extends Module {
.build()
);

private final Setting<Boolean> smartToggle = sgGeneral.add(new BoolSetting.Builder()
.name("smart-toggle")
.description("Disables Auto Log after a low-health logout. WILL re-enable once you heal.")
.defaultValue(false)
.build()
);

private final Setting<Boolean> toggleOff = sgGeneral.add(new BoolSetting.Builder()
.name("toggle-off")
.description("Disables Auto Log after usage.")
.defaultValue(true)
.build()
);

// Entities

private final Setting<Set<EntityType<?>>> entities = sgEntities.add(new EntityTypeListSetting.Builder()
.name("entities")
.description("Disconnects when a specified entity is present within a specified range.")
Expand Down Expand Up @@ -110,23 +123,8 @@ public class AutoLog extends Module {
.build()
);

private final Setting<Boolean> smartToggle = sgGeneral.add(new BoolSetting.Builder()
.name("smart-toggle")
.description("Disables Auto Log after a low-health logout. WILL re-enable once you heal.")
.defaultValue(false)
.build()
);

private final Setting<Boolean> toggleOff = sgGeneral.add(new BoolSetting.Builder()
.name("toggle-off")
.description("Disables Auto Log after usage.")
.defaultValue(true)
.build()
);

//Declaring variables outside the loop for better efficiency
private final Object2IntMap<EntityType<?>> entityCounts = new Object2IntOpenHashMap<>();
private int totalEntities = 0;

public AutoLog() {
super(Categories.Combat, "auto-log", "Automatically disconnects you when certain requirements are met.");
Expand All @@ -141,14 +139,14 @@ private void onTick(TickEvent.Post event) {
}
if (playerHealth <= health.get()) {
disconnect("Health was lower than " + health.get() + ".");
if(smartToggle.get()) {
this.toggle();
if (smartToggle.get()) {
if (isActive()) this.toggle();
enableHealthListener();
return;
}
}

if (smart.get() && playerHealth + mc.player.getAbsorptionAmount()
- PlayerUtils.possibleHealthReductions() < health.get()) {
if (smart.get() && playerHealth + mc.player.getAbsorptionAmount() - PlayerUtils.possibleHealthReductions() < health.get()) {
disconnect("Health was going to be lower than " + health.get() + ".");
if (toggleOff.get()) this.toggle();
}
Expand All @@ -159,24 +157,24 @@ private void onTick(TickEvent.Post event) {
for (Entity entity : mc.world.getEntities()) {
if (entity instanceof PlayerEntity player && player.getUuid() != mc.player.getUuid()) {
if (onlyTrusted.get() && player != mc.player && !Friends.get().isFriend(player)) {
disconnect("A non-trusted player appeared in your render distance.");
disconnect(Text.literal("Non-trusted player '" + Formatting.RED + player.getName().getString() + Formatting.WHITE + "' appeared in your render distance."));
if (toggleOff.get()) this.toggle();
break;
return;
}

if (instantDeath.get() && PlayerUtils.isWithin(entity, 8) && DamageUtils.getAttackDamage(player, mc.player)
> playerHealth + mc.player.getAbsorptionAmount()) {
disconnect("Anti-32k measures.");
if (toggleOff.get())
this.toggle();
break;
if (toggleOff.get()) this.toggle();
return;
}
}
}

// Entities detection Logic
if (!entities.get().isEmpty()) {
// Reset totalEntities count and clear the entityCounts map
totalEntities = 0;
int totalEntities = 0;
entityCounts.clear();

// Iterate through all entities in the world and count the ones that match the selected types and are within range
Expand All @@ -191,27 +189,30 @@ private void onTick(TickEvent.Post event) {

if (useTotalCount.get() && totalEntities >= combinedEntityThreshold.get()) {
disconnect("Total number of selected entities within range exceeded the limit.");
if (toggleOff.get())
this.toggle();
} else if (!useTotalCount.get()) {
if (toggleOff.get()) this.toggle();
}
else if (!useTotalCount.get()) {
// Check if the count of each entity type exceeds the specified limit
for (Object2IntMap.Entry<EntityType<?>> entry : entityCounts.object2IntEntrySet()) {
if (entry.getIntValue() >= individualEntityThreshold.get()) {
disconnect("Number of " + entry.getKey().getName().getString()
+ " within range exceeded the limit.");
if (toggleOff.get())
this.toggle();
break;
disconnect("Number of " + entry.getKey().getName().getString() + " within range exceeded the limit.");
if (toggleOff.get()) this.toggle();
return;
}
}
}
}
}

private void disconnect(String reason) {
MutableText text = Text.literal("[AutoLog] " + reason);
AutoReconnect autoReconnect = Modules.get().get(AutoReconnect.class);
disconnect(Text.literal(reason));
}

private void disconnect(Text reason) {
MutableText text = Text.literal("[AutoLog] ");
text.append(reason);

AutoReconnect autoReconnect = Modules.get().get(AutoReconnect.class);
if (autoReconnect.isActive()) {
text.append(Text.literal("\n\nINFO - AutoReconnect was disabled").withColor(Colors.GRAY));
autoReconnect.toggle();
Expand All @@ -228,6 +229,7 @@ private void healthListener(TickEvent.Post event) {
else if (Utils.canUpdate()
&& !mc.player.isDead()
&& mc.player.getHealth() > health.get()) {
info("Player health greater than minimum, re-enabling module.");
toggle();
disableHealthListener();
}
Expand Down

0 comments on commit c84577a

Please sign in to comment.