spawn-proofer module

spawn-proofer: Minecraft 26.3 cheat module, full source for every implementation (1 client: Meteor Client).

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.

Meteor ClientWorldsrc/main/java/meteordevelopment/meteorclient/systems/modules/world/SpawnProofer.javaJava · 210 lines · 7.3 KB

Automatically spawnproofs unlit areas.

Settingsplace-delayplace-rangewalls-rangeblocks-per-ticklight-levelblocksmoderotate
SpawnProofer.javaJava · Minecraft 26.2 · 210 lines · 7.3 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.world;
7
8
import meteordevelopment.meteorclient.events.world.TickEvent;
9
import meteordevelopment.meteorclient.settings.*;
10
import meteordevelopment.meteorclient.systems.modules.Categories;
11
import meteordevelopment.meteorclient.systems.modules.Module;
12
import meteordevelopment.meteorclient.utils.misc.Pool;
13
import meteordevelopment.meteorclient.utils.player.FindItemResult;
14
import meteordevelopment.meteorclient.utils.player.InvUtils;
15
import meteordevelopment.meteorclient.utils.player.PlayerUtils;
16
import meteordevelopment.meteorclient.utils.world.BlockIterator;
17
import meteordevelopment.meteorclient.utils.world.BlockUtils;
18
import meteordevelopment.orbit.EventHandler;
19
import net.minecraft.core.BlockPos;
20
import net.minecraft.world.level.ClipContext;
21
import net.minecraft.world.level.block.*;
22
import net.minecraft.world.phys.BlockHitResult;
23
import net.minecraft.world.phys.Vec3;
24
25
import java.util.ArrayList;
26
import java.util.Comparator;
27
import java.util.List;
28
29
public class SpawnProofer extends Module {
30
    private final SettingGroup sgGeneral = settings.getDefaultGroup();
31
32
    private final Setting<Integer> placeDelay = sgGeneral.add(new IntSetting.Builder()
33
        .name("place-delay")
34
        .description("The tick delay between placing blocks.")
35
        .defaultValue(1)
36
        .range(0, 10)
37
        .build()
38
    );
39
40
    private final Setting<Double> placeRange = sgGeneral.add(new DoubleSetting.Builder()
41
        .name("place-range")
42
        .description("How far away from the player you can place a block.")
43
        .defaultValue(4.5)
44
        .min(0)
45
        .sliderMax(6)
46
        .build()
47
    );
48
49
    private final Setting<Double> wallsRange = sgGeneral.add(new DoubleSetting.Builder()
50
        .name("walls-range")
51
        .description("How far away from the player you can place a block behind walls.")
52
        .defaultValue(4.5)
53
        .min(0)
54
        .sliderMax(6)
55
        .build()
56
    );
57
58
    private final Setting<Integer> blocksPerTick = sgGeneral.add(new IntSetting.Builder()
59
        .name("blocks-per-tick")
60
        .description("How many blocks to place in one tick.")
61
        .defaultValue(1)
62
        .min(1)
63
        .build()
64
    );
65
66
    private final Setting<Integer> lightLevel = sgGeneral.add(new IntSetting.Builder()
67
        .name("light-level")
68
        .description("Light levels to spawn proof. Old spawning light: 7.")
69
        .defaultValue(0)
70
        .min(0)
71
        .sliderMax(15)
72
        .build()
73
    );
74
75
    private final Setting<List<Block>> blocks = sgGeneral.add(new BlockListSetting.Builder()
76
        .name("blocks")
77
        .description("Block to use for spawn proofing.")
78
        .defaultValue(Blocks.TORCH, Blocks.STONE_BUTTON, Blocks.STONE_SLAB)
79
        .filter(this::filterBlocks)
80
        .build()
81
    );
82
83
    private final Setting<Mode> mode = sgGeneral.add(new EnumSetting.Builder<Mode>()
84
        .name("mode")
85
        .description("Which spawn types should be spawn proofed.")
86
        .defaultValue(Mode.Both)
87
        .build()
88
    );
89
90
    private final Setting<Boolean> rotate = sgGeneral.add(new BoolSetting.Builder()
91
        .name("rotate")
92
        .description("Rotates towards the blocks being placed.")
93
        .defaultValue(true)
94
        .build()
95
    );
96
97
    private final Pool<BlockPos.MutableBlockPos> spawnPool = new Pool<>(BlockPos.MutableBlockPos::new);
98
    private final List<BlockPos.MutableBlockPos> spawns = new ArrayList<>();
99
    private int timer;
100
101
    public SpawnProofer() {
102
        super(Categories.World, "spawn-proofer", "Automatically spawnproofs unlit areas.");
103
    }
104
105
    @EventHandler
106
    private void onTickPre(TickEvent.Pre event) {
107
        if (timer < placeDelay.get()) return;
108
109
        // Find slot
110
        boolean foundBlock = InvUtils.testInHotbar(itemStack -> blocks.get().contains(Block.byItem(itemStack.getItem())));
111
        if (!foundBlock) {
112
            error("Found none of the chosen blocks in hotbar.");
113
            toggle();
114
            return;
115
        }
116
117
        // Find spawn locations
118
        spawnPool.freeAll(spawns);
119
        spawns.clear();
120
121
        BlockIterator.register((int) Math.ceil(placeRange.get()), (int) Math.ceil(placeRange.get()), (blockPos, blockState) -> {
122
            BlockUtils.MobSpawn spawn = BlockUtils.isValidMobSpawn(blockPos, blockState, lightLevel.get());
123
124
            if ((spawn == BlockUtils.MobSpawn.Always && (mode.get() == Mode.Always || mode.get() == Mode.Both)) ||
125
                spawn == BlockUtils.MobSpawn.Potential && (mode.get() == Mode.Potential || mode.get() == Mode.Both)) {
126
127
                if (!BlockUtils.canPlace(blockPos)) return;
128
129
                // Check range and raycast
130
                if (isOutOfRange(blockPos)) return;
131
132
                spawns.add(spawnPool.get().set(blockPos));
133
            }
134
        });
135
    }
136
137
    @EventHandler
138
    private void onTickPost(TickEvent.Post event) {
139
        // Delay
140
        if (timer++ < placeDelay.get()) return;
141
142
        if (spawns.isEmpty()) return;
143
144
        // Find slot
145
        FindItemResult block = InvUtils.findInHotbar(itemStack -> blocks.get().contains(Block.byItem(itemStack.getItem())));
146
        if (!block.found()) {
147
            error("Found none of the chosen blocks in hotbar.");
148
            toggle();
149
            return;
150
        }
151
152
        int placedCount = 0;
153
154
        // Sort blocks to use the lowest light level spawns first
155
        if (isLightSource(Block.byItem(mc.player.getInventory().getItem(block.slot()).getItem()))) {
156
            spawns.sort(Comparator.comparingInt(blockPos -> mc.level.getMaxLocalRawBrightness(blockPos)));
157
            placedCount = blocksPerTick.get() - 1; // Force only one light source per tick to stop unnecessary placements
158
        }
159
160
        // Place blocks!
161
        for (BlockPos blockPos : spawns) {
162
            if (placedCount >= blocksPerTick.get()) continue;
163
164
            if (BlockUtils.place(blockPos, block, rotate.get(), -50, false)) {
165
                placedCount++;
166
            }
167
        }
168
169
        timer = 0;
170
    }
171
172
    private boolean isOutOfRange(BlockPos blockPos) {
173
        Vec3 pos = Vec3.atCenterOf(blockPos);
174
        if (!PlayerUtils.isWithin(pos, placeRange.get())) return true;
175
176
        ClipContext raycastContext = new ClipContext(mc.player.getEyePosition(), pos, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mc.player);
177
        BlockHitResult result = mc.level.clip(raycastContext);
178
        if (result == null || !result.getBlockPos().equals(blockPos))
179
            return !PlayerUtils.isWithin(pos, wallsRange.get());
180
181
        return false;
182
    }
183
184
    private boolean filterBlocks(Block block) {
185
        return isNonOpaqueBlock(block) || isLightSource(block);
186
    }
187
188
    private boolean isNonOpaqueBlock(Block block) {
189
        return block instanceof ButtonBlock ||
190
            block instanceof SlabBlock ||
191
            block instanceof BasePressurePlateBlock ||
192
            block instanceof TransparentBlock ||
193
            block instanceof TripWireBlock ||
194
            block instanceof CarpetBlock ||
195
            block instanceof LeverBlock ||
196
            block instanceof DiodeBlock ||
197
            block instanceof BaseRailBlock;
198
    }
199
200
    private boolean isLightSource(Block block) {
201
        return block.defaultBlockState().getLightEmission() > 0;
202
    }
203
204
    public enum Mode {
205
        Always,
206
        Potential,
207
        Both
208
    }
209
}
210