Created
September 10, 2024 04:47
-
-
Save Densamisten/cf404b5aabce3d1c92c7a4da4759179f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package exonihility.client.module.render; | |
| import exonihility.client.module.Extension; | |
| import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; | |
| import net.minecraft.block.Block; | |
| import net.minecraft.block.Blocks; | |
| import net.minecraft.client.MinecraftClient; | |
| import net.minecraft.client.render.RenderLayer; | |
| import net.minecraft.client.world.ClientWorld; | |
| import net.minecraft.util.math.BlockPos; | |
| import net.minecraft.util.math.ChunkPos; | |
| import net.minecraft.world.chunk.ChunkManager; | |
| import java.util.HashSet; | |
| import java.util.Set; | |
| public class Xray extends Extension { | |
| private static final Set<Block> xrayBlocks = new HashSet<>(); | |
| public Xray() { | |
| super("Xray", "See through blocks", Extension.Category.RENDER); | |
| initializeXrayBlocks(); | |
| } | |
| private void initializeXrayBlocks() { | |
| // Add blocks that you want to see through using X-ray | |
| xrayBlocks.add(Blocks.LAVA); | |
| xrayBlocks.add(Blocks.CHEST); | |
| xrayBlocks.add(Blocks.FURNACE); | |
| xrayBlocks.add(Blocks.END_GATEWAY); | |
| xrayBlocks.add(Blocks.COMMAND_BLOCK); | |
| xrayBlocks.add(Blocks.ANCIENT_DEBRIS); | |
| xrayBlocks.add(Blocks.REDSTONE_ORE); | |
| } | |
| @Override | |
| public void onEnabled() { | |
| super.onEnabled(); | |
| enableXray(); | |
| } | |
| @Override | |
| public void onDisabled() { | |
| disableXray(); | |
| } | |
| public static void enableXray() { | |
| MinecraftClient client = MinecraftClient.getInstance(); | |
| ClientWorld world = client.world; | |
| if (world != null) { | |
| ChunkManager chunkManager = world.getChunkManager(); | |
| // Get the player's current chunk | |
| ChunkPos playerChunkPos = client.player.getChunkPos(); | |
| // Define the range around the player to apply X-ray (16 chunk radius here) | |
| int radius = 16; | |
| // Iterate over a radius of chunks around the player | |
| for (int chunkX = playerChunkPos.x - radius; chunkX <= playerChunkPos.x + radius; chunkX++) { | |
| for (int chunkZ = playerChunkPos.z - radius; chunkZ <= playerChunkPos.z + radius; chunkZ++) { | |
| // Only process loaded chunks | |
| if (chunkManager.isChunkLoaded(chunkX, chunkZ)) { | |
| for (int x = 0; x < 16; x++) { | |
| for (int z = 0; z < 16; z++) { | |
| for (int y = 0; y < world.getHeight(); y++) { | |
| BlockPos blockPos = new BlockPos(chunkX * 16 + x, y, chunkZ * 16 + z); | |
| Block block = world.getBlockState(blockPos).getBlock(); | |
| if (xrayBlocks.contains(block)) { | |
| // Set block to be rendered with a translucent layer | |
| BlockRenderLayerMap.INSTANCE.putBlock(block, RenderLayer.getTranslucent()); | |
| } else { | |
| // Set all other blocks to be invisible | |
| BlockRenderLayerMap.INSTANCE.putBlock(block, RenderLayer.getTranslucent()); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| // Trigger a world renderer reload to apply changes | |
| client.worldRenderer.reload(); | |
| } | |
| } | |
| public static boolean shouldXray(Block block) { | |
| // Return true if the block should be visible in X-ray mode | |
| return xrayBlocks.contains(block); | |
| } | |
| private void disableXray() { | |
| MinecraftClient client = MinecraftClient.getInstance(); | |
| // Reset all blocks to their original render states | |
| client.worldRenderer.reload(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment