<commit_before>package com.ptsmods.morecommands.mixin.client;

import com.ptsmods.morecommands.MoreCommands;
import com.ptsmods.morecommands.clientoption.ClientOptions;
import com.ptsmods.morecommands.commands.server.elevated.ReachCommand;
import com.ptsmods.morecommands.mixin.common.accessor.MixinEntityAccessor;
import dev.architectury.networking.NetworkManager;
import io.netty.buffer.Unpooled;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerInteractionManager;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.Identifier;
import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.hit.HitResult;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Objects;

@Mixin(GameRenderer.class)
public class MixinGameRenderer {
    private static final @Unique Identifier entityTargetPacketId = new Identifier("morecommands:entity_target_update");
    @Shadow @Final private MinecraftClient client;
    private @Unique Entity lastTargetedEntity = null;

    @ModifyVariable(at = @At(value = "STORE", ordinal = 0), method = "updateTargetedEntity(F)V")
    public double updateTargetedEntity_d(double d) {
        return ReachCommand.getReach(Objects.requireNonNull(client.player), false);
    }

    @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;raycast(DFZ)Lnet/minecraft/util/hit/HitResult;"), method = "updateTargetedEntity(F)V")
    public HitResult updateTargetedEntity_raycast(Entity entity, double reach, float tickDelta, boolean includeFluids) {
        return entity.raycast(reach, tickDelta, ClientOptions.Tweaks.targetFluids.getValue() || includeFluids);
    }

    @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;hasExtendedReach()Z"), method = "updateTargetedEntity(F)V")
    public boolean updateTargetedEntity_hasExtendedReach(ClientPlayerInteractionManager interactionManager) {
        return false;
    }

    @ModifyVariable(at = @At(value = "STORE", ordinal = 1), method = "updateTargetedEntity(F)V")
    public boolean updateTargetedEntity_bl(boolean bl) {
        return false;
    }

    @Inject(at = @At("RETURN"), method = "updateTargetedEntity")
    public void updateTargetedEntity(float tickDelta, CallbackInfo cbi) {
        if (!NetworkManager.canServerReceive(entityTargetPacketId)) return;

        // If there's an entity the player is targeting within reach, use that. Otherwise, check if there is one within 160 blocks of reach.
        HitResult hit = client.targetedEntity == null ? MoreCommands.getRayTraceTarget(client.player, 160, false, true) : null;
        Entity target = client.targetedEntity == null ? hit.getType() == HitResult.Type.ENTITY ? ((EntityHitResult) hit).getEntity() : null : client.targetedEntity;

        if (target == lastTargetedEntity) return;
<commit_msg>Just leave it at the client targeted entity<commit_after>package com.ptsmods.morecommands.mixin.client;

import com.ptsmods.morecommands.clientoption.ClientOptions;
import com.ptsmods.morecommands.commands.server.elevated.ReachCommand;
import com.ptsmods.morecommands.mixin.common.accessor.MixinEntityAccessor;
import dev.architectury.networking.NetworkManager;
import io.netty.buffer.Unpooled;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerInteractionManager;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.Identifier;
import net.minecraft.util.hit.HitResult;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Objects;

@Mixin(GameRenderer.class)
public class MixinGameRenderer {
    private static final @Unique Identifier entityTargetPacketId = new Identifier("morecommands:entity_target_update");
    @Shadow @Final private MinecraftClient client;
    private @Unique Entity lastTargetedEntity = null;

    @ModifyVariable(at = @At(value = "STORE", ordinal = 0), method = "updateTargetedEntity(F)V")
    public double updateTargetedEntity_d(double d) {
        return ReachCommand.getReach(Objects.requireNonNull(client.player), false);
    }

    @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;raycast(DFZ)Lnet/minecraft/util/hit/HitResult;"), method = "updateTargetedEntity(F)V")
    public HitResult updateTargetedEntity_raycast(Entity entity, double reach, float tickDelta, boolean includeFluids) {
        return entity.raycast(reach, tickDelta, ClientOptions.Tweaks.targetFluids.getValue() || includeFluids);
    }

    @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;hasExtendedReach()Z"), method = "updateTargetedEntity(F)V")
    public boolean updateTargetedEntity_hasExtendedReach(ClientPlayerInteractionManager interactionManager) {
        return false;
    }

    @ModifyVariable(at = @At(value = "STORE", ordinal = 1), method = "updateTargetedEntity(F)V")
    public boolean updateTargetedEntity_bl(boolean bl) {
        return false;
    }

    @Inject(at = @At("RETURN"), method = "updateTargetedEntity")
    public void updateTargetedEntity(float tickDelta, CallbackInfo cbi) {
        if (!NetworkManager.canServerReceive(entityTargetPacketId) || client.targetedEntity == lastTargetedEntity) return;

{'fraction_non_alphanumeric': 0.10569882203120025, 'fraction_numerical': 0.001591849729385546, 'mean_word_length': 5.698294243070363, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5531027', 'n_tokens_mistral': 1902, 'n_tokens_neox': 1859, 'n_words': 345}