Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added exposed distance to batter filter obfuscated blocks in x-ray #4481

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ public class Xray extends Module {
if (isActive()) mc.worldRenderer.reload();
})
.build());

private final Setting<Integer> 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.");
Expand Down Expand Up @@ -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) {
Expand All @@ -135,4 +147,4 @@ else if (xray.isActive() && !wallHack.isActive() && xray.isBlocked(state.getBloc

return -1;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

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;
Expand All @@ -14,16 +16,30 @@
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.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;
Expand All @@ -37,9 +53,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;
Expand Down Expand Up @@ -85,11 +98,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);

Expand Down Expand Up @@ -140,7 +149,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
Expand All @@ -150,11 +159,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) {
Expand Down Expand Up @@ -231,19 +236,17 @@ 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;

InstantRebreak ir = Modules.get().get(InstantRebreak.class);
if (ir != null && ir.isActive() && ir.blockPos.equals(pos) && ir.shouldMine()) {
ir.sendPacket();
return true;
}

if (mc.interactionManager.isBreakingBlock())
mc.interactionManager.updateBlockBreakingProgress(pos, getDirection(blockPos));
else mc.interactionManager.attackBlock(pos, getDirection(blockPos));
Expand Down Expand Up @@ -349,14 +352,22 @@ public enum MobSpawn {
Potential,
Always
}

private static final ThreadLocal<BlockPos.Mutable> 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;
}

Expand Down Expand Up @@ -407,8 +418,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);
}
}
}
Loading