Skip to content

Commit

Permalink
Beta 22
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandra-Myers committed Aug 31, 2023
1 parent 3e7320e commit b7ab734
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 39 deletions.
6 changes: 1 addition & 5 deletions src/main/java/net/atlas/combatify/mixin/GuiMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 0 additions & 22 deletions src/main/java/net/atlas/combatify/mixin/MinecraftMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -73,9 +68,6 @@ public abstract class MinecraftMixin implements IMinecraft {
@Shadow
public int missTime;

@Unique
Entity lastPickedEntity = null;

@Shadow
@Nullable
public Screen screen;
Expand All @@ -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;
}
Expand Down Expand Up @@ -163,17 +152,6 @@ public boolean redirectAttack(Minecraft instance) {
private void startAttack(CallbackInfoReturnable<Boolean> 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) {
Expand Down
25 changes: 17 additions & 8 deletions src/main/java/net/atlas/combatify/mixin/ServerPlayerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<HitResult> oldHitResults = new ArrayList<>();
public Map<HitResult, Float[]> hitResultToRotationMap = new HashMap<>();
public ArrayList<Integer> pastPings = new ArrayList<>();
public boolean awaitingResponse = false;
public int responseTimer = 0;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.*;

Expand Down Expand Up @@ -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())) {
Expand Down

0 comments on commit b7ab734

Please sign in to comment.