Jump to content

Forge1.18.1 how to raycast?


volkov

Recommended Posts

5 hours ago, Luis_ST said:

re you exactly talking about

ammm a ray casting like when you send a ray from one dot in direction of another

in my case cast a ray from player's head in direction of players view ,sorry for confusion

Link to comment
Share on other sites

thanks b.t.w. dose anybody know how to detect entity that collides with ray

public static BlockHitResult getTargetofgun(Level pLevel, Player pPlayer, ClipContext.Fluid pFluidMode,double reach/*reach*/) {
        float f = pPlayer.getXRot();
        float f1 = pPlayer.getYRot();
        Vec3 vec3 = pPlayer.getEyePosition();
        float f2 = Mth.cos(-f1 * ((float)Math.PI / 180F) - (float)Math.PI);
        float f3 = Mth.sin(-f1 * ((float)Math.PI / 180F) - (float)Math.PI);
        float f4 = -Mth.cos(-f * ((float)Math.PI / 180F));
        float f5 = Mth.sin(-f * ((float)Math.PI / 180F));
        float f6 = f3 * f4;
        float f7 = f2 * f4;
        Vec3 vec31 = vec3.add((double)f6 * reach, (double)f5 * reach, (double)f7 * reach);
        return pLevel.clip(new ClipContext(vec3, vec31, ClipContext.Block.OUTLINE, pFluidMode, pPlayer));
    }

is there a function like clip() that detects LivingEntity instead of block

Link to comment
Share on other sites

33 minutes ago, MFMods said:

that sounds a lot like looking at enderman to piss if off. look at vanilla code.

im looked if im not mistaken you are talking about function isLookingAtMe()?

boolean isLookingAtMe(Player pPlayer) {
      ItemStack itemstack = pPlayer.getInventory().armor.get(3);
      if (itemstack.isEnderMask(pPlayer, this)) {
         return false;
      } else {
         Vec3 vec3 = pPlayer.getViewVector(1.0F).normalize();
         Vec3 vec31 = new Vec3(this.getX() - pPlayer.getX(), this.getEyeY() - pPlayer.getEyeY(), this.getZ() - pPlayer.getZ());
         double d0 = vec31.length();
         vec31 = vec31.normalize();
         double d1 = vec3.dot(vec31);
         return d1 > 1.0D - 0.025D / d0 ? pPlayer.hasLineOfSight(this) : false;
      }
   }

 

Link to comment
Share on other sites

yes.

scalar product of two vectors is "length" (magnitude) of first one, multiplied by "length" (magnitude) of second one, multiplied by cosine of angle between them. in this case first two are equal to 1 and d1 is cosine of angle between players exact line of sight and the line between player and enderman. then you basically say "if angle is small enough (and has line of sight), return true".

Link to comment
Share on other sites

  • 3 weeks later...

sorry for stupid question that im about to ask but dose vectors need tow dots but vec3 constructor only requires 1 dot(set of coordinates) and is called vector ?

also it works thanks!

boolean islookinatit(Player player,LivingEntity entity) {
        Vec3 vec3 = player.getViewVector(1.0F).normalize();
        Vec3 vec31 = new Vec3(entity.getX() - player.getX(), entity.getY() - player.getEyeY(), entity.getZ() - player.getZ());
        double d0 = vec31.length();
        vec31 = vec31.normalize();
        double d1 = vec3.dot(vec31);
        return d1 > 1.0D - 0.025D / d0 && AtoElineOfSight(player, entity);
    }
    public boolean AtoElineOfSight(Entity Ea,Entity Eb) {
        if (Eb.level != Ea.level) {
            return false;
        } else {
            Vec3 Avec = new Vec3(Ea.getX(), Ea.getEyeY(), Ea.getZ());
            Vec3 Bvec = new Vec3(Eb.getX(), Eb.getY(), Eb.getZ());
            if (Bvec.distanceTo(Avec) > 128.0D) {
                return false;
            } else {
                return Ea.level.clip(new ClipContext(Avec, Bvec, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, Ea)).getType() == HitResult.Type.MISS;
            }
        }
    }

but seems like im understood that im need it to collide not just with position of entity but with its boundingbox or hitbox of entity sorry for putting question so badly and also sorry for such a long delay with answer

Link to comment
Share on other sites

2 hours ago, volkov said:

sorry for stupid question that im about to ask but dose vectors need tow dots but vec3 constructor only requires 1 dot(set of coordinates) and is called vector ?

it is just a name, there is no physical connection

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • 国内貸出業者▷BCGAME33·COM←ペルー貸出ポーカー大会国内コソボ貸出キャッシュゲーム[本社お問い合わせテレJBOX7]国内貸出▼◇接続サンマリノ貸出サイト国内モナコ国内貸出中継[総販お問い合わせカカオトークJBOX7]国内貸出♠♨戦略フォックスウッドカジノ貸出遊び場国内エチオピア国内貸し出しおすすめ[各種オフィコミュニティ制作]韓国貸し出し º クープーンエクアドル貸し出しサイト韓国ヘルツェゴビナ韓国貸し出し総販[マーケティングお問い合わせ]韓国貸し出し▲▷京畿ジャマイカ貸し出し映像 韓国内貸し出しサイト[カジノ本社]韓国内貸し出し↗↑ボリビアツアー映像 国内クラウンカジノ国内貸出サイト[ト本社お問い合わせ]国内貸出◀◁ゲームエストニア貸出業者国内ソロモン諸島国内貸出放送[トト総販購入]国内貸出&ºクープーントランプタジマハルカジノ貸出中継国内北キプロス国内貸出検証[カジノ総販]韓国内貸出↖ 홀ホールダンパブポーランド貸し出し募集 韓国西アフリカ国内貸し出しユーチューブ[ヤマト本社]韓国内貸し出し† 방송放送キプロス貸し出しゲーム場韓国内イラン国内貸し出しおすすめ[バカラ総販]韓国内貸し出し▽▥カジノパブアルバニア貸し出しサイト韓国内トルクメニスタンブローン
    • 按摩女孩总经销㏇BCGAME55·COM▣按摩女孩Instagram巴西柔术按摩女孩社区篮球按摩女孩Instagram游泳按摩女孩视频[本社咨询的Tele@JBOX7]按摩女孩总经销拳击按摩女孩度假村调整按摩女孩youtube诱导 按摩女郎业所招募[总经销的Kakao Talk JBOX7] 按摩女童 摔跤运动爱好者协会推特[推特] [赌场总公司] [CHUW BUW按摩女孩链接 滑雪 CHOW BUW按摩女孩 雅东 按摩女孩 巡回 曲棍球 按摩女孩 推荐 [体育总公司] CHOW BUW 按摩女孩 验证 乒乓球 按摩女孩 [购买 Telegram 铁饼 按摩女孩故事台球 按摩女孩位置[TOTO总部咨询] CHOW BUW 按摩女郎系统 GESTIVALKY MASOOO ONE Open聊天 Sky Mating Skey Matchange] 北欧按摩女孩登录[Bacara总经销] Chuubu按摩女孩度假村 Speed Chuubu按摩女孩社区摔跤按摩女孩视频拳击按摩女孩联谊会[赛马总经销] Chuubu按摩女孩场所 射箭 Chuubu按摩女孩旅行击剑击剑按摩女孩视频网球 按摩女郎招聘广告[BCGAME BC游戏总经销咨询] 设置通知 推荐 订阅 点赞
    • 海外大和トーナメント↘BCGAME33·COM♠ウクライナ大和戦略海外トルコ大和接続[本社お問い合わせテレJBOX7]海外大和▼↙本社フィリピン大和京畿海外コンゴ民主海外大和賭博場[総販お問い合わせカカオトークJBOX7]海外大和▷○募集北マケドニア大和接続海外リゾートワールドカジノ海外ヤマト放送[各種オフィコミュニティ制作] 海外ヤマト※ª クープーン台湾ヤマト検証 海外サモア 海外ヤマトホールダンパブ[マーケティングお問い合わせ] 海外ヤマト←◁映像ブックキプロスヤマト サイト 海外ヤマト 募集 §◎ 旅行南スーダン大和住所 海外イエメン海外ヤマトトーナメント [トト本社お問い合わせ] 海外ヤマト▨→方法 ベトナムヤマト検証 海外スリナム海外ヤマトバカラパブ [トト総販購入] 海外ヤマト▷◁リーグコソボヤマト募集 海外セネガル海外ヤマトホールダンパブ[カジノ総販] 海外ヤマト↔@中継 ヨーロッパ大和検証 海外ラオス海外大和中継[大和本社] 海外大和*◐ゲームセンターMGMカジノ大和クープーン海外ハイチ海外大和クープーン[バカラ総販]海外大和検証@オランダビデオ オランダ領馬海外ユブビア]
    • 关东俱乐部最新地址◀BCGAME55·COM▲关东俱乐部总经销网络游戏关东俱乐部网站壁球俱乐部推特赛艇比赛俱乐部新地址[本社文之电讯@JBOX7]关东俱乐部连接掰手腕俱乐部广播掷标枪俱乐部亚东花样游泳俱乐部队[总经销文之Kakao Talk JBOX7]关东俱乐部的系统掷铅球 关东俱乐部的位置足球俱乐部队优兔F1大奖赛[各种官方制作链接 制作 关东俱乐部的 短视频 度假村] 俱乐部招聘广告F1大奖赛俱乐部招聘广告[体育总公司]关东俱乐部视频Flag关东俱乐部位置掷标枪俱乐部Telegram游泳俱乐部YouTube[咨询]关东俱乐部最新地址棒球关东俱乐部旅行软网球俱乐部的总经销藤球俱乐部的推特[买关东总经销]关东俱乐部的位置网球俱乐部的网球拍打铁饼俱乐部的举办地功夫俱乐部的地址[赌场总经销]关东俱乐部的总经销诱导的Instagram跳水俱乐部的总经销网] Sparketarketakragram 棒球运动会的总经销社推特[买办地]关东总经销] 棒球比赛场  视频[赛马总经销]关东俱乐部最新地址篮球关东俱乐部网站铅球俱乐部链接拳击俱乐部视频[BCGAME BC游戏总经销咨询]设置通知推荐订阅点赞
    • How would I give an item (from my mod) lore? I overrode the appendHoverText method but I haven't been able to figure out how to add something to it.
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.