1818import net .minecraft .util .Hand ;
1919import net .minecraft .util .hit .EntityHitResult ;
2020
21- import java .util .ArrayList ;
22- import java .util .List ;
23- import java .util .Set ;
21+ import java .util .*;
2422
2523public class AutoBreed extends Module {
2624 private final SettingGroup sgGeneral = settings .getDefaultGroup ();
@@ -58,7 +56,25 @@ public class AutoBreed extends Module {
5856 .build ()
5957 );
6058
61- private final List <Entity > animalsFed = new ArrayList <>();
59+ private final Setting <Boolean > continuousBreeding = sgGeneral .add (new BoolSetting .Builder ()
60+ .name ("continuous-breeding" )
61+ .description ("Whether to feed the same animal again after a certain time period." )
62+ .defaultValue (false )
63+ .build ()
64+ );
65+
66+ private final Setting <Integer > breedingInterval = sgGeneral .add (new IntSetting .Builder ()
67+ .name ("breeding-interval" )
68+ .description ("Determines how often the same animal is fed in ticks." )
69+ .min (1 )
70+ .sliderMax (24000 )
71+ .defaultValue (6600 ) // 30s in love mode and the 5-minute breeding cooldown
72+ .visible (continuousBreeding ::get )
73+ .build ()
74+ );
75+
76+ private final LinkedHashMap <Entity , Integer > animalsFed = new LinkedHashMap <>();
77+ private int tickCounter = 0 ;
6278
6379 public AutoBreed () {
6480 super (Categories .World , "auto-breed" , "Automatically breeds specified animals." );
@@ -67,6 +83,7 @@ public AutoBreed() {
6783 @ Override
6884 public void onActivate () {
6985 animalsFed .clear ();
86+ tickCounter = 0 ;
7087 }
7188
7289 @ EventHandler
@@ -75,12 +92,8 @@ private void onTick(TickEvent.Pre event) {
7592 if (!(entity instanceof AnimalEntity animal )) continue ;
7693
7794 if (!entities .get ().contains (animal .getType ())
78- || !switch (mobAgeFilter .get ()) {
79- case Baby -> animal .isBaby ();
80- case Adult -> !animal .isBaby ();
81- case Both -> true ;
82- }
83- || animalsFed .contains (animal )
95+ || !isCorrectAge (animal )
96+ || animalsFed .containsKey (animal )
8497 || !PlayerUtils .isWithin (animal , range .get ())
8598 || !animal .isBreedingItem (hand .get () == Hand .MAIN_HAND ? mc .player .getMainHandStack () : mc .player .getOffHandStack ()))
8699 continue ;
@@ -90,10 +103,16 @@ private void onTick(TickEvent.Pre event) {
90103 mc .interactionManager .interactEntityAtLocation (mc .player , animal , location , hand .get ());
91104 mc .interactionManager .interactEntity (mc .player , animal , hand .get ());
92105 mc .player .swingHand (hand .get ());
93- animalsFed .add (animal );
106+ animalsFed .putLast (animal , tickCounter );
94107 });
108+ break ;
109+ }
95110
96- return ;
111+ if (continuousBreeding .get ()) {
112+ while (!animalsFed .isEmpty () && animalsFed .firstEntry ().getValue () < tickCounter - breedingInterval .get ()) {
113+ animalsFed .pollFirstEntry ();
114+ }
115+ tickCounter ++;
97116 }
98117 }
99118
@@ -102,4 +121,12 @@ public enum EntityAge {
102121 Adult ,
103122 Both
104123 }
124+
125+ private boolean isCorrectAge (AnimalEntity animal ) {
126+ return switch (mobAgeFilter .get ()) {
127+ case Baby -> animal .isBaby ();
128+ case Adult -> !animal .isBaby ();
129+ case Both -> true ;
130+ };
131+ }
105132}
0 commit comments