EChestFarmer module

EChestFarmer: 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/EChestFarmer.javaJava · 171 lines · 6.3 KB

Places and breaks ender chests to farm obsidian.

SettingsStop at amountCount existingAmountRotateShow target
EChestFarmer.javaJava · Minecraft 26.2 · 171 lines · 6.3 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.Render3DEvent;
5
import com.jellypudding.offlineclient.event.events.TickEvent;
6
import com.jellypudding.offlineclient.module.Category;
7
import com.jellypudding.offlineclient.module.ExclusivityGroup;
8
import com.jellypudding.offlineclient.module.Module;
9
import com.jellypudding.offlineclient.render.BoxStyle;
10
import com.jellypudding.offlineclient.setting.BoolSetting;
11
import com.jellypudding.offlineclient.setting.EnumSetting;
12
import com.jellypudding.offlineclient.setting.NumberSetting;
13
import com.jellypudding.offlineclient.util.BlockMiner;
14
import com.jellypudding.offlineclient.util.BlockUtil;
15
import com.jellypudding.offlineclient.util.ChatUtil;
16
import com.jellypudding.offlineclient.util.InventoryUtil;
17
import com.jellypudding.offlineclient.util.InventoryUtil.SlotSwap;
18
import com.jellypudding.offlineclient.util.ItemUtil;
19
import com.jellypudding.offlineclient.util.SwingMode;
20
import net.minecraft.core.BlockPos;
21
import net.minecraft.core.Direction;
22
import net.minecraft.world.item.Items;
23
import net.minecraft.world.item.enchantment.Enchantments;
24
import net.minecraft.world.level.block.Blocks;
25
import net.minecraft.world.level.block.state.BlockState;
26
import net.minecraft.world.phys.BlockHitResult;
27
import net.minecraft.world.phys.HitResult;
28
29
// An ender chest breaks into eight obsidian without silk touch. The chest
30
// goes on the block you look at and is mined straight back out.
31
public final class EChestFarmer extends Module {
32
33
    private final BoolSetting stopAtAmount = new BoolSetting("Stop at amount",
34
        "Turns off once you hold enough obsidian.", false);
35
    private final BoolSetting countExisting = new BoolSetting("Count existing",
36
        "Obsidian you already carry counts towards the amount.", false).under(stopAtAmount);
37
    private final NumberSetting amount = new NumberSetting("Amount",
38
        "How much obsidian to gather.", 64, 8, 256, 8).min(1).max(2304).under(stopAtAmount);
39
    private final BoolSetting rotate = new BoolSetting("Rotate",
40
        "Turn towards the chest on the server side.", true);
41
    private final EnumSetting<SwingMode> swing = SwingMode.setting(SwingMode.BOTH);
42
    private final BoolSetting render = new BoolSetting("Show target",
43
        "Outlines where the chest goes.", true);
44
    private final BoxStyle targetBox = new BoxStyle(BoxStyle.Shape.BOTH, 0).under(render);
45
46
    private BlockPos target;
47
    private int startCount;
48
    private final SlotSwap slots = new SlotSwap();
49
50
    public EChestFarmer() {
51
        super("EChestFarmer", "Places and breaks ender chests to farm obsidian.", Category.WORLD);
52
        addSettings(stopAtAmount, countExisting, amount, rotate, swing, render);
53
        addSettings(targetBox.settings());
54
        searchTags("obsidian farm", "ender chest");
55
    }
56
57
    @Override
58
    public ExclusivityGroup getExclusivityGroup() {
59
        return ExclusivityGroup.MINING;
60
    }
61
62
    @Override
63
    protected void onEnable() {
64
        target = null;
65
        startCount = obsidianCount();
66
    }
67
68
    @Override
69
    protected void onDisable() {
70
        BlockMiner.release();
71
        slots.restoreIfMine();
72
        target = null;
73
    }
74
75
    @Subscribe
76
    private void onTick(TickEvent event) {
77
        if (!inGame() || mc.player.isSpectator() || mc.gui.screen() != null) {
78
            return;
79
        }
80
        if (target == null && !pickTarget()) {
81
            return;
82
        }
83
        if (BlockUtil.distanceTo(target) > mc.player.blockInteractionRange()) {
84
            ChatUtil.error("The chest spot is out of reach.");
85
            target = null;
86
            return;
87
        }
88
        // Stepping onto the spot would leave every placement refused.
89
        if (BlockUtil.intersectsPlayer(target)) {
90
            target = null;
91
            return;
92
        }
93
        if (stopAtAmount.isOn() && gathered() >= amount.getInt()) {
94
            ChatUtil.message("§bEChestFarmer §7gathered enough obsidian.");
95
            setEnabled(false);
96
            return;
97
        }
98
        BlockState state = BlockUtil.state(target);
99
        if (state.is(Blocks.ENDER_CHEST)) {
100
            breakChest();
101
        } else if (state.canBeReplaced()) {
102
            placeChest();
103
        }
104
    }
105
106
    // The block above whatever the crosshair rests on.
107
    private boolean pickTarget() {
108
        if (!(mc.hitResult instanceof BlockHitResult hit) || hit.getType() != HitResult.Type.BLOCK) {
109
            return false;
110
        }
111
        BlockPos above = hit.getBlockPos().above();
112
        BlockState state = BlockUtil.state(above);
113
        // A spot the player is standing in refuses every placement.
114
        if (BlockUtil.intersectsPlayer(above)) {
115
            return false;
116
        }
117
        if (!state.canBeReplaced() && !state.is(Blocks.ENDER_CHEST)) {
118
            return false;
119
        }
120
        target = above.immutable();
121
        return true;
122
    }
123
124
    // Silk touch would give the chest back whole.
125
    private void breakChest() {
126
        int slot = ItemUtil.bestToolSlot(BlockUtil.state(target), 1,
127
            stack -> ItemUtil.enchantLevel(Enchantments.SILK_TOUCH, stack) == 0,
128
            InventoryUtil.HOTBAR_SIZE);
129
        if (slot == -1) {
130
            ChatUtil.error("No pickaxe without Silk Touch in the hotbar.");
131
            setEnabled(false);
132
            return;
133
        }
134
        slots.select(slot);
135
        BlockMiner.mine(target, rotate.isOn(), swing.getValue());
136
    }
137
138
    private void placeChest() {
139
        BlockMiner.release();
140
        int slot = InventoryUtil.hotbarSlot(stack -> stack.is(Items.ENDER_CHEST));
141
        if (slot == -1) {
142
            ChatUtil.error("No ender chests in the hotbar.");
143
            setEnabled(false);
144
            return;
145
        }
146
        Direction support = BlockUtil.findPlaceSupport(target);
147
        if (support == null) {
148
            return;
149
        }
150
        slots.select(slot);
151
        if (BlockUtil.place(target, support, rotate.isOn(), false)) {
152
            swing.getValue().swing();
153
        }
154
    }
155
156
    private int gathered() {
157
        return obsidianCount() - (countExisting.isOn() ? 0 : startCount);
158
    }
159
160
    private int obsidianCount() {
161
        return InventoryUtil.count(Items.OBSIDIAN, InventoryUtil.WHOLE_INVENTORY);
162
    }
163
164
    @Subscribe
165
    private void onRender3D(Render3DEvent event) {
166
        if (render.isOn() && target != null) {
167
            targetBox.draw(event.getBatch(), target, false);
168
        }
169
    }
170
}
171