TemplateTool module

TemplateTool: 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/TemplateTool.javaJava · 129 lines · 4.8 KB

Saves a build as a shape AutoBuild can put up again.

SettingsNameSave block types
TemplateTool.javaJava · Minecraft 26.2 · 129 lines · 4.8 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.module.Category;
7
import com.jellypudding.offlineclient.module.Module;
8
import com.jellypudding.offlineclient.render.BoxStyle;
9
import com.jellypudding.offlineclient.setting.BoolSetting;
10
import com.jellypudding.offlineclient.setting.TextSetting;
11
import com.jellypudding.offlineclient.util.BlockUtil;
12
import com.jellypudding.offlineclient.util.ChatUtil;
13
import net.minecraft.core.BlockPos;
14
import net.minecraft.core.Direction;
15
import net.minecraft.world.level.block.state.BlockState;
16
import net.minecraft.world.phys.AABB;
17
import net.minecraft.world.phys.BlockHitResult;
18
import net.minecraft.world.phys.HitResult;
19
20
import java.io.IOException;
21
import java.util.ArrayList;
22
import java.util.List;
23
24
// Saves a build as a template for AutoBuild. Press the bind on two corners and
25
// then on the block the build should grow from. The facing at the last press
26
// becomes the front of the template.
27
public final class TemplateTool extends Module {
28
29
    private final TextSetting name = new TextSetting("Name",
30
        "The file the template is saved as. Click to type it.", "My build");
31
    private final BoolSetting saveBlocks = new BoolSetting("Save block types",
32
        "Remembers which block sits where. Off saves the shape alone.", true);
33
    private final BoxStyle boxStyle = new BoxStyle(BoxStyle.Shape.LINES, 200);
34
35
    private BlockPos first;
36
    private BlockPos second;
37
38
    public TemplateTool() {
39
        super("TemplateTool", "Saves a build as a shape AutoBuild can put up again.", Category.WORLD);
40
        addSettings(name, saveBlocks);
41
        addSettings(boxStyle.settings());
42
        searchTags("template", "save build", "copy structure");
43
    }
44
45
    @Override
46
    public boolean savesEnabledState() {
47
        return false;
48
    }
49
50
    @Override
51
    public String getSuffix() {
52
        if (first == null) {
53
            return "pick a corner";
54
        }
55
        return second == null ? "pick the other corner" : "pick the origin";
56
    }
57
58
    @Override
59
    protected void onEnable() {
60
        first = null;
61
        second = null;
62
    }
63
64
    // Each press marks the next spot. A press on nothing switches the tool off.
65
    @Override
66
    public void onKeybind() {
67
        if (!isEnabled() || !inGame()) {
68
            toggle();
69
            return;
70
        }
71
        if (!(mc.hitResult instanceof BlockHitResult hit) || hit.getType() != HitResult.Type.BLOCK) {
72
            toggle();
73
            return;
74
        }
75
        BlockPos pos = hit.getBlockPos().immutable();
76
        if (first == null) {
77
            first = pos;
78
            ChatUtil.message("§bTemplateTool §7first corner at §f" + BlockUtil.text(pos) + "§7.");
79
        } else if (second == null) {
80
            second = pos;
81
            ChatUtil.message("§bTemplateTool §7second corner at §f" + BlockUtil.text(pos)
82
                + "§7. Now press the bind on the block the build grows from.");
83
        } else {
84
            save(pos);
85
        }
86
    }
87
88
    private void save(BlockPos origin) {
89
        Direction front = mc.player.getDirection();
90
        Direction left = front.getCounterClockWise();
91
        List<BuildTemplate.Entry> entries = new ArrayList<>();
92
        for (BlockPos pos : BlockPos.betweenClosed(first, second)) {
93
            BlockState state = BlockUtil.state(pos);
94
            if (state.isAir() || !state.getFluidState().isEmpty()) {
95
                continue;
96
            }
97
            BlockPos offset = pos.subtract(origin);
98
            int forward = offset.getX() * front.getStepX() + offset.getZ() * front.getStepZ();
99
            int sideways = offset.getX() * left.getStepX() + offset.getZ() * left.getStepZ();
100
            entries.add(new BuildTemplate.Entry(sideways, offset.getY(), forward,
101
                saveBlocks.isOn() ? state.getBlock() : null));
102
        }
103
        if (entries.isEmpty()) {
104
            ChatUtil.error("There are no blocks between the corners.");
105
            setEnabled(false);
106
            return;
107
        }
108
        try {
109
            BuildTemplate.save(name.getValue().trim().isEmpty() ? "My build" : name.getValue().trim(),
110
                entries);
111
            ChatUtil.message("§bTemplateTool §7saved §f" + entries.size() + "§7 blocks as §f"
112
                + name.getValue().trim() + "§7.");
113
        } catch (IOException error) {
114
            ChatUtil.error("Could not write the template file.");
115
        }
116
        setEnabled(false);
117
    }
118
119
    @Subscribe
120
    private void onRender3D(Render3DEvent event) {
121
        if (first == null) {
122
            return;
123
        }
124
        AABB box = second == null ? new AABB(first)
125
            : AABB.encapsulatingFullBlocks(first, second);
126
        boxStyle.draw(event.getBatch(), box.inflate(0.005), true);
127
    }
128
}
129