AutoBuild module

AutoBuild: Minecraft 26.3 cheat module, full source for every implementation (2 clients: OfflineClient, LiquidBounce (Kotlin)).

2 implementationsWORLD

Full module source: 2 implementations

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

OfflineClientWORLDsrc/main/java/com/jellypudding/offlineclient/modules/world/AutoBuild.javaJava · 222 lines · 8.3 KB

Builds a saved shape where you right click.

SettingsTemplateRangeLine of sightUse saved blocksInstantFast placeStrict orderShow blocks
AutoBuild.javaJava · Minecraft 26.2 · 222 lines · 8.3 KB · complete file, verbatimOriginal ↗
1
package com.jellypudding.offlineclient.modules.world;
2
3
import com.jellypudding.offlineclient.config.BuildTemplate;
4
import com.jellypudding.offlineclient.event.Subscribe;
5
import com.jellypudding.offlineclient.event.events.Render3DEvent;
6
import com.jellypudding.offlineclient.event.events.RightClickEvent;
7
import com.jellypudding.offlineclient.event.events.TickEvent;
8
import com.jellypudding.offlineclient.module.Category;
9
import com.jellypudding.offlineclient.module.Module;
10
import com.jellypudding.offlineclient.render.BoxStyle;
11
import com.jellypudding.offlineclient.setting.BoolSetting;
12
import com.jellypudding.offlineclient.setting.ChoiceListSetting;
13
import com.jellypudding.offlineclient.setting.EnumSetting;
14
import com.jellypudding.offlineclient.setting.NumberSetting;
15
import com.jellypudding.offlineclient.util.BlockUtil;
16
import com.jellypudding.offlineclient.util.ChatUtil;
17
import com.jellypudding.offlineclient.util.FaceMode;
18
import com.jellypudding.offlineclient.util.InventoryUtil;
19
import com.jellypudding.offlineclient.util.InventoryUtil.SlotSwap;
20
import com.jellypudding.offlineclient.util.RotationPriority;
21
import com.jellypudding.offlineclient.util.SwingMode;
22
import net.minecraft.core.BlockPos;
23
import net.minecraft.core.Direction;
24
import net.minecraft.world.InteractionHand;
25
import net.minecraft.world.item.BlockItem;
26
import net.minecraft.world.level.block.Block;
27
import net.minecraft.world.phys.BlockHitResult;
28
import net.minecraft.world.phys.HitResult;
29
import net.minecraft.world.phys.Vec3;
30
31
import java.util.Iterator;
32
import java.util.LinkedHashMap;
33
import java.util.Map;
34
35
// Right click a block and the picked template goes up from there the way you face.
36
public final class AutoBuild extends Module {
37
38
    private static final int PLACE_DELAY = 4;
39
    // How many boxes are drawn at most whilst a big shape goes up.
40
    private static final int MAX_DRAWN = 1024;
41
42
    private final ChoiceListSetting template = new ChoiceListSetting("Template",
43
        "Which shape to build. The first one picked wins. Files live in offlineclient/templates.",
44
        BuildTemplate::names);
45
    private final NumberSetting range = new NumberSetting("Range",
46
        "How far from your eyes a block may go.", 6, 1, 10, 0.05).min(1).max(10);
47
    private final BoolSetting lineOfSight = new BoolSetting("Line of sight",
48
        "Never places through a wall. Safer against anti cheats and slower.", false);
49
    private final BoolSetting savedBlocks = new BoolSetting("Use saved blocks",
50
        "Places the blocks named in the template. Off builds it from whatever you hold.", true);
51
    private final BoolSetting instant = new BoolSetting("Instant",
52
        "Places the whole shape in one tick. Only creative mode will let that through.", false);
53
    private final EnumSetting<FaceMode> faceTarget = FaceMode.setting(FaceMode.SERVER);
54
    private final EnumSetting<SwingMode> swing = SwingMode.setting(SwingMode.PACKET);
55
    private final BoolSetting fastPlace = new BoolSetting("Fast place",
56
        "Ignores the vanilla wait between placements.", true);
57
    private final BoolSetting strictOrder = new BoolSetting("Strict order",
58
        "Places the blocks in the order the template lists them. Slower and tidier.", false);
59
    private final BoolSetting render = new BoolSetting("Show blocks",
60
        "Outlines what is still to be placed.", true);
61
    private final BoxStyle todoBox = new BoxStyle(BoxStyle.Shape.LINES, 120).under(render);
62
63
    private final SlotSwap slots = new SlotSwap();
64
    private BuildTemplate loaded;
65
    private final Map<BlockPos, Block> remaining = new LinkedHashMap<>();
66
    private int total;
67
68
    public AutoBuild() {
69
        super("AutoBuild", "Builds a saved shape where you right click.", Category.WORLD);
70
        addSettings(template, range, lineOfSight, savedBlocks, instant, faceTarget, swing, fastPlace,
71
            strictOrder, render);
72
        addSettings(todoBox.settings());
73
        searchTags("auto build", "insta build", "template", "structure");
74
    }
75
76
    @Override
77
    public String getSuffix() {
78
        if (loaded == null) {
79
            return null;
80
        }
81
        if (remaining.isEmpty()) {
82
            return loaded.name();
83
        }
84
        return loaded.name() + " " + (total - remaining.size()) * 100 / total + "%";
85
    }
86
87
    @Override
88
    protected void onEnable() {
89
        remaining.clear();
90
        loaded = null;
91
    }
92
93
    @Override
94
    protected void onDisable() {
95
        remaining.clear();
96
        slots.restoreIfMine();
97
    }
98
99
    private String chosenName() {
100
        Iterator<String> picked = template.chosen().iterator();
101
        return picked.hasNext() ? picked.next() : null;
102
    }
103
104
    // A fresh pick in the list swaps the shape between builds.
105
    private boolean loadChosen() {
106
        String name = chosenName();
107
        if (name == null) {
108
            return false;
109
        }
110
        if (loaded == null || !loaded.name().equals(name)) {
111
            loaded = BuildTemplate.load(name);
112
        }
113
        return loaded != null;
114
    }
115
116
    @Subscribe
117
    private void onRightClick(RightClickEvent event) {
118
        if (!inGame() || !remaining.isEmpty()) {
119
            return;
120
        }
121
        if (!(mc.hitResult instanceof BlockHitResult hit) || hit.getType() != HitResult.Type.BLOCK) {
122
            return;
123
        }
124
        if (!loadChosen()) {
125
            ChatUtil.error("Pick a template first.");
126
            return;
127
        }
128
        BlockPos origin = hit.getBlockPos().relative(hit.getDirection());
129
        remaining.putAll(loaded.layOut(origin, mc.player.getDirection()));
130
        total = remaining.size();
131
        event.cancel();
132
    }
133
134
    @Subscribe
135
    private void onTick(TickEvent event) {
136
        if (!inGame()) {
137
            return;
138
        }
139
        if (remaining.isEmpty()) {
140
            slots.restoreIfMine();
141
            loadChosen();
142
            return;
143
        }
144
        remaining.keySet().removeIf(pos -> !BlockUtil.isReplaceable(pos));
145
        if (remaining.isEmpty()) {
146
            ChatUtil.message("§bAutoBuild §7finished §f" + loaded.name() + "§7.");
147
            return;
148
        }
149
        if (!instant.isOn() && !fastPlace.isOn() && mc.rightClickDelay > 0) {
150
            return;
151
        }
152
        for (Map.Entry<BlockPos, Block> entry : remaining.entrySet()) {
153
            boolean placed = tryPlace(entry.getKey(), entry.getValue());
154
            if (placed && !instant.isOn()) {
155
                return;
156
            }
157
            if (!placed && strictOrder.isOn()) {
158
                return;
159
            }
160
        }
161
    }
162
163
    private boolean tryPlace(BlockPos pos, Block wanted) {
164
        Direction support = BlockUtil.findPlaceSupport(pos);
165
        if (support == null) {
166
            return false;
167
        }
168
        Vec3 hit = BlockUtil.hitPoint(pos.relative(support), support.getOpposite());
169
        if (mc.player.getEyePosition().distanceToSqr(hit) > range.getValue() * range.getValue()) {
170
            return false;
171
        }
172
        if (lineOfSight.isOn() && !BlockUtil.canSee(hit)) {
173
            return false;
174
        }
175
        if (!holdBlock(wanted)) {
176
            return false;
177
        }
178
        faceTarget.getValue().face(hit, RotationPriority.PLACE);
179
        if (!BlockUtil.place(pos, support, false, false)) {
180
            return false;
181
        }
182
        swing.getValue().swing(InteractionHand.MAIN_HAND);
183
        mc.rightClickDelay = PLACE_DELAY;
184
        return true;
185
    }
186
187
    // The named block goes in hand when the template asks for one. Otherwise any block.
188
    private boolean holdBlock(Block wanted) {
189
        Block needed = savedBlocks.isOn() ? wanted : null;
190
        if (needed == null) {
191
            return mc.player.getMainHandItem().getItem() instanceof BlockItem
192
                || pickSlot(BlockUtil.findBlockSlot());
193
        }
194
        if (mc.player.getMainHandItem().getItem() instanceof BlockItem item && item.getBlock() == needed) {
195
            return true;
196
        }
197
        return pickSlot(BlockUtil.findBlockSlot(block -> block == needed));
198
    }
199
200
    private boolean pickSlot(int slot) {
201
        if (slot == -1) {
202
            return false;
203
        }
204
        slots.select(slot);
205
        return true;
206
    }
207
208
    @Subscribe
209
    private void onRender3D(Render3DEvent event) {
210
        if (!render.isOn() || remaining.isEmpty()) {
211
            return;
212
        }
213
        int drawn = 0;
214
        for (BlockPos pos : remaining.keySet()) {
215
            if (drawn++ >= MAX_DRAWN) {
216
                break;
217
            }
218
            todoBox.draw(event.getBatch(), pos, true);
219
        }
220
    }
221
}
222
LiquidBounce (Kotlin)WORLDsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/world/autobuild/ModuleAutoBuild.ktKotlin · 66 lines · 2.1 KB

Automatically builds certain structures.

ModuleAutoBuild.ktKotlin · Minecraft 26.2 · 66 lines · 2.1 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
3
 *
4
 * Copyright (c) 2015 - 2026 CCBlueX
5
 *
6
 * LiquidBounce is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * LiquidBounce is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
18
 */
19
package net.ccbluex.liquidbounce.features.module.modules.world.autobuild
20
21
import net.ccbluex.liquidbounce.config.types.group.Mode
22
import net.ccbluex.liquidbounce.config.types.group.ModeValueGroup
23
import net.ccbluex.liquidbounce.features.module.ClientModule
24
import net.ccbluex.liquidbounce.features.module.ModuleCategories
25
import net.ccbluex.liquidbounce.utils.block.placer.BlockPlacer
26
import net.ccbluex.liquidbounce.utils.inventory.HotbarItemSlot
27
import net.ccbluex.liquidbounce.utils.kotlin.Priority
28
29
/**
30
 * AutoBuild module
31
 *
32
 * Builds structures.
33
 */
34
object ModuleAutoBuild : ClientModule("AutoBuild", ModuleCategories.WORLD, aliases = listOf("Platform", "AutoPortal")) {
35
36
    private val mode = choices("Mode", PortalMode, arrayOf(PortalMode, PlatformMode)).apply { tagBy(this) }
37
    val placer = tree(BlockPlacer("Placing", this, Priority.NORMAL, { mode.activeMode.getSlot() }))
38
39
    init {
40
        mode.onChanged { enabled = false }
41
    }
42
43
    override fun onEnabled() {
44
        mode.activeMode.enabled()
45
    }
46
47
    override fun onDisabled() {
48
        placer.disable()
49
        mode.activeMode.disabled()
50
    }
51
52
    abstract class AutoBuildMode(name: String) : Mode(name) {
53
54
        abstract fun getSlot(): HotbarItemSlot?
55
56
        open fun enabled() {}
57
58
        open fun disabled() {}
59
60
        override val parent: ModeValueGroup<*>
61
            get() = mode
62
63
    }
64
65
}
66