Skip to content

Commit

Permalink
speed mine: prevent ghost blocks spawning (#2860)
Browse files Browse the repository at this point in the history
  • Loading branch information
hexadecimal233 authored Dec 16, 2022
1 parent e0a12e4 commit 9a1741b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
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,18 @@ 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());

HitResult result = mc.crosshairTarget;
if (result != null && result.getType() == HitResult.Type.BLOCK) {
BlockPos pos = ((BlockHitResult) result).getBlockPos();
if (module.modifier.get() < 1 || (BlockUtils.canInstaBreak(pos, breakSpeed) == BlockUtils.canInstaBreak(pos, breakSpeedMod)))
cir.setReturnValue(breakSpeedMod);
else
cir.setReturnValue(0.9f / BlockUtils.calcBlockBreakingDelta2(pos, 1));
}

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 @@ -182,14 +182,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 @@ -205,15 +208,29 @@ 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;
}
}

// Other
Expand All @@ -237,7 +254,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

0 comments on commit 9a1741b

Please sign in to comment.