Skip to content

Commit

Permalink
jump time and shield fix
Browse files Browse the repository at this point in the history
  • Loading branch information
breelock committed Aug 28, 2024
1 parent 6dad809 commit 2c127b9
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ I (mod author) do not take any responsibility for your banned accounts on public
- [GitHub Releases](https://github.com/breelock/autoclicky/releases)
- [CurseForge](https://www.curseforge.com/minecraft/mc-mods/autoclicky)
- [Modrinth](https://modrinth.com/mod/autoclicky)
- [Minecraft Inside](https://minecraft-inside.ru/mods/178960-autoclicky.html)

## Dependencies
- [Fabric API](https://www.curseforge.com/minecraft/mc-mods/fabric-api)
63 changes: 51 additions & 12 deletions src/main/java/com/breelock/autoclicky/PlayerMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,60 @@
import net.minecraft.block.Blocks;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.Entity;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.AxeItem;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.tag.FluidTags;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;

public class PlayerMethods {
public static void attack(MinecraftClient client, boolean isNewPvP) {
if (client.player != null && client.crosshairTarget != null && !client.player.isSpectator() && client.interactionManager != null && client.world != null) {
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;

float jumpCooldown = 400f;
float cooldownTime = getAttackSpeedInTicks(client.player) * 50;
float attackCooldown = getAttackCooldownInTicks(client.player) * 50;

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 (interrupt(client, true)) return;
PlayerMethods.attackEntity(client);
if (!targetIsProtectedByShield(client, ((EntityHitResult) client.crosshairTarget).getEntity())) {
if (attackCooldown >= cooldownTime - jumpCooldown && ModConfig.NewPvP.autoJump && client.player.isOnGround() && !client.player.isTouchingWater() && !isInLava)
client.player.jump();

if (attackCooldown >= cooldownTime) {
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);
}
}
}
}
}
else {
if (client.crosshairTarget.getType() == HitResult.Type.ENTITY && client.player.getAttackCooldownProgress(0.0F) >= 0.7F && ModConfig.NewPvP.autoJump && client.player.isOnGround() && !client.player.isTouchingWater() && !isInLava)
client.player.jump();
if (client.crosshairTarget.getType() == HitResult.Type.ENTITY && attackCooldown >= cooldownTime - jumpCooldown && ModConfig.NewPvP.autoJump && client.player.isOnGround() && !client.player.isTouchingWater() && !isInLava) {
if (!targetIsProtectedByShield(client, ((EntityHitResult) client.crosshairTarget).getEntity()))
client.player.jump();
}

if (client.player.getAttackCooldownProgress(0.0F) >= 1.0F) {
if (attackCooldown >= cooldownTime) {
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);
if (!targetIsProtectedByShield(client, ((EntityHitResult) client.crosshairTarget).getEntity())) {
if (!isOnGround && client.player.getVelocity().y < -0.1 || client.player.isOnGround() || client.player.abilities.flying || client.player.isTouchingWater() || isInLava)
PlayerMethods.attackEntity(client);
}
}
else if (client.crosshairTarget.getType() == HitResult.Type.BLOCK)
PlayerMethods.breakBlock(client);
Expand Down Expand Up @@ -122,6 +137,30 @@ private static void attackEntity(MinecraftClient client) {
}
}

private static boolean targetIsProtectedByShield(MinecraftClient client, Entity targetEntity) {
if (client.player != null) {
if (targetEntity instanceof PlayerEntity) {
PlayerEntity targetPlayer = (PlayerEntity) targetEntity;
ItemStack heldItem = client.player.getMainHandStack();
if (heldItem.getItem() instanceof AxeItem)
return false;

return targetPlayer.isUsingItem() && targetPlayer.getActiveItem().getItem() == Items.SHIELD;
}
}
return false;
}

private static int getAttackCooldownInTicks(PlayerEntity player) {
float cooldown = player.getAttackCooldownProgress(0.0f);
return MathHelper.ceil(cooldown * getAttackSpeedInTicks(player));
}

private static float getAttackSpeedInTicks(PlayerEntity player) {
float attackSpeed = (float) player.getAttributeValue(EntityAttributes.GENERIC_ATTACK_SPEED);
return (1.0f / attackSpeed) * 20.0f;
}

private static void breakBlock(MinecraftClient client) {
if (client != null && client.interactionManager != null && client.player != null && client.world != null) {
BlockHitResult blockHitResult = (BlockHitResult) client.crosshairTarget;
Expand Down

0 comments on commit 2c127b9

Please sign in to comment.