#Is there any way to modify the base mining speed? [SOLVED]

10 messages · Page 1 of 1 (latest)

opaque pewter
#

I'm trying to modify mining speed with a mixin but it doesn't seem to work.

@Mixin(AbstractBlock.AbstractBlockState.class)
public abstract class AbstractBlockMixin {
    @Inject(method = "calcBlockBreakingDelta", at = @At("RETURN"), cancellable = true)
    private void modifyBreakingDelta(PlayerEntity player, BlockView world, BlockPos pos, CallbackInfoReturnable<Float> cir) {
        if (player.getWorld().isClient()) return;
        if (!player.getMainHandStack().isEmpty()) return;

        PlayerStats stats = ModComponents.STATS.get(player).getStats();
        Stat fuerza = stats.getStat(PlayerStats.StatEnum.FUERZA);
        float fuerzaValor = fuerza.getValor();

        // Bonus: +5% por punto de fuerza
        float fuerzaMultiplier = fuerzaValor * 0.01f;
        float original = cir.getReturnValueF();
        float result = original * fuerzaMultiplier;

        cir.setReturnValue(result);
    }
}
#

When result is greater or equal to 1, it insta mines the blocks, but if its less than that, it just goes with the normal mining speed

pliant lake
#

I was able to modify it fine by mixing into the same method, though I used an injector that I would recommend for this use case: @ModifyReturnValue

#

After just doing the following mixin:

@Mixin(AbstractBlock.AbstractBlockState.class)
public class AbstractBlockStateMixin {
    @ModifyReturnValue(method = "calcBlockBreakingDelta", at = @At("RETURN"))
    private float modifyBlockBreakSpeed(float original) {
        return 0.5F;
    }
}

and running a test run, I was getting a non-instant break speed that was absolutely modified by my Mixin

#

(Do mind I tested it out in 1.21.1, there may be some differences I failed to account for here)

opaque pewter
#

wow dude this TOTALLY works but mind if I ask, how would i acces the parameters of the function then? i need to access the player that is breaking the blocks to get a unique value for a component each has

pliant lake
opaque pewter
#

so after 2 days i solved it.
the code needed to be run on BOTH client and server because both ask the method:

I did it like this:

@Mixin(AbstractBlock.AbstractBlockState.class)
public abstract class AbstractBlockMixin {
    @Inject(method = "calcBlockBreakingDelta", at = @At("RETURN"), cancellable = true)
    private void modifyBreakingDelta(PlayerEntity player, BlockView world, BlockPos pos, CallbackInfoReturnable<Float> cir) {
        // without checking if is server
        if (!player.getMainHandStack().isEmpty()) return;

        PlayerStats stats = ModComponents.STATS.get(player).getStats();
        Stat fuerza = stats.getStat(PlayerStats.StatEnum.FUERZA);
        float fuerzaValor = fuerza.getValor();

        // Bonus: +5% por punto de fuerza
        float fuerzaMultiplier = fuerzaValor * 0.01f;
        float original = cir.getReturnValueF();
        float result = original * fuerzaMultiplier;
        cir.setReturnValue(result);
    }
}```
If server breaks faster than client, the client does the normal calculation and tells the server, hey i want to break the block now, while the server already permited it much earlier and responds to slower call. If client breaks faster than server, it results it in "laggy" interaction where the block reappears and then trully breaks. If both are in sync, the speed is just modified.