diff --git a/src/main/java/net/atlas/combatify/mixin/GuiMixin.java b/src/main/java/net/atlas/combatify/mixin/GuiMixin.java index 041f9301..c6a7e541 100644 --- a/src/main/java/net/atlas/combatify/mixin/GuiMixin.java +++ b/src/main/java/net/atlas/combatify/mixin/GuiMixin.java @@ -86,11 +86,7 @@ public void renderCrosshair1(GuiGraphics guiGraphics, CallbackInfo ci) { EntityHitResult hitResult = minecraft.hitResult instanceof EntityHitResult ? (EntityHitResult) minecraft.hitResult : null; minecraft.crosshairPickEntity = hitResult != null ? hitResult.getEntity() : minecraft.crosshairPickEntity; if (this.minecraft.crosshairPickEntity != null && this.minecraft.crosshairPickEntity instanceof LivingEntity && f >= maxIndicator) { - Vec3 vec3 = minecraft.player.getEyePosition(0.0F); - Vec3 vec31 = ((AABBExtensions)this.minecraft.crosshairPickEntity.getBoundingBox()).getNearestPointTo(vec3); - double dist = vec3.distanceTo(vec31); - bl = dist <= ((PlayerExtensions)minecraft.player).getAttackRange(0.0F); - bl &= this.minecraft.crosshairPickEntity.isAlive(); + bl = this.minecraft.crosshairPickEntity.isAlive(); } if (bl) { guiGraphics.blit(GUI_ICONS_LOCATION, k, j, 68, 94, 16, 16); diff --git a/src/main/java/net/atlas/combatify/mixin/MinecraftMixin.java b/src/main/java/net/atlas/combatify/mixin/MinecraftMixin.java index fb1dd91a..649c8bd4 100644 --- a/src/main/java/net/atlas/combatify/mixin/MinecraftMixin.java +++ b/src/main/java/net/atlas/combatify/mixin/MinecraftMixin.java @@ -17,11 +17,6 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntitySelector; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.ambient.Bat; -import net.minecraft.world.entity.animal.*; -import net.minecraft.world.entity.animal.frog.Frog; -import net.minecraft.world.entity.monster.Guardian; -import net.minecraft.world.entity.monster.Vex; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.projectile.ProjectileUtil; import net.minecraft.world.item.Item; @@ -73,9 +68,6 @@ public abstract class MinecraftMixin implements IMinecraft { @Shadow public int missTime; - @Unique - Entity lastPickedEntity = null; - @Shadow @Nullable public Screen screen; @@ -90,9 +82,6 @@ public abstract class MinecraftMixin implements IMinecraft { @Inject(method = "tick", at = @At(value = "TAIL")) public void injectSomething(CallbackInfo ci) { assert player != null; - if(crosshairPickEntity != null && hitResult != null && (this.hitResult).distanceTo(this.crosshairPickEntity) <= ((PlayerExtensions)player).getAttackRange(0.0F)) { - lastPickedEntity = crosshairPickEntity; - } if (screen != null) { this.retainAttack = false; } @@ -163,17 +152,6 @@ public boolean redirectAttack(Minecraft instance) { private void startAttack(CallbackInfoReturnable cir) { this.retainAttack = false; } - @Redirect(method = "startAttack", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/MultiPlayerGameMode;attack(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/entity/Entity;)V")) - public void redirectAttack(MultiPlayerGameMode instance, Player player, Entity entity) { - Vec3 vec3 = player.getEyePosition(0.0F); - Vec3 vec31 = ((AABBExtensions)entity.getBoundingBox()).getNearestPointTo(vec3); - double dist = vec3.distanceTo(vec31); - if (dist <= ((PlayerExtensions)player).getAttackRange(0.0F)) { - instance.attack(player, entity); - } else { - ((IPlayerGameMode)instance).swingInAir(player); - } - } @SuppressWarnings("unused") @ModifyExpressionValue(method = "startAttack", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/MultiPlayerGameMode;hasMissTime()Z")) public boolean removeMissTime(boolean original) { diff --git a/src/main/java/net/atlas/combatify/mixin/ServerPlayerMixin.java b/src/main/java/net/atlas/combatify/mixin/ServerPlayerMixin.java index ede77dbf..040d5fee 100644 --- a/src/main/java/net/atlas/combatify/mixin/ServerPlayerMixin.java +++ b/src/main/java/net/atlas/combatify/mixin/ServerPlayerMixin.java @@ -32,9 +32,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import java.util.ArrayList; -import java.util.Collections; -import java.util.TimerTask; +import java.util.*; import static net.atlas.combatify.Combatify.scheduleHitResult; @@ -48,13 +46,10 @@ public abstract class ServerPlayerMixin extends PlayerMixin implements ServerPla @Shadow public abstract void swing(InteractionHand interactionHand); - - @Shadow - @Final - private static Logger LOGGER; @Shadow public ServerGamePacketListenerImpl connection; public ArrayList oldHitResults = new ArrayList<>(); + public Map hitResultToRotationMap = new HashMap<>(); public ArrayList pastPings = new ArrayList<>(); public boolean awaitingResponse = false; public int responseTimer = 0; @@ -115,6 +110,17 @@ public void removeReset(InteractionHand hand, CallbackInfo ci) { for (HitResult hitResultToChoose : oldHitResults) { if(hitResultToChoose == null) continue; + Float[] rotations = null; + if (hitResultToRotationMap.containsKey(hitResultToChoose)) + rotations = hitResultToRotationMap.get(hitResultToChoose); + float xRot = getXRot() % 360; + float yRot = getYHeadRot() % 360; + if(rotations != null) { + float xDiff = Math.abs(xRot - rotations[1]); + float yDiff = Math.abs(yRot - rotations[0]); + if(xDiff > 20 || yDiff > 20) + continue; + } if (hitResultToChoose.getType() == HitResult.Type.ENTITY) { hitResult = hitResultToChoose; break; @@ -293,7 +299,10 @@ public void adjustHitResults(HitResult newValue) { else oldHitResults.add(newValue); oldHitResults.removeIf(hitResult -> oldHitResults.indexOf(hitResult) > currentAveragePing + 1); - LOGGER.info("Adjusted results"); + Float[] rotations = new Float[2]; + rotations[0] = getYHeadRot() % 360; + rotations[1] = getXRot() % 360; + hitResultToRotationMap.put(newValue, rotations); } @Override diff --git a/src/main/java/net/atlas/combatify/networking/NetworkingHandler.java b/src/main/java/net/atlas/combatify/networking/NetworkingHandler.java index da18f9bb..d2d44084 100644 --- a/src/main/java/net/atlas/combatify/networking/NetworkingHandler.java +++ b/src/main/java/net/atlas/combatify/networking/NetworkingHandler.java @@ -1,18 +1,15 @@ package net.atlas.combatify.networking; +import com.mojang.logging.LogUtils; import net.atlas.combatify.Combatify; -import net.atlas.combatify.extensions.ServerPlayerExtensions; import net.fabricmc.fabric.api.event.player.*; import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.minecraft.network.chat.Component; -import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResultHolder; -import net.minecraft.world.entity.Entity; import java.util.Timer; -import java.util.TimerTask; import static net.atlas.combatify.Combatify.*; @@ -40,6 +37,7 @@ public NetworkingHandler() { Combatify.isPlayerAttacking.put(handler.player.getUUID(), true); Combatify.finalizingAttack.put(handler.player.getUUID(), true); scheduleHitResult.put(handler.player.getUUID(), new Timer()); + LogUtils.getLogger().info("Unmodded player joined: " + handler.player.getUUID()); return; } if (unmoddedPlayers.contains(handler.player.getUUID())) {