xray module

xray: Minecraft 26.3 cheat module, full source for every implementation (6 clients: Meteor Client, MelaHack (ThunderHack fork), OfflineClient, …).

6 implementationsRenderMISCRENDER

Full module source: 6 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/Xray.javaJava · 193 lines · 7.3 KB

Only renders specified blocks. Good for mining.

Settingswhitelistopacityfluid-opacityexposed-only
Xray.javaJava · Minecraft 26.2 · 193 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.render;
7
8
import meteordevelopment.meteorclient.MixinPlugin;
9
import meteordevelopment.meteorclient.events.render.RenderBlockEntityEvent;
10
import meteordevelopment.meteorclient.events.world.AmbientOcclusionEvent;
11
import meteordevelopment.meteorclient.events.world.ChunkOcclusionEvent;
12
import meteordevelopment.meteorclient.gui.GuiTheme;
13
import meteordevelopment.meteorclient.gui.widgets.WWidget;
14
import meteordevelopment.meteorclient.mixin.BlockEntityRenderStateAccessor;
15
import meteordevelopment.meteorclient.settings.*;
16
import meteordevelopment.meteorclient.systems.modules.Categories;
17
import meteordevelopment.meteorclient.systems.modules.Module;
18
import meteordevelopment.meteorclient.systems.modules.Modules;
19
import meteordevelopment.meteorclient.utils.world.BlockUtils;
20
import meteordevelopment.orbit.EventHandler;
21
import net.irisshaders.iris.api.v0.IrisApi;
22
import net.minecraft.core.BlockPos;
23
import net.minecraft.core.Direction;
24
import net.minecraft.tags.FluidTags;
25
import net.minecraft.world.level.BlockGetter;
26
import net.minecraft.world.level.block.Block;
27
import net.minecraft.world.level.block.Blocks;
28
import net.minecraft.world.level.block.state.BlockState;
29
import net.minecraft.world.level.material.FluidState;
30
import net.minecraft.world.phys.shapes.Shapes;
31
32
import java.util.List;
33
34
public class Xray extends Module {
35
    private final SettingGroup sgGeneral = settings.getDefaultGroup();
36
37
    public static final List<Block> ORES = List.of(Blocks.COAL_ORE, Blocks.DEEPSLATE_COAL_ORE, Blocks.IRON_ORE, Blocks.DEEPSLATE_IRON_ORE, Blocks.GOLD_ORE, Blocks.DEEPSLATE_GOLD_ORE, Blocks.LAPIS_ORE, Blocks.DEEPSLATE_LAPIS_ORE, Blocks.REDSTONE_ORE, Blocks.DEEPSLATE_REDSTONE_ORE, Blocks.DIAMOND_ORE, Blocks.DEEPSLATE_DIAMOND_ORE, Blocks.EMERALD_ORE, Blocks.DEEPSLATE_EMERALD_ORE, Blocks.COPPER_ORE, Blocks.DEEPSLATE_COPPER_ORE, Blocks.NETHER_GOLD_ORE, Blocks.NETHER_QUARTZ_ORE, Blocks.ANCIENT_DEBRIS);
38
39
    private final Setting<List<Block>> blocks = sgGeneral.add(new BlockListSetting.Builder()
40
        .name("whitelist")
41
        .description("Which blocks to show x-rayed.")
42
        .defaultValue(ORES)
43
        .onChanged(_ -> {
44
            if (isActive()) {
45
                mc.levelExtractor.allChanged();
46
            }
47
        })
48
        .build()
49
    );
50
51
    public final Setting<Integer> opacity = sgGeneral.add(new IntSetting.Builder()
52
        .name("opacity")
53
        .description("The opacity for all other blocks.")
54
        .defaultValue(25)
55
        .range(0, 255)
56
        .sliderMax(255)
57
        .onChanged(_ -> {
58
            if (isActive()) {
59
                mc.levelExtractor.allChanged();
60
            }
61
        })
62
        .build()
63
    );
64
65
    private final Setting<FluidOpacity> fluidOpacity = sgGeneral.add(new EnumSetting.Builder<FluidOpacity>()
66
        .name("fluid-opacity")
67
        .description("Which fluids should use xray opacity.")
68
        .defaultValue(FluidOpacity.Both)
69
        .onChanged(_ -> {
70
            if (isActive()) {
71
                mc.levelExtractor.allChanged();
72
            }
73
        })
74
        .build()
75
    );
76
77
    private final Setting<Boolean> exposedOnly = sgGeneral.add(new BoolSetting.Builder()
78
        .name("exposed-only")
79
        .description("Show only exposed ores.")
80
        .defaultValue(false)
81
        .onChanged(_ -> {
82
            if (isActive()) {
83
                mc.levelExtractor.allChanged();
84
            }
85
        })
86
        .build());
87
88
    public Xray() {
89
        super(Categories.Render, "xray", "Only renders specified blocks. Good for mining.");
90
    }
91
92
    @Override
93
    public void onActivate() {
94
        mc.levelExtractor.allChanged();
95
    }
96
97
    @Override
98
    public void onDeactivate() {
99
        mc.levelExtractor.allChanged();
100
    }
101
102
    @Override
103
    public WWidget getWidget(GuiTheme theme) {
104
        if (MixinPlugin.isIrisPresent && IrisApi.getInstance().isShaderPackInUse())
105
            return theme.label("Warning: Due to shaders in use, opacity is overridden to 0.");
106
107
        return null;
108
    }
109
110
    @EventHandler
111
    private void onRenderBlockEntity(RenderBlockEntityEvent event) {
112
        BlockState state = ((BlockEntityRenderStateAccessor) event.blockEntityState).meteor$getBlockState();
113
        if (getAlpha(state, event.blockEntityState.blockPos) == 0) event.cancel();
114
    }
115
116
    @EventHandler
117
    private void onChunkOcclusion(ChunkOcclusionEvent event) {
118
        event.cancel();
119
    }
120
121
    @EventHandler
122
    private void onAmbientOcclusion(AmbientOcclusionEvent event) {
123
        event.lightLevel = 1;
124
    }
125
126
    public boolean modifyDrawSide(BlockState state, BlockGetter view, BlockPos pos, Direction facing, boolean returns) {
127
        if (!returns && !isBlocked(state.getBlock(), pos)) {
128
            BlockPos adjPos = pos.relative(facing);
129
            BlockState adjState = view.getBlockState(adjPos);
130
            return adjState.getFaceOcclusionShape(facing.getOpposite()) != Shapes.block() || adjState.getBlock() != state.getBlock() || !adjState.isSolidRender() || isBlocked(adjState.getBlock(), adjPos);
131
        }
132
133
        return returns;
134
    }
135
136
    public boolean isBlocked(Block block, BlockPos blockPos) {
137
        return !(blocks.get().contains(block) && (!exposedOnly.get() || (blockPos == null || BlockUtils.isExposed(blockPos))));
138
    }
139
140
    public static int getAlpha(BlockState state, BlockPos pos) {
141
        WallHack wallHack = Modules.get().get(WallHack.class);
142
        Xray xray = Modules.get().get(Xray.class);
143
        Block block = state.getBlock();
144
145
        if (wallHack.isActive() && wallHack.blocks.get().contains(block)) {
146
            if (MixinPlugin.isIrisPresent && IrisApi.getInstance().isShaderPackInUse()) return 0;
147
148
            int alpha;
149
150
            if (xray.isActive()) alpha = xray.opacity.get();
151
            else alpha = wallHack.opacity.get();
152
153
            return alpha;
154
        } else if (xray.isActive() && !wallHack.isActive() && xray.isBlocked(block, pos)) {
155
            return (MixinPlugin.isIrisPresent && IrisApi.getInstance().isShaderPackInUse()) ? 0 : xray.opacity.get();
156
        }
157
158
        return -1;
159
    }
160
161
    public static int getFluidAlpha(FluidState state, BlockPos pos) {
162
        WallHack wallHack = Modules.get().get(WallHack.class);
163
        Xray xray = Modules.get().get(Xray.class);
164
        Block fluidBlock = state.createLegacyBlock().getBlock();
165
166
        if (wallHack.isActive() && wallHack.blocks.get().contains(fluidBlock)) {
167
            if (MixinPlugin.isIrisPresent && IrisApi.getInstance().isShaderPackInUse()) return 0;
168
169
            return xray.isActive() ? xray.opacity.get() : wallHack.opacity.get();
170
        } else if (xray.isActive() && !wallHack.isActive() && xray.shouldApplyFluidOpacity(state) && xray.isBlocked(fluidBlock, pos)) {
171
            return (MixinPlugin.isIrisPresent && IrisApi.getInstance().isShaderPackInUse()) ? 0 : xray.opacity.get();
172
        }
173
174
        return -1;
175
    }
176
177
    private boolean shouldApplyFluidOpacity(FluidState state) {
178
        return switch (fluidOpacity.get()) {
179
            case None -> false;
180
            case Water -> state.is(FluidTags.WATER);
181
            case Lava -> state.is(FluidTags.LAVA);
182
            case Both -> state.is(FluidTags.WATER) || state.is(FluidTags.LAVA);
183
        };
184
    }
185
186
    public enum FluidOpacity {
187
        None,
188
        Water,
189
        Lava,
190
        Both
191
    }
192
}
193
MelaHack (ThunderHack fork)MISCsrc/main/java/thunder/hack/features/modules/render/XRay.javaJava · 274 lines · 13.7 KB

Diamonds? No problem.

SettingsPluginWallHackOreDeobfFastDelayRadiusUpDownNetheriteDiamondGoldIronEmeraldRedstoneLapisCoalQuartzWaterLava
XRay.javaJava · Minecraft 26.2 · 274 lines · 13.7 KB · complete file, verbatimOriginal ↗
1
package thunder.hack.features.modules.render;
2
3
import meteordevelopment.orbit.EventHandler;
4
import net.minecraft.client.gui.GuiGraphicsExtractor;
5
import net.minecraft.core.BlockPos;
6
import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket;
7
import net.minecraft.network.protocol.game.ServerboundSwingPacket;
8
import net.minecraft.tags.ItemTags;
9
import net.minecraft.util.Mth;
10
import net.minecraft.world.InteractionHand;
11
import net.minecraft.world.level.block.Block;
12
import net.minecraft.world.level.block.Blocks;
13
import net.minecraft.world.phys.AABB;
14
import org.jetbrains.annotations.NotNull;
15
import thunder.hack.events.impl.EventMove;
16
import thunder.hack.events.impl.EventSetting;
17
import thunder.hack.events.impl.PacketEvent;
18
import thunder.hack.features.modules.Module;
19
import thunder.hack.features.modules.client.HudEditor;
20
import thunder.hack.gui.font.FontRenderers;
21
import thunder.hack.setting.Setting;
22
import thunder.hack.utility.Timer;
23
import thunder.hack.utility.math.FrameRateCounter;
24
import thunder.hack.utility.math.MathUtility;
25
import thunder.hack.utility.player.MovementUtility;
26
import thunder.hack.utility.render.Render2DEngine;
27
import thunder.hack.utility.render.Render3DEngine;
28
29
import java.awt.*;
30
import java.util.ArrayList;
31
import java.util.concurrent.ThreadLocalRandom;
32
33
import static thunder.hack.features.modules.client.ClientSettings.isRu;
34
35
import com.mojang.blaze3d.vertex.PoseStack;
36
37
public class XRay extends Module {
38
    public XRay() {
39
        super("XRay", Category.MISC);
40
    }
41
42
    private final Setting<Plugin> plugin = new Setting<>("Plugin", Plugin.New);
43
    public final Setting<Boolean> wallHack = new Setting<>("WallHack", false);
44
    private final Setting<Boolean> brutForce = new Setting<>("OreDeobf", false);
45
    private final Setting<Boolean> fast = new Setting<>("Fast", false, v -> brutForce.getValue());
46
    private final Setting<Integer> delay = new Setting<>("Delay", 25, 1, 100, v -> brutForce.getValue());
47
    private final Setting<Integer> radius = new Setting<>("Radius", 5, 1, 64, v -> brutForce.getValue());
48
    private final Setting<Integer> up = new Setting<>("Up", 5, 1, 32, v -> brutForce.getValue());
49
    private final Setting<Integer> down = new Setting<>("Down", 5, 1, 32, v -> brutForce.getValue());
50
    private static final Setting<Boolean> netherite = new Setting<>("Netherite", false);
51
    private static final Setting<Boolean> diamond = new Setting<>("Diamond ", false);
52
    private static final Setting<Boolean> gold = new Setting<>("Gold", false);
53
    private static final Setting<Boolean> iron = new Setting<>("Iron", false);
54
    private static final Setting<Boolean> emerald = new Setting<>("Emerald", false);
55
    private static final Setting<Boolean> redstone = new Setting<>("Redstone", false);
56
    private static final Setting<Boolean> lapis = new Setting<>("Lapis", false);
57
    private static final Setting<Boolean> coal = new Setting<>("Coal", false);
58
    private static final Setting<Boolean> quartz = new Setting<>("Quartz", false);
59
    private static final Setting<Boolean> water = new Setting<>("Water", false);
60
    private static final Setting<Boolean> lava = new Setting<>("Lava", false);
61
62
    private final Timer delayTimer = new Timer();
63
    private final ArrayList<BlockPos> ores = new ArrayList<>();
64
    private final ArrayList<BlockPos> toCheck = new ArrayList<>();
65
    private final ArrayList<BlockMemory> checked = new ArrayList<>();
66
    private BlockPos displayBlock;
67
    private int done, all;
68
    private AABB area = new AABB(BlockPos.ZERO);
69
70
    @Override
71
    public void onEnable() {
72
        ores.clear();
73
        toCheck.clear();
74
        checked.clear();
75
        toCheck.addAll(getBlocks());
76
        all = toCheck.size();
77
        done = 0;
78
        mc.smartCull = false;
79
        mc.levelRenderer.invalidateCompiledGeometry(mc.level, mc.options, mc.gameRenderer.mainCamera(), mc.getBlockColors());
80
        area = getArea();
81
    }
82
83
    @Override
84
    public void onDisable() {
85
        mc.levelRenderer.invalidateCompiledGeometry(mc.level, mc.options, mc.gameRenderer.mainCamera(), mc.getBlockColors());
86
        mc.smartCull = true;
87
    }
88
89
    @EventHandler
90
    public void onReceivePacket(PacketEvent.Receive e) {
91
        if (e.getPacket() instanceof ClientboundBlockUpdatePacket pac) {
92
            debug(((ClientboundBlockUpdatePacket) e.getPacket()).getBlockState().getBlock().getName().getString() + " " + pac.getPos().toString());
93
            if (isCheckableOre(pac.getBlockState().getBlock()) && !ores.contains(pac.getPos())) ores.add(pac.getPos());
94
        }
95
    }
96
97
    @EventHandler
98
    public void onSettingChange(EventSetting e) {
99
        if (e.getSetting() == wallHack) {
100
            mc.levelRenderer.invalidateCompiledGeometry(mc.level, mc.options, mc.gameRenderer.mainCamera(), mc.getBlockColors());
101
        }
102
    }
103
104
    @EventHandler
105
    public void onMove(EventMove e) {
106
        if (brutForce.getValue()) {
107
            if (all != done) {
108
                e.setZ(0);
109
                e.setX(0);
110
                e.cancel();
111
                if (mc.player.tickCount % 8 == 0 && MovementUtility.isMoving())
112
                    sendMessage(isRu() ? "Не двигайся пока идет деобфускация!" : "Don't move while deobf!");
113
            } else {
114
                AABB newArea = getArea();
115
                if (!newArea.intersects(area)) {
116
                    area = newArea;
117
                    toCheck.clear();
118
                    toCheck.addAll(getBlocks());
119
                    checked.clear();
120
                    all = toCheck.size();
121
                    done = 0;
122
                }
123
            }
124
        }
125
    }
126
127
    @NotNull
128
    private AABB getArea() {
129
        int radius_ = plugin.is(Plugin.New) ? Math.min(4, radius.getValue()) : radius.getValue();
130
        int down_ = plugin.is(Plugin.New) ? Math.min(3, down.getValue()) : down.getValue();
131
        int up_ = plugin.is(Plugin.New) ? Math.min(4, up.getValue()) : up.getValue();
132
        return new AABB(mc.player.getX() - radius_, mc.player.getY() - down_, mc.player.getZ() - radius_, mc.player.getX() + radius_, mc.player.getY() + up_, mc.player.getZ() + radius_);
133
    }
134
135
    @Override
136
    public void onUpdate() {
137
        if (plugin.is(Plugin.New))
138
            checked.forEach(blockMemory -> {
139
                if (blockMemory.isDelayed() && !ores.contains(blockMemory.bp))
140
                    ores.add(blockMemory.bp);
141
            });
142
    }
143
144
    public void onRender3D(PoseStack stack) { //FABOS IDI NAHUI
145
        for (BlockPos pos : ores) {
146
            Block block = mc.level.getBlockState(pos).getBlock();
147
            if ((block == Blocks.DIAMOND_ORE || block == Blocks.DEEPSLATE_DIAMOND_ORE) && diamond.getValue())
148
                draw(pos, 0, 255, 255);
149
            if ((block == Blocks.GOLD_ORE || block == Blocks.DEEPSLATE_GOLD_ORE) && gold.getValue())
150
                draw(pos, 255, 215, 0);
151
            if (block == Blocks.NETHER_GOLD_ORE && gold.getValue()) draw(pos, 255, 215, 0);
152
            if ((block == Blocks.IRON_ORE || block == Blocks.DEEPSLATE_IRON_ORE) && iron.getValue())
153
                draw(pos, 213, 213, 213);
154
            if ((block == Blocks.EMERALD_ORE || block == Blocks.DEEPSLATE_EMERALD_ORE) && emerald.getValue())
155
                draw(pos, 0, 255, 77);
156
            if ((block == Blocks.REDSTONE_ORE || block == Blocks.DEEPSLATE_REDSTONE_ORE) && redstone.getValue())
157
                draw(pos, 255, 0, 0);
158
            if (block == Blocks.COAL_ORE && coal.getValue()) draw(pos, 0, 0, 0);
159
            if ((block == Blocks.LAPIS_ORE || block == Blocks.DEEPSLATE_LAPIS_ORE) && lapis.getValue())
160
                draw(pos, 38, 97, 156);
161
            if (block == Blocks.ANCIENT_DEBRIS && netherite.getValue()) draw(pos, 255, 255, 255);
162
            if (block == Blocks.NETHER_QUARTZ_ORE && quartz.getValue()) draw(pos, 170, 170, 170);
163
        }
164
165
        if (displayBlock != null && (done != all)) draw(displayBlock, 255, 0, 60);
166
167
        if (brutForce.getValue())
168
            Render3DEngine.OUTLINE_QUEUE.add(new Render3DEngine.OutlineAction(area, HudEditor.getColor(1), 2));
169
170
        if (toCheck.isEmpty() || !brutForce.getValue()) return;
171
172
        if (mc.isLocalServer()) {
173
            disable(isRu() ? "Братан, ты в синглплеере" : "Bro, you're in singleplayer");
174
            return;
175
        }
176
177
        if (mc.player.getMainHandItem().is(ItemTags.PICKAXES)) {
178
            if (mc.player.tickCount % 8 == 0) disable(isRu() ? "Убери кирку из руки!" : "Remove pickaxe from ur hand!");
179
            return;
180
        }
181
182
        if (delayTimer.every(delay.getValue())) {
183
            BlockPos pos = toCheck.remove(toCheck.size() - 1 <= 1 ? 0 : ThreadLocalRandom.current().nextInt(0, toCheck.size() - 1));
184
            mc.gameMode.startDestroyBlock(displayBlock = pos, mc.player.getDirection());
185
            mc.gameMode.stopDestroyBlock();
186
            sendPacket(new ServerboundSwingPacket(InteractionHand.MAIN_HAND));
187
            checked.add(new BlockMemory(pos));
188
            ++done;
189
        }
190
    }
191
192
    private void draw(BlockPos pos, int r, int g, int b) {
193
        Render3DEngine.FILLED_QUEUE.add(new Render3DEngine.FillAction(new AABB(pos), new Color(r, g, b, 100)));
194
        Render3DEngine.OUTLINE_QUEUE.add(new Render3DEngine.OutlineAction(new AABB(pos), new Color(r, g, b, 200), 2));
195
    }
196
197
    public void onRender2D(GuiGraphicsExtractor context) {
198
        if (brutForce.getValue()) {
199
200
            float posX = mc.getWindow().getGuiScaledWidth() / 2f - 68;
201
            float posY = mc.getWindow().getGuiScaledHeight() / 2f + 68;
202
203
            Render2DEngine.drawGradientBlurredShadow(context.pose(), posX + 2, posY + 2, 133, 44, 14, HudEditor.getColor(270), HudEditor.getColor(0), HudEditor.getColor(180), HudEditor.getColor(90));
204
            Render2DEngine.renderRoundedGradientRect(context.pose(), HudEditor.getColor(270), HudEditor.getColor(0), HudEditor.getColor(180), HudEditor.getColor(90), posX, posY, 137, 47.5f, 9);
205
            Render2DEngine.drawRound(context.pose(), posX + 0.5f, posY + 0.5f, 136f, 46, 9, Render2DEngine.injectAlpha(Color.BLACK, 220));
206
207
            Render2DEngine.drawGradientRound(context.pose(), posX + 4, posY + 32, 129, 11, 4f, HudEditor.getColor(0).darker().darker(), HudEditor.getColor(0).darker().darker().darker().darker(), HudEditor.getColor(0).darker().darker().darker().darker(), HudEditor.getColor(0).darker().darker().darker().darker());
208
209
            Render2DEngine.renderRoundedGradientRect(context.pose(), HudEditor.getColor(270), HudEditor.getColor(0), HudEditor.getColor(0), HudEditor.getColor(270), posX + 4, posY + 32, (int) Mth.clamp((129 * ((float) done / Math.max((float) all, 1))), 8, 129), 11, 4f);
210
211
            FontRenderers.sf_bold.drawCenteredString(context.pose(), (int) ((float) done / (float) all * 100) + "%", posX + 68, posY + 35f, -1);
212
            FontRenderers.sf_bold.drawCenteredString(context.pose(), "XRay", posX + 68, posY + 7, -1);
213
            double time = 0;
214
            try {
215
                time = MathUtility.round((all - done) * ((1000. / FrameRateCounter.INSTANCE.getFps() + delay.getValue()) / 1000f), 1);
216
            } catch (NumberFormatException ignored) {
217
            }
218
            FontRenderers.sf_bold.drawCenteredString(context.pose(), done + " / " + all + (isRu() ? " Осталось: " : " Estimated time: ") + time + "s", posX + 68, posY + 18, -1);
219
220
        }
221
    }
222
223
    public static boolean isCheckableOre(Block block) {
224
        if (diamond.getValue() && (block == Blocks.DIAMOND_ORE || block == Blocks.DEEPSLATE_DIAMOND_ORE)) return true;
225
        if (gold.getValue() && (block == Blocks.GOLD_ORE || block == Blocks.DEEPSLATE_GOLD_ORE || block == Blocks.NETHER_GOLD_ORE))
226
            return true;
227
        if (iron.getValue() && (block == Blocks.IRON_ORE || block == Blocks.DEEPSLATE_IRON_ORE)) return true;
228
        if (emerald.getValue() && (block == Blocks.EMERALD_ORE || block == Blocks.DEEPSLATE_EMERALD_ORE)) return true;
229
        if (redstone.getValue() && (block == Blocks.REDSTONE_ORE || block == Blocks.DEEPSLATE_REDSTONE_ORE))
230
            return true;
231
        if (coal.getValue() && (block == Blocks.COAL_ORE || block == Blocks.DEEPSLATE_COAL_ORE)) return true;
232
        if (netherite.getValue() && block == Blocks.ANCIENT_DEBRIS) return true;
233
        if (water.getValue() && block == Blocks.WATER) return true;
234
        if (lava.getValue() && block == Blocks.LAVA) return true;
235
        if (quartz.getValue() && block == Blocks.NETHER_QUARTZ_ORE) return true;
236
        if (lapis.getValue() && (block == Blocks.LAPIS_ORE || block == Blocks.DEEPSLATE_LAPIS_ORE)) return true;
237
        return lapis.getValue() && (block == Blocks.LAPIS_ORE || block == Blocks.DEEPSLATE_LAPIS_ORE);
238
    }
239
240
    private ArrayList<BlockPos> getBlocks() {
241
        int radius_ = plugin.is(Plugin.New) ? Math.min(4, radius.getValue()) : radius.getValue();
242
        int down_ = plugin.is(Plugin.New) ? Math.min(3, down.getValue()) : down.getValue();
243
        int up_ = plugin.is(Plugin.New) ? Math.min(4, up.getValue()) : up.getValue();
244
245
        ArrayList<BlockPos> positions = new ArrayList<>();
246
        for (int x = (int) (mc.player.getX() - radius_); x < mc.player.getX() + radius_; x++)
247
            for (int y = (int) (mc.player.getY() - down_); y < mc.player.getY() + up_; y++)
248
                for (int z = (int) (mc.player.getZ() - radius_); z < mc.player.getZ() + radius_; z++) {
249
                    BlockPos pos = new BlockPos(x, y, z);
250
                    if (mc.level.isEmptyBlock(pos) || (fast.getValue() && plugin.is(Plugin.Old) && (x % 2 == 0 || y % 2 == 0 || z % 2 == 0)))
251
                        continue;
252
                    positions.add(pos);
253
                }
254
        return positions;
255
    }
256
257
    public class BlockMemory {
258
        private final BlockPos bp;
259
        private long time = 0;
260
261
        public BlockMemory(BlockPos bp) {
262
            this.bp = bp;
263
        }
264
265
        private boolean isDelayed() {
266
            return this.time++ > 10;
267
        }
268
    }
269
270
    private enum Plugin {
271
        Old, New;
272
    }
273
}
274
OfflineClientRENDERsrc/main/java/com/jellypudding/offlineclient/modules/render/XRay.javaJava · 190 lines · 6.5 KB

See ores through the ground.

SettingsBlocksLavaWaterExposed onlyOpacity
XRay.javaJava · Minecraft 26.2 · 190 lines · 6.5 KB · complete file, verbatimOriginal ↗
1
package com.jellypudding.offlineclient.modules.render;
2
3
import com.jellypudding.offlineclient.event.Subscribe;
4
import com.jellypudding.offlineclient.event.events.TickEvent;
5
import com.jellypudding.offlineclient.module.Category;
6
import com.jellypudding.offlineclient.module.Module;
7
import com.jellypudding.offlineclient.setting.BoolSetting;
8
import com.jellypudding.offlineclient.setting.NumberSetting;
9
import com.jellypudding.offlineclient.setting.RegistryListSetting;
10
import com.jellypudding.offlineclient.util.ChunkRebuild;
11
import net.minecraft.core.BlockPos;
12
import net.minecraft.core.Direction;
13
import net.minecraft.core.registries.BuiltInRegistries;
14
import net.minecraft.world.level.BlockGetter;
15
import net.minecraft.world.level.block.Block;
16
import net.minecraft.world.level.block.Blocks;
17
import net.minecraft.world.level.block.state.BlockState;
18
19
import java.util.HashSet;
20
import java.util.List;
21
import java.util.Set;
22
23
// The chunk mesher asks this module which blocks to keep.
24
// Chunks are rebuilt whenever a setting changes.
25
public final class XRay extends Module {
26
27
    // The chunk mesher reads this once per block.
28
    private static volatile XRay instance;
29
30
    private final RegistryListSetting<Block> blocks = new RegistryListSetting<>("Blocks",
31
        "The blocks that stay visible.", BuiltInRegistries.BLOCK,
32
        List.of(Blocks.DIAMOND_ORE, Blocks.DEEPSLATE_DIAMOND_ORE,
33
            Blocks.EMERALD_ORE, Blocks.DEEPSLATE_EMERALD_ORE,
34
            Blocks.GOLD_ORE, Blocks.DEEPSLATE_GOLD_ORE,
35
            Blocks.IRON_ORE, Blocks.DEEPSLATE_IRON_ORE,
36
            Blocks.REDSTONE_ORE, Blocks.DEEPSLATE_REDSTONE_ORE,
37
            Blocks.LAPIS_ORE, Blocks.DEEPSLATE_LAPIS_ORE,
38
            Blocks.COAL_ORE, Blocks.DEEPSLATE_COAL_ORE,
39
            Blocks.COPPER_ORE, Blocks.DEEPSLATE_COPPER_ORE,
40
            Blocks.ANCIENT_DEBRIS, Blocks.NETHER_GOLD_ORE, Blocks.NETHER_QUARTZ_ORE));
41
    private final BoolSetting lava = new BoolSetting("Lava",
42
        "Shows lava before you dig into it.", true);
43
    private final BoolSetting water = new BoolSetting("Water",
44
        "Show water.", false);
45
    private final BoolSetting exposedOnly = new BoolSetting("Exposed only",
46
        "Only show ores that touch air or a cave.", false);
47
    private final NumberSetting opacity = new NumberSetting("Opacity",
48
        "How visible the hidden blocks stay.",
49
        0, 0, 100, 5, "%").max(100);
50
51
    // Alpha of the block being meshed on the current worker thread. Minus one
52
    // means the block is untouched.
53
    private static final ThreadLocal<Integer> MESH_ALPHA = ThreadLocal.withInitial(() -> -1);
54
55
    // Read from worker threads and replaced whole.
56
    private volatile Set<Block> visible = Set.of();
57
    private volatile boolean exposed;
58
    private volatile int alpha;
59
    private final ChunkRebuild rebuild = new ChunkRebuild();
60
61
    public XRay() {
62
        super("XRay", "See ores through the ground.", Category.RENDER);
63
        addSettings(blocks, lava, water, exposedOnly, opacity);
64
        searchTags("ore", "wallhack");
65
        instance = this;
66
    }
67
68
    // Puts a block on the list or takes it off. True when it went on.
69
    public boolean toggleBlock(Block block) {
70
        if (blocks.contains(block)) {
71
            blocks.remove(block);
72
            return false;
73
        }
74
        blocks.add(block);
75
        return true;
76
    }
77
78
    // Null before the client has started.
79
    public static XRay get() {
80
        return instance;
81
    }
82
83
    // The alpha the chunk mesher gives this block. Minus one leaves it alone
84
    // and zero skips it. WallHack drives the same path with the list turned round.
85
    public static int meshAlphaFor(BlockGetter level, BlockState state, BlockPos pos) {
86
        XRay xray = instance;
87
        if (xray != null && xray.isEnabled()) {
88
            return xray.alphaFor(level, state, pos);
89
        }
90
        WallHack wallHack = WallHack.get();
91
        return wallHack == null ? -1 : wallHack.alphaFor(state.getBlock());
92
    }
93
94
    public static void setMeshAlpha(int alpha) {
95
        MESH_ALPHA.set(alpha);
96
    }
97
98
    public static int meshAlpha() {
99
        return MESH_ALPHA.get();
100
    }
101
102
    public static boolean meshingTranslucent() {
103
        int alpha = MESH_ALPHA.get();
104
        return alpha > 0 && alpha < 255;
105
    }
106
107
    @Override
108
    public String getSuffix() {
109
        int a = alpha;
110
        return a > 0 ? opacity.getValueString() : null;
111
    }
112
113
    @Override
114
    protected void onEnable() {
115
        snapshot();
116
        ChunkRebuild.now();
117
    }
118
119
    @Override
120
    protected void onDisable() {
121
        ChunkRebuild.now();
122
    }
123
124
    @Subscribe
125
    private void onTick(TickEvent event) {
126
        rebuild.tick(snapshot());
127
    }
128
129
    // True if anything changed.
130
    private boolean snapshot() {
131
        Set<Block> next = new HashSet<>(blocks.resolved());
132
        if (lava.isOn()) {
133
            next.add(Blocks.LAVA);
134
        }
135
        if (water.isOn()) {
136
            next.add(Blocks.WATER);
137
        }
138
        int nextAlpha = (int) Math.round(opacity.getValue() / 100.0 * 255.0);
139
        boolean nextExposed = exposedOnly.isOn();
140
141
        boolean changed = !next.equals(visible) || nextAlpha != alpha || nextExposed != exposed;
142
        if (changed) {
143
            visible = Set.copyOf(next);
144
            alpha = nextAlpha;
145
            exposed = nextExposed;
146
        }
147
        return changed;
148
    }
149
150
    // A null position skips the exposed only check.
151
    public boolean isVisible(BlockGetter level, Block block, BlockPos pos) {
152
        if (!visible.contains(block)) {
153
            return false;
154
        }
155
        if (exposed && pos != null && level != null) {
156
            return isExposed(level, pos);
157
        }
158
        return true;
159
    }
160
161
    // Ignores the exposed only check.
162
    public boolean isVisible(Block block) {
163
        return visible.contains(block);
164
    }
165
166
    // Minus one leaves the block alone and zero skips it. Anything else is the
167
    // alpha for a see through version.
168
    public int alphaFor(BlockGetter level, BlockState state, BlockPos pos) {
169
        if (!isEnabled()) {
170
            return -1;
171
        }
172
        if (isVisible(level, state.getBlock(), pos)) {
173
            return -1;
174
        }
175
        int a = alpha;
176
        return a >= 255 ? -1 : a;
177
    }
178
179
    private static boolean isExposed(BlockGetter level, BlockPos pos) {
180
        BlockPos.MutableBlockPos cursor = new BlockPos.MutableBlockPos();
181
        for (Direction side : Direction.values()) {
182
            cursor.setWithOffset(pos, side);
183
            if (!level.getBlockState(cursor).isSolidRender()) {
184
                return true;
185
            }
186
        }
187
        return false;
188
    }
189
}
190
NicotineRendersrc/client/java/nicotine/mod/mods/render/Xray.javaJava · 87 lines · 2.4 KB
SettingsBlocks
Xray.javaJava · Minecraft 26.3 · 87 lines · 2.4 KB · complete file, verbatimOriginal ↗
1
package nicotine.mod.mods.render;
2
3
import com.mojang.blaze3d.platform.InputConstants;
4
import net.minecraft.world.item.BlockItem;
5
import net.minecraft.world.item.Item;
6
import net.minecraft.world.level.block.Blocks;
7
import nicotine.events.GetFaceOcclusionShapeEvent;
8
import nicotine.events.GetRenderShapeEvent;
9
import nicotine.mod.Mod;
10
import nicotine.mod.ModCategory;
11
import nicotine.mod.option.ItemSelectionOption;
12
import nicotine.util.EventBus;
13
14
import java.util.Arrays;
15
16
import static nicotine.util.Common.mc;
17
18
public class Xray extends Mod {
19
20
    private final ItemSelectionOption blocks = new ItemSelectionOption("Blocks") {
21
        @Override
22
        public boolean filter(Item item) {
23
            return item instanceof BlockItem;
24
        }
25
    };
26
27
    public Xray() {
28
        super(ModCategory.Render, "Xray");
29
30
        this.keybind.keyCode = InputConstants.KEY_X;
31
32
        blocks.items.addAll(Arrays.asList(
33
                Blocks.IRON_ORE.asItem(),
34
                Blocks.LAPIS_ORE.asItem(),
35
                Blocks.REDSTONE_ORE.asItem(),
36
                Blocks.EMERALD_ORE.asItem(),
37
                Blocks.DIAMOND_ORE.asItem(),
38
39
                Blocks.DEEPSLATE_IRON_ORE.asItem(),
40
                Blocks.DEEPSLATE_LAPIS_ORE.asItem(),
41
                Blocks.DEEPSLATE_REDSTONE_ORE.asItem(),
42
                Blocks.DEEPSLATE_EMERALD_ORE.asItem(),
43
                Blocks.DEEPSLATE_DIAMOND_ORE.asItem(),
44
45
                Blocks.NETHER_QUARTZ_ORE.asItem(),
46
                Blocks.ANCIENT_DEBRIS.asItem(),
47
48
                Blocks.NETHER_PORTAL.asItem(),
49
50
                Blocks.END_PORTAL.asItem(),
51
                Blocks.END_PORTAL_FRAME.asItem()
52
        ));
53
54
        this.addOptions(blocks);
55
    }
56
57
    @Override
58
    public void toggle() {
59
        this.enabled = !this.enabled;
60
        mc.smartCull = !this.enabled;
61
        mc.levelExtractor.allChanged();
62
    }
63
64
    @Override
65
    protected void init() {
66
        EventBus.register(GetRenderShapeEvent.class, event -> {
67
            if (!this.enabled || mc.player == null) {
68
                return true;
69
            }
70
71
            if (blocks.items.contains(event.blockState.getBlock().asItem()))
72
                return true;
73
74
            return false;
75
        });
76
77
        EventBus.register(GetFaceOcclusionShapeEvent.class, event -> {
78
            if (!this.enabled || mc.player == null)
79
                return true;
80
81
            if (blocks.items.contains(event.block.asItem()))
82
                return true;
83
84
            return false;
85
        });
86
    }
87
}
KiwiClientRENDERsrc/main/java/com/tangykiwi/kiwiclient/module/render/XRay.javaJava · 96 lines · 3.0 KB

Shows ores

SettingsFluids
XRay.javaJava · Minecraft 26.2 · 96 lines · 3.0 KB · complete file, verbatimOriginal ↗
1
package com.tangykiwi.kiwiclient.module.render;
2
3
import com.google.common.eventbus.Subscribe;
4
import com.tangykiwi.kiwiclient.event.ChunkOcclusionEvent;
5
import com.tangykiwi.kiwiclient.module.Category;
6
import com.tangykiwi.kiwiclient.module.Module;
7
8
import net.minecraft.core.BlockPos;
9
import net.minecraft.core.Direction;
10
import net.minecraft.world.level.BlockGetter;
11
import net.minecraft.world.level.block.Block;
12
import net.minecraft.world.level.block.Blocks;
13
import net.minecraft.world.level.block.state.BlockState;
14
15
import static com.tangykiwi.kiwiclient.KiwiClient.mc;
16
17
import java.util.ArrayList;
18
import java.util.List;
19
20
public class XRay extends Module {
21
    public ArrayList<Block> blocks = new ArrayList<>(List.of(
22
        Blocks.COAL_ORE,
23
        Blocks.DEEPSLATE_COAL_ORE,
24
        Blocks.COAL_BLOCK,
25
        Blocks.COPPER_ORE,
26
        Blocks.DEEPSLATE_COPPER_ORE,
27
        Blocks.RAW_COPPER_BLOCK,
28
        Blocks.IRON_ORE,
29
        Blocks.DEEPSLATE_IRON_ORE,
30
        Blocks.IRON_BLOCK,
31
        Blocks.RAW_IRON_BLOCK,
32
        Blocks.GOLD_ORE,
33
        Blocks.DEEPSLATE_GOLD_ORE,
34
        Blocks.GOLD_BLOCK,
35
        Blocks.RAW_GOLD_BLOCK,
36
        Blocks.LAPIS_ORE,
37
        Blocks.DEEPSLATE_LAPIS_ORE,
38
        Blocks.LAPIS_BLOCK,
39
        Blocks.REDSTONE_ORE,
40
        Blocks.DEEPSLATE_REDSTONE_ORE,
41
        Blocks.REDSTONE_BLOCK,
42
        Blocks.DIAMOND_ORE,
43
        Blocks.DEEPSLATE_DIAMOND_ORE,
44
        Blocks.DIAMOND_BLOCK,
45
        Blocks.NETHER_GOLD_ORE,
46
        Blocks.ANCIENT_DEBRIS,
47
        Blocks.NETHERITE_BLOCK,
48
        Blocks.SPAWNER,
49
        Blocks.END_PORTAL_FRAME
50
    )); 
51
52
    public XRay() {
53
        super("XRay", "Shows ores", KEY_UNBOUND, Category.RENDER
54
        /*new ToggleSetting("Fluids", "Show fluids, toggle xray to see changes", true)*/);
55
        for(Block block : Blocks.COPPER_BLOCK.asList()) {
56
            blocks.add(block);
57
        }
58
    }
59
60
    @Override
61
    public void onEnable() {
62
        super.onEnable();
63
64
        mc.levelRenderer.invalidateCompiledGeometry(mc.level, mc.options, mc.gameRenderer.mainCamera(), mc.getBlockColors());
65
    }
66
67
    @Override
68
    public void onDisable() {
69
        mc.levelRenderer.invalidateCompiledGeometry(mc.level, mc.options, mc.gameRenderer.mainCamera(), mc.getBlockColors());
70
71
        super.onDisable();
72
    }
73
74
    // light handling in BlockBehaviorMixin
75
76
    @Subscribe
77
    public void onChunkOcclusion(ChunkOcclusionEvent e) {
78
        e.cancel();
79
    }
80
81
    public boolean modifyDrawSide(BlockState state, BlockGetter view, BlockPos pos, Direction facing, boolean returns) {
82
        return blocks.contains(state.getBlock());
83
    }
84
85
    private static final ThreadLocal<BlockPos.MutableBlockPos> EXPOSED_POS = ThreadLocal.withInitial(BlockPos.MutableBlockPos::new);
86
87
    public boolean isExposed(BlockPos blockPos) {
88
        for (Direction direction : Direction.values()) {
89
            if (!mc.level.getBlockState(EXPOSED_POS.get().setWithOffset(blockPos, direction)).isSolidRender())
90
                return true;
91
        }
92
93
        return false;
94
    }
95
}
96
LiquidBounce (Kotlin)RENDERsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleXRay.ktKotlin · 354 lines · 12.3 KB

Only renders selected blocks.

SettingsFullBrightExposedOnlyBackgroundOpacityBlocks
ModuleXRay.ktKotlin · Minecraft 26.2 · 354 lines · 12.3 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.render
20
21
import net.ccbluex.fastutil.Pool.Companion.use
22
import net.ccbluex.liquidbounce.features.command.commands.module.CommandXRay
23
import net.ccbluex.liquidbounce.features.module.ClientModule
24
import net.ccbluex.liquidbounce.features.module.ModuleCategories
25
import net.ccbluex.liquidbounce.utils.block.state
26
import net.ccbluex.liquidbounce.utils.collection.Pools
27
import net.ccbluex.liquidbounce.utils.collection.blockSortedSetOf
28
import net.ccbluex.liquidbounce.utils.kotlin.addAll
29
import net.minecraft.core.BlockPos
30
import net.minecraft.core.Direction
31
import net.minecraft.world.level.BlockGetter
32
import net.minecraft.world.level.block.Block
33
import net.minecraft.world.level.block.Blocks.ANCIENT_DEBRIS
34
import net.minecraft.world.level.block.Blocks.ANVIL
35
import net.minecraft.world.level.block.Blocks.BARREL
36
import net.minecraft.world.level.block.Blocks.BEACON
37
import net.minecraft.world.level.block.Blocks.BLAST_FURNACE
38
import net.minecraft.world.level.block.Blocks.BOOKSHELF
39
import net.minecraft.world.level.block.Blocks.BREWING_STAND
40
import net.minecraft.world.level.block.Blocks.CARTOGRAPHY_TABLE
41
import net.minecraft.world.level.block.Blocks.CAULDRON
42
import net.minecraft.world.level.block.Blocks.CHAIN_COMMAND_BLOCK
43
import net.minecraft.world.level.block.Blocks.CHEST
44
import net.minecraft.world.level.block.Blocks.CHIPPED_ANVIL
45
import net.minecraft.world.level.block.Blocks.CLAY
46
import net.minecraft.world.level.block.Blocks.COAL_BLOCK
47
import net.minecraft.world.level.block.Blocks.COAL_ORE
48
import net.minecraft.world.level.block.Blocks.COMMAND_BLOCK
49
import net.minecraft.world.level.block.Blocks.COMPOSTER
50
import net.minecraft.world.level.block.Blocks.COPPER_BLOCK
51
import net.minecraft.world.level.block.Blocks.COPPER_CHEST
52
import net.minecraft.world.level.block.Blocks.COPPER_ORE
53
import net.minecraft.world.level.block.Blocks.CRAFTING_TABLE
54
import net.minecraft.world.level.block.Blocks.DAMAGED_ANVIL
55
import net.minecraft.world.level.block.Blocks.DEEPSLATE_COAL_ORE
56
import net.minecraft.world.level.block.Blocks.DEEPSLATE_COPPER_ORE
57
import net.minecraft.world.level.block.Blocks.DEEPSLATE_DIAMOND_ORE
58
import net.minecraft.world.level.block.Blocks.DEEPSLATE_EMERALD_ORE
59
import net.minecraft.world.level.block.Blocks.DEEPSLATE_GOLD_ORE
60
import net.minecraft.world.level.block.Blocks.DEEPSLATE_IRON_ORE
61
import net.minecraft.world.level.block.Blocks.DEEPSLATE_LAPIS_ORE
62
import net.minecraft.world.level.block.Blocks.DEEPSLATE_REDSTONE_ORE
63
import net.minecraft.world.level.block.Blocks.DIAMOND_BLOCK
64
import net.minecraft.world.level.block.Blocks.DIAMOND_ORE
65
import net.minecraft.world.level.block.Blocks.DISPENSER
66
import net.minecraft.world.level.block.Blocks.DRAGON_EGG
67
import net.minecraft.world.level.block.Blocks.DROPPER
68
import net.minecraft.world.level.block.Blocks.DYED_SHULKER_BOX
69
import net.minecraft.world.level.block.Blocks.EMERALD_BLOCK
70
import net.minecraft.world.level.block.Blocks.EMERALD_ORE
71
import net.minecraft.world.level.block.Blocks.ENCHANTING_TABLE
72
import net.minecraft.world.level.block.Blocks.ENDER_CHEST
73
import net.minecraft.world.level.block.Blocks.END_PORTAL
74
import net.minecraft.world.level.block.Blocks.END_PORTAL_FRAME
75
import net.minecraft.world.level.block.Blocks.FIRE
76
import net.minecraft.world.level.block.Blocks.FLETCHING_TABLE
77
import net.minecraft.world.level.block.Blocks.FLOWER_POT
78
import net.minecraft.world.level.block.Blocks.FURNACE
79
import net.minecraft.world.level.block.Blocks.GOLD_BLOCK
80
import net.minecraft.world.level.block.Blocks.GOLD_ORE
81
import net.minecraft.world.level.block.Blocks.GRINDSTONE
82
import net.minecraft.world.level.block.Blocks.HOPPER
83
import net.minecraft.world.level.block.Blocks.IRON_BLOCK
84
import net.minecraft.world.level.block.Blocks.IRON_ORE
85
import net.minecraft.world.level.block.Blocks.JUKEBOX
86
import net.minecraft.world.level.block.Blocks.LAPIS_BLOCK
87
import net.minecraft.world.level.block.Blocks.LAPIS_ORE
88
import net.minecraft.world.level.block.Blocks.LAVA
89
import net.minecraft.world.level.block.Blocks.LAVA_CAULDRON
90
import net.minecraft.world.level.block.Blocks.LECTERN
91
import net.minecraft.world.level.block.Blocks.LODESTONE
92
import net.minecraft.world.level.block.Blocks.LOOM
93
import net.minecraft.world.level.block.Blocks.NETHERITE_BLOCK
94
import net.minecraft.world.level.block.Blocks.NETHER_GOLD_ORE
95
import net.minecraft.world.level.block.Blocks.NETHER_PORTAL
96
import net.minecraft.world.level.block.Blocks.NETHER_QUARTZ_ORE
97
import net.minecraft.world.level.block.Blocks.QUARTZ_BLOCK
98
import net.minecraft.world.level.block.Blocks.RAW_COPPER_BLOCK
99
import net.minecraft.world.level.block.Blocks.RAW_GOLD_BLOCK
100
import net.minecraft.world.level.block.Blocks.RAW_IRON_BLOCK
101
import net.minecraft.world.level.block.Blocks.REDSTONE_BLOCK
102
import net.minecraft.world.level.block.Blocks.REDSTONE_ORE
103
import net.minecraft.world.level.block.Blocks.REPEATING_COMMAND_BLOCK
104
import net.minecraft.world.level.block.Blocks.RESPAWN_ANCHOR
105
import net.minecraft.world.level.block.Blocks.SHULKER_BOX
106
import net.minecraft.world.level.block.Blocks.SMITHING_TABLE
107
import net.minecraft.world.level.block.Blocks.SMOKER
108
import net.minecraft.world.level.block.Blocks.SPAWNER
109
import net.minecraft.world.level.block.Blocks.STONECUTTER
110
import net.minecraft.world.level.block.Blocks.TNT
111
import net.minecraft.world.level.block.Blocks.TRAPPED_CHEST
112
import net.minecraft.world.level.block.Blocks.WATER
113
import net.minecraft.world.level.block.Blocks.WATER_CAULDRON
114
import net.minecraft.world.level.block.state.BlockState
115
import net.minecraft.world.phys.shapes.Shapes
116
117
/**
118
 * XRay module
119
 *
120
 * Allows you to see ores through walls.
121
 *
122
 * Command: [CommandXRay]
123
 */
124
object ModuleXRay : ClientModule("XRay", ModuleCategories.RENDER) {
125
126
    // Lighting of blocks through walls
127
    val fullBright by boolean("FullBright", true)
128
        .onChanged(::valueChangedReload)
129
130
    // Only render blocks with non-solid blocks around
131
    private val exposedOnly by boolean("ExposedOnly", false)
132
        .onChanged(::valueChangedReload)
133
134
    val backgroundOpacity by int("BackgroundOpacity", 0, 0..255)
135
        .onChanged(::valueChangedReload)
136
137
    private val defaultBlocks = arrayOf<Block>(
138
        // Overworld ores
139
        COAL_ORE,
140
        COPPER_ORE,
141
        DIAMOND_ORE,
142
        EMERALD_ORE,
143
        GOLD_ORE,
144
        IRON_ORE,
145
        LAPIS_ORE,
146
        REDSTONE_ORE,
147
148
        // Overworld ores (deepslate variants)
149
        DEEPSLATE_COAL_ORE,
150
        DEEPSLATE_COPPER_ORE,
151
        DEEPSLATE_DIAMOND_ORE,
152
        DEEPSLATE_EMERALD_ORE,
153
        DEEPSLATE_GOLD_ORE,
154
        DEEPSLATE_IRON_ORE,
155
        DEEPSLATE_LAPIS_ORE,
156
        DEEPSLATE_REDSTONE_ORE,
157
158
        // Overworld mineral blocks
159
        COAL_BLOCK,
160
        DIAMOND_BLOCK,
161
        EMERALD_BLOCK,
162
        GOLD_BLOCK,
163
        IRON_BLOCK,
164
        LAPIS_BLOCK,
165
        REDSTONE_BLOCK,
166
167
        // Overworld raw mineral blocks
168
        RAW_COPPER_BLOCK,
169
        RAW_GOLD_BLOCK,
170
        RAW_IRON_BLOCK,
171
172
        // Nether ores
173
        ANCIENT_DEBRIS,
174
        NETHER_GOLD_ORE,
175
        NETHER_QUARTZ_ORE,
176
177
        // Nether material blocks
178
        NETHERITE_BLOCK,
179
        QUARTZ_BLOCK,
180
181
        // Storage blocks
182
        CHEST,
183
        DISPENSER,
184
        DROPPER,
185
        ENDER_CHEST,
186
        HOPPER,
187
        TRAPPED_CHEST,
188
        SHULKER_BOX,
189
190
        // Utility blocks
191
        BEACON,
192
        CRAFTING_TABLE,
193
        ENCHANTING_TABLE,
194
        FURNACE,
195
        FLOWER_POT,
196
        JUKEBOX,
197
        LODESTONE,
198
        RESPAWN_ANCHOR,
199
200
        // Utility blocks (anvil variants)
201
        ANVIL,
202
        CHIPPED_ANVIL,
203
        DAMAGED_ANVIL,
204
205
        // Utility blocks (job variants)
206
        BARREL,
207
        BLAST_FURNACE,
208
        BREWING_STAND,
209
        CARTOGRAPHY_TABLE,
210
        COMPOSTER,
211
        FLETCHING_TABLE,
212
        GRINDSTONE,
213
        LECTERN,
214
        LOOM,
215
        SMITHING_TABLE,
216
        SMOKER,
217
        STONECUTTER,
218
219
        // Utility blocks (job variants (cauldron variants))
220
        CAULDRON,
221
        LAVA_CAULDRON,
222
        WATER_CAULDRON,
223
224
        // Liquids
225
        LAVA,
226
        WATER,
227
228
        // Portals
229
        END_PORTAL,
230
        END_PORTAL_FRAME,
231
        NETHER_PORTAL,
232
233
        // Command block variants
234
        CHAIN_COMMAND_BLOCK,
235
        COMMAND_BLOCK,
236
        REPEATING_COMMAND_BLOCK,
237
238
        // Remaining blocks
239
        BOOKSHELF,
240
        CLAY,
241
        DRAGON_EGG,
242
        FIRE,
243
        SPAWNER,
244
        TNT
245
    )
246
247
    // Set of blocks that will not be excluded
248
    val blocks: MutableSet<Block> by blocks(
249
        "Blocks",
250
        blockSortedSetOf(blocks = defaultBlocks).apply {
251
            // Copper blocks
252
            addAll(COPPER_BLOCK)
253
254
            // Shulkers, Copper chests
255
            addAll(DYED_SHULKER_BOX)
256
            addAll(COPPER_CHEST)
257
        }
258
    ).onChanged(::valueChangedReload)
259
260
    /**
261
     * Checks if the block should be rendered or not.
262
     * This can be used to exclude blocks that should not be rendered.
263
     * Also features an option to only render blocks that are exposed to air.
264
     */
265
    fun shouldRender(blockState: BlockState, blockPos: BlockPos) = when {
266
        blockState.block !in blocks -> false
267
268
        exposedOnly -> Pools.MutableBlockPos.use { pos ->
269
            Direction.entries.any {
270
                pos.set(blockPos).move(it).state?.isRedstoneConductor(world, pos) == false
271
            }
272
        }
273
274
        else -> true
275
    }
276
277
    fun shouldRenderTransparentBackground(blockState: BlockState) =
278
        backgroundOpacity > 0 && blockState.block !in blocks && !blockState.isAir
279
280
    fun shouldSkipRender(blockState: BlockState, blockPos: BlockPos) =
281
        !shouldRender(blockState, blockPos) && !shouldRenderTransparentBackground(blockState)
282
283
    fun transparentBackgroundAlpha(blockState: BlockState) =
284
        if (shouldRenderTransparentBackground(blockState)) backgroundOpacity else 255
285
286
    /**
287
     * Keeps vanilla/Sodium face culling unless this is a whitelisted XRay block hidden behind another block.
288
     *
289
     * @see net.minecraft.client.renderer.block.ModelBlockRenderer.shouldRenderFace
290
     * @see net.caffeinemc.mods.sodium.client.render.model.AbstractBlockRenderContext.shouldDrawSide
291
     */
292
    fun modifyDrawSide(
293
        blockState: BlockState,
294
        level: BlockGetter,
295
        blockPos: BlockPos,
296
        side: Direction,
297
        original: Boolean
298
    ): Boolean {
299
        if (original || !shouldRender(blockState, blockPos)) {
300
            return original
301
        }
302
303
        val adjacentPos = blockPos.relative(side)
304
        val adjacentState = level.getBlockState(adjacentPos)
305
306
        return adjacentState.getFaceOcclusionShape(side.opposite) != Shapes.block()
307
            || adjacentState.block != blockState.block
308
            || !adjacentState.isSolidRender
309
            || !shouldRender(adjacentState, adjacentPos)
310
    }
311
312
    fun shouldRender(state: BlockState, otherState: BlockState, side: Direction) = when {
313
        state.block !in blocks -> false
314
315
        exposedOnly -> !state.skipRendering(otherState, side)
316
317
        else -> true
318
    }
319
320
    fun modifyShouldRenderFace(original: Boolean, state: BlockState, otherState: BlockState, side: Direction) =
321
        if (shouldRenderTransparentBackground(state)) {
322
            original
323
        } else {
324
            shouldRender(state, otherState, side)
325
        }
326
327
    /**
328
     * Resets the block list to the default values
329
     */
330
    fun applyDefaults() {
331
        blocks.clear()
332
        blocks.addAll(defaultBlocks)
333
    }
334
335
    override fun onEnabled() {
336
        mc.levelExtractor.allChanged()
337
    }
338
339
    override fun onDisabled() {
340
        mc.levelExtractor.allChanged()
341
    }
342
343
    @Suppress("UNUSED_PARAMETER")
344
    fun valueChangedReload(it: Any) {
345
        if (!running) return
346
347
        mc.execute {
348
            // Reload world renderer on block list change
349
            mc.levelExtractor.allChanged()
350
        }
351
    }
352
353
}
354