com.magistuarmory.client.ClientHelper Maven / Gradle / Ivy
package com.magistuarmory.client;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.ProjectileUtil;
import net.minecraft.world.phys.*;
import java.util.Objects;
@Environment(EnvType.CLIENT)
public class ClientHelper
{
public static HitResult getMouseOver(Minecraft mc, float reach)
{
HitResult result = null;
Player player = mc.f_91074_;
if (player != null)
{
result = player.m_19907_(reach, 0.0F, false);
Vec3 eyepos = player.m_146892_();
double d1 = result.m_82450_().m_82557_(eyepos);
Vec3 view = player.m_20252_(1.0F);
Vec3 attackvec = eyepos.m_82520_(view.f_82479_ * (double) reach, view.f_82480_ * (double) reach, view.f_82481_ * (double) reach);
AABB expBounds = player.m_20191_().m_82369_(view.m_82490_(reach)).m_82377_(1.0D, 1.0D, 1.0D);
EntityHitResult entityhitresult = ProjectileUtil.m_37287_(player, eyepos, attackvec, expBounds, entity -> (!entity.m_5833_() && entity.m_6087_()), d1);
result = Objects.requireNonNullElseGet(entityhitresult, () -> BlockHitResult.m_82426_(attackvec, Direction.m_122366_(view.f_82479_, view.f_82480_, view.f_82481_), new BlockPos((int) attackvec.f_82479_, (int) attackvec.f_82480_, (int) attackvec.f_82481_)));
}
return result;
}
}