Skip to content

Commit

Permalink
AutoBreed mob age filter
Browse files Browse the repository at this point in the history
Add the option to target only babies, adults, or both.
  • Loading branch information
Big-Iron-Cheems committed Dec 18, 2023
1 parent b1d9cf0 commit daa7584
Showing 1 changed file with 20 additions and 12 deletions.
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
}
}

0 comments on commit daa7584

Please sign in to comment.