All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.magistuarmory.client.ClientHelper Maven / Gradle / Ivy

The newest version!
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.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;
		Entity cameraentity = mc.m_91288_();

		if (cameraentity != null)
		{
			result = cameraentity.m_19907_(reach, 0.0F, false);
			Vec3 eyepos = cameraentity.m_146892_();
			double d1 = reach;
			d1 *= d1;
			if (result != null)
				d1 = result.m_82450_().m_82557_(eyepos);
			Vec3 view = cameraentity.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 = cameraentity.m_142469_().m_82369_(view.m_82490_(reach)).m_82377_(1.0D, 1.0D, 1.0D);
			EntityHitResult entityhitresult = ProjectileUtil.m_37287_(cameraentity, 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;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy