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

speed mine: prevent ghost blocks spawning #2860

Merged
merged 4 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -11,19 +11,25 @@
import meteordevelopment.meteorclient.systems.modules.Modules;
import meteordevelopment.meteorclient.systems.modules.movement.Anchor;
import meteordevelopment.meteorclient.systems.modules.player.SpeedMine;
import meteordevelopment.meteorclient.utils.world.BlockUtils;
import net.minecraft.block.BlockState;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import static meteordevelopment.meteorclient.MeteorClient.mc;

@Mixin(PlayerEntity.class)
public abstract class PlayerEntityMixin extends LivingEntity {
protected PlayerEntityMixin(EntityType<? extends LivingEntity> entityType, World world) {
Expand All @@ -48,8 +54,23 @@ private void onDropItem(ItemStack stack, boolean bl, boolean bl2, CallbackInfoRe
public void onGetBlockBreakingSpeed(BlockState block, CallbackInfoReturnable<Float> cir) {
SpeedMine module = Modules.get().get(SpeedMine.class);
if (!module.isActive() || module.mode.get() != SpeedMine.Mode.Normal) return;
float breakSpeed = cir.getReturnValue();
float breakSpeedMod = (float) (breakSpeed * module.modifier.get());

if (module.modifier.get() < 1) {
cir.setReturnValue(breakSpeedMod);
return;
}

HitResult result = mc.player.raycast(mc.interactionManager.getReachDistance(), 1f / 20f, false);
hexadecimal233 marked this conversation as resolved.
Show resolved Hide resolved
if (result.getType() == HitResult.Type.BLOCK) {
BlockPos pos = ((BlockHitResult) result).getBlockPos();
if (BlockUtils.canInstaBreak(pos, breakSpeed) == BlockUtils.canInstaBreak(pos, breakSpeedMod))
cir.setReturnValue(breakSpeedMod);
else
cir.setReturnValue(BlockUtils.getMaxNonInstantBreakSpeed(pos));
}

cir.setReturnValue((float) (cir.getReturnValue() * module.modifier.get()));
}

@Inject(method = "jump", at = @At("HEAD"), cancellable = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,17 @@ private static void onTickPost(TickEvent.Post event) {
}
}

/** Needs to be used in {@link TickEvent.Pre} */
/**
* 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
BlockPos pos = blockPos instanceof BlockPos.Mutable ? new BlockPos(blockPos) : blockPos;

if (mc.interactionManager.isBreakingBlock()) mc.interactionManager.updateBlockBreakingProgress(pos, Direction.UP);
if (mc.interactionManager.isBreakingBlock())
mc.interactionManager.updateBlockBreakingProgress(pos, Direction.UP);
else mc.interactionManager.attackBlock(pos, Direction.UP);

if (swing) mc.player.swingHand(Hand.MAIN_HAND);
Expand All @@ -199,15 +202,40 @@ public static boolean canBreak(BlockPos blockPos, BlockState state) {
if (!mc.player.isCreative() && state.getHardness(mc.world, blockPos) < 0) return false;
return state.getOutlineShape(mc.world, blockPos) != VoxelShapes.empty();
}

public static boolean canBreak(BlockPos blockPos) {
return canBreak(blockPos, mc.world.getBlockState(blockPos));
}

public static boolean canInstaBreak(BlockPos blockPos, BlockState state) {
return mc.player.isCreative() || state.calcBlockBreakingDelta(mc.player, mc.world, blockPos) >= 1;
public static boolean canInstaBreak(BlockPos blockPos, float breakSpeed) {
return mc.player.isCreative() || calcBlockBreakingDelta2(blockPos, breakSpeed) >= 1;
}

public static boolean canInstaBreak(BlockPos blockPos) {
return canInstaBreak(blockPos, mc.world.getBlockState(blockPos));
BlockState state = mc.world.getBlockState(blockPos);
return canInstaBreak(blockPos, mc.player.getBlockBreakingSpeed(state));
}

public static float calcBlockBreakingDelta2(BlockPos blockPos, float breakSpeed) {
BlockState state = mc.world.getBlockState(blockPos);
float f = state.getHardness(mc.world, blockPos);
if (f == -1.0F) {
return 0.0F;
} else {
int i = mc.player.canHarvest(state) ? 30 : 100;
return breakSpeed / f / (float) i;
}
}

public static float getMaxNonInstantBreakSpeed(BlockPos blockPos) {
BlockState state = mc.world.getBlockState(blockPos);
float f = state.getHardness(mc.world, blockPos);
if (f == -1.0F) {
return 0.0F;
} else {
int i = mc.player.canHarvest(state) ? 30 : 100;
return 0.9F * (float) i * f;
}
}

// Other
Expand All @@ -231,7 +259,8 @@ public static MobSpawn isValidMobSpawn(BlockPos blockPos, boolean newMobSpawnLig
mc.world.getBlockState(blockPos.down()).getBlock() == Blocks.BEDROCK) return MobSpawn.Never;

if (!topSurface(mc.world.getBlockState(blockPos.down()))) {
if (mc.world.getBlockState(blockPos.down()).getCollisionShape(mc.world, blockPos.down()) != VoxelShapes.fullCube()) return MobSpawn.Never;
if (mc.world.getBlockState(blockPos.down()).getCollisionShape(mc.world, blockPos.down()) != VoxelShapes.fullCube())
return MobSpawn.Never;
if (mc.world.getBlockState(blockPos.down()).isTranslucent(mc.world, blockPos.down())) return MobSpawn.Never;
}

Expand Down