marker module

marker: Minecraft 26.3 cheat module, full source for every implementation (2 clients: Meteor Client, OfflineClient).

2 implementationsRenderRENDER

Clients with this module

Full module source: 2 implementations

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

Meteor ClientRendersrc/main/java/meteordevelopment/meteorclient/systems/modules/render/marker/Marker.javaJava · 147 lines · 4.9 KB

Renders shapes. Useful for large scale projects

Marker.javaJava · Minecraft 26.2 · 147 lines · 4.9 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client).
3
 * Copyright (c) Meteor Development.
4
 */
5
6
package meteordevelopment.meteorclient.systems.modules.render.marker;
7
8
import meteordevelopment.meteorclient.events.render.Render3DEvent;
9
import meteordevelopment.meteorclient.events.world.TickEvent;
10
import meteordevelopment.meteorclient.gui.GuiTheme;
11
import meteordevelopment.meteorclient.gui.renderer.GuiRenderer;
12
import meteordevelopment.meteorclient.gui.widgets.WLabel;
13
import meteordevelopment.meteorclient.gui.widgets.WWidget;
14
import meteordevelopment.meteorclient.gui.widgets.containers.WHorizontalList;
15
import meteordevelopment.meteorclient.gui.widgets.containers.WVerticalList;
16
import meteordevelopment.meteorclient.gui.widgets.input.WDropdown;
17
import meteordevelopment.meteorclient.gui.widgets.pressable.WButton;
18
import meteordevelopment.meteorclient.gui.widgets.pressable.WCheckbox;
19
import meteordevelopment.meteorclient.gui.widgets.pressable.WMinus;
20
import meteordevelopment.meteorclient.systems.modules.Categories;
21
import meteordevelopment.meteorclient.systems.modules.Module;
22
import meteordevelopment.orbit.EventHandler;
23
import net.minecraft.nbt.CompoundTag;
24
import net.minecraft.nbt.ListTag;
25
import net.minecraft.nbt.Tag;
26
27
import java.util.ArrayList;
28
29
public class Marker extends Module {
30
    private final MarkerFactory factory = new MarkerFactory();
31
    private final ArrayList<BaseMarker> markers = new ArrayList<>();
32
33
    public Marker() {
34
        super(Categories.Render, "marker", "Renders shapes. Useful for large scale projects");
35
    }
36
37
    @EventHandler
38
    private void onTick(TickEvent.Post event) {
39
        for (BaseMarker marker : markers) {
40
            if (marker.isVisible()) marker.tick();
41
        }
42
    }
43
44
    @EventHandler
45
    private void onRender(Render3DEvent event) {
46
        for (BaseMarker marker : markers) {
47
            if (marker.isVisible()) marker.render(event);
48
        }
49
    }
50
51
    @Override
52
    public CompoundTag toTag() {
53
        CompoundTag tag = super.toTag();
54
55
        ListTag list = new ListTag();
56
        for (BaseMarker marker : markers) {
57
            CompoundTag mTag = new CompoundTag();
58
            mTag.putString("type", marker.getTypeName());
59
            mTag.put("marker", marker.toTag());
60
61
            list.add(mTag);
62
        }
63
64
        tag.put("markers", list);
65
        return tag;
66
    }
67
68
    @Override
69
    public Module fromTag(CompoundTag tag) {
70
        super.fromTag(tag);
71
72
        markers.clear();
73
        ListTag list = tag.getListOrEmpty("markers");
74
75
        for (Tag tagII : list) {
76
            CompoundTag tagI = (CompoundTag) tagII;
77
78
            String type = tagI.getStringOr("type", "");
79
            BaseMarker marker = factory.createMarker(type);
80
81
            if (marker != null) {
82
                CompoundTag markerTag = (CompoundTag) tagI.get("marker");
83
                if (markerTag != null) marker.fromTag(markerTag);
84
85
                markers.add(marker);
86
            }
87
        }
88
89
        return this;
90
    }
91
92
    @Override
93
    public WWidget getWidget(GuiTheme theme) {
94
        WVerticalList list = theme.verticalList();
95
        fillList(theme, list);
96
        return list;
97
    }
98
99
    protected void fillList(GuiTheme theme, WVerticalList list) {
100
        // Marker List
101
        for (BaseMarker marker : markers) {
102
            WHorizontalList hList = list.add(theme.horizontalList()).expandX().widget();
103
104
            // Name
105
            WLabel label = hList.add(theme.label(marker.name.get())).widget();
106
            label.tooltip = marker.description.get();
107
108
            // Dimension
109
            hList.add(theme.label(" - " + marker.getDimension().toString())).expandX().widget().color = theme.textSecondaryColor();
110
111
            // Toggle
112
            WCheckbox checkbox = hList.add(theme.checkbox(marker.isActive())).widget();
113
            checkbox.action = () -> {
114
                if (marker.isActive() != checkbox.checked) marker.toggle();
115
            };
116
117
            // Edit
118
            WButton edit = hList.add(theme.button(GuiRenderer.EDIT)).widget();
119
            edit.action = () -> mc.gui.setScreen(marker.getScreen(theme));
120
121
            // Remove
122
            WMinus remove = hList.add(theme.minus()).widget();
123
            remove.action = () -> {
124
                markers.remove(marker);
125
                marker.settings.unregisterColorSettings();
126
127
                list.clear();
128
                fillList(theme, list);
129
            };
130
        }
131
132
        // Bottom
133
        WHorizontalList bottom = list.add(theme.horizontalList()).expandX().widget();
134
135
        WDropdown<String> newMarker = bottom.add(theme.dropdown(factory.getNames(), factory.getNames()[0])).widget();
136
        WButton add = bottom.add(theme.button("Add")).expandX().widget();
137
        add.action = () -> {
138
            String name = newMarker.get();
139
            markers.add(factory.createMarker(name));
140
141
            list.clear();
142
            fillList(theme, list);
143
        };
144
145
    }
146
}
147
OfflineClientRENDERsrc/main/java/com/jellypudding/offlineclient/modules/render/Marker.javaJava · 429 lines · 15.8 KB

Draws shapes you place yourself to build against.

SettingsNew nameNew shapeAddNext layerPrevious layerThrough wallsMarkers
Marker.javaJava · Minecraft 26.2 · 429 lines · 15.8 KB · complete file, verbatimOriginal ↗
1
package com.jellypudding.offlineclient.modules.render;
2
3
import com.google.gson.JsonArray;
4
import com.google.gson.JsonElement;
5
import com.google.gson.JsonObject;
6
import com.jellypudding.offlineclient.event.Subscribe;
7
import com.jellypudding.offlineclient.event.events.KeyPressEvent;
8
import com.jellypudding.offlineclient.event.events.Render3DEvent;
9
import com.jellypudding.offlineclient.event.events.TickEvent;
10
import com.jellypudding.offlineclient.module.Category;
11
import com.jellypudding.offlineclient.module.Module;
12
import com.jellypudding.offlineclient.render.BoxStyle;
13
import com.jellypudding.offlineclient.render.DrawBatch;
14
import com.jellypudding.offlineclient.setting.BoolSetting;
15
import com.jellypudding.offlineclient.setting.EnumSetting;
16
import com.jellypudding.offlineclient.setting.KeybindSetting;
17
import com.jellypudding.offlineclient.setting.NumberSetting;
18
import com.jellypudding.offlineclient.setting.Setting;
19
import com.jellypudding.offlineclient.setting.TextSetting;
20
import com.jellypudding.offlineclient.util.BlockUtil;
21
import com.jellypudding.offlineclient.util.ChatUtil;
22
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
23
import net.minecraft.core.BlockPos;
24
import net.minecraft.core.Direction;
25
import net.minecraft.resources.ResourceKey;
26
import net.minecraft.world.level.Level;
27
import net.minecraft.world.phys.AABB;
28
import net.minecraft.world.phys.BlockHitResult;
29
import net.minecraft.world.phys.HitResult;
30
import org.lwjgl.glfw.GLFW;
31
32
import java.util.ArrayList;
33
import java.util.List;
34
35
// Shapes you place yourself for building. Every one is saved with the module.
36
public final class Marker extends Module {
37
38
    public enum Shape { CUBOID, SPHERE }
39
40
    public enum World { OVERWORLD, NETHER, END }
41
42
    // A sphere slice is one block tall. Its blocks only ever touch sideways.
43
    private static final Direction[] AROUND = {
44
        Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST};
45
46
    private final TextSetting newName = new TextSetting("New name",
47
        "Name for the next marker you add.", "Marker");
48
    private final EnumSetting<Shape> newShape = new EnumSetting<>("New shape",
49
        "Which shape the next marker takes.", Shape.CUBOID)
50
        .describe(Shape.CUBOID, "A box between two corners.")
51
        .describe(Shape.SPHERE, "One flat slice of a ball of blocks.");
52
    private final KeybindSetting addKey = new KeybindSetting("Add",
53
        "Press to add a marker where you are looking.", GLFW.GLFW_KEY_BACKSLASH);
54
    private final KeybindSetting nextLayerKey = new KeybindSetting("Next layer",
55
        "Press to raise the drawn slice of every sphere marker.", GLFW.GLFW_KEY_RIGHT_BRACKET);
56
    private final KeybindSetting prevLayerKey = new KeybindSetting("Previous layer",
57
        "Press to lower the drawn slice of every sphere marker.", GLFW.GLFW_KEY_LEFT_BRACKET);
58
    private final BoolSetting throughWalls = new BoolSetting("Through walls",
59
        "Show the markers behind blocks.", true);
60
61
    private final List<Entry> entries = new ArrayList<>();
62
63
    // One saved entry. The rows are rebuilt from it after the config has loaded.
64
    private final Setting<Void> store = new Setting<Void>("Markers",
65
        "Where every marker is kept.", null) {
66
67
        @Override
68
        public JsonElement toJson() {
69
            JsonArray out = new JsonArray();
70
            for (Entry entry : entries) {
71
                if (!entry.isDropped()) {
72
                    out.add(entry.toJson());
73
                }
74
            }
75
            return out;
76
        }
77
78
        @Override
79
        public void fromJson(JsonElement json) {
80
            if (!json.isJsonArray()) {
81
                return;
82
            }
83
            entries.clear();
84
            for (JsonElement element : json.getAsJsonArray()) {
85
                Entry entry = Entry.read(element);
86
                if (entry != null) {
87
                    entries.add(entry);
88
                }
89
            }
90
        }
91
92
        @Override
93
        public void reset() {
94
            entries.clear();
95
        }
96
    }.visibleWhen(() -> false);
97
98
    public Marker() {
99
        super("Marker", "Draws shapes you place yourself to build against.", Category.RENDER);
100
        addSettings(newName, newShape, addKey, nextLayerKey, prevLayerKey, throughWalls, store);
101
        searchTags("build", "shape", "sphere", "cuboid");
102
    }
103
104
    // The rows of every marker follow the list. One can be added at any time.
105
    @Override
106
    public List<Setting<?>> getSettings() {
107
        List<Setting<?>> all = new ArrayList<>(super.getSettings());
108
        for (Entry entry : entries) {
109
            if (!entry.isDropped()) {
110
                entry.addTo(all);
111
            }
112
        }
113
        return all;
114
    }
115
116
    @Override
117
    public String getSuffix() {
118
        return count(entries.size());
119
    }
120
121
    @Subscribe
122
    private void onTick(TickEvent event) {
123
        entries.removeIf(Entry::isDropped);
124
    }
125
126
    @Subscribe
127
    private void onKeyPress(KeyPressEvent event) {
128
        if (event.getAction() != GLFW.GLFW_PRESS || mc.gui.screen() != null || !inGame()) {
129
            return;
130
        }
131
        int key = event.getKey();
132
        if (addKey.isBound() && key == addKey.getValue()) {
133
            add();
134
        } else if (nextLayerKey.isBound() && key == nextLayerKey.getValue()) {
135
            stepLayer(1);
136
        } else if (prevLayerKey.isBound() && key == prevLayerKey.getValue()) {
137
            stepLayer(-1);
138
        }
139
    }
140
141
    // The block you are looking at or the one you stand on.
142
    private void add() {
143
        BlockPos pos = mc.player.blockPosition();
144
        if (mc.hitResult instanceof BlockHitResult hit && hit.getType() == HitResult.Type.BLOCK) {
145
            pos = hit.getBlockPos();
146
        }
147
        String label = freeName(newName.getValue().trim());
148
        entries.add(new Entry(label, newShape.getValue(), worldOf(mc.level.dimension()), pos));
149
        ChatUtil.message("Added marker " + label + ".");
150
    }
151
152
    // Two markers with one name would share their rows.
153
    private String freeName(String wanted) {
154
        String base = wanted.isEmpty() ? "Marker" : wanted;
155
        String label = base;
156
        int number = 1;
157
        while (taken(label)) {
158
            number++;
159
            label = base + " " + number;
160
        }
161
        return label;
162
    }
163
164
    // A marker named after one of the rows above would fight it for the name.
165
    private boolean taken(String label) {
166
        for (Setting<?> setting : super.getSettings()) {
167
            if (setting.getName().equalsIgnoreCase(label)) {
168
                return true;
169
            }
170
        }
171
        for (Entry entry : entries) {
172
            if (entry.label().equalsIgnoreCase(label)) {
173
                return true;
174
            }
175
        }
176
        return false;
177
    }
178
179
    private void stepLayer(int step) {
180
        for (Entry entry : entries) {
181
            entry.stepLayer(step);
182
        }
183
    }
184
185
    private static World worldOf(ResourceKey<Level> key) {
186
        if (key == Level.NETHER) {
187
            return World.NETHER;
188
        }
189
        return key == Level.END ? World.END : World.OVERWORLD;
190
    }
191
192
    @Subscribe
193
    private void onRender3D(Render3DEvent event) {
194
        if (!inGame()) {
195
            return;
196
        }
197
        World here = worldOf(mc.level.dimension());
198
        boolean through = throughWalls.isOn();
199
        for (Entry entry : entries) {
200
            entry.draw(event.getBatch(), here, through);
201
        }
202
    }
203
204
    // One marker and the rows that shape it.
205
    private static final class Entry {
206
207
        private final String label;
208
        private final Shape shape;
209
        private final BoolSetting active;
210
        private final EnumSetting<World> world;
211
        private final TextSetting first;
212
        private final TextSetting second;
213
        private final NumberSetting radius;
214
        private final NumberSetting layer;
215
        private final BoxStyle style;
216
        private final BoolSetting drop;
217
218
        // The ring of the current slice and the numbers it was worked out from.
219
        private List<BlockPos> ring = List.of();
220
        private String ringKey = "";
221
        private final LongOpenHashSet ringKeys = new LongOpenHashSet();
222
223
        private Entry(String label, Shape shape, World world, BlockPos pos) {
224
            this.label = label;
225
            this.shape = shape;
226
            boolean sphere = shape == Shape.SPHERE;
227
            active = new BoolSetting(label, "Draw this marker.", true);
228
            this.world = new EnumSetting<>(label + " dimension",
229
                "The world this marker belongs to.", world).under(active);
230
            first = new TextSetting(label + (sphere ? " centre" : " corner one"),
231
                "Three numbers for x and y and z.", BlockUtil.text(pos)).under(active);
232
            second = sphere ? null : new TextSetting(label + " corner two",
233
                "Three numbers for x and y and z.", BlockUtil.text(pos)).under(active);
234
            radius = sphere ? new NumberSetting(label + " radius",
235
                "How wide the ball is.", 20, 1, 64, 1, " blocks").min(1).max(256).under(active) : null;
236
            layer = sphere ? new NumberSetting(label + " layer",
237
                "Which slice of the ball is drawn counting up from the bottom.",
238
                20, 0, 40, 1).min(0).max(512).under(active) : null;
239
            style = new BoxStyle(label, BoxStyle.Shape.BOTH, 217).under(active);
240
            drop = new BoolSetting(label + " remove", "Tick to delete this marker.", false)
241
                .under(active);
242
        }
243
244
        private String label() {
245
            return label;
246
        }
247
248
        private boolean isDropped() {
249
            return drop.isOn();
250
        }
251
252
        private void addTo(List<Setting<?>> out) {
253
            out.add(active);
254
            out.add(world);
255
            out.add(first);
256
            if (second != null) {
257
                out.add(second);
258
            }
259
            if (radius != null) {
260
                out.add(radius);
261
                out.add(layer);
262
            }
263
            for (Setting<?> setting : style.settings()) {
264
                out.add(setting);
265
            }
266
            out.add(drop);
267
        }
268
269
        private void stepLayer(int step) {
270
            if (layer == null || !active.isOn()) {
271
                return;
272
            }
273
            layer.setValue((double) Math.clamp(layer.getInt() + step, 0, 2 * radius.getInt()));
274
        }
275
276
        private void draw(DrawBatch batch, World here, boolean through) {
277
            if (!active.isOn() || world.getValue() != here) {
278
                return;
279
            }
280
            if (shape == Shape.CUBOID) {
281
                drawCuboid(batch, through);
282
            } else {
283
                drawSphere(batch, through);
284
            }
285
        }
286
287
        private void drawCuboid(DrawBatch batch, boolean through) {
288
            BlockPos one = parse(first.getValue());
289
            BlockPos two = parse(second.getValue());
290
            if (one == null || two == null) {
291
                return;
292
            }
293
            AABB box = new AABB(Math.min(one.getX(), two.getX()), Math.min(one.getY(), two.getY()),
294
                Math.min(one.getZ(), two.getZ()), Math.max(one.getX(), two.getX()) + 1,
295
                Math.max(one.getY(), two.getY()) + 1, Math.max(one.getZ(), two.getZ()) + 1);
296
            style.draw(batch, box, through);
297
        }
298
299
        private void drawSphere(DrawBatch batch, boolean through) {
300
            BlockPos centre = parse(first.getValue());
301
            if (centre == null) {
302
                return;
303
            }
304
            rebuildRing(centre);
305
            for (BlockPos pos : ring) {
306
                int hidden = 0;
307
                for (Direction side : AROUND) {
308
                    if (ringKeys.contains(BlockPos.offset(pos.asLong(), side))) {
309
                        hidden |= DrawBatch.sideBit(side);
310
                    }
311
                }
312
                style.drawJoined(batch, new AABB(pos.getX(), pos.getY(), pos.getZ(),
313
                    pos.getX() + 1, pos.getY() + 1, pos.getZ() + 1), hidden, through);
314
            }
315
        }
316
317
        // The slice only changes when one of the numbers behind it does.
318
        private void rebuildRing(BlockPos centre) {
319
            int r = radius.getInt();
320
            int slice = Math.min(layer.getInt(), 2 * r);
321
            String key = centre.asLong() + ":" + r + ":" + slice;
322
            if (key.equals(ringKey)) {
323
                return;
324
            }
325
            ringKey = key;
326
            List<BlockPos> found = new ArrayList<>();
327
            ringKeys.clear();
328
            int dy = slice - r;
329
            int flat = (int) Math.ceil(Math.sqrt(Math.max(0, (double) r * r - (double) dy * dy)));
330
            for (int dx = -flat - 1; dx <= flat + 1; dx++) {
331
                for (int dz = -flat - 1; dz <= flat + 1; dz++) {
332
                    double distance = Math.sqrt((double) dx * dx + (double) dy * dy + (double) dz * dz);
333
                    if (distance < r - 0.5 || distance >= r + 0.5) {
334
                        continue;
335
                    }
336
                    BlockPos pos = centre.offset(dx, dy, dz);
337
                    found.add(pos);
338
                    ringKeys.add(pos.asLong());
339
                }
340
            }
341
            ring = found;
342
        }
343
344
        private JsonObject toJson() {
345
            JsonObject out = new JsonObject();
346
            out.addProperty("name", label);
347
            out.addProperty("shape", shape.name());
348
            out.add("active", active.toJson());
349
            out.add("world", world.toJson());
350
            out.add("first", first.toJson());
351
            if (second != null) {
352
                out.add("second", second.toJson());
353
            }
354
            if (radius != null) {
355
                out.add("radius", radius.toJson());
356
                out.add("layer", layer.toJson());
357
            }
358
            JsonArray rows = new JsonArray();
359
            for (Setting<?> setting : style.settings()) {
360
                rows.add(setting.toJson());
361
            }
362
            out.add("style", rows);
363
            return out;
364
        }
365
366
        private static Entry read(JsonElement json) {
367
            if (!json.isJsonObject()) {
368
                return null;
369
            }
370
            JsonObject o = json.getAsJsonObject();
371
            if (!o.has("name") || !o.has("shape")) {
372
                return null;
373
            }
374
            Shape shape;
375
            try {
376
                shape = Shape.valueOf(o.get("shape").getAsString());
377
            } catch (IllegalArgumentException e) {
378
                return null;
379
            }
380
            Entry entry = new Entry(o.get("name").getAsString(), shape,
381
                World.OVERWORLD, BlockPos.ZERO);
382
            entry.apply(o);
383
            return entry;
384
        }
385
386
        private void apply(JsonObject o) {
387
            if (o.has("active")) {
388
                active.fromJson(o.get("active"));
389
            }
390
            if (o.has("world")) {
391
                world.fromJson(o.get("world"));
392
            }
393
            if (o.has("first")) {
394
                first.fromJson(o.get("first"));
395
            }
396
            if (second != null && o.has("second")) {
397
                second.fromJson(o.get("second"));
398
            }
399
            if (radius != null && o.has("radius")) {
400
                radius.fromJson(o.get("radius"));
401
            }
402
            if (layer != null && o.has("layer")) {
403
                layer.fromJson(o.get("layer"));
404
            }
405
            if (o.has("style") && o.get("style").isJsonArray()) {
406
                JsonArray rows = o.getAsJsonArray("style");
407
                Setting<?>[] settings = style.settings();
408
                for (int i = 0; i < settings.length && i < rows.size(); i++) {
409
                    settings[i].fromJson(rows.get(i));
410
                }
411
            }
412
        }
413
414
        // Null when the text is not three whole numbers.
415
        private static BlockPos parse(String text) {
416
            String[] parts = text.trim().split("\\s+");
417
            if (parts.length != 3) {
418
                return null;
419
            }
420
            try {
421
                return new BlockPos(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]),
422
                    Integer.parseInt(parts[2]));
423
            } catch (NumberFormatException e) {
424
                return null;
425
            }
426
        }
427
    }
428
}
429