From f160e8126e163ef2791fa10b5e33f617e054d6a5 Mon Sep 17 00:00:00 2001 From: Hackerokuz Date: Wed, 27 Mar 2024 17:23:14 +0100 Subject: [PATCH] Added exposed distance to batter filter obfuscated blocks --- .../systems/modules/render/Xray.java | 18 ++++- .../meteorclient/utils/world/BlockUtils.java | 71 ++++++++++--------- 2 files changed, 53 insertions(+), 36 deletions(-) diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Xray.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Xray.java index 2ab23b7150..a823f0390c 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Xray.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Xray.java @@ -63,6 +63,18 @@ public class Xray extends Module { if (isActive()) mc.worldRenderer.reload(); }) .build()); + + private final Setting exposedOnlyDistance = sgGeneral.add(new IntSetting.Builder() + .name("exposed-only-distance") + .description("Specify the distance of opeque blocks for ore to be considered as exposed.") + .defaultValue(1) + .min(1) + .max(10) + .visible(exposedOnly::get) + .onChanged(onChanged -> { + if (isActive()) mc.worldRenderer.reload(); + }) + .build()); public Xray() { super(Categories.Render, "xray", "Only renders specified blocks. Good for mining."); @@ -105,14 +117,14 @@ public boolean modifyDrawSide(BlockState state, BlockView view, BlockPos pos, Di if (!returns && !isBlocked(state.getBlock(), pos)) { BlockPos adjPos = pos.offset(facing); BlockState adjState = view.getBlockState(adjPos); - return adjState.getCullingFace(view, adjPos, facing.getOpposite()) != VoxelShapes.fullCube() || adjState.getBlock() != state.getBlock() || BlockUtils.isExposed(adjPos); + return adjState.getCullingFace(view, adjPos, facing.getOpposite()) != VoxelShapes.fullCube() || adjState.getBlock() != state.getBlock() || BlockUtils.isExposed(adjPos, exposedOnlyDistance.get()); } return returns; } public boolean isBlocked(Block block, BlockPos blockPos) { - return !(blocks.get().contains(block) && (!exposedOnly.get() || (blockPos == null || BlockUtils.isExposed(blockPos)))); + return !(blocks.get().contains(block) && (!exposedOnly.get() || (blockPos == null || BlockUtils.isExposed(blockPos, exposedOnlyDistance.get())))); } public static int getAlpha(BlockState state, BlockPos pos) { @@ -135,4 +147,4 @@ else if (xray.isActive() && !wallHack.isActive() && xray.isBlocked(state.getBloc return -1; } -} +} \ No newline at end of file diff --git a/src/main/java/meteordevelopment/meteorclient/utils/world/BlockUtils.java b/src/main/java/meteordevelopment/meteorclient/utils/world/BlockUtils.java index 1ee7a88b9d..7d4a2a669c 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/world/BlockUtils.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/world/BlockUtils.java @@ -5,25 +5,39 @@ package meteordevelopment.meteorclient.utils.world; +import static meteordevelopment.meteorclient.MeteorClient.mc; + import meteordevelopment.meteorclient.MeteorClient; import meteordevelopment.meteorclient.events.world.TickEvent; -import meteordevelopment.meteorclient.systems.modules.Modules; -import meteordevelopment.meteorclient.systems.modules.player.InstaMine; import meteordevelopment.meteorclient.utils.PreInit; import meteordevelopment.meteorclient.utils.player.FindItemResult; import meteordevelopment.meteorclient.utils.player.InvUtils; import meteordevelopment.meteorclient.utils.player.Rotations; -import meteordevelopment.meteorclient.utils.player.SlotUtils; import meteordevelopment.orbit.EventHandler; import meteordevelopment.orbit.EventPriority; -import net.minecraft.block.*; +import net.minecraft.block.AbstractPressurePlateBlock; +import net.minecraft.block.AirBlock; +import net.minecraft.block.AnvilBlock; +import net.minecraft.block.BedBlock; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.BlockWithEntity; +import net.minecraft.block.Blocks; +import net.minecraft.block.ButtonBlock; +import net.minecraft.block.CraftingTableBlock; +import net.minecraft.block.DoorBlock; +import net.minecraft.block.FenceGateBlock; +import net.minecraft.block.NoteBlock; +import net.minecraft.block.ShapeContext; +import net.minecraft.block.SlabBlock; +import net.minecraft.block.StairsBlock; +import net.minecraft.block.TrapdoorBlock; import net.minecraft.block.enums.BlockHalf; import net.minecraft.block.enums.SlabType; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.enchantment.Enchantments; import net.minecraft.entity.effect.StatusEffectUtil; import net.minecraft.entity.effect.StatusEffects; -import net.minecraft.item.BlockItem; import net.minecraft.item.ItemStack; import net.minecraft.network.packet.c2s.play.HandSwingC2SPacket; import net.minecraft.registry.tag.FluidTags; @@ -37,9 +51,6 @@ import net.minecraft.world.LightType; import net.minecraft.world.World; -import static meteordevelopment.meteorclient.MeteorClient.mc; - -@SuppressWarnings("ConstantConditions") public class BlockUtils { public static boolean breaking; private static boolean breakingThisTick; @@ -82,11 +93,7 @@ public static boolean place(BlockPos blockPos, FindItemResult findItemResult, bo public static boolean place(BlockPos blockPos, Hand hand, int slot, boolean rotate, int rotationPriority, boolean swingHand, boolean checkEntities, boolean swapBack) { if (slot < 0 || slot > 8) return false; - - Block toPlace = Blocks.OBSIDIAN; - ItemStack i = hand == Hand.MAIN_HAND ? mc.player.getInventory().getStack(slot) : mc.player.getInventory().getStack(SlotUtils.OFFHAND); - if (i.getItem() instanceof BlockItem blockItem) toPlace = blockItem.getBlock(); - if (!canPlaceBlock(blockPos, checkEntities, toPlace)) return false; + if (!canPlace(blockPos, checkEntities)) return false; Vec3d hitPos = Vec3d.ofCenter(blockPos); @@ -137,7 +144,7 @@ public static void interact(BlockHitResult blockHitResult, Hand hand, boolean sw mc.player.input.sneaking = wasSneaking; } - public static boolean canPlaceBlock(BlockPos blockPos, boolean checkEntities, Block block) { + public static boolean canPlace(BlockPos blockPos, boolean checkEntities) { if (blockPos == null) return false; // Check y level @@ -147,11 +154,7 @@ public static boolean canPlaceBlock(BlockPos blockPos, boolean checkEntities, Bl if (!mc.world.getBlockState(blockPos).isReplaceable()) return false; // Check if intersects entities - return !checkEntities || mc.world.canPlace(block.getDefaultState(), blockPos, ShapeContext.absent()); - } - - public static boolean canPlace(BlockPos blockPos, boolean checkEntities) { - return canPlaceBlock(blockPos, checkEntities, Blocks.OBSIDIAN); + return !checkEntities || mc.world.canPlace(Blocks.OBSIDIAN.getDefaultState(), blockPos, ShapeContext.absent()); } public static boolean canPlace(BlockPos blockPos) { @@ -219,19 +222,13 @@ private static void onTickPost(TickEvent.Post event) { /** * Needs to be used in {@link TickEvent.Pre} - */ + */ public static boolean breakBlock(BlockPos blockPos, boolean swing) { if (!canBreak(blockPos, mc.world.getBlockState(blockPos))) return false; - // Creating new instance of block pos because minecraft assigns the parameter to a field, and we don't want it to change when it has been stored in a field somewhere + // Creating new instance of block pos because minecraft assigns the parameter to a field and we don't want it to change when it has been stored in a field somewhere BlockPos pos = blockPos instanceof BlockPos.Mutable ? new BlockPos(blockPos) : blockPos; - InstaMine im = Modules.get().get(InstaMine.class); - if (im.isActive() && im.blockPos.equals(pos) && im.shouldMine()) { - im.sendPacket(); - return true; - } - if (mc.interactionManager.isBreakingBlock()) mc.interactionManager.updateBlockBreakingProgress(pos, getDirection(blockPos)); else mc.interactionManager.attackBlock(pos, getDirection(blockPos)); @@ -333,14 +330,22 @@ public enum MobSpawn { Potential, Always } - + private static final ThreadLocal EXPOSED_POS = ThreadLocal.withInitial(BlockPos.Mutable::new); - public static boolean isExposed(BlockPos blockPos) { + public static boolean isExposed(BlockPos blockPos, Integer distanceToCheck) { + + outerloop: for (Direction direction : Direction.values()) { - if (!mc.world.getBlockState(EXPOSED_POS.get().set(blockPos, direction)).isOpaque()) return true; + EXPOSED_POS.get().set(blockPos); + for (int i = 1; i <= distanceToCheck; i++) { + BlockState neighbourBlockState = mc.world.getBlockState(EXPOSED_POS.get().move(direction, 1)); + if(neighbourBlockState.isOpaque()) { + continue outerloop; + } + } + return true; } - return false; } @@ -391,8 +396,8 @@ private static double getBlockBreakingSpeed(int slot, BlockState block) { /** * Mutates a {@link BlockPos.Mutable} around an origin - */ + */ public static BlockPos.Mutable mutateAround(BlockPos.Mutable mutable, BlockPos origin, int xOffset, int yOffset, int zOffset) { return mutable.set(origin.getX() + xOffset, origin.getY() + yOffset, origin.getZ() + zOffset); } -} +} \ No newline at end of file