Compare commits

...

2 Commits

Author SHA1 Message Date
rfresh2 b738c21bd6
Merge 15fdbb2312 into 62b2f81ba1 2024-04-08 03:53:10 +00:00
rfresh2 15fdbb2312
revert API renaming 2024-04-07 20:30:16 -07:00
6 changed files with 31 additions and 30 deletions

View File

@ -387,7 +387,7 @@ public final class Settings {
/**
* How many ticks between breaking a block and starting to break the next block. Default in game is 6 ticks.
* Values under 2 will be clamped.
* Values under 1 will be clamped. The delay only applies to non-instant (1-tick) breaks.
*/
public final Setting<Integer> blockBreakSpeed = new Setting<>(6);

View File

@ -37,7 +37,7 @@ public interface IPlayerController {
void syncHeldItem();
boolean isDestroyingBlock();
boolean hasBrokenBlock();
boolean onPlayerDamageBlock(BlockPos pos, Direction side);
@ -53,9 +53,7 @@ public interface IPlayerController {
boolean clickBlock(BlockPos loc, Direction face);
void setDestroyingBlock(boolean hittingBlock);
void setDestroyDelay(int destroyDelay);
void setHittingBlock(boolean hittingBlock);
default double getBlockReachDistance() {
return this.getGameType().isCreative() ? 5.0F : BaritoneAPI.getSettings().blockReachDistance.value;

View File

@ -29,11 +29,15 @@ public abstract class MixinPlayerController implements IPlayerControllerMP {
@Accessor("isDestroying")
@Override
public abstract void setIsDestroyingBlock(boolean isDestroyingBlock);
public abstract void setIsHittingBlock(boolean isHittingBlock);
@Accessor("isDestroying")
@Override
public abstract boolean isDestroyingBlock();
public abstract boolean isHittingBlock();
@Accessor("destroyBlockPos")
@Override
public abstract BlockPos getCurrentBlock();
@Invoker("ensureHasSentCarriedItem")
@Override

View File

@ -19,6 +19,7 @@ package baritone.utils;
import baritone.api.BaritoneAPI;
import baritone.api.utils.IPlayerContext;
import baritone.utils.accessor.IPlayerControllerMP;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
@ -32,7 +33,7 @@ public final class BlockBreakHelper {
private static final int BASE_BREAK_DELAY = 1;
private final IPlayerContext ctx;
private boolean wasDestroyingBlockLastTick;
private boolean wasHitting;
private int breakDelayTimer = 0;
BlockBreakHelper(IPlayerContext ctx) {
@ -41,10 +42,10 @@ public final class BlockBreakHelper {
public void stopBreakingBlock() {
// The player controller will never be null, but the player can be
if (ctx.player() != null && wasDestroyingBlockLastTick) {
ctx.playerController().setDestroyingBlock(false);
if (ctx.player() != null && wasHitting) {
ctx.playerController().setHittingBlock(false);
ctx.playerController().resetBlockRemoving();
wasDestroyingBlockLastTick = false;
wasHitting = false;
}
}
@ -57,8 +58,8 @@ public final class BlockBreakHelper {
boolean isBlockTrace = trace != null && trace.getType() == HitResult.Type.BLOCK;
if (isLeftClick && isBlockTrace) {
ctx.playerController().setDestroyingBlock(wasDestroyingBlockLastTick);
if (!ctx.playerController().isDestroyingBlock()) {
ctx.playerController().setHittingBlock(wasHitting);
if (ctx.playerController().hasBrokenBlock()) {
ctx.playerController().syncHeldItem();
ctx.playerController().clickBlock(((BlockHitResult) trace).getBlockPos(), ((BlockHitResult) trace).getDirection());
ctx.player().swing(InteractionHand.MAIN_HAND);
@ -66,21 +67,21 @@ public final class BlockBreakHelper {
if (ctx.playerController().onPlayerDamageBlock(((BlockHitResult) trace).getBlockPos(), ((BlockHitResult) trace).getDirection())) {
ctx.player().swing(InteractionHand.MAIN_HAND);
}
if (!ctx.playerController().isDestroyingBlock()) { // block broken this tick
if (ctx.playerController().hasBrokenBlock()) { // block broken this tick
// break delay timer only applies for multi-tick block breaks like vanilla
breakDelayTimer = BaritoneAPI.getSettings().blockBreakSpeed.value - BASE_BREAK_DELAY;
// must reset controller's destroy delay to prevent the client from delaying itself unnecessarily
ctx.playerController().setDestroyDelay(0);
((IPlayerControllerMP) ctx.minecraft().gameMode).setDestroyDelay(0);
}
}
// if true, we're breaking a block. if false, we broke the block this tick
wasDestroyingBlockLastTick = ctx.playerController().isDestroyingBlock();
wasHitting = !ctx.playerController().hasBrokenBlock();
// this value will be reset by the MC client handling mouse keys
// since we're not spoofing the click keybind to the client, the client will stop the break if isDestroyingBlock is true
// we store and restore this value on the next tick to determine if we're breaking a block
ctx.playerController().setDestroyingBlock(false);
ctx.playerController().setHittingBlock(false);
} else {
wasDestroyingBlockLastTick = false;
wasHitting = false;
}
}
}

View File

@ -17,11 +17,15 @@
package baritone.utils.accessor;
import net.minecraft.core.BlockPos;
public interface IPlayerControllerMP {
void setIsDestroyingBlock(boolean isDestroyingBlock);
void setIsHittingBlock(boolean isHittingBlock);
boolean isDestroyingBlock();
boolean isHittingBlock();
BlockPos getCurrentBlock();
void callSyncCurrentPlayItem();

View File

@ -20,7 +20,6 @@ package baritone.utils.player;
import baritone.api.utils.IPlayerController;
import baritone.utils.accessor.IPlayerControllerMP;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
@ -53,13 +52,8 @@ public final class BaritonePlayerController implements IPlayerController {
}
@Override
public boolean isDestroyingBlock() {
return ((IPlayerControllerMP) mc.gameMode).isDestroyingBlock();
}
@Override
public void setDestroyDelay(int destroyDelay) {
((IPlayerControllerMP) mc.gameMode).setDestroyDelay(destroyDelay);
public boolean hasBrokenBlock() {
return !((IPlayerControllerMP) mc.gameMode).isHittingBlock();
}
@Override
@ -99,7 +93,7 @@ public final class BaritonePlayerController implements IPlayerController {
}
@Override
public void setDestroyingBlock(boolean destroyingBlock) {
((IPlayerControllerMP) mc.gameMode).setIsDestroyingBlock(destroyingBlock);
public void setHittingBlock(boolean hittingBlock) {
((IPlayerControllerMP) mc.gameMode).setIsHittingBlock(hittingBlock);
}
}