use of net.minecraft.util.math.EntityRayTraceResult in project Overloaded by CJ-MC-Mods.
the class ItemRailGun method use.
@Override
@Nonnull
@OnlyIn(Dist.CLIENT)
public ActionResult<ItemStack> use(World worldIn, @Nonnull PlayerEntity playerIn, @Nonnull Hand handIn) {
if (worldIn.isClientSide) {
int distance = OverloadedConfig.INSTANCE.railGun.maxRange;
Vector3d vec3d = playerIn.getEyePosition(Minecraft.getInstance().getFrameTime());
Vector3d vec3d1 = playerIn.getViewVector(Minecraft.getInstance().getFrameTime());
Vector3d vec3d2 = vec3d.add(vec3d1.x * distance, vec3d1.y * distance, vec3d1.z * distance);
float f = 1.0F;
AxisAlignedBB axisalignedbb = playerIn.getBoundingBox().expandTowards(vec3d1.scale(distance)).inflate(1.0D, 1.0D, 1.0D);
EntityRayTraceResult ray = ProjectileHelper.getEntityHitResult(playerIn, vec3d, vec3d2, axisalignedbb, (p_215312_0_) -> !p_215312_0_.isSpectator() && p_215312_0_.isPickable(), distance * distance);
if (ray != null) {
Vector3d moveVev = playerIn.getEyePosition(1).subtract(ray.getLocation()).normalize().scale(-1.0);
Overloaded.proxy.networkWrapper.sendToServer(new RailGunFireMessage(ray.getEntity().getId(), moveVev, handIn));
} else {
Overloaded.proxy.networkWrapper.sendToServer(new RailGunFireMessage(0, Vector3d.ZERO, handIn));
}
}
return new ActionResult<>(ActionResultType.SUCCESS, playerIn.getItemInHand(handIn));
}
Aggregations