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 47b1d048f..399763223 100644 --- a/src/main/scala/li/cil/oc/server/component/MotionSensor.scala +++ b/src/main/scala/li/cil/oc/server/component/MotionSensor.scala @@ -102,18 +102,15 @@ class MotionSensor(val host: EnvironmentHost) extends prefab.AbstractManagedEnvi // 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 && */ { - var ox = x + 0.5 - var oy = y + 0.5 - var oz = z + 0.5 + var origin = new Vec3d(x, y, z) val target = new Vec3d(entity.posX, entity.posY, entity.posZ) - // Start trace outside of this block. - if (entity.posX < x) ox -= 0.75 - if (entity.posX > x + 1) ox += 0.75 - if (entity.posY < y) oy -= 0.75 - if (entity.posY > y + 1) oy += 0.75 - if (entity.posZ < z) oz -= 0.75 - if (entity.posZ > z + 1) oz += 0.75 - world.rayTraceBlocks(new Vec3d(ox, oy, oz), target) == null + 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 } private def sendSignal(entity: EntityLivingBase) {