Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
breelock committed Aug 18, 2024
1 parent 34dca9f commit 600ab36
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
1 change: 0 additions & 1 deletion src/main/java/com/breelock/autoclicky/AutoClicky.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import net.minecraft.text.LiteralText;
import net.minecraft.text.TranslatableText;


import org.lwjgl.glfw.GLFW;

import org.apache.logging.log4j.LogManager;
Expand Down
31 changes: 22 additions & 9 deletions src/main/java/com/breelock/autoclicky/PlayerMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,17 @@ public static void attack(MinecraftClient client, boolean isNewPvP) {
boolean isInLava = client.world.getBlockState(new BlockPos(client.player.getX(), client.player.getY(), client.player.getZ())).getBlock() == Blocks.LAVA || client.player.isSubmergedIn(FluidTags.LAVA);
boolean isOnGround = client.player.isOnGround() && !client.player.isTouchingWater() && !isInLava;

if (client.player.isUsingItem()) {
if (isNewPvP && ModConfig.NewPvP.interrupt || !isNewPvP && ModConfig.OldPvP.interrupt)
client.interactionManager.stopUsingItem(client.player);
else
return;
}
if (isNewPvP) {
if (ModConfig.NewPvP.onlyEntity) {
if (client.crosshairTarget.getType() == HitResult.Type.ENTITY) {
if (client.player.getAttackCooldownProgress(0.0F) >= 0.7F && ModConfig.NewPvP.autoJump && client.player.isOnGround() && !client.player.isTouchingWater() && !isInLava)
client.player.jump();

if (client.player.getAttackCooldownProgress(0.0F) >= 1.0F) {
if (!isOnGround && client.player.getVelocity().y < -0.1 || client.player.isOnGround() || client.player.abilities.flying || client.player.isTouchingWater() || isInLava)
if (!isOnGround && client.player.getVelocity().y < -0.1 || client.player.isOnGround() || client.player.abilities.flying || client.player.isTouchingWater() || isInLava) {
if (interrupt(client, true)) return;
PlayerMethods.attackEntity(client);
}
}
}
}
Expand All @@ -41,6 +37,8 @@ public static void attack(MinecraftClient client, boolean isNewPvP) {
client.player.jump();

if (client.player.getAttackCooldownProgress(0.0F) >= 1.0F) {
if (interrupt(client, true)) return;

if (client.crosshairTarget.getType() == HitResult.Type.ENTITY) {
if (!isOnGround && client.player.getVelocity().y < -0.1 || client.player.isOnGround() || client.player.abilities.flying || client.player.isTouchingWater() || isInLava)
PlayerMethods.attackEntity(client);
Expand All @@ -55,14 +53,18 @@ else if (client.crosshairTarget.getType() == HitResult.Type.MISS) {
}
}
else {
if (client.crosshairTarget.getType() == HitResult.Type.ENTITY && ModConfig.NewPvP.autoJump && client.player.isOnGround() && !client.player.isTouchingWater() && !isInLava)
if (client.crosshairTarget.getType() == HitResult.Type.ENTITY && ModConfig.OldPvP.autoJump && client.player.isOnGround() && !client.player.isTouchingWater() && !isInLava)
client.player.jump();

if (ModConfig.OldPvP.onlyEntity) {
if (client.crosshairTarget.getType() == HitResult.Type.ENTITY)
if (client.crosshairTarget.getType() == HitResult.Type.ENTITY) {
if (interrupt(client, false)) return;
PlayerMethods.attackEntity(client);
}
}
else {
if (interrupt(client, false)) return;

if (client.crosshairTarget.getType() == HitResult.Type.ENTITY)
PlayerMethods.attackEntity(client);
else if (client.crosshairTarget.getType() == HitResult.Type.BLOCK)
Expand Down Expand Up @@ -93,6 +95,17 @@ else if (client.crosshairTarget.getType() == HitResult.Type.BLOCK) {
}
}

private static boolean interrupt(MinecraftClient client, boolean isNewPvP) {
if (client != null && client.player != null && client.interactionManager != null && client.player.isUsingItem()) {
if (isNewPvP && ModConfig.NewPvP.interrupt || !isNewPvP && ModConfig.OldPvP.interrupt)
client.interactionManager.stopUsingItem(client.player);
else
return true;
}

return false;
}

private static void resetAttackCooldown(MinecraftClient client) {
if (client.player != null) {
client.player.resetLastAttackedTicks();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/breelock/autoclicky/pages/NewCombat.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ protected void applyValue() {

// Exit without saving button
this.addButton(new ButtonWidget(centerX - buttonWidth - 5, startY + 5 * spacing, buttonWidth, 20, new LiteralText(new TranslatableText("gui.autoclicky.cancel").getString()), button -> {
this.client.openScreen(null); // Close the screen without saving
this.client.openScreen(null); // Close the screen
}));
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/breelock/autoclicky/pages/OldCombat.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected void applyValue() {

// Exit without saving button
this.addButton(new ButtonWidget(centerX - buttonWidth - 5, startY + 5 * spacing, buttonWidth, 20, new LiteralText(new TranslatableText("gui.autoclicky.cancel").getString()), button -> {
this.client.openScreen(null); // Close the screen without saving
this.client.openScreen(null); // Close the screen
}));
}

Expand Down

0 comments on commit 600ab36

Please sign in to comment.