Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mob age filter #4285

Merged
merged 2 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ public class KillAura extends Module {
.build()
);

private final Setting<Boolean> ignoreBabies = sgTargeting.add(new BoolSetting.Builder()
.name("ignore-babies")
.description("Whether or not to attack baby variants of the entity.")
.defaultValue(true)
private final Setting<EntityAge> mobAgeFilter = sgTargeting.add(new EnumSetting.Builder<EntityAge>()
.name("mob-age-filter")
.description("Determines the age of the mobs to target (baby, adult, or both).")
.defaultValue(EntityAge.Adult)
.build()
);

Expand Down Expand Up @@ -233,7 +233,6 @@ public class KillAura extends Module {
.build()
);

CrystalAura ca = Modules.get().get(CrystalAura.class);
private final List<Entity> targets = new ArrayList<>();
private int switchTimer, hitTimer;
private boolean wasPathing = false;
Expand All @@ -253,7 +252,7 @@ private void onTick(TickEvent.Pre event) {
if (pauseOnUse.get() && (mc.interactionManager.isBreakingBlock() || mc.player.isUsingItem())) return;
if (onlyOnClick.get() && !mc.options.attackKey.isPressed()) return;
if (TickRate.INSTANCE.getTimeSinceLastTick() >= 1f && pauseOnLag.get()) return;
if (pauseOnCA.get() && ca.isActive() && ca.kaTimer > 0) return;
if (pauseOnCA.get() && Modules.get().get(CrystalAura.class).isActive() && Modules.get().get(CrystalAura.class).kaTimer > 0) return;

if (onlyOnLook.get()) {
Entity targeted = mc.targetedEntity;
Expand Down Expand Up @@ -327,7 +326,7 @@ private boolean shouldShieldBreak() {

private boolean entityCheck(Entity entity) {
if (entity.equals(mc.player) || entity.equals(mc.cameraEntity)) return false;
if ((entity instanceof LivingEntity && ((LivingEntity) entity).isDead()) || !entity.isAlive()) return false;
if ((entity instanceof LivingEntity livingEntity && livingEntity.isDead()) || !entity.isAlive()) return false;

Box hitbox = entity.getBoundingBox();
if (!PlayerUtils.isWithin(
Expand Down Expand Up @@ -357,7 +356,14 @@ private boolean entityCheck(Entity entity) {
if (!Friends.get().shouldAttack(player)) return false;
if (shieldMode.get() == ShieldMode.Ignore && player.blockedByShield(mc.world.getDamageSources().playerAttack(mc.player))) return false;
}
return !(entity instanceof AnimalEntity animal) || !ignoreBabies.get() || !animal.isBaby();
if (entity instanceof AnimalEntity animal) {
return switch (mobAgeFilter.get()) {
case Baby -> animal.isBaby();
case Adult -> !animal.isBaby();
case Both -> true;
};
}
return true;
}

private boolean delayCheck() {
Expand Down Expand Up @@ -426,4 +432,10 @@ public enum ShieldMode {
Break,
None
}

public enum EntityAge {
Baby,
Adult,
Both
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ public class AutoBreed extends Module {
.build()
);

private final Setting<Boolean> ignoreBabies = sgGeneral.add(new BoolSetting.Builder()
.name("ignore-babies")
.description("Whether or not to ignore the baby variants of the specified entity.")
.defaultValue(true)
private final Setting<EntityAge> mobAgeFilter = sgGeneral.add(new EnumSetting.Builder<EntityAge>()
.name("mob-age-filter")
.description("Determines the age of the mobs to target (baby, adult, or both).")
.defaultValue(EntityAge.Adult)
.build()
);

Expand All @@ -71,16 +71,18 @@ public void onActivate() {
@EventHandler
private void onTick(TickEvent.Pre event) {
for (Entity entity : mc.world.getEntities()) {
AnimalEntity animal;

if (!(entity instanceof AnimalEntity)) continue;
else animal = (AnimalEntity) entity;
if (!(entity instanceof AnimalEntity animal)) continue;

if (!entities.get().contains(animal.getType())
|| (animal.isBaby() && !ignoreBabies.get())
|| animalsFed.contains(animal)
|| !PlayerUtils.isWithin(animal, range.get())
|| !animal.isBreedingItem(hand.get() == Hand.MAIN_HAND ? mc.player.getMainHandStack() : mc.player.getOffHandStack())) continue;
|| !switch (mobAgeFilter.get()) {
case Baby -> animal.isBaby();
case Adult -> !animal.isBaby();
case Both -> true;
}
|| animalsFed.contains(animal)
|| !PlayerUtils.isWithin(animal, range.get())
|| !animal.isBreedingItem(hand.get() == Hand.MAIN_HAND ? mc.player.getMainHandStack() : mc.player.getOffHandStack()))
continue;

Rotations.rotate(Rotations.getYaw(entity), Rotations.getPitch(entity), -100, () -> {
mc.interactionManager.interactEntity(mc.player, animal, hand.get());
Expand All @@ -91,4 +93,10 @@ private void onTick(TickEvent.Pre event) {
return;
}
}

public enum EntityAge {
Baby,
Adult,
Both
}
}