MarbleGate
我需要解决这样一个问题:判定在某个坐标位置,能否直接看到看到某个Entity。不用考虑透明方块或者非标准模型的问题。
目前能想到的笨办法:手动算两个坐标之间的所有整数坐标的集合,然后遍历check一次。是否有更高效或者Forge提供的方法?

LoserXM
发射一个无惯性的/超高速投掷物,看是否返回伤害

MarbleGate
本帖最后由 MarbleGate 于 2020-12-10 17:35 编辑
LoserXM 发表于 2020-12-10 14:33
发射一个无惯性的/超高速投掷物,看是否返回伤害


Negative 很有创意的想法,但不现实...
因为我要做的就是判断是否能看到,然后再造成伤害。

594524502
public static boolean canLook(Entity e1, Entity e2) {
    Vector3d vector3d1 = e1.getLook(1).scale(128);
    RayTraceResult raytraceresult1 = e1.world.rayTraceBlocks(new RayTraceContext(e1.getEyePosition(0), e2.getPositionVec(), RayTraceContext.BlockMode.COLLIDER, RayTraceContext.FluidMode.NONE, e1));
    RayTraceResult raytraceresult2 = e1.world.rayTraceBlocks(new RayTraceContext(e1.getEyePosition(0), e2.getPositionVec().add(0, 1, 0), RayTraceContext.BlockMode.COLLIDER, RayTraceContext.FluidMode.NONE, e1));
    if (raytraceresult1.getType() != RayTraceResult.Type.MISS && raytraceresult2.getType() != RayTraceResult.Type.MISS) {
        return false;
    }
    AxisAlignedBB axisalignedbb = e1.getBoundingBox().expand(vector3d1).grow(3.0D);
    Predicate<Entity> predicate = (entity) -> !entity.isSpectator() && entity.canBeCollidedWith();
    EntityRayTraceResult entityHitResult = ProjectileHelper.rayTraceEntities(e1.world, e1, vector3d1, e2.getPositionVec(), axisalignedbb, predicate);
    return entityHitResult != null && entityHitResult.getEntity() == e2;
}

MarbleGate
594524502 发表于 2020-12-11 20:51
public static boolean canLook(Entity e1, Entity e2) {
    Vector3d vector3d1 = e1.getLook(1).scale(1 ...

非常有意思的思路...但如果我这里不打算再额外在TileEntity的位置创建一个entity, 那我没法用这个办法。
并且这个办法,我记得Predicate里面有一个什么什么Sight可以代表是否能看到来着....

第一页 上一页 下一页 最后一页