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

add continuous breeding #4545 #4598

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -17,9 +17,7 @@
import net.minecraft.entity.passive.AnimalEntity;
import net.minecraft.util.Hand;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.*;

public class AutoBreed extends Module {
private final SettingGroup sgGeneral = settings.getDefaultGroup();
Expand Down Expand Up @@ -57,7 +55,25 @@ public class AutoBreed extends Module {
.build()
);

private final List<Entity> animalsFed = new ArrayList<>();
private final Setting<Boolean> continuousBreeding = sgGeneral.add(new BoolSetting.Builder()
.name("continuous-breeding")
.description("Whether to feed the same animal again after a certain time period.")
.defaultValue(false)
.build()
);

private final Setting<Integer> breedingInterval = sgGeneral.add(new IntSetting.Builder()
.name("breeding-interval")
.description("Determines how often the same animal is fed in ticks.")
.min(1)
.sliderMax(24000)
.defaultValue(6600) // 30s in love mode and the 5-minute breeding cooldown
.visible(continuousBreeding::get)
.build()
);

private final LinkedHashMap<Entity, Integer> animalsFed = new LinkedHashMap<>();
private int tickCounter = 0;

public AutoBreed() {
super(Categories.World, "auto-breed", "Automatically breeds specified animals.");
Expand All @@ -66,6 +82,7 @@ public AutoBreed() {
@Override
public void onActivate() {
animalsFed.clear();
tickCounter = 0;
}

@EventHandler
Expand All @@ -74,23 +91,25 @@ private void onTick(TickEvent.Pre event) {
if (!(entity instanceof AnimalEntity animal)) continue;

if (!entities.get().contains(animal.getType())
|| !switch (mobAgeFilter.get()) {
case Baby -> animal.isBaby();
case Adult -> !animal.isBaby();
case Both -> true;
}
|| animalsFed.contains(animal)
|| !isCorrectAge(animal)
|| animalsFed.containsKey(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());
mc.player.swingHand(hand.get());
animalsFed.add(animal);
animalsFed.putLast(animal, tickCounter);
});
break;
}

return;
if (continuousBreeding.get()) {
while (!animalsFed.isEmpty() && animalsFed.firstEntry().getValue() < tickCounter - breedingInterval.get()) {
animalsFed.pollFirstEntry();
}
tickCounter++;
}
}

Expand All @@ -99,4 +118,12 @@ public enum EntityAge {
Adult,
Both
}

private boolean isCorrectAge(AnimalEntity animal) {
return switch (mobAgeFilter.get()) {
case Baby -> animal.isBaby();
case Adult -> !animal.isBaby();
case Both -> true;
};
}
}
Loading