AutoBreed module

AutoBreed: Minecraft 26.3 cheat module, full source for every implementation (1 client: OfflineClient).

1 implementationWORLD

Clients with this module

Full module source: 1 implementation

Every implementation below is the complete module file, verbatim. Expand a client to read its code.

OfflineClientWORLDsrc/main/java/com/jellypudding/offlineclient/modules/world/AutoBreed.javaJava · 148 lines · 6.2 KB

Breeds the animals around you with the food you hold.

SettingsAnimalsRangeHandAgeSkip untamedFeed againIntervalRotate
AutoBreed.javaJava · Minecraft 26.2 · 148 lines · 6.2 KB · complete file, verbatimOriginal ↗
1
package com.jellypudding.offlineclient.modules.world;
2
3
import com.jellypudding.offlineclient.event.Subscribe;
4
import com.jellypudding.offlineclient.event.events.TickEvent;
5
import com.jellypudding.offlineclient.module.Category;
6
import com.jellypudding.offlineclient.module.Module;
7
import com.jellypudding.offlineclient.setting.BoolSetting;
8
import com.jellypudding.offlineclient.setting.EnumSetting;
9
import com.jellypudding.offlineclient.setting.NumberSetting;
10
import com.jellypudding.offlineclient.setting.RegistryListSetting;
11
import com.jellypudding.offlineclient.util.BlockUtil;
12
import net.minecraft.core.registries.BuiltInRegistries;
13
import net.minecraft.world.InteractionHand;
14
import net.minecraft.world.entity.Entity;
15
import net.minecraft.world.entity.EntityType;
16
import net.minecraft.world.entity.EntityTypes;
17
import net.minecraft.world.entity.TamableAnimal;
18
import net.minecraft.world.entity.animal.Animal;
19
import net.minecraft.world.item.ItemStack;
20
import net.minecraft.world.phys.EntityHitResult;
21
22
import java.util.Iterator;
23
import java.util.LinkedHashMap;
24
import java.util.List;
25
import java.util.Map;
26
27
// Feeds the food in your hand to any animal that will take it.
28
public final class AutoBreed extends Module {
29
30
    public enum Age { ADULTS, BABIES, BOTH }
31
32
    public enum Hand { MAIN_HAND, OFF_HAND }
33
34
    private final RegistryListSetting<EntityType<?>> animals = new RegistryListSetting<>("Animals",
35
        "The animals to feed.", BuiltInRegistries.ENTITY_TYPE,
36
        List.of(EntityTypes.COW, EntityTypes.MOOSHROOM, EntityTypes.SHEEP, EntityTypes.PIG,
37
            EntityTypes.CHICKEN, EntityTypes.HORSE, EntityTypes.DONKEY, EntityTypes.WOLF,
38
            EntityTypes.CAT, EntityTypes.OCELOT, EntityTypes.RABBIT, EntityTypes.LLAMA,
39
            EntityTypes.TURTLE, EntityTypes.PANDA, EntityTypes.FOX, EntityTypes.BEE,
40
            EntityTypes.STRIDER, EntityTypes.HOGLIN, EntityTypes.GOAT, EntityTypes.AXOLOTL,
41
            EntityTypes.FROG, EntityTypes.CAMEL, EntityTypes.SNIFFER, EntityTypes.ARMADILLO));
42
    private final NumberSetting range = new NumberSetting("Range",
43
        "How close an animal has to be.", 4.5, 1, 6, 0.1).max(6);
44
    private final EnumSetting<Hand> hand = new EnumSetting<>("Hand",
45
        "Which hand holds the food.", Hand.MAIN_HAND);
46
    private final EnumSetting<Age> age = new EnumSetting<>("Age",
47
        "Which animals are fed.", Age.ADULTS)
48
        .describe(Age.ADULTS, "Grown animals. Feeding them breeds them.")
49
        .describe(Age.BABIES, "Young animals. Feeding them makes them grow faster.")
50
        .describe(Age.BOTH, "Every animal that will eat.");
51
    private final BoolSetting skipUntamed = new BoolSetting("Skip untamed",
52
        "Leaves wolves and cats and other pets that nobody owns alone.", false);
53
    private final BoolSetting repeat = new BoolSetting("Feed again",
54
        "Feeds the same animal again once its cooldown has passed.", false);
55
    private final NumberSetting interval = new NumberSetting("Interval",
56
        "Ticks before the same animal is fed again. Love lasts thirty seconds and the cooldown five minutes.",
57
        6600, 100, 24000, 100, " ticks").min(1).under(repeat);
58
    private final BoolSetting rotate = new BoolSetting("Rotate",
59
        "Turn towards the animal on the server side.", true);
60
61
    private static final int FULL_COOLDOWN = 6600;
62
63
    // Every animal fed and the tick it was fed on.
64
    private final Map<Integer, Integer> fed = new LinkedHashMap<>();
65
    private int count;
66
    private int lastTick;
67
68
    public AutoBreed() {
69
        super("AutoBreed", "Breeds the animals around you with the food you hold.", Category.WORLD);
70
        addSettings(animals, range, hand, age, skipUntamed, repeat, interval, rotate);
71
        searchTags("breed", "feed animals", "farm");
72
    }
73
74
    @Override
75
    public String getSuffix() {
76
        return count == 0 ? null : count + " fed";
77
    }
78
79
    @Override
80
    protected void onEnable() {
81
        fed.clear();
82
        count = 0;
83
    }
84
85
    @Subscribe
86
    private void onTick(TickEvent event) {
87
        if (!inGame() || mc.player.isSpectator() || mc.gui.screen() != null) {
88
            return;
89
        }
90
        int now = mc.player.tickCount;
91
        forgetOld(now);
92
        InteractionHand useHand = hand.is(Hand.OFF_HAND) ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND;
93
        ItemStack food = mc.player.getItemInHand(useHand);
94
        if (food.isEmpty()) {
95
            return;
96
        }
97
        for (Entity entity : mc.level.entitiesForRendering()) {
98
            if (!(entity instanceof Animal animal) || !wanted(animal, food)) {
99
                continue;
100
            }
101
            if (mc.player.distanceTo(animal) > range.getValue()) {
102
                continue;
103
            }
104
            if (rotate.isOn()) {
105
                BlockUtil.faceVector(animal.getBoundingBox().getCenter());
106
            }
107
            EntityHitResult hit = new EntityHitResult(animal, animal.getBoundingBox().getCenter());
108
            if (mc.gameMode.interact(mc.player, animal, hit, useHand).consumesAction()) {
109
                mc.player.swing(useHand);
110
                count++;
111
                fed.put(animal.getId(), now);
112
            }
113
            return;
114
        }
115
    }
116
117
    private boolean wanted(Animal animal, ItemStack food) {
118
        if (!animal.isAlive() || !animals.contains(animal.getType()) || fed.containsKey(animal.getId())) {
119
            return false;
120
        }
121
        if (skipUntamed.isOn() && animal instanceof TamableAnimal tamable && !tamable.isTame()) {
122
            return false;
123
        }
124
        boolean baby = animal.isBaby();
125
        if (age.is(Age.ADULTS) && baby || age.is(Age.BABIES) && !baby) {
126
            return false;
127
        }
128
        return animal.isFood(food);
129
    }
130
131
    // An animal only comes back onto the list when feeding again is allowed.
132
    private void forgetOld(int now) {
133
        // The tick count restarts on a respawn.
134
        if (now < lastTick) {
135
            fed.clear();
136
        }
137
        lastTick = now;
138
        // Without repeats an animal only returns after the game's longest cooldown.
139
        int keep = repeat.isOn() ? interval.getInt() : FULL_COOLDOWN;
140
        Iterator<Map.Entry<Integer, Integer>> it = fed.entrySet().iterator();
141
        while (it.hasNext()) {
142
            if (now - it.next().getValue() >= keep) {
143
                it.remove();
144
            }
145
        }
146
    }
147
}
148