From 7933f5d7b45a174609d485040146be2854522fcd Mon Sep 17 00:00:00 2001 From: payonel Date: Sun, 10 Dec 2017 03:37:38 -0800 Subject: [PATCH] fix motion sensor line of site a new solution to use a normalized path vector and move the origin directly towards the player by .75m closes #2615 --- .../cil/oc/server/component/MotionSensor.scala | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/scala/li/cil/oc/server/component/MotionSensor.scala b/src/main/scala/li/cil/oc/server/component/MotionSensor.scala index 9432a00b4..9016b22a3 100644 --- a/src/main/scala/li/cil/oc/server/component/MotionSensor.scala +++ b/src/main/scala/li/cil/oc/server/component/MotionSensor.scala @@ -97,21 +97,20 @@ class MotionSensor(val host: EnvironmentHost) extends prefab.ManagedEnvironment private def isInRange(entity: EntityLivingBase) = entity.getDistanceSq(x + 0.5, y + 0.5, z + 0.5) <= radius * radius - private def isVisible(entity: EntityLivingBase) = + private def isVisible(entity: EntityLivingBase): Boolean = entity.getActivePotionEffect(Potion.invisibility) == null && // Note: it only working in lit conditions works and is neat, but this // is pseudo-infrared driven (it only works for *living* entities, after // all), so I think it makes more sense for it to work in the dark, too. /* entity.getBrightness(0) > 0.2 && */ { - val origin = Vec3.createVectorHelper(x + 0.5, y + 0.5, z + 0.5) + var origin = Vec3.createVectorHelper(x, y, z) val target = Vec3.createVectorHelper(entity.posX, entity.posY, entity.posZ) - // Start trace outside of this block. - if (entity.posX < x) origin.xCoord -= 0.75 - if (entity.posX > x + 1) origin.xCoord += 0.75 - if (entity.posY < y) origin.yCoord -= 0.75 - if (entity.posY > y + 1) origin.yCoord += 0.75 - if (entity.posZ < z) origin.zCoord -= 0.75 - if (entity.posZ > z + 1) origin.zCoord += 0.75 + val path = origin.subtract(target).normalize() + origin = origin.addVector( + path.xCoord * 0.75, + path.yCoord * 0.75, + path.zCoord * 0.75 + ) world.rayTraceBlocks(origin, target) == null }