Skip to content

Commit 0e908db

Browse files
committed
Address Codacy feedback
1 parent 5a48840 commit 0e908db

4 files changed

Lines changed: 51 additions & 11 deletions

File tree

src/api/java/baritone/api/utils/IInputOverrideHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ default boolean isBreakingBlock(BlockPos pos) {
3939
}
4040

4141
default void setBlockBreakTarget(BlockPos pos) {
42+
// Optional hook for handlers that support targeted block breaking.
4243
}
4344

4445
default void setBlockPlaceTarget(BlockPos pos, Direction side) {
46+
// Optional hook for handlers that support targeted block placing.
4547
}
4648
}

src/launch/java/baritone/launch/mixins/MixinClientPlayerEntity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ private void onPreUpdate(CallbackInfo ci) {
6262
at = @At("HEAD"),
6363
cancellable = true
6464
)
65+
@SuppressWarnings({"unused", "PMD.UnusedPrivateMethod"})
6566
private void getViewYRot(float partialTicks, CallbackInfoReturnable<Float> cir) {
6667
Rotation visualRotation = this.getVisualRotation(partialTicks);
6768
if (visualRotation != null) {
@@ -74,6 +75,7 @@ private void getViewYRot(float partialTicks, CallbackInfoReturnable<Float> cir)
7475
at = @At("HEAD"),
7576
cancellable = true
7677
)
78+
@SuppressWarnings({"unused", "PMD.UnusedPrivateMethod"})
7779
private void getViewXRot(float partialTicks, CallbackInfoReturnable<Float> cir) {
7880
Rotation visualRotation = this.getVisualRotation(partialTicks);
7981
if (visualRotation != null) {

src/main/java/baritone/behavior/LookBehavior.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ private void updateInterpolation(
250250
boolean restartArc,
251251
Target.Mode mode) {
252252
final int interpolationSpeed = Baritone.settings().interpolatedLookLength.value;
253+
Rotation arcStart = start;
253254

254255
if (this.interpolationArc != null && this.interpolationMode != mode) {
255256
this.interpolationArc = null;
@@ -259,12 +260,15 @@ private void updateInterpolation(
259260

260261
if (this.interpolationArc != null
261262
&& (restartArc || this.interpolationOriginMoved(origin))) {
262-
start = this.interpolationArc.getCurrentRotation();
263+
arcStart = this.interpolationArc.getCurrentRotation();
263264
this.interpolationArc = null;
264265
}
265266

266267
if (this.interpolationArc == null) {
267-
this.interpolationArc = RotationArc.fromAngularSpeed(start, actual, interpolationSpeed);
268+
this.interpolationArc = RotationArc.fromAngularSpeed(
269+
arcStart,
270+
actual,
271+
interpolationSpeed);
268272
this.interpolationMode = mode;
269273
this.interpolationOrigin = origin;
270274
}

src/main/java/baritone/utils/BlockPlaceHelper.java

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,55 @@ public class BlockPlaceHelper {
3838
}
3939

4040
public void tick(boolean rightClickRequested, BlockPos target, Direction side) {
41+
if (this.isCoolingDown()) {
42+
return;
43+
}
44+
45+
BlockHitResult blockHit = this.targetedBlockHit(rightClickRequested, target, side);
46+
if (blockHit == null) {
47+
return;
48+
}
49+
50+
rightClickTimer = Baritone.settings().rightClickSpeed.value - BASE_PLACE_DELAY;
51+
this.tryRightClick(blockHit);
52+
}
53+
54+
private boolean isCoolingDown() {
4155
if (rightClickTimer > 0) {
4256
rightClickTimer--;
43-
return;
57+
return true;
4458
}
59+
return false;
60+
}
61+
62+
private BlockHitResult targetedBlockHit(
63+
boolean rightClickRequested,
64+
BlockPos target,
65+
Direction side) {
66+
if (!rightClickRequested || ctx.player().isHandsBusy()) {
67+
return null;
68+
}
69+
4570
HitResult mouseOver = ctx.objectMouseOver();
46-
if (!rightClickRequested
47-
|| ctx.player().isHandsBusy()
48-
|| mouseOver == null
71+
if (mouseOver == null
4972
|| mouseOver.getType() != HitResult.Type.BLOCK) {
50-
return;
73+
return null;
5174
}
75+
5276
BlockHitResult blockHit = (BlockHitResult) mouseOver;
53-
if (target != null
54-
&& (!blockHit.getBlockPos().equals(target) || blockHit.getDirection() != side)) {
55-
return;
77+
if (!this.matchesTarget(blockHit, target, side)) {
78+
return null;
5679
}
57-
rightClickTimer = Baritone.settings().rightClickSpeed.value - BASE_PLACE_DELAY;
80+
81+
return blockHit;
82+
}
83+
84+
private boolean matchesTarget(BlockHitResult blockHit, BlockPos target, Direction side) {
85+
return target == null
86+
|| (blockHit.getBlockPos().equals(target) && blockHit.getDirection() == side);
87+
}
88+
89+
private void tryRightClick(BlockHitResult blockHit) {
5890
for (InteractionHand hand : InteractionHand.values()) {
5991
if (ctx.playerController().processRightClickBlock(
6092
ctx.player(),

0 commit comments

Comments
 (0)